Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default sourceFileName. #7764

Merged
merged 6 commits into from Apr 27, 2018

Commits on Apr 27, 2018

  1. Fix default sourceFileName.

    This deals with a problem mentioned in [babel/babelify#255][0]. I'm not
    super sure about the implications, but it seems this may have been a
    regression from Babel 6.
    
    In babel@6, the default `sourceFileName` was the basename of the input
    file:
    
    ```js
    require('babel-core').transform('var a = 10', {
      filename: __filename,
      sourceMaps: true
    }).map
    // { version: 3,
    //   sources: [ 'index.js' ],
    //   names: [ 'a' ],
    //   mappings: 'AAAA,IAAIA,IAAI,EAAR',
    //   file: 'index.js',
    //   sourcesContent: [ 'var a = 10' ] } }
    ```
    
    Currently however, the full file path is used:
    
    ```js
    require('@babel/core').transformSync('var a = 10', {
      filename: __filename,
      sourceMaps: true
    }).map
    // { version: 3,
    //   sources: [ '/home/goto-bus-stop/Code/babel/repro-babelify-255/index.js' ],
    //   names: [ 'a' ],
    //   mappings: 'AAAA,IAAIA,IAAI,EAAR',
    //   file: '/home/goto-bus-stop/Code/babel/repro-babelify-255/index.js',
    //   sourcesContent: [ 'var a = 10' ] } }
    ```
    
    This patch adds the `path.basename()` call that [Babel 6 used][1] to
    @babel/core's default options, so it's the same as back then.
    
    ```js
    require('../babel/packages/babel-core').transform('var a = 10', {
      filename: __filename,
      sourceMaps: true
    }).map
    // { version: 3,
    //   sources: [ 'index.js' ],
    //   names: [ 'a' ],
    //   mappings: 'AAAA,IAAIA,IAAI,EAAR',
    //   sourcesContent: [ 'var a = 10' ] }
    ```
    
    This is the desired behaviour for browserify at least, as it expects
    relative paths in the source maps and rebases them to a root directory
    when generating the final source map.
    
    [0]: babel/babelify#255
    [1]: https://github.com/babel/babel/blob/6689d2d23cdb607c326ed5a06855bfb84c050c56/packages/babel-core/src/transformation/file/index.js#L163-L172
    goto-bus-stop committed Apr 27, 2018
    Copy the full SHA
    95974b1 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    dd6e195 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    7546ac7 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    2182a03 View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    9412a4b View commit details
    Browse the repository at this point in the history
  6. Copy the full SHA
    628699b View commit details
    Browse the repository at this point in the history