Skip to content

Commit

Permalink
Add parenthesis around $parcel$interopDefault call for externals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Oct 26, 2021
1 parent 530e06a commit 8afcd1e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
@@ -0,0 +1,3 @@
import Foo from "test";

new Foo();

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

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

Expand Up @@ -6,6 +6,7 @@
"node": ">= 10.x"
},
"dependencies": {
"lodash": "*"
"lodash": "*",
"test": "*"
}
}
15 changes: 14 additions & 1 deletion packages/core/integration-tests/test/output-formats.js
Expand Up @@ -168,6 +168,19 @@ describe('output formats', function() {
assert.equal((await run(b)).bar, 3);
});

it('should support commonjs output with external modules (default import new call)', async function() {
let b = await bundle(
path.join(
__dirname,
'/integration/formats/commonjs-external/default-new.js',
),
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(dist.includes('$parcel$interopDefault'));
await run(b);
});

it('should support commonjs output with external modules (multiple specifiers)', async function() {
let b = await bundle(
path.join(
Expand All @@ -178,7 +191,7 @@ describe('output formats', function() {

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(dist.includes('= require("lodash")'));
assert(dist.includes('= $parcel$interopDefault('));
assert(dist.includes('= ($parcel$interopDefault('));
assert(/var {add: \s*\$.+?\$add\s*} = lodash/);
assert.equal((await run(b)).bar, 6);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/packagers/js/src/ScopeHoistingPackager.js
Expand Up @@ -580,7 +580,7 @@ ${code}
if (imported === '*') {
replacement = renamed;
} else if (imported === 'default') {
replacement = `$parcel$interopDefault(${renamed})`;
replacement = `($parcel$interopDefault(${renamed}))`;
this.usedHelpers.add('$parcel$interopDefault');
} else {
replacement = this.getPropertyAccess(renamed, imported);
Expand Down

0 comments on commit 8afcd1e

Please sign in to comment.