Browse Source

dont rewrite var foo as var exports.foo

contingency-plan
Rich-Harris 9 years ago
parent
commit
c2ebdcbe4c
  1. 6
      src/Module.js
  2. 11
      test/function/export-and-import-reference-share-var/_config.js
  3. 2
      test/function/export-and-import-reference-share-var/foo.js
  4. 13
      test/function/export-and-import-reference-share-var/main.js

6
src/Module.js

@ -641,7 +641,11 @@ export default class Module {
// split up/remove var declarations as necessary
if ( statement.node.isSynthetic ) {
magicString.insert( statement.start, `${statement.node.kind} ` );
// insert `var/let/const` if necessary
if ( !allBundleExports[ statement.node.declarations[0].id.name ] ) {
magicString.insert( statement.start, `${statement.node.kind} ` );
}
magicString.overwrite( statement.end, statement.next, ';\n' ); // TODO account for trailing newlines
}

11
test/function/export-and-import-reference-share-var/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'allows export and import reference to share name',
exports: function ( exports ) {
assert.equal( exports.b, 9 );
},
solo: true
};
// adapted from es6-module-transpiler

2
test/function/export-and-import-reference-share-var/foo.js

@ -0,0 +1,2 @@
export var a = 1;
assert.equal(a, 1);

13
test/function/export-and-import-reference-share-var/main.js

@ -0,0 +1,13 @@
import { a } from './foo';
// This variable declaration is going to be altered because `b` needs to be
// re-written. We need to make sure that the `a` re-writing and the unaffected
// `c` declarator are not being clobbered by that alteration.
var a_ = a, b = 9, c = 'c';
assert.equal(a, 1);
assert.equal(a_, 1);
assert.equal(b, 9);
assert.equal(c, 'c');
export { b };
Loading…
Cancel
Save