From 28bac1c48c917dce32a5fd87a94e25f42c9c7692 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 3 Jan 2025 15:22:55 -0800 Subject: [PATCH] fix(ssr): fix constructor with args Fixes #5080 --- .../src/__tests__/utils/expected-failures.ts | 1 - packages/@lwc/ssr-compiler/src/compile-js/index.ts | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/@lwc/ssr-compiler/src/__tests__/utils/expected-failures.ts b/packages/@lwc/ssr-compiler/src/__tests__/utils/expected-failures.ts index d67a49cc5f..383eaefaa4 100644 --- a/packages/@lwc/ssr-compiler/src/__tests__/utils/expected-failures.ts +++ b/packages/@lwc/ssr-compiler/src/__tests__/utils/expected-failures.ts @@ -26,7 +26,6 @@ export const expectedFailures = new Set([ 'slot-not-at-top-level/with-adjacent-text-nodes/lwcIf/light/index.js', 'slot-not-at-top-level/with-adjacent-text-nodes/if/light/index.js', 'slot-not-at-top-level/with-adjacent-text-nodes/if-as-sibling/light/index.js', - 'superclass/with-props/index.js', 'wire/errors/throws-on-computed-key/index.js', 'wire/errors/throws-when-colliding-prop-then-method/index.js', ]); diff --git a/packages/@lwc/ssr-compiler/src/compile-js/index.ts b/packages/@lwc/ssr-compiler/src/compile-js/index.ts index e83f8de2e4..431f91c209 100644 --- a/packages/@lwc/ssr-compiler/src/compile-js/index.ts +++ b/packages/@lwc/ssr-compiler/src/compile-js/index.ts @@ -168,7 +168,11 @@ const visitors: Visitors = { switch (node.key.name) { case 'constructor': - node.value.params = [b.identifier('propsAvailableAtConstruction')]; + // add our own custom arg after any pre-existing constructor args + node.value.params = [ + ...structuredClone(node.value.params), + b.identifier('propsAvailableAtConstruction'), + ]; break; case 'connectedCallback': state.hasConnectedCallback = true; @@ -196,7 +200,11 @@ const visitors: Visitors = { path.parentPath && path.parentPath.node?.type === 'CallExpression' ) { - path.parentPath.node.arguments = [b.identifier('propsAvailableAtConstruction')]; + // add our own custom arg after any pre-existing super() args + path.parentPath.node.arguments = [ + ...structuredClone(path.parentPath.node.arguments), + b.identifier('propsAvailableAtConstruction'), + ]; } }, Program: {