Skip to content

Commit

Permalink
fix(compiler): force rollup to use named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pmdartus committed Mar 4, 2020
1 parent bb2c442 commit fd92fd2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.

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

0 comments on commit fd92fd2

Please sign in to comment.