Skip to content

Commit

Permalink
Fix hoist of modules with multiple aliases (#2077)
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb authored and devongovett committed Oct 6, 2018
1 parent fa4c467 commit adf49c2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/packagers/JSConcatPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/integration/scope-hoisting/commonjs/wrap-aliases/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
try {
output = require('foo')
}
catch(_) {
output = require('foo-bar')
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "a",
"browser": {
"foo": "foo-bar"
}
}
12 changes: 12 additions & 0 deletions test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit adf49c2

Please sign in to comment.