Browse Source

generate correct sourcemap with reified namespaces (#668)

semi-dynamic-namespace-imports
Rich Harris 9 years ago
parent
commit
3eae936dbc
  1. 3
      package.json
  2. 22
      test/sourcemaps/reified-namespace/_config.js
  3. 1
      test/sourcemaps/reified-namespace/foo.js
  4. 3
      test/sourcemaps/reified-namespace/main.js
  5. 4
      test/utils/getLocation.js

3
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", "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", "ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov",
"build": "git rev-parse HEAD > .commithash && rollup -c", "build": "git rev-parse HEAD > .commithash && rollup -c",
"watch": "rollup -c -w",
"build:cli": "rollup -c rollup.config.cli.js", "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", "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", "prepublish": "npm run lint && npm test && npm run build:browser",
@ -49,7 +50,7 @@
"eslint": "^2.13.0", "eslint": "^2.13.0",
"estree-walker": "^0.2.1", "estree-walker": "^0.2.1",
"istanbul": "^0.4.3", "istanbul": "^0.4.3",
"magic-string": "^0.15.1", "magic-string": "^0.15.2",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"mocha": "^2.5.3", "mocha": "^2.5.3",
"remap-istanbul": "^0.6.4", "remap-istanbul": "^0.6.4",

22
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' );
}
};

1
test/sourcemaps/reified-namespace/foo.js

@ -0,0 +1 @@
export var bar = 42;

3
test/sourcemaps/reified-namespace/main.js

@ -0,0 +1,3 @@
import * as foo from './foo.js';
assert.deepEqual( foo, { bar: 42 });

4
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 lines = source.split( '\n' );
var len = lines.length; var len = lines.length;
var lineStart = 0; var lineStart = 0;
var i; var i;
const charIndex = typeof search === 'number' ? search : source.indexOf( search );
for ( i = 0; i < len; i += 1 ) { for ( i = 0; i < len; i += 1 ) {
var line = lines[i]; var line = lines[i];
var lineEnd = lineStart + line.length + 1; // +1 for newline var lineEnd = lineStart + line.length + 1; // +1 for newline

Loading…
Cancel
Save