diff --git a/packages/core/parcel/src/packagers/JSConcatPackager.js b/packages/core/parcel/src/packagers/JSConcatPackager.js index 2c339c90128..ee8b2485c65 100644 --- a/packages/core/parcel/src/packagers/JSConcatPackager.js +++ b/packages/core/parcel/src/packagers/JSConcatPackager.js @@ -219,8 +219,10 @@ class JSConcatPackager extends Packager { let depAsts = new Map(); for (let depAsset of asset.depAssets.values()) { - let depAst = this.addDeps(depAsset, included); - depAsts.set(depAsset, depAst); + if (!depAsts.has(depAsset)) { + let depAst = this.addDeps(depAsset, included); + depAsts.set(depAsset, depAst); + } } let statements; diff --git a/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/a.js b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/a.js new file mode 100644 index 00000000000..b7a009c7e33 --- /dev/null +++ b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/a.js @@ -0,0 +1,6 @@ +try { + output = require('foo') +} +catch(_) { + output = require('foo-bar') +} diff --git a/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/node_modules/foo-bar/index.js b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/node_modules/foo-bar/index.js new file mode 100644 index 00000000000..a8653a9c926 --- /dev/null +++ b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/node_modules/foo-bar/index.js @@ -0,0 +1 @@ +module.exports = 42 diff --git a/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/package.json b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/package.json new file mode 100644 index 00000000000..c9981d2b7b0 --- /dev/null +++ b/packages/core/parcel/test/integration/scope-hoisting/commonjs/wrap-aliases/package.json @@ -0,0 +1,6 @@ +{ + "name": "a", + "browser": { + "foo": "foo-bar" + } +} \ No newline at end of file diff --git a/packages/core/parcel/test/scope-hoisting.js b/packages/core/parcel/test/scope-hoisting.js index 17ef11470b9..65dd8a71f55 100644 --- a/packages/core/parcel/test/scope-hoisting.js +++ b/packages/core/parcel/test/scope-hoisting.js @@ -1054,6 +1054,18 @@ describe('scope hoisting', function() { assert.deepEqual(output, 9); }); + it('should support two aliases to the same module', async function() { + let b = await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/commonjs/wrap-aliases/a.js' + ) + ); + + let output = await run(b); + assert.deepEqual(output, 42); + }); + it('should support optional requires', async function() { let b = await bundle( path.join(