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

fix(compiler): Force rollup to use named exports #1752

Merged
merged 1 commit into from Mar 17, 2020
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

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.

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

12 changes: 10 additions & 2 deletions packages/@lwc/compiler/src/bundler/bundler.ts
Expand Up @@ -117,10 +117,18 @@ export async function bundle(options: NormalizedCompileOptions): Promise<BundleR
});

const { output } = await rollupBundler.generate({
format,
amd: { id: namespace + '/' + name },
strict: false,
sourcemap: outputConfig.sourcemap,
format,

// Adding use strict is unnecessary because all the modules in Core are evaluated
// automatically in strict mode.
strict: false,

// [W-7272006] Force generated modules to use named exports. This prevents running into
// issue when the interop code generated by rollup throws an exception when the exported
// object prototype is null.
exports: 'named',
});

// Rollup produces multiple chunks when a module uses "import()" with a relative import
Expand Down
Expand Up @@ -41,7 +41,7 @@ describe('module resolver', () => {

expect(success).toBe(true);
expect(pretify(result.code)).toBe(
pretify(`define('x/class_and_template', ['lwc'], function (lwc) {
pretify(`define('x/class_and_template', ['exports', 'lwc'], function (exports, lwc) {
function tmpl($api, $cmp, $slotset, $ctx) {
const {
t: api_text,
Expand All @@ -66,7 +66,8 @@ describe('module resolver', () => {
}
}

return Test;
exports.default = Test;
Object.defineProperty(exports, '__esModule', { value: true });
});`)
);
});
Expand All @@ -90,7 +91,7 @@ describe('module resolver', () => {
const { success, result } = await compile(noOutputConfig);
expect(success).toBe(true);
expect(pretify(result.code)).toBe(
pretify(`define('x/class_and_template', ['lwc'], function (lwc) {
pretify(`define('x/class_and_template', ['exports', 'lwc'], function (exports, lwc) {
function tmpl($api, $cmp, $slotset, $ctx) {
const {
t: api_text,
Expand All @@ -115,7 +116,8 @@ describe('module resolver', () => {
}
}

return Test;
exports.default = Test;
Object.defineProperty(exports, '__esModule', { value: true });
});`)
);
});
Expand Down