Skip to content

Commit

Permalink
Merge pull request #485 from rollup/gh-484
Browse files Browse the repository at this point in the history
correctly rewrite exported var declarations
  • Loading branch information
Rich-Harris committed Jan 31, 2016
2 parents 51a87a8 + 366b414 commit 1e99194
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ export default class Module {
const declaration = this.declarations[ declarator.id.name ];

if ( declaration.exportName && declaration.isReassigned ) { // `var foo = ...` becomes `exports.foo = ...`
magicString.remove( statement.start, declarator.init ? declarator.start : statement.next );
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;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/function/disappearing-exported-value/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var assert = require( 'assert' );

module.exports = {
description: 'exported values do not mysteriously disappear (#484)',
exports: function ( exports ) {
assert.equal( exports.exportedAnswer, 42 );
assert.equal( exports.foo(), 42 );
}
};
2 changes: 2 additions & 0 deletions test/function/disappearing-exported-value/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var answer = 42;
export { answer };
8 changes: 8 additions & 0 deletions test/function/disappearing-exported-value/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { answer as importedAnswer } from './answer.js';
export { answer as exportedAnswer } from './answer.js';

export function foo () {
var value;
value = importedAnswer;
return value;
}

0 comments on commit 1e99194

Please sign in to comment.