diff --git a/src/Module.js b/src/Module.js index 3e5ee58..aada683 100644 --- a/src/Module.js +++ b/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; } } diff --git a/test/function/assignment-to-exports-b/_config.js b/test/function/assignment-to-exports-b/_config.js new file mode 100644 index 0000000..9abbeab --- /dev/null +++ b/test/function/assignment-to-exports-b/_config.js @@ -0,0 +1,8 @@ +const assert = require( 'assert' ); + +module.exports = { + description: 'exports are rewritten inside a variable init', + exports: exports => { + assert.equal( exports.b, 42 ); + } +}; diff --git a/test/function/assignment-to-exports-b/main.js b/test/function/assignment-to-exports-b/main.js new file mode 100644 index 0000000..d503419 --- /dev/null +++ b/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 };