react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Source map for the bundle is not generated correctly when fat arrow function is used

Open changsi-an opened this issue 10 years ago • 6 comments

Issue Description

Source map is not generated correctly when fat arrow function is used.

Steps to Reproduce / Code Snippets

Create a react native project

react-native init react_native_example2

Add a fat arrow function in the main component (** index.ios.js**).

1  /**
2   * Sample React Native App
3   * https://github.com/facebook/react-native
4   * @flow
5   */
6  
7  import React, { Component } from 'react';
8  import {
9    AppRegistry,
10    StyleSheet,
11    Text,
12    View
13  } from 'react-native';
14  
15  class react_native_example2 extends Component {
16  
17    op1() {
18      console.log("hi")
19    }
20  
21    op2 = () =>{
22      console.log("hi")
23    }
24  
25    render() {
26      return (
27        <View style={styles.container}>
28          <Text style={styles.welcome}>
29            Welcome to React Native!
30          </Text>
31          <Text style={styles.instructions} onPress={() => this.op1()}>
32            To get started, edit index.ios.js
33          </Text>
34          <Text style={styles.instructions} onPress={this.op2}>
35            Press Cmd+R to reload,{'\n'}
36            Cmd+D or shake for dev menu
37          </Text>
38        </View>
39      );
40    }
41  }
42  
43  const styles = StyleSheet.create({
44    container: {
45      flex: 1,
46      justifyContent: 'center',
47      alignItems: 'center',
48      backgroundColor: '#F5FCFF',
49    },
50    welcome: {
51      fontSize: 20,
52      textAlign: 'center',
53      margin: 10,
54    },
55    instructions: {
56      textAlign: 'center',
57      color: '#333333',
58      marginBottom: 5,
59    },
60  });
61  
62  AppRegistry.registerComponent('react_native_example2', () => react_native_example2);
63  

Run the app

react-native run-ios

Pull down the bundle and the source map

curl "http://localhost:8081/index.ios.bundle" -o index.ios.bundle
curl "http://localhost:8081/index.ios.map" -o index.ios.map

Those two files are attached. Archive.zip

Then use the following script to inspect the source map:

var fs = require('fs');
var sm = require('source-map');

var sourceMap = './index.ios.map';
var smap = JSON.parse(fs.readFileSync(sourceMap));

var sourceMapConsumer = new sm.SourceMapConsumer(smap);

console.log(sourceMapConsumer.generatedPositionFor({
    source:'ORIGINAL_SOURCE_LOCATION_for_index.ios.js', 
    line: 18, 
    column: 0
}));

it yields:

{ line: 1504, column: 0, lastColumn: null }

But in index.ios.bundle file, line 1504 is a blank line:

image

Removing the fat arrow functionop2 can have the line in op1 reported correctly.

Expected Results

The line in the bundle should be reported as 1509, where it actually is at.

Additional Information

  • React Native version: 0.32.0
  • Platform(s) (iOS, Android, or both?): iOS (haven't tested Android)
  • Operating System (macOS, Linux, or Windows?): macOS (haven't tested others)

changsi-an avatar Sep 06 '16 21:09 changsi-an

@MSLaguana

changsi-an avatar Sep 06 '16 21:09 changsi-an

@facebook-github-bot label Icebox

charpeni avatar Nov 14 '16 01:11 charpeni

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/source-map-for-the-bundle-is-not-generated-correctly-when-fat-arrow-function-is-used

ProductPains helps the community prioritize the most important issues thanks to its voting feature. It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix. We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

charpeni avatar Nov 14 '16 01:11 charpeni

@facebook-github-bot close

charpeni avatar Nov 14 '16 01:11 charpeni

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

facebook-github-bot avatar Nov 14 '16 01:11 facebook-github-bot