Skip to content

Commit

Permalink
chore: address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
divmain committed Apr 25, 2024
1 parent 4f4cc72 commit 5b2f725
Show file tree
Hide file tree
Showing 44 changed files with 483 additions and 265 deletions.
3 changes: 1 addition & 2 deletions packages/@lwc/aria-reflection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/babel-plugin-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/engine-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/engine-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/engine-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/module-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
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 @@ -37,3 +37,4 @@ export default {
- `disableSyntheticShadowSupport` (type: `boolean`, default: `false`) - Set to true if synthetic shadow DOM support is not needed, which can result in smaller output.
- `apiVersion` (type: `number`, default: `undefined`) - Set to a valid API version such as 58, 59, etc. This will be overriden if the component itself overrides the version with a `*.js-meta.xml` file.
- `enableStaticContentOptimization` (type: `boolean`, optional) - True if the static content optimization should be enabled. Passed to `@lwc/template-compiler`. True by default.
- `targetSSR` (type: `boolean`) - Utilize the experimental SSR compilation mode. False by default. Do not use unless you know what you're doing.
3 changes: 1 addition & 2 deletions packages/@lwc/rollup-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand Down
57 changes: 57 additions & 0 deletions packages/@lwc/shared/src/ecmascript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export const reservedKeywords = new Set([
'NaN',
'arguments',
'break',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'enum',
'eval',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'implements',
'import',
'in',
'instanceof',
'interface',
'let',
'new',
'null',
'package',
'private',
'protected',
'public',
'return',
'static',
'super',
'switch',
'this',
'throw',
'true',
'try',
'typeof',
'undefined',
'var',
'void',
'while',
'with',
'yield',
]);
1 change: 1 addition & 0 deletions packages/@lwc/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as assert from './assert';

export * from './api-version';
export * from './aria';
export * from './ecmascript';
export * from './language';
export * from './keys';
export * from './void-elements';
Expand Down
9 changes: 5 additions & 4 deletions packages/@lwc/ssr-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"version": "6.5.3",
"description": "Compile component for use during server-side rendering",
"keywords": [
"lwc"
"compiler",
"lwc",
"ssr"
],
"homepage": "https://lwc.dev",
"repository": {
Expand All @@ -30,8 +32,7 @@
],
"scripts": {
"build": "rollup --config ../../../scripts/rollup/rollup.config.js",
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen",
"test-manual": "jest ./src/**/*.spec.ts"
"dev": "rollup --config ../../../scripts/rollup/rollup.config.js --watch --no-watch.clearScreen"
},
"nx": {
"targets": {
Expand All @@ -47,7 +48,7 @@
"@lwc/sfdc-compiler-utils": "6.5.3-0",
"@lwc/style-compiler": "6.5.3",
"@lwc/template-compiler": "6.5.3",
"acorn": "~8.10.0",
"acorn": "8.10.0",
"astring": "^1.8.6",
"estree-toolkit": "^1.7.3",
"immer": "^10.0.3",
Expand Down
186 changes: 186 additions & 0 deletions packages/@lwc/ssr-compiler/src/__tests__/estemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { is, builders as b } from 'estree-toolkit';
import { esTemplate, esTemplateWithYield } from '../estemplate';

Object.entries({
esTemplate,
esTemplateWithYield,
}).forEach(([topLevelFnName, topLevelFn]) => {
const yieldStmtsAllowed = topLevelFnName === 'esTemplateWithYield';

describe(topLevelFnName, () => {
describe('failure upon parse', () => {
yieldStmtsAllowed ||
test('with yield statements', () => {
const createTemplate = () => topLevelFn`
const foo = "bar";
yield foo;
`;
expect(createTemplate).toThrow('Unexpected token');
});

test('when attempting to replace unreplaceable code constructs', () => {
// Someone might try to create a template where 'class' or 'function'
// is provided as an argument to the ES template.
const isFunctionOrClass = (node: any) =>
is.functionDeclaration(node) || is.classDeclaration(node);
const createTemplate = () => topLevelFn`
${isFunctionOrClass} classOrFunctionDecl {}
`;
expect(createTemplate).toThrow('Unexpected token');
});

test('syntax errors due to typo', () => {
const createTemplate = () => topLevelFn`
calss MyCmp extends LightningElement {
connectedCallbac() {
console.log('if you see this, calss has been added to the JS language');
}
}
`;
expect(createTemplate).toThrow('Unexpected token');
});
});

describe('failure upon invocation', () => {
test('when replacing incorrect node type', () => {
const tmpl = topLevelFn`
const ${is.identifier} = 'foo';
`;
const doReplacement = () => tmpl(b.literal('I am not an identifier'));
expect(doReplacement).toThrow(
'Validation failed for templated node of type Identifier'
);
});
});

describe('successful replacement', () => {
yieldStmtsAllowed &&
test('with yield statements', () => {
const tmpl = topLevelFn`
yield ${is.literal};
`;
const replacedAst = tmpl(b.literal('foo'));

expect(replacedAst).toMatchObject({
expression: {
argument: {
type: 'Literal',
value: 'foo',
},
delegate: false,
type: 'YieldExpression',
},
type: 'ExpressionStatement',
});
});

test('with LH identifier nodes', () => {
const tmpl = topLevelFn`
const ${is.identifier} = 'foobar'
`;
const replacedAst = tmpl(b.identifier('heyImNewHere'));
expect(replacedAst).toMatchObject({
declarations: [
{
id: {
name: 'heyImNewHere',
type: 'Identifier',
},
init: {
type: 'Literal',
value: 'foobar',
},
type: 'VariableDeclarator',
},
],
kind: 'const',
type: 'VariableDeclaration',
});
});
test('with multiple nodes', () => {
const tmpl = topLevelFn`
const foo = ${is.literal} + ${is.identifier};
fnCall(foo, ${is.objectExpression});
`;
const replacedAst = tmpl(
b.literal(5),
b.identifier('bar'),
b.objectExpression([
b.property('init', b.literal('config'), b.literal('someConfig')),
])
);

expect(replacedAst).toMatchObject([
{
declarations: [
{
id: {
name: 'foo',
type: 'Identifier',
},
init: {
left: {
type: 'Literal',
value: 5,
},
operator: '+',
right: {
name: 'bar',
type: 'Identifier',
},
type: 'BinaryExpression',
},
type: 'VariableDeclarator',
},
],
kind: 'const',
type: 'VariableDeclaration',
},
{
expression: {
arguments: [
{
name: 'foo',
type: 'Identifier',
},
{
properties: [
{
computed: false,
key: {
type: 'Literal',
value: 'config',
},
kind: 'init',
shorthand: false,
type: 'Property',
value: {
type: 'Literal',
value: 'someConfig',
},
},
],
type: 'ObjectExpression',
},
],
callee: {
name: 'fnCall',
type: 'Identifier',
},
optional: false,
type: 'CallExpression',
},
type: 'ExpressionStatement',
},
]);
});
});
});
});
Loading

0 comments on commit 5b2f725

Please sign in to comment.