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): update wire adapter validation @ W-17274788 #4910

Merged
merged 13 commits into from
Nov 21, 2024
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<x-wire>
<template shadowrootmode="open">
Wire adapter value: {
: ,
0: 0,
variable: 4404,
prop: not magic,
array: [
value
],
fakeMagic: [
$cmpProp,
$ string in arrays aren&#x27;t magic
],
true: true,
array: [value],
fakeMagic: [$cmpProp,$ string in arrays aren&#x27;t magic],
false: false,
null: null,
Infinity: null,
magic: 123,
NaN: null,
: ,
magic: 123
null: null,
prop: not magic,
true: true,
undefined: undefined,
variable: 4404,
why: undefined,
}
</template>
</x-wire>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export class adapter {
connect() {}

update(config) {
// Quotes are encoded in the output, which is ugly
this.dc(JSON.stringify(config, null, 4).replace(/"/g, ''));
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
const output = Object.entries(config)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
.join('\n')
// Quotes are encoded as &quot; in the output, which makes it harder to read...
.replace(/"/g, '');

this.dc(`{\n${output}\n}`);
}

disconnect() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<x-wire>
<template shadowrootmode="open">
wired field value: {
key2: [
fixed,
array
],
key1: foo
key1: foo,
key2: [fixed,array],
}
</template>
</x-wire>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export default class adapter {
connect() {}

update(config) {
// Quotes are encoded in the output, which is ugly
this.dc(JSON.stringify(config, null, 4).replace(/"/g, ''));
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
const output = Object.entries(config)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
.join('\n')
// Quotes are encoded as &quot; in the output, which makes it harder to read...
.replace(/"/g, '');

this.dc(`{\n${output}\n}`);
}

disconnect() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<x-wire>
<template shadowrootmode="open">
wired field value: {
key2: [
fixed,
array
],
key1: foo
key1: foo,
key2: [fixed,array],
}
</template>
</x-wire>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export default class adapter {
connect() {}

update(config) {
// Quotes are encoded in the output, which is ugly
this.dc(JSON.stringify(config, null, 4).replace(/"/g, ''));
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
const output = Object.entries(config)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
.join('\n')
// Quotes are encoded as &quot; in the output, which makes it harder to read...
.replace(/"/g, '');

this.dc(`{\n${output}\n}`);
}

disconnect() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,4 @@ export const expectedFailures = new Set([
'slot-not-at-top-level/lwcIf/light/index.js',
'slot-not-at-top-level/lwcIf/shadow/index.js',
'svgs/index.js',
'wire/config/index.js',
'wire/deep-reference/index.js',
'wire/field/index.js',
'wire/imported-member/index.js',
'wire/method/index.js',
]);
4 changes: 2 additions & 2 deletions packages/@lwc/ssr-compiler/src/compile-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const visitors: Visitors = {
is.identifier(decoratedExpression.callee) &&
decoratedExpression.callee.name === 'wire'
) {
catalogWireAdapters(state, node);
catalogWireAdapters(path, state);
state.privateFields.push(node.key.name);
} else {
state.privateFields.push(node.key.name);
Expand Down Expand Up @@ -111,7 +111,7 @@ const visitors: Visitors = {
is.identifier(decoratedExpression.callee) &&
decoratedExpression.callee.name === 'wire'
) {
catalogWireAdapters(state, node);
catalogWireAdapters(path, state);
}

switch (node.key.name) {
Expand Down
19 changes: 11 additions & 8 deletions packages/@lwc/ssr-compiler/src/compile-js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
*/

import type { traverse } from 'estree-toolkit';
import type { Node } from 'estree';
import type {
Identifier,
MemberExpression,
MethodDefinition,
Node,
ObjectExpression,
PropertyDefinition,
} from 'estree';

export type Visitors = Parameters<typeof traverse<Node, ComponentMetaState>>[1];

export interface WireAdapter {
fieldName: string;
adapterConstructorId: string;
config: Array<{
configKey: string;
referencedField: string;
}>;
fieldType: 'property' | 'method';
adapterId: Identifier | MemberExpression;
config: ObjectExpression;
field: MethodDefinition | PropertyDefinition;
}

export interface ComponentMetaState {
Expand Down
Loading