@openelement/compiler 1.0.0-alpha.15 → 1.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/compiler.d.ts +8 -6
- package/src/compiler.js +7 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +5 -30
- package/src/internal/compiler/compiled-artifact-class-candidates.js +18 -32
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +9 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +9 -7
- package/src/internal/compiler/plugin.d.ts +31 -50
- package/src/internal/compiler/plugin.js +41 -108
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +1 -45
- package/src/internal/compiler/semantic-core/analyze-module.js +10 -405
- package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
- package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
- package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
- package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
- package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
- package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
- package/src/internal/compiler/semantic-core/lower-program.d.ts +51 -0
- package/src/internal/compiler/semantic-core/lower-program.js +186 -90
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +28 -5
- package/src/internal/compiler/semantic-core/module-analysis.js +16 -17
- package/src/internal/compiler/semantic-core/parse-module.js +16 -16
- package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
- package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
- package/src/internal/compiler/semantic-core/server-component.d.ts +22 -7
- package/src/internal/compiler/semantic-core/server-component.js +163 -57
- package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
- package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
- package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
- package/src/internal/compiler/style-requests.d.ts +0 -8
- package/src/internal/compiler/style-requests.js +1 -14
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -47
- package/src/internal/compiler/semantic-core/compile.js +0 -100
- package/src/internal/compiler/semantic-core/emit-module.js +0 -317
- package/src/internal/compiler/semantic-core/emit-program.js +0 -141
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import { BOOLEAN_ATTRIBUTES } from "../../semantic-core/attribute-classification.js";
|
|
2
|
+
import { ADMITTED_ATTRIBUTE_CHANNELS, ATTRIBUTE_PATTERN, CLIENT_ONLY_ATTRIBUTE_CHANNELS, CONSUMED_ATTRIBUTE_CHANNELS, IDENTIFIER_PATTERN, INTERNAL_PREFIX, MOUNT_HOST, MOUNT_PROPS, MOUNT_SCOPE, SSR_CHILDREN_RENDER, SSR_HELPER_PREFIX, SSR_SUFFIX, TAG_PATTERN, componentPropAdmitted, declareReads, diag, fragmentLineCount, nextName, push, pushParts, recordFor } from "./emission.js";
|
|
3
|
+
import { assertTextBoundaryContext, componentProjectsChildren, declaredRecipeIdSet, directoryParentAllowed, emissionNodes, lightSlotAnchorsEnabled, normalizeTextRuns, referencedRecipeIds, slotNameOf, ssrSlotAnchorOrdinals, staticElementDirectory, textOrdinal, textSlotOrdinals, treeHasComposition } from "./structure.js";
|
|
4
|
+
import { GENERATED_CONTEXT_SCOPE_RECORD, SSR_CONTEXT_PARAM, componentNeedsSsrContextScope, componentUsesContextIntrinsic, emitContextProviders, emitSetupBinding, emitSsrContextScope } from "./instance-emission.js";
|
|
5
|
+
import { VOID_TAGS } from "@openelement/protocol/part-program";
|
|
6
|
+
import { unsafeStreamFrameAttribute } from "@openelement/protocol/stream-frame-policy";
|
|
7
|
+
//#region src/internal/compiler/semantic-ir/generated-leaf/server-emission.ts
|
|
8
|
+
/**
|
|
9
|
+
* SSR producer, static slice (M08-1a).
|
|
10
|
+
*
|
|
11
|
+
* A claimable component whose roots are fully static also emits `<Name>__ssr()`,
|
|
12
|
+
* which returns the HTML the mount would build — at compile time, because a
|
|
13
|
+
* static subtree's bytes are known then. The point is the pairing: a generated
|
|
14
|
+
* module that can claim existing DOM can now also produce that DOM, which is
|
|
15
|
+
* the precondition for the M08 SSR→claim parity proof.
|
|
16
|
+
*
|
|
17
|
+
* Boundary of this slice: dynamic text/attribute/property slots, conditions,
|
|
18
|
+
* lists, component references and insertion sites return `null`, so no `__ssr`
|
|
19
|
+
* is emitted for them. Slice M08-1b adds the admitted dynamic slots; the
|
|
20
|
+
* void-element slice admits canonical `VOID_TAGS` as a start tag + attributes
|
|
21
|
+
* with no close tag. For every other shape the absence of `__ssr` is the honest
|
|
22
|
+
* shape of "this component is not SSR-producible yet".
|
|
23
|
+
*
|
|
24
|
+
* Escaping is NOT re-implemented here: the emitted code calls the runtime's
|
|
25
|
+
* `escapeText` / `escapeAttrValue`, which are the same contract the serializers
|
|
26
|
+
* use. A second escape table in the compiler would be exactly the drift P6
|
|
27
|
+
* forbids.
|
|
28
|
+
*/
|
|
29
|
+
function staticSsrDirectory(ranges, slots) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
for (const [ordinal, range] of ranges.entries()) {
|
|
32
|
+
const inner = staticSsrNode(range, false, slots);
|
|
33
|
+
if (inner === null) return null;
|
|
34
|
+
parts.push(`"<!--" + markerText(rangeMarker(${ordinal})) + "-->"`, inner, `"<!--" + markerText(rangeMarker(${ordinal}, true)) + "-->"`);
|
|
35
|
+
}
|
|
36
|
+
return parts.length === 0 ? "\"\"" : parts.join(" + ");
|
|
37
|
+
}
|
|
38
|
+
function staticSsrExpression(nodes, markers, slots) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
for (const node of normalizeTextRuns(nodes)) {
|
|
41
|
+
const part = staticSsrNode(node, markers, slots);
|
|
42
|
+
if (part === null) return null;
|
|
43
|
+
parts.push(part);
|
|
44
|
+
}
|
|
45
|
+
return parts.length === 0 ? "\"\"" : parts.join(" + ");
|
|
46
|
+
}
|
|
47
|
+
function literalText(value) {
|
|
48
|
+
return JSON.stringify(value);
|
|
49
|
+
}
|
|
50
|
+
function staticSsrNode(node, markers, slots) {
|
|
51
|
+
if (node.kind === "text") return `escapeText(${literalText(node.value)})`;
|
|
52
|
+
if (node.kind === "fragment") return staticSsrExpression(node.children, markers, slots);
|
|
53
|
+
if (node.kind !== "element") return null;
|
|
54
|
+
if (!TAG_PATTERN.test(node.tag)) return null;
|
|
55
|
+
if (node.tag.includes("-")) return null;
|
|
56
|
+
const isVoid = VOID_TAGS.has(node.tag);
|
|
57
|
+
if (isVoid && node.children.length > 0) return null;
|
|
58
|
+
const attributes = [];
|
|
59
|
+
for (const attribute of node.attributes) {
|
|
60
|
+
if (attribute.kind === "dynamic" && CLIENT_ONLY_ATTRIBUTE_CHANNELS.has(attribute.channel)) continue;
|
|
61
|
+
if (attribute.kind !== "static") return null;
|
|
62
|
+
if (unsafeStreamFrameAttribute(attribute.name, attribute.value)) return null;
|
|
63
|
+
const staticValue = BOOLEAN_ATTRIBUTES.has(attribute.name.toLowerCase()) ? "" : attribute.value;
|
|
64
|
+
attributes.push([
|
|
65
|
+
"\" \"",
|
|
66
|
+
literalText(`${attribute.name}="`),
|
|
67
|
+
`escapeAttrValue(${literalText(staticValue)})`,
|
|
68
|
+
literalText("\"")
|
|
69
|
+
].join(" + "));
|
|
70
|
+
}
|
|
71
|
+
const open = `"<${node.tag}"`;
|
|
72
|
+
if (isVoid) return [
|
|
73
|
+
open,
|
|
74
|
+
...attributes,
|
|
75
|
+
"\">\""
|
|
76
|
+
].join(" + ");
|
|
77
|
+
const directory = markers ? staticElementDirectory(node.children) : null;
|
|
78
|
+
const children = directory === null ? staticSsrExpression(node.children, markers, slots) : staticSsrDirectory(directory, slots);
|
|
79
|
+
if (children === null) return null;
|
|
80
|
+
const close = `"</${node.tag}>"`;
|
|
81
|
+
if (node.tag !== "slot" || slots === null) return [
|
|
82
|
+
open,
|
|
83
|
+
...attributes,
|
|
84
|
+
"\">\"",
|
|
85
|
+
children,
|
|
86
|
+
close
|
|
87
|
+
].join(" + ");
|
|
88
|
+
const ordinal = slots.get(node);
|
|
89
|
+
const name = ordinal === void 0 ? null : slotNameOf(node);
|
|
90
|
+
if (name === null || ordinal === void 0) return [
|
|
91
|
+
open,
|
|
92
|
+
...attributes,
|
|
93
|
+
"\">\"",
|
|
94
|
+
children,
|
|
95
|
+
close
|
|
96
|
+
].join(" + ");
|
|
97
|
+
return [
|
|
98
|
+
open,
|
|
99
|
+
...attributes,
|
|
100
|
+
"\">\"",
|
|
101
|
+
`"<!--" + markerText(slotAnchorMarker(${ordinal}, ${literalText(name)})) + "-->"`,
|
|
102
|
+
children,
|
|
103
|
+
`"<!--" + markerText(slotAnchorMarker(${ordinal}, ${literalText(name)}, true)) + "-->"`,
|
|
104
|
+
close
|
|
105
|
+
].join(" + ");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A fresh `EmitState` for SSR. SSR uses only the expression placement/segment
|
|
109
|
+
* machinery and the binding declaration; the mount-only fields stay inert.
|
|
110
|
+
*/
|
|
111
|
+
function ssrEmitState(component, file, propsName, componentByName, projectsChildren) {
|
|
112
|
+
return {
|
|
113
|
+
component,
|
|
114
|
+
lines: [],
|
|
115
|
+
physicalLine: 0,
|
|
116
|
+
indent: 1,
|
|
117
|
+
diagnostics: [],
|
|
118
|
+
requiredBindings: /* @__PURE__ */ new Set(),
|
|
119
|
+
requiredProps: /* @__PURE__ */ new Set(),
|
|
120
|
+
hostBindings: /* @__PURE__ */ new Set(),
|
|
121
|
+
localResources: /* @__PURE__ */ new Set(),
|
|
122
|
+
counter: { value: 0 },
|
|
123
|
+
propsName,
|
|
124
|
+
requiresPropsChanged: false,
|
|
125
|
+
segments: [],
|
|
126
|
+
placements: [],
|
|
127
|
+
segmentKeys: /* @__PURE__ */ new Set(),
|
|
128
|
+
scopeVar: MOUNT_SCOPE,
|
|
129
|
+
hostVar: MOUNT_HOST,
|
|
130
|
+
componentByName,
|
|
131
|
+
declaredRecipeIds: declaredRecipeIdSet(component),
|
|
132
|
+
recipeNames: /* @__PURE__ */ new Set(),
|
|
133
|
+
recipeVars: /* @__PURE__ */ new Map(),
|
|
134
|
+
entryNames: /* @__PURE__ */ new Set(),
|
|
135
|
+
refreshStack: [],
|
|
136
|
+
listDepth: 0,
|
|
137
|
+
recipeDepth: 0,
|
|
138
|
+
childrenRecipeVar: null,
|
|
139
|
+
ssrRecipeVars: /* @__PURE__ */ new Map(),
|
|
140
|
+
ssrChildrenRenderVar: projectsChildren ? SSR_CHILDREN_RENDER : null,
|
|
141
|
+
directorySource: `${file}#${component.name}`,
|
|
142
|
+
usesStaticSiblingDirectoryConsumer: false,
|
|
143
|
+
claimCursorShared: false,
|
|
144
|
+
claimStyleLinkPrefix: false,
|
|
145
|
+
claimAdoptedVar: null,
|
|
146
|
+
claimActivationVar: null,
|
|
147
|
+
usesClaimRecipe: false,
|
|
148
|
+
emitDirectoryMarkers: false,
|
|
149
|
+
emitTextBoundaries: true,
|
|
150
|
+
textOrdinals: textSlotOrdinals(component.roots),
|
|
151
|
+
claimEntry: null,
|
|
152
|
+
usesLeafClaimMismatch: false,
|
|
153
|
+
retention: null,
|
|
154
|
+
retainBody: false,
|
|
155
|
+
leafBody: false,
|
|
156
|
+
retainsChildren: false,
|
|
157
|
+
claimTimeRecipeDepth: 0
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function failedSsr(state) {
|
|
161
|
+
return {
|
|
162
|
+
lines: [],
|
|
163
|
+
diagnostics: state.diagnostics,
|
|
164
|
+
segments: [],
|
|
165
|
+
placements: []
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* One request-time attribute fragment. `channel` is admitted by the leaf claim
|
|
170
|
+
* boundary, so `attribute`/`boolean` are the only dynamic non-static channels
|
|
171
|
+
* that can reach this emitter.
|
|
172
|
+
*/
|
|
173
|
+
function emitSsrDynamicAttribute(state, attribute, outVar, records, pairsVar, slotCaptureVar, valueCaptureVar) {
|
|
174
|
+
if (CLIENT_ONLY_ATTRIBUTE_CHANNELS.has(attribute.channel)) return false;
|
|
175
|
+
if (!ADMITTED_ATTRIBUTE_CHANNELS.has(attribute.channel)) return false;
|
|
176
|
+
const record = recordFor(state, attribute.expression, records);
|
|
177
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
178
|
+
const literal = JSON.stringify(attribute.name);
|
|
179
|
+
if (attribute.channel === "boolean") {
|
|
180
|
+
if (pairsVar !== void 0) {
|
|
181
|
+
pushParts(state, [
|
|
182
|
+
`if (Boolean((`,
|
|
183
|
+
{ record },
|
|
184
|
+
`))) { ${outVar}.push(${JSON.stringify(` ${attribute.name}=""`)}); ${pairsVar}.push([${literal}, ${JSON.stringify("")}]); }`
|
|
185
|
+
], attribute.span);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
pushParts(state, [
|
|
189
|
+
`if (Boolean((`,
|
|
190
|
+
{ record },
|
|
191
|
+
`))) ${outVar}.push(${JSON.stringify(` ${attribute.name}=""`)});`
|
|
192
|
+
], attribute.span);
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (attribute.channel !== "attribute" && attribute.channel !== "property") return false;
|
|
196
|
+
const valueVar = nextName(state, "value");
|
|
197
|
+
pushParts(state, [
|
|
198
|
+
`const ${valueVar} = attributeValueOf((`,
|
|
199
|
+
{ record },
|
|
200
|
+
"));"
|
|
201
|
+
], attribute.span);
|
|
202
|
+
if (valueCaptureVar !== void 0) push(state, `${valueCaptureVar} = ${valueVar};`, attribute.span);
|
|
203
|
+
if (slotCaptureVar !== void 0 && attribute.name.toLowerCase() === "slot") push(state, `${slotCaptureVar} = ${valueVar} ?? \"\";`, attribute.span);
|
|
204
|
+
push(state, `if (${valueVar} !== null) {`, attribute.span);
|
|
205
|
+
push(state, ` assertSafeUrlAttribute(${literal}, ${valueVar});`, attribute.span);
|
|
206
|
+
push(state, ` ${outVar}.push(${JSON.stringify(` ${attribute.name}="`)}, escapeAttrValue(${valueVar}), ${JSON.stringify("\"")});`, attribute.span);
|
|
207
|
+
if (pairsVar !== void 0) push(state, ` ${pairsVar}.push([${literal}, ${valueVar}]);`, attribute.span);
|
|
208
|
+
push(state, `}`, attribute.span);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* M08 composition SSR — one component reference. The emitted call uses the
|
|
213
|
+
* SAME model component map and the SAME per-read props record the mount builds:
|
|
214
|
+
* a fresh `{ get name() { return <lowered record>; } }` object at this call
|
|
215
|
+
* site, never a cached value. The child body is emitted once per module
|
|
216
|
+
* (`<Child>__ssr`), so two references with different props call one function
|
|
217
|
+
* twice and each call evaluates its own record.
|
|
218
|
+
*
|
|
219
|
+
* A children-projecting target is called through its module-local
|
|
220
|
+
* `__oe_ssrComponent_<Child>` helper with the children recipe's render function as the
|
|
221
|
+
* third argument; that function is the one referenced-recipe helper, so a
|
|
222
|
+
* child projecting twice calls it twice. A reference with JSX children to a
|
|
223
|
+
* child that ignores them passes no renderer, exactly like mount's unused
|
|
224
|
+
* children channel.
|
|
225
|
+
*/
|
|
226
|
+
function emitSsrComponentRef(state, node, outVar, records) {
|
|
227
|
+
const span = node.span;
|
|
228
|
+
if (state.listDepth > 0) {
|
|
229
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_COMPONENT", `component '<${node.name}>' inside a list entry template needs the child update hook (M06b1b); a keyed reuse would keep the first mount's props`, span);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const target = state.componentByName.get(node.name);
|
|
233
|
+
if (target === void 0) {
|
|
234
|
+
diag(state, "OEIR_LEAF_UNKNOWN_COMPONENT", `component '<${node.name}>' is not declared in this module (external components are M06b2)`, span);
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
if (target.propsParam === null) {
|
|
238
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_COMPONENT", `component '<${node.name}>' has no named props parameter (destructured or absent); component references need a named props parameter (M06b2 owns destructuring)`, span);
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (target.resources.filter((resource) => resource.kind === "signal" || resource.kind === "computed").length > 0) {
|
|
242
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_COMPONENT", `component '<${node.name}>' owns signal/computed resources; a child instance cannot resolve host bindings without sharing the parent instance (M06b2/M07 own it)`, span);
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
if (node.childrenRecipeId !== null && state.recipeDepth > 0) {
|
|
246
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_CHILDREN", `children on '<${node.name}>' inside a reusable JSX value body are outside the M06b2a slice: the children recipe would be created once per component mount, but its definition owner is the recipe instance scope (created per insertion)`, span);
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (node.childrenRecipeId === null && componentProjectsChildren(target)) {
|
|
250
|
+
diag(state, "OEIR_LEAF_MISSING_CHILDREN", `component '<${node.name}>' projects props.children but this reference passes no JSX children; every projection needs a children recipe`, span);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
const childrenRenderVar = node.childrenRecipeId === null ? null : state.ssrRecipeVars.get(node.childrenRecipeId) ?? null;
|
|
254
|
+
if (node.childrenRecipeId !== null && childrenRenderVar === null) {
|
|
255
|
+
diag(state, "OEIR_LEAF_MISSING_RECIPE", `children recipe '${node.childrenRecipeId}' of '<${node.name}>' has no emitted SSR render function (it is not reachable from any admitted root)`, span);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
const admitted = [];
|
|
259
|
+
let refused = false;
|
|
260
|
+
for (const attribute of node.props) {
|
|
261
|
+
if (attribute.name === "key") continue;
|
|
262
|
+
if (attribute.name === "children") {
|
|
263
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_COMPONENT", `'children' on component '<${node.name}>' must be authored as JSX children, not a prop value: it is the recipe projection channel (JSX value model §4.4)`, span);
|
|
264
|
+
refused = true;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (!componentPropAdmitted(state, attribute, node.name, span)) {
|
|
268
|
+
refused = true;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
admitted.push(attribute);
|
|
272
|
+
}
|
|
273
|
+
if (refused) return false;
|
|
274
|
+
const resolved = [];
|
|
275
|
+
for (const prop of admitted) {
|
|
276
|
+
if (prop.kind === "static") {
|
|
277
|
+
resolved.push(prop);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const record = recordFor(state, prop.expression, records);
|
|
281
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
282
|
+
resolved.push({
|
|
283
|
+
kind: "dynamic",
|
|
284
|
+
name: prop.name,
|
|
285
|
+
record,
|
|
286
|
+
span: prop.span
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
let propsExpr = "{}";
|
|
290
|
+
if (resolved.length > 0) {
|
|
291
|
+
const id = state.counter.value++;
|
|
292
|
+
const propsVar = `${INTERNAL_PREFIX}childProps${id}`;
|
|
293
|
+
push(state, `const ${propsVar} = {`, span);
|
|
294
|
+
state.indent += 1;
|
|
295
|
+
for (const prop of resolved) {
|
|
296
|
+
const key = IDENTIFIER_PATTERN.test(prop.name) ? prop.name : JSON.stringify(prop.name);
|
|
297
|
+
if (prop.kind === "static") {
|
|
298
|
+
push(state, `${key}: ${JSON.stringify(prop.value)},`);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
pushParts(state, [
|
|
302
|
+
`get ${key}() { return (`,
|
|
303
|
+
{ record: prop.record },
|
|
304
|
+
"); },"
|
|
305
|
+
], prop.span);
|
|
306
|
+
}
|
|
307
|
+
state.indent -= 1;
|
|
308
|
+
push(state, "};");
|
|
309
|
+
propsExpr = propsVar;
|
|
310
|
+
}
|
|
311
|
+
const childScopeArg = componentNeedsSsrContextScope(target, state.componentByName) ? `, ${GENERATED_CONTEXT_SCOPE_RECORD}` : "";
|
|
312
|
+
if (componentProjectsChildren(target)) {
|
|
313
|
+
if (childrenRenderVar === null) return false;
|
|
314
|
+
push(state, `${outVar}.push(${SSR_HELPER_PREFIX}${target.name}(${propsExpr}, ${state.hostVar}, ${childrenRenderVar}${childScopeArg}));`, span);
|
|
315
|
+
} else push(state, `${outVar}.push(${node.name}${SSR_SUFFIX}(${propsExpr}, ${state.hostVar}${childScopeArg}));`, span);
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* M08 composition SSR — one module-local render function per referenced
|
|
320
|
+
* reusable-JSX/children recipe. All function names are published before any
|
|
321
|
+
* body is emitted so a site inside another recipe body can reference any
|
|
322
|
+
* recipe (the mount graph is acyclic, so this cannot recurse unboundedly).
|
|
323
|
+
* Each helper is its own text/ordinal chunk, matching the mount recipe body and
|
|
324
|
+
* the claim-time recipe chunk.
|
|
325
|
+
*/
|
|
326
|
+
function emitSsrRecipeHelpers(state, records) {
|
|
327
|
+
const referenced = referencedRecipeIds(state.component);
|
|
328
|
+
if (referenced.size === 0) return true;
|
|
329
|
+
const plans = [];
|
|
330
|
+
for (const recipe of state.component.recipes) {
|
|
331
|
+
if (!referenced.has(recipe.id)) continue;
|
|
332
|
+
const name = nextName(state, "ssrRecipe");
|
|
333
|
+
state.ssrRecipeVars.set(recipe.id, name);
|
|
334
|
+
plans.push({
|
|
335
|
+
recipe,
|
|
336
|
+
name
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
for (const plan of plans) {
|
|
340
|
+
const outerOrdinals = state.textOrdinals;
|
|
341
|
+
const prepared = normalizeTextRuns([plan.recipe.target]);
|
|
342
|
+
state.textOrdinals = textSlotOrdinals(prepared);
|
|
343
|
+
if (!assertTextBoundaryContext(state, prepared)) {
|
|
344
|
+
state.textOrdinals = outerOrdinals;
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
push(state, `function ${plan.name}() {`, plan.recipe.span);
|
|
348
|
+
state.indent += 1;
|
|
349
|
+
const outVar = nextName(state, "ssrOut");
|
|
350
|
+
push(state, `const ${outVar} = [];`);
|
|
351
|
+
const outerDepth = state.recipeDepth;
|
|
352
|
+
state.recipeDepth = outerDepth + 1;
|
|
353
|
+
const emitted = emitDynamicSsrNodes(state, prepared, outVar, true, records, null);
|
|
354
|
+
state.recipeDepth = outerDepth;
|
|
355
|
+
state.textOrdinals = outerOrdinals;
|
|
356
|
+
if (!emitted) return false;
|
|
357
|
+
push(state, `return ${outVar}.join("");`);
|
|
358
|
+
state.indent -= 1;
|
|
359
|
+
push(state, "}");
|
|
360
|
+
}
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Walk the admitted M08-1b tree into `outVar`. Returns false for any shape
|
|
365
|
+
* outside the dynamic leaf slice; the caller then emits no `__ssr` rather than
|
|
366
|
+
* a partial producer. The marker rule mirrors `staticSsrNode`: a range
|
|
367
|
+
* interior recurses with markers suppressed, so the SSR output is what the
|
|
368
|
+
* M07b directory parser accepts.
|
|
369
|
+
*/
|
|
370
|
+
function staticCompositionSlotName(node) {
|
|
371
|
+
if (node.kind !== "element") return "";
|
|
372
|
+
const slot = node.attributes.find((attribute) => attribute.name.toLowerCase() === "slot");
|
|
373
|
+
return slot === void 0 ? "" : slot.kind === "static" ? slot.value : null;
|
|
374
|
+
}
|
|
375
|
+
function emitDynamicSsrNodes(state, nodes, outVar, markers, records, slots, slotCaptureVar, formContext, composition) {
|
|
376
|
+
const list = state.emitTextBoundaries ? normalizeTextRuns(nodes) : nodes;
|
|
377
|
+
for (const node of list) {
|
|
378
|
+
if (composition !== void 0 && node.kind !== "fragment" && node.kind !== "condition" && node.kind !== "list") {
|
|
379
|
+
const childHtmlVar = nextName(state, "nestedChild");
|
|
380
|
+
const childSlotVar = nextName(state, "nestedChildSlot");
|
|
381
|
+
const staticSlot = staticCompositionSlotName(node);
|
|
382
|
+
push(state, `const ${childHtmlVar} = [];`, node.span);
|
|
383
|
+
push(state, `let ${childSlotVar} = ${staticSlot === null ? "\"\"" : literalText(staticSlot)};`, node.span);
|
|
384
|
+
if (!emitDynamicSsrNodes(state, [node], childHtmlVar, markers, records, slots, childSlotVar, formContext)) return false;
|
|
385
|
+
const childHtmlTextVar = nextName(state, "nestedChildText");
|
|
386
|
+
push(state, `const ${childHtmlTextVar} = ${childHtmlVar}.join("");`, node.span);
|
|
387
|
+
push(state, `${outVar}.push(${childHtmlTextVar});`, node.span);
|
|
388
|
+
push(state, `${composition.groups}.push([${childSlotVar}, ${childHtmlTextVar}]);`, node.span);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (node.kind === "text") {
|
|
392
|
+
if (formContext?.optionText !== void 0) push(state, `${formContext.optionText}.push(${literalText(node.value)});`, node.span);
|
|
393
|
+
push(state, `${outVar}.push(escapeText(${literalText(node.value)}));`, node.span);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (node.kind === "fragment") {
|
|
397
|
+
if (!emitDynamicSsrNodes(state, node.children, outVar, markers, records, slots, slotCaptureVar, formContext, composition)) return false;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (node.kind === "dynamic-text") {
|
|
401
|
+
const record = recordFor(state, node.expression, records);
|
|
402
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
403
|
+
const ordinal = textOrdinal(state, node);
|
|
404
|
+
if (ordinal === null) return false;
|
|
405
|
+
const optionTextCaptureVar = formContext?.optionText;
|
|
406
|
+
const textValueVar = optionTextCaptureVar === void 0 ? void 0 : nextName(state, "ssrTextValue");
|
|
407
|
+
if (textValueVar !== void 0) {
|
|
408
|
+
pushParts(state, [
|
|
409
|
+
`const ${textValueVar} = displayValue((`,
|
|
410
|
+
{ record },
|
|
411
|
+
"));"
|
|
412
|
+
], node.span);
|
|
413
|
+
push(state, `${optionTextCaptureVar}.push(${textValueVar});`, node.span);
|
|
414
|
+
}
|
|
415
|
+
push(state, `${outVar}.push("<!--", markerText(textSlotMarker(${ordinal})), "-->");`, node.span);
|
|
416
|
+
if (textValueVar !== void 0) push(state, `${outVar}.push(escapeText(${textValueVar}));`, node.span);
|
|
417
|
+
else pushParts(state, [
|
|
418
|
+
`${outVar}.push(escapeText(displayValue((`,
|
|
419
|
+
{ record },
|
|
420
|
+
"))));"
|
|
421
|
+
], node.span);
|
|
422
|
+
push(state, `${outVar}.push("<!--", markerText(textSlotMarker(${ordinal}, true)), "-->");`, node.span);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (node.kind === "condition") {
|
|
426
|
+
const record = recordFor(state, node.test, records);
|
|
427
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
428
|
+
const testVar = nextName(state, "whenTest");
|
|
429
|
+
pushParts(state, [
|
|
430
|
+
`const ${testVar} = (`,
|
|
431
|
+
{ record },
|
|
432
|
+
");"
|
|
433
|
+
], node.span);
|
|
434
|
+
push(state, `${outVar}.push("<!--", markerText(MARKERS.when), "-->");`, node.span);
|
|
435
|
+
push(state, `if (${testVar}) {`, node.span);
|
|
436
|
+
state.indent += 1;
|
|
437
|
+
const thenOrdinals = state.textOrdinals;
|
|
438
|
+
const preparedThen = emissionNodes(state, node.consequent);
|
|
439
|
+
state.textOrdinals = textSlotOrdinals(preparedThen);
|
|
440
|
+
if (!emitDynamicSsrNodes(state, preparedThen, outVar, markers, records, slots, slotCaptureVar, formContext, composition)) {
|
|
441
|
+
state.textOrdinals = thenOrdinals;
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
state.textOrdinals = thenOrdinals;
|
|
445
|
+
state.indent -= 1;
|
|
446
|
+
push(state, "} else {", node.span);
|
|
447
|
+
state.indent += 1;
|
|
448
|
+
if (node.alternate !== null && node.alternate.length > 0) {
|
|
449
|
+
const elseOrdinals = state.textOrdinals;
|
|
450
|
+
const preparedElse = emissionNodes(state, node.alternate);
|
|
451
|
+
state.textOrdinals = textSlotOrdinals(preparedElse);
|
|
452
|
+
if (!emitDynamicSsrNodes(state, preparedElse, outVar, markers, records, slots, slotCaptureVar, formContext, composition)) {
|
|
453
|
+
state.textOrdinals = elseOrdinals;
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
state.textOrdinals = elseOrdinals;
|
|
457
|
+
}
|
|
458
|
+
state.indent -= 1;
|
|
459
|
+
push(state, "}", node.span);
|
|
460
|
+
push(state, `${outVar}.push("<!--", markerText(MARKERS.whenEnd), "-->");`, node.span);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (node.kind === "list") {
|
|
464
|
+
const itemsRecord = recordFor(state, node.items, records);
|
|
465
|
+
if (itemsRecord === null || !declareReads(state, itemsRecord)) return false;
|
|
466
|
+
if (!IDENTIFIER_PATTERN.test(node.parameter) || node.parameter.startsWith("__oe_")) return false;
|
|
467
|
+
const itemsVar = nextName(state, "eachItems");
|
|
468
|
+
pushParts(state, [
|
|
469
|
+
`const ${itemsVar} = (`,
|
|
470
|
+
{ record: itemsRecord },
|
|
471
|
+
");"
|
|
472
|
+
], node.span);
|
|
473
|
+
push(state, `${outVar}.push("<!--", markerText(MARKERS.each), "-->");`, node.span);
|
|
474
|
+
const indexVar = nextName(state, "eachIndex");
|
|
475
|
+
push(state, `for (let ${indexVar} = 0; ${indexVar} < ${itemsVar}.length; ${indexVar}++) {`);
|
|
476
|
+
state.indent += 1;
|
|
477
|
+
const itemVar = node.parameter;
|
|
478
|
+
push(state, `const ${itemVar} = ${itemsVar}[${indexVar}];`);
|
|
479
|
+
const outerEntryName = state.entryNames.has(node.parameter);
|
|
480
|
+
state.entryNames.add(node.parameter);
|
|
481
|
+
const tokenVar = nextName(state, "eachToken");
|
|
482
|
+
if (node.key !== null) {
|
|
483
|
+
const keyRecord = recordFor(state, node.key, records);
|
|
484
|
+
if (keyRecord === null || !declareReads(state, keyRecord)) {
|
|
485
|
+
if (!outerEntryName) state.entryNames.delete(node.parameter);
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
pushParts(state, [
|
|
489
|
+
`const ${tokenVar} = encodeListKey((`,
|
|
490
|
+
{ record: keyRecord },
|
|
491
|
+
"));"
|
|
492
|
+
], node.key.span);
|
|
493
|
+
} else push(state, `const ${tokenVar} = encodeListKey(${indexVar});`, node.span);
|
|
494
|
+
push(state, `${outVar}.push("<!--", markerText(entryKeyMarker(${tokenVar})), "-->");`, node.span);
|
|
495
|
+
const outerOrdinals = state.textOrdinals;
|
|
496
|
+
const prepared = emissionNodes(state, node.template);
|
|
497
|
+
state.textOrdinals = textSlotOrdinals(prepared);
|
|
498
|
+
state.listDepth += 1;
|
|
499
|
+
const entriesEmitted = emitDynamicSsrNodes(state, prepared, outVar, markers, records, slots, slotCaptureVar, formContext, composition);
|
|
500
|
+
state.listDepth -= 1;
|
|
501
|
+
state.textOrdinals = outerOrdinals;
|
|
502
|
+
if (!outerEntryName) state.entryNames.delete(node.parameter);
|
|
503
|
+
if (!entriesEmitted) return false;
|
|
504
|
+
state.indent -= 1;
|
|
505
|
+
push(state, "}");
|
|
506
|
+
push(state, `${outVar}.push("<!--", markerText(MARKERS.eachEnd), "-->");`, node.span);
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (node.kind === "component-ref") {
|
|
510
|
+
if (formContext?.select !== void 0 || formContext?.optionText !== void 0) {
|
|
511
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_NODE", "a controlled select cannot determine option selectedness across a component reference", node.span);
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
if (!emitSsrComponentRef(state, node, outVar, records)) return false;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (node.kind === "insertion-site") {
|
|
518
|
+
if (formContext?.select !== void 0 || formContext?.optionText !== void 0) {
|
|
519
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_NODE", "a controlled select cannot determine option selectedness across a reusable JSX value", node.span);
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
if (!state.declaredRecipeIds.has(node.recipeId)) {
|
|
523
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_RECIPE", `insertion site '${node.recipeId}' does not target a direct component-local JSX initializer; only those values are reusable recipes in this slice`, node.span);
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
const renderRecipe = state.ssrRecipeVars.get(node.recipeId);
|
|
527
|
+
if (renderRecipe === void 0) {
|
|
528
|
+
diag(state, "OEIR_LEAF_MISSING_RECIPE", `insertion site '${node.recipeId}' has no emitted SSR render function (the value is not reachable from any admitted root)`, node.span);
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
push(state, `${outVar}.push(${renderRecipe}());`, node.span);
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
if (node.kind === "children-projection") {
|
|
535
|
+
if (formContext?.select !== void 0 || formContext?.optionText !== void 0) {
|
|
536
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_NODE", "a controlled select cannot determine option selectedness across children projection", node.span);
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
if (state.recipeDepth > 0) {
|
|
540
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_NODE", `children projection inside a reusable JSX value body is outside the M06b2a slice: the projection would need the recipe instance scope, which exists only at insertion time`, node.span);
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
if (state.ssrChildrenRenderVar === null) {
|
|
544
|
+
diag(state, "OEIR_LEAF_MISSING_CHILDREN", "children projection has no server children renderer (internal model mismatch)", node.span);
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
push(state, `${outVar}.push(${state.ssrChildrenRenderVar}());`, node.span);
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (node.kind !== "element") return false;
|
|
551
|
+
if (!TAG_PATTERN.test(node.tag)) return false;
|
|
552
|
+
const isVoid = VOID_TAGS.has(node.tag);
|
|
553
|
+
if (isVoid && node.children.length > 0) {
|
|
554
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_VOID_CHILDREN", `void element <${node.tag}> may not have children`, node.span);
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
const tagName = node.tag.toLowerCase();
|
|
558
|
+
const attributeOf = (name) => node.attributes.find((attribute) => attribute.name.toLowerCase() === name);
|
|
559
|
+
const selectValueAttribute = tagName === "select" ? attributeOf("value") : void 0;
|
|
560
|
+
let activeSelect = formContext?.select;
|
|
561
|
+
let selectValueVar;
|
|
562
|
+
let selectMultipleVar;
|
|
563
|
+
if (selectValueAttribute !== void 0) {
|
|
564
|
+
selectValueVar = nextName(state, "selectValue");
|
|
565
|
+
selectMultipleVar = nextName(state, "selectMultiple");
|
|
566
|
+
push(state, `let ${selectValueVar};`, node.span);
|
|
567
|
+
push(state, `let ${selectMultipleVar} = false;`, node.span);
|
|
568
|
+
const stateVar = nextName(state, "selectState");
|
|
569
|
+
push(state, `const ${stateVar} = { selected: false };`, node.span);
|
|
570
|
+
activeSelect = {
|
|
571
|
+
value: selectValueVar,
|
|
572
|
+
multiple: selectMultipleVar,
|
|
573
|
+
state: stateVar
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
const textareaValueAttribute = tagName === "textarea" ? attributeOf("value") : void 0;
|
|
577
|
+
let textareaValueVar;
|
|
578
|
+
if (textareaValueAttribute !== void 0) {
|
|
579
|
+
textareaValueVar = nextName(state, "textareaValue");
|
|
580
|
+
push(state, `let ${textareaValueVar};`, node.span);
|
|
581
|
+
}
|
|
582
|
+
const controlledOption = tagName === "option" && activeSelect !== void 0;
|
|
583
|
+
const optionOpenVar = controlledOption ? nextName(state, "optionOpen") : void 0;
|
|
584
|
+
const optionChildrenVar = controlledOption ? nextName(state, "optionChildren") : void 0;
|
|
585
|
+
const optionTextVar = controlledOption ? nextName(state, "optionText") : void 0;
|
|
586
|
+
const optionValueVar = controlledOption ? nextName(state, "optionValue") : void 0;
|
|
587
|
+
if (controlledOption) {
|
|
588
|
+
push(state, `const ${optionOpenVar} = [];`, node.span);
|
|
589
|
+
push(state, `const ${optionChildrenVar} = [];`, node.span);
|
|
590
|
+
push(state, `const ${optionTextVar} = [];`, node.span);
|
|
591
|
+
push(state, `let ${optionValueVar} = null;`, node.span);
|
|
592
|
+
const staticValue = attributeOf("value");
|
|
593
|
+
if (staticValue?.kind === "static") push(state, `${optionValueVar} = ${literalText(staticValue.value)};`, staticValue.span);
|
|
594
|
+
}
|
|
595
|
+
const childFormContext = controlledOption && activeSelect !== void 0 ? {
|
|
596
|
+
select: activeSelect,
|
|
597
|
+
optionText: optionTextVar
|
|
598
|
+
} : activeSelect === void 0 ? formContext : {
|
|
599
|
+
select: activeSelect,
|
|
600
|
+
...formContext?.optionText === void 0 ? {} : { optionText: formContext.optionText }
|
|
601
|
+
};
|
|
602
|
+
if (formContext?.select !== void 0 && node.tag.includes("-")) {
|
|
603
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_NODE", "a controlled select cannot determine option selectedness across a custom-element host", node.span);
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
const slotOrdinal = node.tag === "slot" && slots !== null ? slots.get(node) : void 0;
|
|
607
|
+
const slotName = slotOrdinal === void 0 ? null : slotNameOf(node);
|
|
608
|
+
const isNestedHost = node.tag.includes("-");
|
|
609
|
+
const bytesVar = isNestedHost ? nextName(state, "nestedOpen") : optionOpenVar ?? outVar;
|
|
610
|
+
const pairsVar = isNestedHost ? nextName(state, "nestedAttrs") : void 0;
|
|
611
|
+
const kidsVar = isNestedHost ? nextName(state, "nestedKids") : void 0;
|
|
612
|
+
const groupsVar = isNestedHost ? nextName(state, "nestedGroups") : void 0;
|
|
613
|
+
if (isNestedHost) {
|
|
614
|
+
push(state, `const ${bytesVar} = [];`, node.span);
|
|
615
|
+
push(state, `const ${pairsVar} = [];`, node.span);
|
|
616
|
+
push(state, `const ${kidsVar} = [];`, node.span);
|
|
617
|
+
push(state, `const ${groupsVar} = [];`, node.span);
|
|
618
|
+
}
|
|
619
|
+
push(state, `${bytesVar}.push(${literalText(`<${node.tag}`)});`, node.span);
|
|
620
|
+
for (const attribute of node.attributes) {
|
|
621
|
+
const attributeName = attribute.name.toLowerCase();
|
|
622
|
+
if (tagName === "select" && selectValueAttribute !== void 0 && attributeName === "value") {
|
|
623
|
+
if (attribute.kind === "static") push(state, `${selectValueVar} = ${literalText(attribute.value)};`, attribute.span);
|
|
624
|
+
else {
|
|
625
|
+
const record = recordFor(state, attribute.expression, records);
|
|
626
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
627
|
+
pushParts(state, [
|
|
628
|
+
`${selectValueVar} = (`,
|
|
629
|
+
{ record },
|
|
630
|
+
");"
|
|
631
|
+
], attribute.span);
|
|
632
|
+
}
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
if (tagName === "textarea" && textareaValueAttribute !== void 0 && attributeName === "value") {
|
|
636
|
+
if (attribute.kind === "static") push(state, `${textareaValueVar} = ${literalText(attribute.value)};`, attribute.span);
|
|
637
|
+
else {
|
|
638
|
+
const record = recordFor(state, attribute.expression, records);
|
|
639
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
640
|
+
pushParts(state, [
|
|
641
|
+
`${textareaValueVar} = (`,
|
|
642
|
+
{ record },
|
|
643
|
+
");"
|
|
644
|
+
], attribute.span);
|
|
645
|
+
}
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
if (controlledOption && attributeName === "selected") continue;
|
|
649
|
+
if (tagName === "select" && selectValueAttribute !== void 0 && attributeName === "multiple" && attribute.kind === "dynamic" && attribute.channel === "boolean") {
|
|
650
|
+
const record = recordFor(state, attribute.expression, records);
|
|
651
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
652
|
+
const multipleValueVar = nextName(state, "selectMultipleValue");
|
|
653
|
+
pushParts(state, [
|
|
654
|
+
`const ${multipleValueVar} = Boolean((`,
|
|
655
|
+
{ record },
|
|
656
|
+
"));"
|
|
657
|
+
], attribute.span);
|
|
658
|
+
push(state, `${selectMultipleVar} = ${multipleValueVar};`, attribute.span);
|
|
659
|
+
push(state, `if (${selectMultipleVar}) ${bytesVar}.push(${JSON.stringify(" multiple=\"\"")});`, attribute.span);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (tagName === "select" && selectValueAttribute !== void 0 && attributeName === "multiple" && attribute.kind === "dynamic" && attribute.channel !== "boolean") {
|
|
663
|
+
const record = recordFor(state, attribute.expression, records);
|
|
664
|
+
if (record === null || !declareReads(state, record)) return false;
|
|
665
|
+
const multipleValueVar = nextName(state, "selectMultipleValue");
|
|
666
|
+
pushParts(state, [
|
|
667
|
+
`const ${multipleValueVar} = attributeValueOf((`,
|
|
668
|
+
{ record },
|
|
669
|
+
"));"
|
|
670
|
+
], attribute.span);
|
|
671
|
+
push(state, `${selectMultipleVar} = ${multipleValueVar} !== null;`, attribute.span);
|
|
672
|
+
push(state, `if (${multipleValueVar} !== null) ${bytesVar}.push(${JSON.stringify(" multiple=\"")}, escapeAttrValue(${multipleValueVar}), ${JSON.stringify("\"")});`, attribute.span);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (tagName === "select" && selectValueAttribute !== void 0 && attributeName === "multiple" && attribute.kind === "static") push(state, `${selectMultipleVar} = true;`, attribute.span);
|
|
676
|
+
if (attribute.kind === "dynamic" && (CONSUMED_ATTRIBUTE_CHANNELS.has(attribute.channel) || CLIENT_ONLY_ATTRIBUTE_CHANNELS.has(attribute.channel))) continue;
|
|
677
|
+
if (attribute.kind === "static") {
|
|
678
|
+
if (!ATTRIBUTE_PATTERN.test(attribute.name)) return false;
|
|
679
|
+
if (unsafeStreamFrameAttribute(attribute.name, attribute.value)) return false;
|
|
680
|
+
const ssrValue = BOOLEAN_ATTRIBUTES.has(attribute.name.toLowerCase()) ? "" : attribute.value;
|
|
681
|
+
push(state, `${bytesVar}.push(${JSON.stringify(` ${attribute.name}="`)}, escapeAttrValue(${literalText(ssrValue)}), ${JSON.stringify("\"")});`, attribute.span);
|
|
682
|
+
if (pairsVar !== void 0) push(state, `${pairsVar}.push([${JSON.stringify(attribute.name)}, ${literalText(ssrValue)}]);`, attribute.span);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
if (!emitSsrDynamicAttribute(state, attribute, bytesVar, records, pairsVar, slotCaptureVar, controlledOption && attributeName === "value" ? optionValueVar : void 0)) return false;
|
|
686
|
+
}
|
|
687
|
+
if (!controlledOption) push(state, `${bytesVar}.push(">");`, node.span);
|
|
688
|
+
if (isVoid) {
|
|
689
|
+
if (isNestedHost) pushNestedHostExpansion(state, outVar, bytesVar, pairsVar, kidsVar, groupsVar, node);
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
const childVar = kidsVar ?? optionChildrenVar ?? outVar;
|
|
693
|
+
if (slotOrdinal !== null && slotName !== null) push(state, `${childVar}.push("<!--", markerText(slotAnchorMarker(${slotOrdinal}, ${literalText(slotName)})), "-->");`, node.span);
|
|
694
|
+
const directory = !isNestedHost && textareaValueVar === void 0 && markers && directoryParentAllowed(node.tag) ? staticElementDirectory(node.children) : null;
|
|
695
|
+
if (isNestedHost) {
|
|
696
|
+
if (!emitDynamicSsrNodes(state, node.children, kidsVar, markers, records, slots, void 0, void 0, { groups: groupsVar })) return false;
|
|
697
|
+
} else if (directory !== null) for (const [ordinal, range] of directory.entries()) {
|
|
698
|
+
push(state, `${childVar}.push("<!--", markerText(rangeMarker(${ordinal})), "-->");`, range.span);
|
|
699
|
+
if (!emitDynamicSsrNodes(state, [range], childVar, false, records, slots, void 0, childFormContext)) return false;
|
|
700
|
+
push(state, `${childVar}.push("<!--", markerText(rangeMarker(${ordinal}, true)), "-->");`, range.span);
|
|
701
|
+
}
|
|
702
|
+
else if (textareaValueVar !== void 0) {
|
|
703
|
+
const textareaTextVar = nextName(state, "textareaText");
|
|
704
|
+
push(state, `if (${textareaValueVar} !== null && ${textareaValueVar} !== undefined) {`, node.span);
|
|
705
|
+
state.indent += 1;
|
|
706
|
+
push(state, `const ${textareaTextVar} = displayValue(${textareaValueVar}).replace(/\\r\\n?/g, "\\n");`, node.span);
|
|
707
|
+
push(state, `${outVar}.push(escapeText(${textareaTextVar}.startsWith("\\n") ? "\\n" + ${textareaTextVar} : ${textareaTextVar}));`, node.span);
|
|
708
|
+
state.indent -= 1;
|
|
709
|
+
push(state, "} else {", node.span);
|
|
710
|
+
state.indent += 1;
|
|
711
|
+
if (!emitDynamicSsrNodes(state, node.children, childVar, markers, records, slots, void 0, childFormContext)) return false;
|
|
712
|
+
state.indent -= 1;
|
|
713
|
+
push(state, "}");
|
|
714
|
+
} else if (!emitDynamicSsrNodes(state, node.children, childVar, markers, records, slots, void 0, childFormContext)) return false;
|
|
715
|
+
if (slotOrdinal !== null && slotName !== null) push(state, `${childVar}.push("<!--", markerText(slotAnchorMarker(${slotOrdinal}, ${literalText(slotName)}, true)), "-->");`, node.span);
|
|
716
|
+
if (isNestedHost) {
|
|
717
|
+
pushNestedHostExpansion(state, outVar, bytesVar, pairsVar, kidsVar, groupsVar, node);
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
if (controlledOption && activeSelect !== void 0) {
|
|
721
|
+
const optionEffectiveValue = nextName(state, "optionEffectiveValue");
|
|
722
|
+
push(state, `const ${optionEffectiveValue} = ${optionValueVar} === null ? selectOptionValue(${optionTextVar}.join("")) : ${optionValueVar};`, node.span);
|
|
723
|
+
push(state, `if (selectOptionSelected(${activeSelect.value}, ${optionEffectiveValue}, ${activeSelect.multiple}, ${activeSelect.state})) ${optionOpenVar}.push(${JSON.stringify(" selected=\"\"")});`, node.span);
|
|
724
|
+
push(state, `${optionOpenVar}.push(">");`, node.span);
|
|
725
|
+
push(state, `${outVar}.push(${optionOpenVar}.join(""), ${optionChildrenVar}.join(""), ${literalText(`</${node.tag}>`)});`, node.span);
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
push(state, `${outVar}.push(${literalText(`</${node.tag}>`)});`, node.span);
|
|
729
|
+
}
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* alpha16 nested-expansion: close one nested custom-element host.
|
|
734
|
+
*
|
|
735
|
+
* The element's bytes are in two buffers (`open`: the start tag plus attributes
|
|
736
|
+
* and `>`; `kids`: its children), and the attribute pairs were recorded as they
|
|
737
|
+
* were serialized. The emitted call hands all three to `nestedHost`, which asks
|
|
738
|
+
* the render's host to expand the tag and falls back to the caller's own literal
|
|
739
|
+
* bytes when nothing admits it — so an un-admitted tag produces exactly the
|
|
740
|
+
* markup the direct pushes would have produced.
|
|
741
|
+
*
|
|
742
|
+
* Stated as a request record (never positional arguments) because the expander
|
|
743
|
+
* is host-supplied code: a named shape is what makes the contract readable at
|
|
744
|
+
* both ends.
|
|
745
|
+
*/
|
|
746
|
+
function pushNestedHostExpansion(state, outVar, openVar, pairsVar, kidsVar, groupsVar, node) {
|
|
747
|
+
const htmlVar = nextName(state, "nestedHtml");
|
|
748
|
+
const kidsHtmlVar = nextName(state, "nestedKids");
|
|
749
|
+
push(state, `const ${htmlVar} = ${openVar}.join("");`, node.span);
|
|
750
|
+
push(state, `const ${kidsHtmlVar} = ${kidsVar}.join("");`, node.span);
|
|
751
|
+
push(state, `${outVar}.push(nestedHost(${state.hostVar}, { tag: ${JSON.stringify(node.tag)}, attributes: ${pairsVar}, open: ${htmlVar}, children: ${kidsHtmlVar}, groups: ${groupsVar}, hasChildren: ${node.children.length > 0}, fallback: ${htmlVar} + ${kidsHtmlVar} + ${JSON.stringify(`</${node.tag}>`)} }));`, node.span);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Which local setup resources the dynamic SSR producer actually evaluates.
|
|
755
|
+
*
|
|
756
|
+
* The producer used to declare/evaluate EVERY local setup resource, even one
|
|
757
|
+
* referenced only from a client-only channel (an event handler or ref
|
|
758
|
+
* callback). Those expressions can read imported callables, so an unused
|
|
759
|
+
* declaration made `__ssr` request a callable it never used. This walk mirrors
|
|
760
|
+
* the producer's traversal — server-rendered text, attribute/boolean values,
|
|
761
|
+
* condition/list expressions, component-reference prop records and every
|
|
762
|
+
* recipe target reachable from an insertion site — and then closes over local
|
|
763
|
+
* resources transitively: a reachable local's initializer may read another
|
|
764
|
+
* local. Resources used only by client-only attributes (or by other pruned
|
|
765
|
+
* locals) are not declared.
|
|
766
|
+
*
|
|
767
|
+
* Deliberately conservative in one direction: an entry-local mapper name that
|
|
768
|
+
* coincides with an outer local resource keeps the outer declaration.
|
|
769
|
+
* Over-declaration reproduces the old bytes; under-declaration would be a
|
|
770
|
+
* runtime ReferenceError. Evaluation order of the SURVIVING locals is the
|
|
771
|
+
* authored order (the loop keeps the component.resources order).
|
|
772
|
+
*/
|
|
773
|
+
function ssrReachableLocalResourceNames(component, records, extraSeeds = []) {
|
|
774
|
+
const localRecords = /* @__PURE__ */ new Map();
|
|
775
|
+
for (const resource of component.resources) {
|
|
776
|
+
if (resource.kind !== "local" || resource.recipeId !== null || resource.expression === null) continue;
|
|
777
|
+
const record = records.get(resource.expression.id);
|
|
778
|
+
if (record !== void 0) localRecords.set(resource.name, record);
|
|
779
|
+
}
|
|
780
|
+
const recipes = new Map(component.recipes.map((recipe) => [recipe.id, recipe]));
|
|
781
|
+
const usedRecords = /* @__PURE__ */ new Set();
|
|
782
|
+
const visitedNodes = /* @__PURE__ */ new Set();
|
|
783
|
+
const visitedRecipes = /* @__PURE__ */ new Set();
|
|
784
|
+
const collect = (ref) => {
|
|
785
|
+
if (ref === null || ref === void 0) return;
|
|
786
|
+
const record = records.get(ref.id);
|
|
787
|
+
if (record !== void 0) usedRecords.add(record);
|
|
788
|
+
};
|
|
789
|
+
const walkAttributes = (attributes) => {
|
|
790
|
+
for (const attribute of attributes) {
|
|
791
|
+
if (attribute.kind !== "dynamic") continue;
|
|
792
|
+
if (CLIENT_ONLY_ATTRIBUTE_CHANNELS.has(attribute.channel)) continue;
|
|
793
|
+
collect(attribute.expression);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
const walkNodes = (nodes) => {
|
|
797
|
+
for (const node of nodes) walkNode(node);
|
|
798
|
+
};
|
|
799
|
+
const walkRecipe = (recipeId) => {
|
|
800
|
+
if (visitedRecipes.has(recipeId)) return;
|
|
801
|
+
visitedRecipes.add(recipeId);
|
|
802
|
+
const recipe = recipes.get(recipeId);
|
|
803
|
+
if (recipe !== void 0) walkNode(recipe.target);
|
|
804
|
+
};
|
|
805
|
+
const walkNode = (node) => {
|
|
806
|
+
if (visitedNodes.has(node)) return;
|
|
807
|
+
visitedNodes.add(node);
|
|
808
|
+
if (node.kind === "text") return;
|
|
809
|
+
if (node.kind === "fragment") {
|
|
810
|
+
walkNodes(node.children);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (node.kind === "dynamic-text") {
|
|
814
|
+
collect(node.expression);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (node.kind === "element") {
|
|
818
|
+
walkAttributes(node.attributes);
|
|
819
|
+
walkNodes(node.children);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
if (node.kind === "condition") {
|
|
823
|
+
collect(node.test);
|
|
824
|
+
walkNodes(node.consequent);
|
|
825
|
+
if (node.alternate !== null) walkNodes(node.alternate);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (node.kind === "list") {
|
|
829
|
+
collect(node.items);
|
|
830
|
+
if (node.key !== null) collect(node.key);
|
|
831
|
+
walkNodes(node.template);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (node.kind === "component-ref") {
|
|
835
|
+
walkAttributes(node.props);
|
|
836
|
+
if (node.childrenRecipeId !== null) walkRecipe(node.childrenRecipeId);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
if (node.kind === "insertion-site") walkRecipe(node.recipeId);
|
|
840
|
+
};
|
|
841
|
+
walkNodes(component.roots);
|
|
842
|
+
for (const record of extraSeeds) usedRecords.add(record);
|
|
843
|
+
const reachable = /* @__PURE__ */ new Set();
|
|
844
|
+
const queue = [...usedRecords];
|
|
845
|
+
const seen = new Set(queue);
|
|
846
|
+
while (queue.length > 0) {
|
|
847
|
+
const record = queue.pop();
|
|
848
|
+
for (const read of record.reads) {
|
|
849
|
+
const localRecord = localRecords.get(read.name);
|
|
850
|
+
if (localRecord === void 0) continue;
|
|
851
|
+
reachable.add(read.name);
|
|
852
|
+
if (!seen.has(localRecord)) {
|
|
853
|
+
seen.add(localRecord);
|
|
854
|
+
queue.push(localRecord);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return reachable;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Emit `<Name>__ssr(props, host)` for a component with at least one admitted
|
|
862
|
+
* dynamic slot. Returns null when the shape is outside the slice (for example
|
|
863
|
+
* a condition, list, component reference, insertion site or property channel);
|
|
864
|
+
* diagnostics are returned as a failed emission so the module fails closed the
|
|
865
|
+
* same way mount/claim failures do. Void elements are admitted: they emit the
|
|
866
|
+
* start tag and attributes only.
|
|
867
|
+
*/
|
|
868
|
+
function emitDynamicSsrFunction(file, component, records, componentByName, slots, elementRootBinding) {
|
|
869
|
+
const propsName = component.propsParam;
|
|
870
|
+
const projectsChildren = componentProjectsChildren(component);
|
|
871
|
+
const composition = treeHasComposition(component.roots);
|
|
872
|
+
const state = ssrEmitState(component, file, propsName, componentByName, projectsChildren);
|
|
873
|
+
if (elementRootBinding) state.elementRootBinding = true;
|
|
874
|
+
if (!assertTextBoundaryContext(state, component.roots)) return failedSsr(state);
|
|
875
|
+
const usesContext = componentUsesContextIntrinsic(component);
|
|
876
|
+
if (componentNeedsSsrContextScope(component, componentByName)) emitSsrContextScope(state);
|
|
877
|
+
if (usesContext) emitContextProviders(state, component.contextProviders, records);
|
|
878
|
+
const reachableLocalResources = ssrReachableLocalResourceNames(component, records, (elementRootBinding ? component.resources : []).filter((resource) => (resource.kind === "signal" || resource.kind === "computed") && resource.expression !== null).map((resource) => records.get(resource.expression.id)).filter((record) => record !== void 0));
|
|
879
|
+
for (const resource of component.resources) {
|
|
880
|
+
if (!IDENTIFIER_PATTERN.test(resource.name) || resource.name.startsWith("__oe_")) continue;
|
|
881
|
+
if (resource.kind === "ref") {
|
|
882
|
+
state.localResources.add(resource.name);
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
if (resource.kind === "context") {
|
|
886
|
+
if (resource.expression === null) continue;
|
|
887
|
+
const record = recordFor(state, resource.expression, records);
|
|
888
|
+
if (record === null || !declareReads(state, record)) return failedSsr(state);
|
|
889
|
+
state.localResources.add(resource.name);
|
|
890
|
+
emitSetupBinding(state, {
|
|
891
|
+
name: resource.name,
|
|
892
|
+
kind: "context",
|
|
893
|
+
record,
|
|
894
|
+
span: resource.span
|
|
895
|
+
});
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (resource.kind === "local") {
|
|
899
|
+
if (resource.recipeId !== null || resource.expression === null) continue;
|
|
900
|
+
state.localResources.add(resource.name);
|
|
901
|
+
if (!reachableLocalResources.has(resource.name)) continue;
|
|
902
|
+
const record = recordFor(state, resource.expression, records);
|
|
903
|
+
if (record === null || !declareReads(state, record)) return failedSsr(state);
|
|
904
|
+
pushParts(state, [
|
|
905
|
+
`const ${resource.name} = (`,
|
|
906
|
+
{ record },
|
|
907
|
+
");"
|
|
908
|
+
], resource.span);
|
|
909
|
+
continue;
|
|
910
|
+
}
|
|
911
|
+
if ((resource.kind === "signal" || resource.kind === "computed") && state.elementRootBinding) {
|
|
912
|
+
if (resource.expression === null) {
|
|
913
|
+
state.hostBindings.add(resource.name);
|
|
914
|
+
state.requiredBindings.add(resource.name);
|
|
915
|
+
continue;
|
|
916
|
+
}
|
|
917
|
+
const record = recordFor(state, resource.expression, records);
|
|
918
|
+
if (record === null || !declareReads(state, record)) return failedSsr(state);
|
|
919
|
+
state.localResources.add(resource.name);
|
|
920
|
+
pushParts(state, [
|
|
921
|
+
resource.kind === "computed" ? `const ${resource.name} = computed(` : `const ${resource.name} = signal((`,
|
|
922
|
+
{ record },
|
|
923
|
+
resource.kind === "computed" ? ");" : "));"
|
|
924
|
+
], resource.span);
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
state.hostBindings.add(resource.name);
|
|
928
|
+
state.requiredBindings.add(resource.name);
|
|
929
|
+
}
|
|
930
|
+
if (state.diagnostics.length > 0) return failedSsr(state);
|
|
931
|
+
if (projectsChildren) push(state, `if (${SSR_CHILDREN_RENDER} === null) throw new Error("OEIR_LEAF_MISSING_CHILDREN: component '<${component.name}>' projects props.children but the server instance was given no children renderer");`, component.span);
|
|
932
|
+
if (composition) {
|
|
933
|
+
if (!emitSsrRecipeHelpers(state, records)) return state.diagnostics.length > 0 ? failedSsr(state) : null;
|
|
934
|
+
}
|
|
935
|
+
const outVar = nextName(state, "out");
|
|
936
|
+
push(state, `const ${outVar} = [];`);
|
|
937
|
+
if (!emitDynamicSsrNodes(state, component.roots, outVar, true, records, slots)) return state.diagnostics.length > 0 ? failedSsr(state) : null;
|
|
938
|
+
push(state, `return ${outVar}.join("");`);
|
|
939
|
+
if (state.diagnostics.length > 0) return failedSsr(state);
|
|
940
|
+
const needsScope = componentNeedsSsrContextScope(component, componentByName);
|
|
941
|
+
const scopeParam = needsScope ? `, ${SSR_CONTEXT_PARAM}` : "";
|
|
942
|
+
const prologue = composition ? [`function ${SSR_HELPER_PREFIX}${component.name}(${MOUNT_PROPS}, ${MOUNT_HOST}, ${SSR_CHILDREN_RENDER}${scopeParam}) {`] : [`export function ${component.name}${SSR_SUFFIX}(${MOUNT_PROPS}, ${MOUNT_HOST}${scopeParam}) {`];
|
|
943
|
+
if (propsName !== null) {
|
|
944
|
+
prologue.push(` const ${propsName} = ${MOUNT_PROPS};`);
|
|
945
|
+
state.requiredProps.add(propsName);
|
|
946
|
+
}
|
|
947
|
+
if (state.requiredBindings.size > 0) {
|
|
948
|
+
prologue.push(` const ${INTERNAL_PREFIX}requireBinding = (name) => { const value = ${MOUNT_HOST}.bindings[name]; if (value === undefined) throw new Error("OEIR_LEAF_MISSING_VALUE: " + name); return value; };`);
|
|
949
|
+
for (const binding of [...state.requiredBindings].sort()) prologue.push(` const ${binding} = ${INTERNAL_PREFIX}requireBinding(${JSON.stringify(binding)});`);
|
|
950
|
+
}
|
|
951
|
+
const wrapper = composition ? [
|
|
952
|
+
`export function ${component.name}${SSR_SUFFIX}(${MOUNT_PROPS}, ${MOUNT_HOST}${scopeParam}) {`,
|
|
953
|
+
` return ${SSR_HELPER_PREFIX}${component.name}(${MOUNT_PROPS}, ${MOUNT_HOST}, null${needsScope ? `, ${SSR_CONTEXT_PARAM}` : ""});`,
|
|
954
|
+
"}",
|
|
955
|
+
""
|
|
956
|
+
] : [];
|
|
957
|
+
const shift = fragmentLineCount(prologue);
|
|
958
|
+
return {
|
|
959
|
+
lines: [
|
|
960
|
+
...prologue,
|
|
961
|
+
...state.lines,
|
|
962
|
+
"}",
|
|
963
|
+
...wrapper
|
|
964
|
+
],
|
|
965
|
+
diagnostics: [],
|
|
966
|
+
segments: state.segments.map((segment) => ({
|
|
967
|
+
...segment,
|
|
968
|
+
generatedLine: segment.generatedLine + shift
|
|
969
|
+
})),
|
|
970
|
+
placements: state.placements.map((placement) => ({
|
|
971
|
+
...placement,
|
|
972
|
+
generatedLine: placement.generatedLine + shift
|
|
973
|
+
}))
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Emit the SSR function for a claimable component. A fully static component
|
|
978
|
+
* keeps the M08-1a `__ssr()` form (no parameters, byte-identical output); a
|
|
979
|
+
* component with an admitted dynamic slot gets the M08-1b
|
|
980
|
+
* `__ssr(props, host)` form. Returns `null` when the tree is outside the
|
|
981
|
+
* producer slice.
|
|
982
|
+
*
|
|
983
|
+
* `lightRoot` is the ONE gate for the slot-anchor family. It is true only for
|
|
984
|
+
* the root component of a light-descriptor generated element; a shadow root's
|
|
985
|
+
* children are distributed by the platform (a `<slot>` in the shadow tree plus
|
|
986
|
+
* light DOM after `</template>`) and a hostless leaf module is not a host, so
|
|
987
|
+
* both emit no anchor and keep their pre-slice bytes.
|
|
988
|
+
*/
|
|
989
|
+
function emitSsrFunction(file, component, rootDirectory, records, componentByName, lightRoot, rootComponent) {
|
|
990
|
+
const state = ssrEmitState(component, file, component.propsParam, componentByName, componentProjectsChildren(component));
|
|
991
|
+
const enabled = lightSlotAnchorsEnabled(state, lightRoot);
|
|
992
|
+
if (state.diagnostics.length > 0) return failedSsr(state);
|
|
993
|
+
const slots = enabled ? ssrSlotAnchorOrdinals(component.roots) : null;
|
|
994
|
+
let expression;
|
|
995
|
+
if (rootDirectory !== null) expression = staticSsrDirectory(rootDirectory, slots);
|
|
996
|
+
else expression = staticSsrExpression(component.roots, true, slots);
|
|
997
|
+
if (expression !== null) return {
|
|
998
|
+
lines: [
|
|
999
|
+
`export function ${component.name}${SSR_SUFFIX}() {`,
|
|
1000
|
+
` return ${expression};`,
|
|
1001
|
+
"}",
|
|
1002
|
+
""
|
|
1003
|
+
],
|
|
1004
|
+
diagnostics: [],
|
|
1005
|
+
segments: [],
|
|
1006
|
+
placements: []
|
|
1007
|
+
};
|
|
1008
|
+
return emitDynamicSsrFunction(file, component, records, componentByName, slots, rootComponent !== null && component.name === rootComponent);
|
|
1009
|
+
}
|
|
1010
|
+
//#endregion
|
|
1011
|
+
export { emitSsrFunction };
|