Skip to content

Commit

Permalink
Prevent nameclashes with internal variables
Browse files Browse the repository at this point in the history
Fixes #1699
  • Loading branch information
fathyb committed Jul 15, 2018
1 parent e0d8821 commit 1b1eea8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scope-hoisting/hoist.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module.exports = {
// Rename each binding in the top-level scope to something unique.
for (let name in scope.bindings) {
if (!name.startsWith('$' + t.toIdentifier(asset.id))) {
let newName = getName(asset, 'var', name);
let newName = getName(asset, 'var', name, '$');
rename(scope, name, newName);
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/scope-hoisting/es6/name-clash/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {foo} from './b'

output = foo()
3 changes: 3 additions & 0 deletions test/integration/scope-hoisting/es6/name-clash/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var $exports = module.exports = {}

$exports.foo = () => 'bar'
9 changes: 9 additions & 0 deletions test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ describe('scope hoisting', function() {
let output = await run(b);
assert.deepEqual(output, 'bar');
});

it('should not nameclash with internal variables', async function() {
let b = await bundle(
__dirname + '/integration/scope-hoisting/es6/name-clash/a.js'
);

let output = await run(b);
assert.deepEqual(output, 'bar');
});
});

describe('commonjs', function() {
Expand Down

0 comments on commit 1b1eea8

Please sign in to comment.