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(ssr-compiler): add SSR for lwc:component #4000

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions packages/@lwc/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@lwc/babel-plugin-component": "6.1.1",
"@lwc/errors": "6.1.1",
"@lwc/shared": "6.1.1",
"@lwc/ssr-compiler": "6.1.1",
"@lwc/style-compiler": "6.1.1",
"@lwc/template-compiler": "6.1.1"
}
Expand Down
1 change: 1 addition & 0 deletions packages/@lwc/compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { transform, transformSync } from './transformers/transformer';

export { TransformResult } from './transformers/transformer';
export {
NormalizedTransformOptions,
TransformOptions,
StylesheetConfig,
CustomPropertiesResolution,
Expand Down
2 changes: 2 additions & 0 deletions packages/@lwc/compiler/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface TransformOptions {
enableLightningWebSecurityTransforms?: boolean;
instrumentation?: InstrumentationObject;
apiVersion?: number;
targetSSR?: boolean;
}

type RequiredTransformOptions = Omit<
Expand Down Expand Up @@ -208,5 +209,6 @@ function normalizeOptions(options: TransformOptions): NormalizedTransformOptions
outputConfig,
experimentalDynamicComponent,
apiVersion,
targetSSR: !!options.targetSSR,
};
}
5 changes: 3 additions & 2 deletions packages/@lwc/compiler/src/transformers/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
invariant,
CompilerDiagnostic,
} from '@lwc/errors';
import { compileComponentForSSR, compileTemplateForSSR } from '@lwc/ssr-compiler';

import { NormalizedTransformOptions, TransformOptions, validateTransformOptions } from '../options';
import styleTransform from './style';
Expand Down Expand Up @@ -76,7 +77,7 @@ function transformFile(

switch (path.extname(filename)) {
case '.html':
transformer = templateTransformer;
transformer = options.targetSSR ? compileTemplateForSSR : templateTransformer;
break;

case '.css':
Expand All @@ -85,7 +86,7 @@ function transformFile(

case '.ts':
case '.js':
transformer = scriptTransformer;
transformer = options.targetSSR ? compileComponentForSSR : scriptTransformer;
break;

default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-cmp';
export { default } from 'x/cmp';
export * from 'x/cmp';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-boolean';
export { default } from 'x/attribute-boolean';
export { default } from 'x/attribute-boolean';
export * from 'x/attribute-boolean';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-component-aria';
export { default } from 'x/attribute-component-aria';
export { default } from 'x/attribute-component-aria';
export * from 'x/attribute-component-aria';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-component-global-html';
export { default } from 'x/attribute-component-global-html';
export { default } from 'x/attribute-component-global-html';
export * from 'x/attribute-component-global-html';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-dynamic-escape';
export { default } from 'x/attribute-dynamic-escape';
export { default } from 'x/attribute-dynamic-escape';
export * from 'x/attribute-dynamic-escape';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-dynamic-with-scoped-css';
export { default } from 'x/attribute-dynamic-with-scoped-css';
export { default } from 'x/attribute-dynamic-with-scoped-css';
export * from 'x/attribute-dynamic-with-scoped-css';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-dynamic';
export { default } from 'x/attribute-dynamic';
export { default } from 'x/attribute-dynamic';
export * from 'x/attribute-dynamic';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-global-html';
export { default } from 'x/attribute-global-html';
export { default } from 'x/attribute-global-html';
export * from 'x/attribute-global-html';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-live-bindings';
export { default } from 'x/attribute-live-bindings';
export { default } from 'x/attribute-live-bindings';
export * from 'x/attribute-live-bindings';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-static';
export { default } from 'x/attribute-static';
export { default } from 'x/attribute-static';
export * from 'x/attribute-static';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attribute-style';
export { default } from 'x/attribute-style';
export { default } from 'x/attribute-style';
export * from 'x/attribute-style';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-attributes-aria';
export { default } from 'x/attributes-aria';
export { default } from 'x/attributes-aria';
export * from 'x/attributes-aria';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-comments-basic';
export { default } from 'x/comments-basic';
export { default } from 'x/comments-basic';
export * from 'x/comments-basic';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-comments-foreach';
export { default } from 'x/comments-foreach';
export { default } from 'x/comments-foreach';
export * from 'x/comments-foreach';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-comments-if';
export { default } from 'x/comments-if';
export { default } from 'x/comments-if';
export * from 'x/comments-if';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-comments-slot';
export { default } from 'x/comments-slot';
export { default } from 'x/comments-slot';
export * from 'x/comments-slot';
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
I am a child component
</template>
</x-child>
<x-anotherchild>
<template shadowrootmode="open">
I am another child component
</template>
</x-anotherchild>
</template>
</x-component>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-component';
export { default } from 'x/component';
export { default } from 'x/component';
export * from 'x/component';
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<template>
<x-child></x-child>
<x-anotherchild></x-anotherchild>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a test here for <lwc:component> ...?

BTW this is a good example of why it'd be nice to have the compiler output as part of the snapshots... would help with visualizing the generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests the import statement we add when we see a child in the template. lwc:component are imported in the JS by the user.

Specifically, here db3322f#diff-17a5fc2e6a05c3f1e674d6942273c831cb914d8d3c3286062c429e5054465bdfR101, we increment UID to add unique import statements for each child.
e.g.

import { generateMarkup as generateMarkup_1 } from 'x/child';
import { generateMarkup as generateMarkup_2 } from 'x/anotherchild';

Definitely agree with having the compiler output in snapshots. This would have been clearer.

</template>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-computed';
export { default } from 'x/computed';
export { default } from 'x/computed';
export * from 'x/computed';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-provider';
export { default } from 'x/provider';
export * from 'x/provider';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-provider';
export { default } from 'x/provider';
export * from 'x/provider';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-provider';
export { default } from 'x/provider';
export * from 'x/provider';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-provider';
export { default } from 'x/provider';
export * from 'x/provider';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-provider';
export { default } from 'x/provider';
export * from 'x/provider';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-root';
export { default } from 'x/root';
export * from 'x/root';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const tagName = 'x-component';
export { default } from 'x/component';
export { default } from 'x/component';
export * from 'x/component';
Loading