diff --git a/test/sourcemaps/loaders/_config.js b/test/sourcemaps/loaders/_config.js index cf13906..d278904 100644 --- a/test/sourcemaps/loaders/_config.js +++ b/test/sourcemaps/loaders/_config.js @@ -10,20 +10,26 @@ module.exports = { plugins: [ { load: function ( id ) { - if ( id.endsWith( 'main.js' ) ) { - id = id.replace( /main.js$/, 'foo.js' ); - } else { - id = id.replace( /foo.js$/, 'main.js' ); + if ( id.endsWith( 'foo.js' ) ) { + id = id.replace( /foo.js$/, 'bar.js' ); + } else if ( id.endsWith( 'bar.js' ) ) { + id = id.replace( /bar.js$/, 'foo.js' ); } var out = babel.transformFileSync( id, { blacklist: [ 'es6.modules' ], - sourceMap: true + sourceMap: true, + comments: false // misalign the columns }); - const slash = out.map.sources[0].lastIndexOf( '/' ) + 1; - out.map.sources = out.map.sources.map( source => '../' + source.slice( slash ) ); - out.map.sourceRoot = 'fake'; + if ( id.endsWith( 'main.js' ) ) { + delete out.map.sources; + //throw new Error(JSON.stringify(out.code)); + } else { + const slash = out.map.sources[0].lastIndexOf( '/' ) + 1; + out.map.sources = out.map.sources.map( source => '../' + source.slice( slash ) ); + out.map.sourceRoot = 'fake'; + } return { code: out.code, map: out.map }; } @@ -33,18 +39,26 @@ module.exports = { test: function ( code, map ) { var smc = new SourceMapConsumer( map ); - var generatedLoc = getLocation( code, code.indexOf( '42' ) ); + var generatedLoc = getLocation( code, code.indexOf( '22' ) ); var originalLoc = smc.originalPositionFor( generatedLoc ); - assert.equal( originalLoc.source, '../main.js' ); + assert.equal( originalLoc.source, '../foo.js' ); assert.equal( originalLoc.line, 1 ); - assert.equal( originalLoc.column, 25 ); + assert.equal( originalLoc.column, 32 ); + + var generatedLoc = getLocation( code, code.indexOf( '20' ) ); + var originalLoc = smc.originalPositionFor( generatedLoc ); + + assert.equal( originalLoc.source, '../bar.js' ); + assert.equal( originalLoc.line, 1 ); + assert.equal( originalLoc.column, 37 ); generatedLoc = getLocation( code, code.indexOf( 'log' ) ); originalLoc = smc.originalPositionFor( generatedLoc ); - assert.equal( originalLoc.source, '../foo.js' ); - assert.equal( originalLoc.line, 3 ); - assert.equal( originalLoc.column, 8 ); + assert.equal( originalLoc.source, '../main.js' ); + assert.ok( /columns/.test( smc.sourceContentFor( '../main.js' ) ) ); + assert.equal( originalLoc.line, 4 ); + assert.equal( originalLoc.column, 19 ); } }; diff --git a/test/sourcemaps/loaders/bar.js b/test/sourcemaps/loaders/bar.js new file mode 100644 index 0000000..6c3e77f --- /dev/null +++ b/test/sourcemaps/loaders/bar.js @@ -0,0 +1 @@ +/*misalign*/export const foo = () => 20; diff --git a/test/sourcemaps/loaders/foo.js b/test/sourcemaps/loaders/foo.js index c0b4c17..9ce4283 100644 --- a/test/sourcemaps/loaders/foo.js +++ b/test/sourcemaps/loaders/foo.js @@ -1,3 +1 @@ -import { foo } from './foo'; - -console.log( `the answer is ${foo()}` ); +/*the*/export const bar = () => 22; diff --git a/test/sourcemaps/loaders/main.js b/test/sourcemaps/loaders/main.js index 0cf01be..df7e27a 100644 --- a/test/sourcemaps/loaders/main.js +++ b/test/sourcemaps/loaders/main.js @@ -1 +1,4 @@ -export const foo = () => 42; +import { foo } from './foo'; +import { bar } from './bar'; + +/*columns*/console.log( `the answer is ${foo() + bar()}` );