From f2330391ebb3a3b1ded9409d6278b959f0bbb969 Mon Sep 17 00:00:00 2001 From: James Tu Date: Wed, 13 Nov 2024 10:48:42 -0800 Subject: [PATCH 1/3] feat: remove decorator imports visitor (#4840) * feat: remove decorator imports visitor * Update packages/@lwc/ssr-compiler/src/compile-js/remove-decorator-import.ts Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com> --------- Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com> --- .../@lwc/ssr-compiler/src/compile-js/index.ts | 2 ++ .../src/compile-js/remove-decorator-import.ts | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packages/@lwc/ssr-compiler/src/compile-js/remove-decorator-import.ts diff --git a/packages/@lwc/ssr-compiler/src/compile-js/index.ts b/packages/@lwc/ssr-compiler/src/compile-js/index.ts index 20ba9b89b7..c05c8f3014 100644 --- a/packages/@lwc/ssr-compiler/src/compile-js/index.ts +++ b/packages/@lwc/ssr-compiler/src/compile-js/index.ts @@ -16,6 +16,7 @@ import { catalogStaticStylesheets, catalogAndReplaceStyleImports } from './style import { addGenerateMarkupExport, assignGenerateMarkupToComponent } from './generate-markup'; import { catalogWireAdapters } from './wire'; +import { removeDecoratorImport } from './remove-decorator-import'; import type { Identifier as EsIdentifier, Program as EsProgram, Expression } from 'estree'; import type { Visitors, ComponentMetaState } from './types'; import type { CompilationMode } from '../shared'; @@ -34,6 +35,7 @@ const visitors: Visitors = { replaceLwcImport(path, state); catalogTmplImport(path, state); catalogAndReplaceStyleImports(path, state); + removeDecoratorImport(path); }, ClassDeclaration(path, state) { if (!path.node?.superClass) { diff --git a/packages/@lwc/ssr-compiler/src/compile-js/remove-decorator-import.ts b/packages/@lwc/ssr-compiler/src/compile-js/remove-decorator-import.ts new file mode 100644 index 0000000000..41d8c14d7f --- /dev/null +++ b/packages/@lwc/ssr-compiler/src/compile-js/remove-decorator-import.ts @@ -0,0 +1,29 @@ +/* + * 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 { ImportDeclaration } from 'estree'; +import { NodePath, builders as b } from 'estree-toolkit'; + +export function removeDecoratorImport(path: NodePath) { + if (!path.node || path.node.source.value !== '@lwc/ssr-runtime') { + return; + } + + const filteredSpecifiers = path.node.specifiers.filter( + (specifier) => + !( + specifier.type === 'ImportSpecifier' && + specifier.imported.type === 'Identifier' && + // Excluding track because it also has a non-decorator signature that might be used + (specifier.imported.name === 'api' || specifier.imported.name === 'wire') + ) + ); + + if (filteredSpecifiers.length !== path.node.specifiers.length) { + path.replaceWith(b.importDeclaration(filteredSpecifiers, b.literal('@lwc/ssr-runtime'))); + } +} From 29a641e2f572b20e015546d398e50a129123f6d9 Mon Sep 17 00:00:00 2001 From: Eugene Kashida Date: Wed, 13 Nov 2024 12:00:47 -0800 Subject: [PATCH 2/3] chore: remove deprecated contextmenu html global attribute (#4834) --- packages/@lwc/babel-plugin-component/src/constants.ts | 1 - .../as-component-prop/undeclared/expected.html | 5 +---- .../as-component-prop/undeclared/modules/x/child/child.html | 1 - .../undeclared/modules/x/component/component.html | 1 - .../as-component-prop/with-@api/expected.html | 5 +---- .../as-component-prop/with-@api/modules/x/child/child.html | 1 - .../as-component-prop/with-@api/modules/x/child/child.js | 1 - .../with-@api/modules/x/component/component.html | 1 - .../as-component-prop/without-@api/expected.html | 5 +---- .../without-@api/modules/x/child/child.html | 1 - .../as-component-prop/without-@api/modules/x/child/child.js | 1 - .../without-@api/modules/x/component/component.html | 1 - packages/@lwc/shared/src/html-attributes.ts | 1 - 13 files changed, 3 insertions(+), 22 deletions(-) diff --git a/packages/@lwc/babel-plugin-component/src/constants.ts b/packages/@lwc/babel-plugin-component/src/constants.ts index 624276a4e5..f8be05db9f 100644 --- a/packages/@lwc/babel-plugin-component/src/constants.ts +++ b/packages/@lwc/babel-plugin-component/src/constants.ts @@ -14,7 +14,6 @@ const AMBIGUOUS_PROP_SET = new Map([ ['bgcolor', 'bgColor'], ['accesskey', 'accessKey'], ['contenteditable', 'contentEditable'], - ['contextmenu', 'contextMenu'], ['tabindex', 'tabIndex'], ['maxlength', 'maxLength'], ['maxvalue', 'maxValue'], diff --git a/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-global-html/as-component-prop/undeclared/expected.html b/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-global-html/as-component-prop/undeclared/expected.html index fd5b663233..e421b7fc85 100644 --- a/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-global-html/as-component-prop/undeclared/expected.html +++ b/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-global-html/as-component-prop/undeclared/expected.html @@ -1,6 +1,6 @@