Browse Source

allow rewrites of variable declarator inits – fixes #632

gh-669
Rich Harris 9 years ago
parent
commit
d0ea2ad2d6
  1. 9
      src/Module.js
  2. 8
      test/function/assignment-to-exports-b/_config.js
  3. 9
      test/function/assignment-to-exports-b/main.js

9
src/Module.js

@ -458,13 +458,8 @@ export default class Module {
const declaration = this.declarations[ declarator.id.name ];
if ( declaration.exportName && declaration.isReassigned ) { // `var foo = ...` becomes `exports.foo = ...`
if ( declarator.init ) {
magicString.overwrite( statement.start, declarator.init.start, `exports.${declaration.exportName} = ` );
} else {
magicString.remove( statement.start, declarator.init ? declarator.start : statement.next );
}
return;
magicString.remove( statement.start, declarator.init ? declarator.start : statement.next );
if ( !declarator.init ) return;
}
}

8
test/function/assignment-to-exports-b/_config.js

@ -0,0 +1,8 @@
const assert = require( 'assert' );
module.exports = {
description: 'exports are kept up-to-date',
exports: exports => {
assert.equal( exports.b, 42 );
}
};

9
test/function/assignment-to-exports-b/main.js

@ -0,0 +1,9 @@
var a = { prop: 42 };
var b = a.prop;
function set ( new_a, new_b ) {
a = new_a;
b = new_b;
}
export { a, b, set };
Loading…
Cancel
Save