Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parenthesis around $parcel$interopDefault call for externals #7113

Merged
merged 5 commits into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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