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): fix constructor with args #5094

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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