diff --git a/package.json b/package.json index d7ccf56..76ee2e6 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", "ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov", "build": "git rev-parse HEAD > .commithash && rollup -c", + "watch": "rollup -c -w", "build:cli": "rollup -c rollup.config.cli.js", "build:browser": "git rev-parse HEAD > .commithash && rollup -c rollup.config.browser.js -o dist/rollup.browser.js", "prepublish": "npm run lint && npm test && npm run build:browser", @@ -49,7 +50,7 @@ "eslint": "^2.13.0", "estree-walker": "^0.2.1", "istanbul": "^0.4.3", - "magic-string": "^0.15.1", + "magic-string": "^0.15.2", "minimist": "^1.2.0", "mocha": "^2.5.3", "remap-istanbul": "^0.6.4", diff --git a/test/sourcemaps/reified-namespace/_config.js b/test/sourcemaps/reified-namespace/_config.js new file mode 100644 index 0000000..8870098 --- /dev/null +++ b/test/sourcemaps/reified-namespace/_config.js @@ -0,0 +1,22 @@ +const fs = require( 'fs' ); +const path = require( 'path' ); +const assert = require( 'assert' ); +const getLocation = require( '../../utils/getLocation' ); +const SourceMapConsumer = require( 'source-map' ).SourceMapConsumer; + +module.exports = { + description: 'generates correct sourcemap with reified namespace (#668)', + test: ( code, map ) => { + const smc = new SourceMapConsumer( map ); + + const main = fs.readFileSync( path.join( __dirname, 'main.js' ), 'utf-8' ); + const generatedLoc = getLocation( code, 'deepEqual' ); + + const actual = smc.originalPositionFor( generatedLoc ); + const expected = getLocation( main, 'deepEqual' ); + + assert.equal( actual.line, expected.line ); + assert.equal( actual.column, expected.column ); + assert.equal( actual.source, '../main.js' ); + } +}; diff --git a/test/sourcemaps/reified-namespace/foo.js b/test/sourcemaps/reified-namespace/foo.js new file mode 100644 index 0000000..ab0c7db --- /dev/null +++ b/test/sourcemaps/reified-namespace/foo.js @@ -0,0 +1 @@ +export var bar = 42; diff --git a/test/sourcemaps/reified-namespace/main.js b/test/sourcemaps/reified-namespace/main.js new file mode 100644 index 0000000..565c1eb --- /dev/null +++ b/test/sourcemaps/reified-namespace/main.js @@ -0,0 +1,3 @@ +import * as foo from './foo.js'; + +assert.deepEqual( foo, { bar: 42 }); diff --git a/test/utils/getLocation.js b/test/utils/getLocation.js index 4993997..b92d38b 100644 --- a/test/utils/getLocation.js +++ b/test/utils/getLocation.js @@ -1,10 +1,12 @@ -module.exports = function getLocation ( source, charIndex ) { +module.exports = function getLocation ( source, search ) { var lines = source.split( '\n' ); var len = lines.length; var lineStart = 0; var i; + const charIndex = typeof search === 'number' ? search : source.indexOf( search ); + for ( i = 0; i < len; i += 1 ) { var line = lines[i]; var lineEnd = lineStart + line.length + 1; // +1 for newline