Skip to content

Commit

Permalink
fix(ssr): fix constructor with args
Browse files Browse the repository at this point in the history
Fixes #5080
  • Loading branch information
nolanlawson committed Jan 3, 2025
1 parent cc7f1b0 commit 28bac1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
12 changes: 10 additions & 2 deletions packages/@lwc/ssr-compiler/src/compile-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 28bac1c

Please sign in to comment.