Skip to content

Commit

Permalink
Merge pull request #1255 from Comandeer/fix-babili
Browse files Browse the repository at this point in the history
Babili's sourcemaps causes error in collapseSourcemaps.js
  • Loading branch information
Rich-Harris committed Mar 9, 2017
2 parents ae54071 + bff7e9e commit 9929d1b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils/collapseSourcemaps.js
Expand Up @@ -31,6 +31,9 @@ class Link {

line.forEach( segment => {
const source = this.sources[ segment[1] ];

if ( !source ) return;

const traced = source.traceSegment( segment[2], segment[3], this.names[ segment[4] ] );

if ( traced ) {
Expand Down
35 changes: 35 additions & 0 deletions test/sourcemaps/transform-bundle-babili/_config.js
@@ -0,0 +1,35 @@
var babiliResults = require( './babili-results' );
var assert = require( 'assert' );
var getLocation = require( '../../utils/getLocation' );
var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;

module.exports = {
description: 'generates valid sourcemap when source could not be determined',
options: {
plugins: [
{
transformBundle: function ( code, options ) {
var format = options.format;

return babiliResults[ format ];
}
}
]
},
test: function ( code, map ) {
var smc = new SourceMapConsumer( map );

var generatedLoc = getLocation( code, code.indexOf( '42' ) );
var originalLoc = smc.originalPositionFor( generatedLoc );

assert.ok( /main/.test( originalLoc.source ) );
assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 13 );

generatedLoc = getLocation( code, code.indexOf( 'log' ) );
originalLoc = smc.originalPositionFor( generatedLoc );

assert.equal( originalLoc.line, 1 );
assert.equal( originalLoc.column, 8 );
}
};
5 changes: 5 additions & 0 deletions test/sourcemaps/transform-bundle-babili/babili-results.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/sourcemaps/transform-bundle-babili/main.js
@@ -0,0 +1 @@
console.log( 42 );

0 comments on commit 9929d1b

Please sign in to comment.