diff --git a/packages/core/parcel/src/scope-hoisting/concat.js b/packages/core/parcel/src/scope-hoisting/concat.js index 5e3f61f71bf..a5bc5eec21c 100644 --- a/packages/core/parcel/src/scope-hoisting/concat.js +++ b/packages/core/parcel/src/scope-hoisting/concat.js @@ -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)' diff --git a/packages/core/parcel/src/scope-hoisting/shake.js b/packages/core/parcel/src/scope-hoisting/shake.js index 40f6964b0f2..563c8313222 100644 --- a/packages/core/parcel/src/scope-hoisting/shake.js +++ b/packages/core/parcel/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 diff --git a/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/a.js b/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/a.js new file mode 100644 index 00000000000..38ca6886091 --- /dev/null +++ b/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/a.js @@ -0,0 +1,3 @@ +import {foo} from './b' + +output = foo() diff --git a/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/b.js b/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/b.js new file mode 100644 index 00000000000..c4d87458429 --- /dev/null +++ b/packages/core/parcel/test/integration/scope-hoisting/es6/name-clash/b.js @@ -0,0 +1,3 @@ +var $exports = module.exports = {} + +$exports.foo = () => 'bar' diff --git a/packages/core/parcel/test/scope-hoisting.js b/packages/core/parcel/test/scope-hoisting.js index b2ea1aa7c37..e88c70ab191 100644 --- a/packages/core/parcel/test/scope-hoisting.js +++ b/packages/core/parcel/test/scope-hoisting.js @@ -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() {