Browse Source

ensure reference is only marked as reassignment if it is the subject of the reassignment – fixes #648

gh-669
Rich Harris 9 years ago
parent
commit
82112f7528
  1. 5
      src/Statement.js
  2. 9
      test/function/export-two-ways-function/_config.js
  3. 8
      test/function/export-two-ways-function/main.js

5
src/Statement.js

@ -65,6 +65,8 @@ export default class Statement {
if ( parent && isModifierNode( parent ) ) {
let subject = parent[ modifierNodes[ parent.type ] ];
if ( node === subject ) {
let depth = 0;
while ( subject.type === 'MemberExpression' ) {
@ -82,13 +84,14 @@ export default class Statement {
if ( depth < minDepth ) {
const err = new Error( `Illegal reassignment to import '${subject.name}'` );
err.file = module.id;
err.loc = getLocation( module.magicString.toString(), subject.start );
err.loc = getLocation( module.magicString.original, subject.start );
throw err;
}
}
isReassignment = !depth;
}
}
if ( isReference( node, parent ) ) {
// function declaration IDs are a special case – they're associated

9
test/function/export-two-ways-function/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
module.exports = {
description: 'exports the same function more than one way (#648)',
exports: function ( exports ) {
assert.equal( exports.foo, exports.bar );
assert.equal( exports.foo(), 42 );
}
};

8
test/function/export-two-ways-function/main.js

@ -0,0 +1,8 @@
var bar;
bar = foo;
function foo () {
return 42;
}
export { foo, bar };
Loading…
Cancel
Save