diff --git a/src/Module.js b/src/Module.js index 3bbf32e..1ee1320 100644 --- a/src/Module.js +++ b/src/Module.js @@ -344,7 +344,7 @@ export default class Module { if ( declaration ) { declaration.addReference( reference ); - } else { + } else if ( statement.node.type !== 'ExportNamedDeclaration' || !this.reexports[ reference.name ] ) { // TODO handle globals this.bundle.assumedGlobals[ reference.name ] = true; } diff --git a/src/ast/attachScopes.js b/src/ast/attachScopes.js index 77b8af4..3f44684 100644 --- a/src/ast/attachScopes.js +++ b/src/ast/attachScopes.js @@ -17,11 +17,10 @@ export default function attachScopes ( statement ) { scope.addDeclaration( node, false, false ); } - // var foo = 1 + // var foo = 1, bar = 2 if ( node.type === 'VariableDeclaration' ) { const isBlockDeclaration = blockDeclarations[ node.kind ]; - // only one declarator per block, because we split them up already - scope.addDeclaration( node.declarations[0], isBlockDeclaration, true ); + node.declarations.forEach( declaration => scope.addDeclaration( declaration, isBlockDeclaration, true ) ); } let newScope; diff --git a/test/function/assignment-to-re-exports-conflict/_config.js b/test/function/assignment-to-re-exports-conflict/_config.js new file mode 100644 index 0000000..376ba32 --- /dev/null +++ b/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 ); + } +}; diff --git a/test/function/assignment-to-re-exports-conflict/count.js b/test/function/assignment-to-re-exports-conflict/count.js new file mode 100644 index 0000000..64bbd5a --- /dev/null +++ b/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; +} diff --git a/test/function/assignment-to-re-exports-conflict/main.js b/test/function/assignment-to-re-exports-conflict/main.js new file mode 100644 index 0000000..1f290f5 --- /dev/null +++ b/test/function/assignment-to-re-exports-conflict/main.js @@ -0,0 +1 @@ +export {count, incr, conflict} from './count'; diff --git a/test/function/assignment-to-re-exports/_config.js b/test/function/assignment-to-re-exports/_config.js new file mode 100644 index 0000000..376ba32 --- /dev/null +++ b/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 ); + } +}; diff --git a/test/function/assignment-to-re-exports/count.js b/test/function/assignment-to-re-exports/count.js new file mode 100644 index 0000000..2ed71df --- /dev/null +++ b/test/function/assignment-to-re-exports/count.js @@ -0,0 +1,5 @@ +export var count = 0; + +export function incr () { + count += 1; +} diff --git a/test/function/assignment-to-re-exports/main.js b/test/function/assignment-to-re-exports/main.js new file mode 100644 index 0000000..97b1267 --- /dev/null +++ b/test/function/assignment-to-re-exports/main.js @@ -0,0 +1 @@ +export {count, incr} from './count';