Browse Source

test for #101

contingency-plan
Rich Harris 9 years ago
parent
commit
ef5d2ba017
  1. 33
      test/sourcemaps/names/_config.js
  2. 1
      test/sourcemaps/names/bar.js
  3. 5
      test/sourcemaps/names/foo.js
  4. 1
      test/sourcemaps/names/main.js

33
test/sourcemaps/names/_config.js

@ -0,0 +1,33 @@
var path = require( 'path' );
var assert = require( 'assert' );
var getLocation = require( '../../utils/getLocation' );
var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
module.exports = {
description: 'names are recovered (https://github.com/rollup/rollup/issues/101)',
options: {
moduleName: 'myModule'
},
test: function ( code, map ) {
var smc = new SourceMapConsumer( map );
var generatedLoc, originalLoc;
var match = /Object\.create\( ([^\.]+)\.prototype/.exec( code );
if ( !match ) throw new Error( 'errr...' );
var deconflictedName = match[1];
if ( deconflictedName === 'Foo' ) throw new Error( 'Need to update this test!' );
var pattern = new RegExp( deconflictedName, 'g' );
var index = code.indexOf( deconflictedName );
generatedLoc = getLocation( code, index );
originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.name, 'Foo' );
var index = code.indexOf( deconflictedName, index + 1 );
generatedLoc = getLocation( code, index );
originalLoc = smc.originalPositionFor( generatedLoc );
assert.equal( originalLoc.name, 'Bar' );
}
};

1
test/sourcemaps/names/bar.js

@ -0,0 +1 @@
export default function Foo () {}

5
test/sourcemaps/names/foo.js

@ -0,0 +1,5 @@
import Bar from './bar';
export default function Foo () {}
Foo.prototype = Object.create( Bar.prototype );

1
test/sourcemaps/names/main.js

@ -0,0 +1 @@
export { default as Foo } from './foo';
Loading…
Cancel
Save