Browse Source

Merge pull request #268 from mbostock/assignment-to-re-exports

Fix assignment to re-exported bindings.
better-aggressive
Rich Harris 9 years ago
parent
commit
790d0d8810
  1. 2
      src/Module.js
  2. 5
      src/ast/attachScopes.js
  3. 10
      test/function/assignment-to-re-exports-conflict/_config.js
  4. 10
      test/function/assignment-to-re-exports-conflict/count.js
  5. 1
      test/function/assignment-to-re-exports-conflict/main.js
  6. 10
      test/function/assignment-to-re-exports/_config.js
  7. 5
      test/function/assignment-to-re-exports/count.js
  8. 1
      test/function/assignment-to-re-exports/main.js

2
src/Module.js

@ -344,7 +344,7 @@ export default class Module {
if ( declaration ) { if ( declaration ) {
declaration.addReference( reference ); declaration.addReference( reference );
} else { } else if ( statement.node.type !== 'ExportNamedDeclaration' || !this.reexports[ reference.name ] ) {
// TODO handle globals // TODO handle globals
this.bundle.assumedGlobals[ reference.name ] = true; this.bundle.assumedGlobals[ reference.name ] = true;
} }

5
src/ast/attachScopes.js

@ -17,11 +17,10 @@ export default function attachScopes ( statement ) {
scope.addDeclaration( node, false, false ); scope.addDeclaration( node, false, false );
} }
// var foo = 1 // var foo = 1, bar = 2
if ( node.type === 'VariableDeclaration' ) { if ( node.type === 'VariableDeclaration' ) {
const isBlockDeclaration = blockDeclarations[ node.kind ]; const isBlockDeclaration = blockDeclarations[ node.kind ];
// only one declarator per block, because we split them up already node.declarations.forEach( declaration => scope.addDeclaration( declaration, isBlockDeclaration, true ) );
scope.addDeclaration( node.declarations[0], isBlockDeclaration, true );
} }
let newScope; let newScope;

10
test/function/assignment-to-re-exports-conflict/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 're-exports are kept up-to-date',
exports: function ( exports ) {
assert.equal( exports.count, 0 );
exports.incr();
assert.equal( exports.count, 1 );
}
};

10
test/function/assignment-to-re-exports-conflict/count.js

@ -0,0 +1,10 @@
export var count = 0;
export function conflict () {
var foo = 0,
count = 42;
}
export function incr () {
count += 1;
}

1
test/function/assignment-to-re-exports-conflict/main.js

@ -0,0 +1 @@
export {count, incr, conflict} from './count';

10
test/function/assignment-to-re-exports/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 're-exports are kept up-to-date',
exports: function ( exports ) {
assert.equal( exports.count, 0 );
exports.incr();
assert.equal( exports.count, 1 );
}
};

5
test/function/assignment-to-re-exports/count.js

@ -0,0 +1,5 @@
export var count = 0;
export function incr () {
count += 1;
}

1
test/function/assignment-to-re-exports/main.js

@ -0,0 +1 @@
export {count, incr} from './count';
Loading…
Cancel
Save