Skip to content

Commit

Permalink
Prevent nameclashes with internal variables (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb authored and devongovett committed Jul 16, 2018
1 parent e0d8821 commit 91a339e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scope-hoisting/concat.js
Expand Up @@ -7,7 +7,7 @@ const treeShake = require('./shake');
const mangleScope = require('./mangler');
const {getName, getIdentifier} = require('./utils');

const EXPORTS_RE = /^\$(.+?)\$exports$/;
const EXPORTS_RE = /^\$([^$]+)\$exports$/;

const DEFAULT_INTEROP_TEMPLATE = template(
'var NAME = $parcel$interopDefault(MODULE)'
Expand Down
2 changes: 1 addition & 1 deletion src/scope-hoisting/shake.js
@@ -1,6 +1,6 @@
const t = require('babel-types');

const EXPORTS_RE = /^\$(.+?)\$exports$/;
const EXPORTS_RE = /^\$([^$]+)\$exports$/;

/**
* This is a small small implementation of dead code removal specialized to handle
Expand Down
3 changes: 3 additions & 0 deletions test/integration/scope-hoisting/es6/name-clash/a.js
@@ -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
@@ -0,0 +1,3 @@
var $exports = module.exports = {}

$exports.foo = () => 'bar'
9 changes: 9 additions & 0 deletions test/scope-hoisting.js
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 91a339e

Please sign in to comment.