Skip to content

Commit

Permalink
feat: add enableLightningWebSecurityTransforms to rollup-plugin (#3582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton authored Jun 19, 2023
1 parent 99a3115 commit 9cdb991
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@lwc/compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const { code } = transformSync(source, filename, options);
- `scopedStyles` (type: `boolean`, optional) - True if the CSS file being compiled is a scoped stylesheet. Passed to `@lwc/style-compiler`.
- `enableStaticContentOptimization` (type: `boolean`, optional) - True if the static content optimization should be enabled. Passed to `@lwc/template-compiler`.
- `customRendererConfig` (type: `object`, optional) - custom renderer config to pass to `@lwc/template-compiler`. See that package's README for details.
- `enableLightningWebSecurityTransforms` (type: `boolean`, default: `false`) - The configuration to enable Lighting Web Security specific transformations.
- `enableLwcSpread` (boolean, optional, `true` by default) - Deprecated. Ignored by compiler. `lwc:spread` is always enabled.
- `disableSyntheticShadowSupport` (type: `boolean`, default: `false`) - Set to true if synthetic shadow DOM support is not needed, which can result in smaller output.
- `instrumentation` (type: `InstrumentationObject`, optional) - instrumentation object to gather metrics and non-error logs for internal use. See the `@lwc/errors` package for details on the interface.
Expand Down
1 change: 1 addition & 0 deletions packages/@lwc/rollup-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export default {
- `experimentalDynamicComponent` (type: `DynamicImportConfig`, default: `null`) - The configuration to pass to `@lwc/compiler`.
- `experimentalDynamicDirective` (type: `boolean`, default: `false`) - The configuration to pass to `@lwc/template-compiler` to enable deprecated dynamic components.
- `enableDynamicComponents` (type: `boolean`, default: `false`) - The configuration to pass to `@lwc/template-compiler` to enable dynamic components.
- `enableLightningWebSecurityTransforms` (type: `boolean`, default: `false`) - The configuration to pass to `@lwc/compiler`.
- `enableLwcSpread` (type: `boolean`, default: `false`) - The configuration to pass to the `@lwc/template-compiler`.
- `disableSyntheticShadowSupport` (type: `boolean`, default: `false`) - Set to true if synthetic shadow DOM support is not needed, which can result in smaller output.
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,38 @@ describe('javaScriptConfig', () => {
expect(output[0].imports).toContain(CUSTOM_LOADER);
});
});

describe('lwsConfig', () => {
it('should accept enableLightningWebSecurityTransforms config flag', async () => {
function stripWhitespace(string: string) {
return string.replace(/\s/g, '');
}

const bundle = await rollup({
input: path.resolve(
__dirname,
'fixtures/lightningWebSecurityTransforms/lightningWebSecurityTransforms.js'
),
plugins: [
lwc({
enableLightningWebSecurityTransforms: true,
}),
],
});

const { output } = await bundle.generate({
format: 'esm',
});

const { code } = output[0];

expect(stripWhitespace(code)).toContain(
stripWhitespace(
'(window === globalThis || window === document ? location : window.location).href'
)
);
expect(code).toContain('_asyncToGenerator');
expect(code).toContain('_wrapAsyncGenerator');
expect(code).toContain('_asyncIterator');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<span>hello world</span>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
test = window.location.href;
async foo() {
await bar();
}
async bar() {
for await (const num of baz()) {
break;
}
}
async * baz() {
yield 1;
yield 2;
}
}
4 changes: 4 additions & 0 deletions packages/@lwc/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface RollupLwcOptions {
experimentalDynamicDirective?: boolean;
/** The configuration to pass to `@lwc/template-compiler`. */
enableDynamicComponents?: boolean;
/** The configuration to pass to `@lwc/compiler`. */
enableLightningWebSecurityTransforms?: boolean;
// TODO [#3370]: remove experimental template expression flag
/** The configuration to pass to `@lwc/template-compiler`. */
experimentalComplexExpressions?: boolean;
Expand Down Expand Up @@ -148,6 +150,7 @@ export default function lwc(pluginOptions: RollupLwcOptions = {}): Plugin {
experimentalDynamicComponent,
experimentalDynamicDirective,
enableDynamicComponents,
enableLightningWebSecurityTransforms,
// TODO [#3370]: remove experimental template expression flag
experimentalComplexExpressions,
disableSyntheticShadowSupport,
Expand Down Expand Up @@ -309,6 +312,7 @@ export default function lwc(pluginOptions: RollupLwcOptions = {}): Plugin {
experimentalDynamicComponent,
experimentalDynamicDirective,
enableDynamicComponents,
enableLightningWebSecurityTransforms,
// TODO [#3370]: remove experimental template expression flag
experimentalComplexExpressions,
preserveHtmlComments,
Expand Down

0 comments on commit 9cdb991

Please sign in to comment.