@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,714 @@
|
|
|
1
|
+
import { ADMITTED_ATTRIBUTE_CHANNELS, ATTRIBUTE_PATTERN, CLIENT_ONLY_ATTRIBUTE_CHANNELS, CONSUMED_ATTRIBUTE_CHANNELS, TAG_PATTERN, diag } from "./emission.js";
|
|
2
|
+
//#region src/internal/compiler/semantic-ir/generated-leaf/structure.ts
|
|
3
|
+
/**
|
|
4
|
+
* Table, select, template, svg, and math parsing contexts. A directory is not
|
|
5
|
+
* emitted under or around these tags. ASCII lowercase, matching intrinsic tags
|
|
6
|
+
* the generator already admits. This is not a new content model.
|
|
7
|
+
*/
|
|
8
|
+
const DIRECTORY_EXCLUDED_TAGS = /* @__PURE__ */ new Set([
|
|
9
|
+
"table",
|
|
10
|
+
"caption",
|
|
11
|
+
"colgroup",
|
|
12
|
+
"col",
|
|
13
|
+
"thead",
|
|
14
|
+
"tbody",
|
|
15
|
+
"tfoot",
|
|
16
|
+
"tr",
|
|
17
|
+
"td",
|
|
18
|
+
"th",
|
|
19
|
+
"select",
|
|
20
|
+
"optgroup",
|
|
21
|
+
"option",
|
|
22
|
+
"template",
|
|
23
|
+
"svg",
|
|
24
|
+
"math"
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Parser contexts that cannot carry the generated text boundary. The split is
|
|
28
|
+
* by actual parser behavior, not by a sticky ancestor:
|
|
29
|
+
*
|
|
30
|
+
* - RCDATA (`textarea`, `title`) and rawtext turn `<!--...-->` into literal
|
|
31
|
+
* text.
|
|
32
|
+
* - `<template>` puts its children in `.content`, not `childNodes`.
|
|
33
|
+
* - `<noscript>` parsing depends on the scripting flag, so the claim cannot
|
|
34
|
+
* assume the comment is a stable Comment node.
|
|
35
|
+
* - The table family keeps comments in the table, but foster-parents
|
|
36
|
+
* non-whitespace text. `td`/`th` (and `caption`) are normal flow content and
|
|
37
|
+
* reset the context.
|
|
38
|
+
* - Foreign content (SVG/MathML) exposes comments as nodes, but the existing
|
|
39
|
+
* generated claim is HTML-namespace-only, so it cannot claim those elements.
|
|
40
|
+
* - The select family is kept as a conservative slice boundary; its insertion
|
|
41
|
+
* mode is not part of this slice's qualified contract.
|
|
42
|
+
*
|
|
43
|
+
* A dynamic-text slot under one of these cannot carry the boundary pair; the
|
|
44
|
+
* generator refuses the component with a source-located diagnostic instead of
|
|
45
|
+
* silently falling back to mount-only output. Static non-whitespace text in a
|
|
46
|
+
* foster-parenting context is refused for the same reason.
|
|
47
|
+
*/
|
|
48
|
+
const TEXT_RCDATA_TAGS = /* @__PURE__ */ new Set(["textarea", "title"]);
|
|
49
|
+
const TEXT_RAWTEXT_TAGS = /* @__PURE__ */ new Set([
|
|
50
|
+
"script",
|
|
51
|
+
"style",
|
|
52
|
+
"xmp",
|
|
53
|
+
"iframe",
|
|
54
|
+
"noembed",
|
|
55
|
+
"noframes",
|
|
56
|
+
"plaintext"
|
|
57
|
+
]);
|
|
58
|
+
const TEXT_FOREIGN_TAGS = /* @__PURE__ */ new Set(["svg", "math"]);
|
|
59
|
+
/** Table-family tags whose non-whitespace text is foster-parented. */
|
|
60
|
+
const TEXT_FOSTER_TAGS = /* @__PURE__ */ new Set([
|
|
61
|
+
"table",
|
|
62
|
+
"colgroup",
|
|
63
|
+
"col",
|
|
64
|
+
"thead",
|
|
65
|
+
"tbody",
|
|
66
|
+
"tfoot",
|
|
67
|
+
"tr"
|
|
68
|
+
]);
|
|
69
|
+
/** Cell/caption boundaries are normal flow content. */
|
|
70
|
+
const TEXT_TABLE_FLOW_TAGS = /* @__PURE__ */ new Set([
|
|
71
|
+
"td",
|
|
72
|
+
"th",
|
|
73
|
+
"caption"
|
|
74
|
+
]);
|
|
75
|
+
const TEXT_SELECT_TAGS = /* @__PURE__ */ new Set([
|
|
76
|
+
"select",
|
|
77
|
+
"optgroup",
|
|
78
|
+
"option"
|
|
79
|
+
]);
|
|
80
|
+
/** HTML "space characters": tab, LF, FF, CR, space (not JS `trim` whitespace). */
|
|
81
|
+
const HTML_WHITESPACE_ONLY = /^[\t\n\f\r ]*$/;
|
|
82
|
+
/**
|
|
83
|
+
* Collect the recipe ids referenced by at least one insertion site reachable
|
|
84
|
+
* from the component roots (M06b1a-2). Delivery is transitive: a site inside a
|
|
85
|
+
* recipe body keeps the referenced recipe alive, while a direct declaration no
|
|
86
|
+
* admitted site reaches is not emitted at all.
|
|
87
|
+
*/
|
|
88
|
+
function referencedRecipeIds(component) {
|
|
89
|
+
const byId = new Map(component.recipes.map((recipe) => [recipe.id, recipe]));
|
|
90
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
91
|
+
const pending = [];
|
|
92
|
+
const collect = (nodes) => {
|
|
93
|
+
for (const node of nodes) switch (node.kind) {
|
|
94
|
+
case "insertion-site":
|
|
95
|
+
if (!referenced.has(node.recipeId)) {
|
|
96
|
+
referenced.add(node.recipeId);
|
|
97
|
+
pending.push(node.recipeId);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "component-ref":
|
|
101
|
+
if (node.childrenRecipeId !== null && !referenced.has(node.childrenRecipeId)) {
|
|
102
|
+
referenced.add(node.childrenRecipeId);
|
|
103
|
+
pending.push(node.childrenRecipeId);
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case "element":
|
|
107
|
+
case "fragment":
|
|
108
|
+
collect(node.children);
|
|
109
|
+
break;
|
|
110
|
+
case "condition":
|
|
111
|
+
collect(node.consequent);
|
|
112
|
+
if (node.alternate !== null) collect(node.alternate);
|
|
113
|
+
break;
|
|
114
|
+
case "list": collect(node.template);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
collect(component.roots);
|
|
118
|
+
while (pending.length > 0) {
|
|
119
|
+
const recipe = byId.get(pending.pop());
|
|
120
|
+
if (recipe !== void 0) collect([recipe.target]);
|
|
121
|
+
}
|
|
122
|
+
return referenced;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Does this component's mount project `props.children`? Only roots (and their
|
|
126
|
+
* condition/list builders) count: a projection inside a reusable recipe body is
|
|
127
|
+
* refused (`recipeDepth`), so the mount-level read is needed exactly when a
|
|
128
|
+
* projection is reachable from the roots (M06b2a).
|
|
129
|
+
*/
|
|
130
|
+
function componentProjectsChildren(component) {
|
|
131
|
+
const walk = (nodes) => {
|
|
132
|
+
for (const node of nodes) switch (node.kind) {
|
|
133
|
+
case "children-projection": return true;
|
|
134
|
+
case "element":
|
|
135
|
+
case "fragment":
|
|
136
|
+
if (walk(node.children)) return true;
|
|
137
|
+
break;
|
|
138
|
+
case "condition":
|
|
139
|
+
if (walk(node.consequent)) return true;
|
|
140
|
+
if (node.alternate !== null && walk(node.alternate)) return true;
|
|
141
|
+
break;
|
|
142
|
+
case "list": if (walk(node.template)) return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
};
|
|
146
|
+
return walk(component.roots);
|
|
147
|
+
}
|
|
148
|
+
function flattenFragments(nodes) {
|
|
149
|
+
const flat = [];
|
|
150
|
+
for (const node of nodes) if (node.kind === "fragment") flat.push(...flattenFragments(node.children));
|
|
151
|
+
else flat.push(node);
|
|
152
|
+
return flat;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* M08 static text-run normalization. Fragments have no DOM identity, so they
|
|
156
|
+
* are flattened first; then each maximal run of adjacent `text` nodes becomes
|
|
157
|
+
* one shallow copy with the concatenated value and the first node's span. Only
|
|
158
|
+
* static text is merged: dynamic text is a slot identity and a pair boundary,
|
|
159
|
+
* never part of a run.
|
|
160
|
+
*
|
|
161
|
+
* The rule is a view, not an IR mutation: callers receive a new list and the
|
|
162
|
+
* model stays authored. It is idempotent, so a surface may normalize again
|
|
163
|
+
* without changing the result.
|
|
164
|
+
*/
|
|
165
|
+
function normalizeTextRuns(nodes) {
|
|
166
|
+
const flat = [];
|
|
167
|
+
const append = (list) => {
|
|
168
|
+
for (const node of list) {
|
|
169
|
+
if (node.kind === "fragment") {
|
|
170
|
+
append(node.children);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (node.kind === "text") {
|
|
174
|
+
const previous = flat[flat.length - 1];
|
|
175
|
+
if (previous !== void 0 && previous.kind === "text") {
|
|
176
|
+
flat[flat.length - 1] = {
|
|
177
|
+
kind: "text",
|
|
178
|
+
value: previous.value + node.value,
|
|
179
|
+
span: previous.span
|
|
180
|
+
};
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
flat.push(node);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
append(nodes);
|
|
188
|
+
return flat;
|
|
189
|
+
}
|
|
190
|
+
/** The child-list view a claimable chunk uses; pure-mount chunks stay authored. */
|
|
191
|
+
function emissionNodes(state, nodes) {
|
|
192
|
+
return state.emitTextBoundaries ? normalizeTextRuns(nodes) : nodes;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Chunk-local pre-order ordinals for dynamic text slots. The walk descends
|
|
196
|
+
* through elements and fragments only: a component reference, insertion site,
|
|
197
|
+
* children projection, condition or list starts/owns another chunk and does not
|
|
198
|
+
* consume an ordinal in this one. Mount, claim and SSR call the same helper, so
|
|
199
|
+
* they agree on the sequence without sharing emission-order state.
|
|
200
|
+
*/
|
|
201
|
+
function textSlotOrdinals(nodes) {
|
|
202
|
+
const ordinals = /* @__PURE__ */ new Map();
|
|
203
|
+
let next = 0;
|
|
204
|
+
const visit = (list) => {
|
|
205
|
+
for (const node of list) {
|
|
206
|
+
if (node.kind === "dynamic-text") {
|
|
207
|
+
ordinals.set(node, next);
|
|
208
|
+
next += 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (node.kind === "element" || node.kind === "fragment") visit(node.children);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
visit(nodes);
|
|
215
|
+
return ordinals;
|
|
216
|
+
}
|
|
217
|
+
/** The slot ordinal for one node, or an internal diagnostic when unmapped. */
|
|
218
|
+
function textOrdinal(state, node) {
|
|
219
|
+
const ordinal = state.textOrdinals.get(node);
|
|
220
|
+
if (ordinal === void 0) {
|
|
221
|
+
diag(state, "OEIR_LEAF_TEXT_BOUNDARY_UNMAPPED", "internal: dynamic text has no chunk-local ordinal; refusing to guess a marker", node.span);
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return ordinal;
|
|
225
|
+
}
|
|
226
|
+
function ssrSlotAnchorOrdinals(nodes) {
|
|
227
|
+
const ordinals = /* @__PURE__ */ new Map();
|
|
228
|
+
let next = 0;
|
|
229
|
+
const visit = (list) => {
|
|
230
|
+
for (const node of list) {
|
|
231
|
+
if (node.kind === "element") {
|
|
232
|
+
if (node.tag === "slot") {
|
|
233
|
+
ordinals.set(node, next);
|
|
234
|
+
next += 1;
|
|
235
|
+
}
|
|
236
|
+
visit(node.children);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (node.kind === "fragment") visit(node.children);
|
|
240
|
+
else if (node.kind === "condition") {
|
|
241
|
+
visit(node.consequent);
|
|
242
|
+
if (node.alternate !== null) visit(node.alternate);
|
|
243
|
+
} else if (node.kind === "list") visit(node.template);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
visit(nodes);
|
|
247
|
+
return ordinals;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Walk the whole component once, before emission, to answer the two questions
|
|
251
|
+
* the per-chunk maps cannot answer:
|
|
252
|
+
*
|
|
253
|
+
* - does this light root contain a `<slot>` at all? (none → emit nothing)
|
|
254
|
+
* - does every `<slot>` declare a STATIC `name`? The anchor carries the name in
|
|
255
|
+
* its marker text so the serializer needs no second lookup, and a `name={…}`
|
|
256
|
+
* binding has no compile-time value to carry — the module is refused rather
|
|
257
|
+
* than baking a guess that would point a projection at a slot the producer
|
|
258
|
+
* never named.
|
|
259
|
+
*
|
|
260
|
+
* A shadow root's children are distributed by the platform (`<slot>` in the
|
|
261
|
+
* shadow tree plus light DOM after the template), and a hostless leaf module is
|
|
262
|
+
* not a host at all, so both answers are "emit nothing" and keep their
|
|
263
|
+
* pre-slice bytes.
|
|
264
|
+
*/
|
|
265
|
+
function lightSlotAnchorsEnabled(state, lightRoot) {
|
|
266
|
+
if (!lightRoot) return false;
|
|
267
|
+
let found = false;
|
|
268
|
+
let refused = false;
|
|
269
|
+
const visit = (list) => {
|
|
270
|
+
for (const node of list) {
|
|
271
|
+
if (node.kind === "element") {
|
|
272
|
+
if (node.tag === "slot") {
|
|
273
|
+
found = true;
|
|
274
|
+
if (slotNameOf(node) === null) {
|
|
275
|
+
refused = true;
|
|
276
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_SLOT_NAME", "a light-root <slot> must declare a static name: the slot anchor carries the name in its marker text so the serializer needs no second lookup, and a dynamic name={…} binding has no compile-time value to carry", node.span);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
visit(node.children);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (node.kind === "fragment") visit(node.children);
|
|
283
|
+
else if (node.kind === "condition") {
|
|
284
|
+
visit(node.consequent);
|
|
285
|
+
if (node.alternate !== null) visit(node.alternate);
|
|
286
|
+
} else if (node.kind === "list") visit(node.template);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
visit(state.component.roots);
|
|
290
|
+
return found && !refused;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The slot name one `<slot>` element declares, read the way the element lane's
|
|
294
|
+
* `slotNameOf` reads it: the static `name` attribute's value, `''` (the default
|
|
295
|
+
* slot) when there is none. `null` is the "no compile-time name" case — a
|
|
296
|
+
* dynamic `name={…}` — which the anchor cannot carry.
|
|
297
|
+
*/
|
|
298
|
+
function slotNameOf(node) {
|
|
299
|
+
if (node.kind !== "element") return null;
|
|
300
|
+
let name = "";
|
|
301
|
+
for (const attribute of node.attributes) {
|
|
302
|
+
if (attribute.name !== "name") continue;
|
|
303
|
+
if (attribute.kind !== "static") return null;
|
|
304
|
+
name = attribute.value;
|
|
305
|
+
}
|
|
306
|
+
return name;
|
|
307
|
+
}
|
|
308
|
+
function textContextWalker(state) {
|
|
309
|
+
return {
|
|
310
|
+
component: (name) => state.componentByName.get(name),
|
|
311
|
+
recipes: state.component.recipes,
|
|
312
|
+
stack: /* @__PURE__ */ new Set()
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The parser context a child element establishes. RCDATA/rawtext/template/
|
|
317
|
+
* noscript/foreign content are sticky: every authored descendant is still
|
|
318
|
+
* parsed in that mode, so an `oe:t` pair cannot be placed there. Foster
|
|
319
|
+
* parenting is different: `td`, `th` and a table-level `caption` are normal
|
|
320
|
+
* flow content and reset it. This is what keeps legal `<td><p>{x}</p>` out of
|
|
321
|
+
* the refusal without accepting `<table>{x}</table>` or `<tr>{x}</tr>`.
|
|
322
|
+
*/
|
|
323
|
+
function textContextForChild(context, tag) {
|
|
324
|
+
if (context.kind !== "flow" && context.kind !== "foster") return context;
|
|
325
|
+
if (context.kind === "foster") {
|
|
326
|
+
if (TEXT_TABLE_FLOW_TAGS.has(tag)) return tag === "caption" && context.tag !== "table" ? context : { kind: "flow" };
|
|
327
|
+
if (tag === "template") return {
|
|
328
|
+
kind: "template",
|
|
329
|
+
tag
|
|
330
|
+
};
|
|
331
|
+
if (TEXT_FOSTER_TAGS.has(tag)) return {
|
|
332
|
+
kind: "foster",
|
|
333
|
+
tag
|
|
334
|
+
};
|
|
335
|
+
return context;
|
|
336
|
+
}
|
|
337
|
+
if (TEXT_RCDATA_TAGS.has(tag)) return {
|
|
338
|
+
kind: "rcdata",
|
|
339
|
+
tag
|
|
340
|
+
};
|
|
341
|
+
if (TEXT_RAWTEXT_TAGS.has(tag)) return {
|
|
342
|
+
kind: "rawtext",
|
|
343
|
+
tag
|
|
344
|
+
};
|
|
345
|
+
if (tag === "template") return {
|
|
346
|
+
kind: "template",
|
|
347
|
+
tag
|
|
348
|
+
};
|
|
349
|
+
if (tag === "noscript") return {
|
|
350
|
+
kind: "noscript",
|
|
351
|
+
tag
|
|
352
|
+
};
|
|
353
|
+
if (TEXT_FOREIGN_TAGS.has(tag)) return {
|
|
354
|
+
kind: "foreign",
|
|
355
|
+
tag
|
|
356
|
+
};
|
|
357
|
+
if (TEXT_FOSTER_TAGS.has(tag)) return {
|
|
358
|
+
kind: "foster",
|
|
359
|
+
tag
|
|
360
|
+
};
|
|
361
|
+
if (TEXT_TABLE_FLOW_TAGS.has(tag)) return { kind: "flow" };
|
|
362
|
+
if (TEXT_SELECT_TAGS.has(tag)) return {
|
|
363
|
+
kind: "select",
|
|
364
|
+
tag
|
|
365
|
+
};
|
|
366
|
+
return context;
|
|
367
|
+
}
|
|
368
|
+
function textContextReason(context) {
|
|
369
|
+
switch (context.kind) {
|
|
370
|
+
case "rcdata": return "RCDATA parses comments as literal text";
|
|
371
|
+
case "rawtext": return "rawtext parses comments as literal text";
|
|
372
|
+
case "template": return "template content lives in .content, not childNodes";
|
|
373
|
+
case "noscript": return "noscript parsing depends on the scripting flag, so comments are not stable Comment nodes";
|
|
374
|
+
case "foreign": return "the generated claim is HTML-namespace-only; foreign content (SVG/MathML) is outside that contract";
|
|
375
|
+
case "foster": return `the HTML parser foster-parents non-whitespace text out of the table (current <${context.tag}>); the generated claim cannot find it in place`;
|
|
376
|
+
case "select": return "the select family is a conservative boundary of this text-boundary slice; its insertion mode is not part of the qualified contract";
|
|
377
|
+
case "flow": return "this context exposes comments as Comment nodes";
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The first text that would land in a restricted parser context, or `null`.
|
|
382
|
+
* The walk crosses component references and insertion-site recipes only while
|
|
383
|
+
* the current context is restricted, because the parent's parser context
|
|
384
|
+
* applies to the child's emitted nodes too. A `props.children` projection under
|
|
385
|
+
* such a context cannot be proven safe at the producer, so it is refused at the
|
|
386
|
+
* projection source.
|
|
387
|
+
*
|
|
388
|
+
* `td`/`th` and table-level `caption` reset the context; table sections/rows
|
|
389
|
+
* and `colgroup` keep it because their text is foster-parented. Cycles are
|
|
390
|
+
* already refused by `findMountCycle`; the path stack keeps this scan finite.
|
|
391
|
+
*/
|
|
392
|
+
function findTextContextViolation(nodes, context, walker) {
|
|
393
|
+
for (const node of nodes) {
|
|
394
|
+
if (node.kind === "dynamic-text") {
|
|
395
|
+
if (context.kind !== "flow") return {
|
|
396
|
+
node,
|
|
397
|
+
context,
|
|
398
|
+
detail: "dynamic text"
|
|
399
|
+
};
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (node.kind === "text") {
|
|
403
|
+
if (context.kind === "foster" && !HTML_WHITESPACE_ONLY.test(node.value)) return {
|
|
404
|
+
node,
|
|
405
|
+
context,
|
|
406
|
+
detail: "static text"
|
|
407
|
+
};
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (node.kind === "fragment") {
|
|
411
|
+
const found = findTextContextViolation(node.children, context, walker);
|
|
412
|
+
if (found !== null) return found;
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (node.kind === "condition") {
|
|
416
|
+
const thenFound = findTextContextViolation(node.consequent, context, walker);
|
|
417
|
+
if (thenFound !== null) return thenFound;
|
|
418
|
+
if (node.alternate !== null) {
|
|
419
|
+
const elseFound = findTextContextViolation(node.alternate, context, walker);
|
|
420
|
+
if (elseFound !== null) return elseFound;
|
|
421
|
+
}
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (node.kind === "list") {
|
|
425
|
+
const entries = findTextContextViolation(node.template, context, walker);
|
|
426
|
+
if (entries !== null) return entries;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (node.kind === "component-ref" && context.kind !== "flow") {
|
|
430
|
+
const key = `c:${node.name}`;
|
|
431
|
+
if (walker.stack.has(key)) continue;
|
|
432
|
+
walker.stack.add(key);
|
|
433
|
+
const target = walker.component(node.name);
|
|
434
|
+
const found = target === void 0 ? null : findTextContextViolation(target.roots, context, {
|
|
435
|
+
...walker,
|
|
436
|
+
recipes: target.recipes
|
|
437
|
+
});
|
|
438
|
+
walker.stack.delete(key);
|
|
439
|
+
if (found !== null) return found;
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (node.kind === "insertion-site" && context.kind !== "flow") {
|
|
443
|
+
const key = `r:${node.recipeId}`;
|
|
444
|
+
if (walker.stack.has(key)) continue;
|
|
445
|
+
walker.stack.add(key);
|
|
446
|
+
const recipe = walker.recipes.find((entry) => entry.id === node.recipeId);
|
|
447
|
+
const found = recipe === void 0 ? null : findTextContextViolation([recipe.target], context, walker);
|
|
448
|
+
walker.stack.delete(key);
|
|
449
|
+
if (found !== null) return found;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (node.kind === "children-projection" && context.kind !== "flow") return {
|
|
453
|
+
node,
|
|
454
|
+
context,
|
|
455
|
+
detail: "a props.children projection"
|
|
456
|
+
};
|
|
457
|
+
if (node.kind !== "element") continue;
|
|
458
|
+
const found = findTextContextViolation(node.children, textContextForChild(context, node.tag), walker);
|
|
459
|
+
if (found !== null) return found;
|
|
460
|
+
}
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Refuse a chunk whose text cannot be claimed in the target parser context.
|
|
465
|
+
* This is a source-located compile failure, not a silent mount-only fallback:
|
|
466
|
+
* the same authored component must not quietly change execution mode. The scan
|
|
467
|
+
* crosses component/insertion chunks because the parent's parser context
|
|
468
|
+
* applies to the child's emitted comments too.
|
|
469
|
+
*/
|
|
470
|
+
function assertTextBoundaryContext(state, nodes) {
|
|
471
|
+
const violation = findTextContextViolation(nodes, { kind: "flow" }, textContextWalker(state));
|
|
472
|
+
if (violation === null) return true;
|
|
473
|
+
diag(state, "OEIR_LEAF_UNSUPPORTED_TEXT_CONTEXT", `${violation.detail} under <${violation.context.tag}> cannot be claimed: ${textContextReason(violation.context)}`, violation.node.span);
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
function directoryParentAllowed(tag) {
|
|
477
|
+
return TAG_PATTERN.test(tag) && !DIRECTORY_EXCLUDED_TAGS.has(tag);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* A dash tag is a nested custom-element host (the same test the SSR producer
|
|
481
|
+
* already applies at its dash-tag branch). A host's content is not this
|
|
482
|
+
* component's template: the render's expander owns it and injects children no
|
|
483
|
+
* authored declaration describes, so the host cannot be a static-sibling range
|
|
484
|
+
* MEMBER either — the parent's directory would then bracket a subtree whose
|
|
485
|
+
* markers and children belong to the nested host's own claim.
|
|
486
|
+
*/
|
|
487
|
+
function isNestedHostTag(tag) {
|
|
488
|
+
return tag.includes("-");
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* A fully static element tree: no dynamic slots, sites, excluded tags, or
|
|
492
|
+
* nested custom-element hosts (see {@linkcode isNestedHostTag}: their expanded
|
|
493
|
+
* interior is another claim's region).
|
|
494
|
+
*/
|
|
495
|
+
function isStaticDirectoryElement(node) {
|
|
496
|
+
if (node.kind !== "element") return false;
|
|
497
|
+
if (!directoryParentAllowed(node.tag)) return false;
|
|
498
|
+
if (isNestedHostTag(node.tag)) return false;
|
|
499
|
+
for (const attribute of node.attributes) if (attribute.kind !== "static" || !ATTRIBUTE_PATTERN.test(attribute.name)) return false;
|
|
500
|
+
for (const child of flattenFragments(node.children)) {
|
|
501
|
+
if (child.kind === "text") continue;
|
|
502
|
+
if (!isStaticDirectoryElement(child)) return false;
|
|
503
|
+
}
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Two or more static element siblings, fragments flattened. One child stays on
|
|
508
|
+
* the M07a path. Text, dynamic slots, and insertion sites make this `null`,
|
|
509
|
+
* so the parent is not wrapped and text is left where it is.
|
|
510
|
+
*/
|
|
511
|
+
function staticElementDirectory(nodes) {
|
|
512
|
+
const flat = normalizeTextRuns(nodes);
|
|
513
|
+
if (flat.length < 2) return null;
|
|
514
|
+
if (!flat.every((node) => isStaticDirectoryElement(node))) return null;
|
|
515
|
+
return flat;
|
|
516
|
+
}
|
|
517
|
+
function declaredStaticLiteral(node) {
|
|
518
|
+
if (node.kind === "text") return `{ kind: "text", nodeValue: ${JSON.stringify(node.value)} }`;
|
|
519
|
+
if (node.kind !== "element") return "{ kind: \"text\", nodeValue: \"\" }";
|
|
520
|
+
const attributes = node.attributes.filter((attribute) => attribute.kind === "static").map((attribute) => `{ name: ${JSON.stringify(attribute.name)}, value: ${JSON.stringify(attribute.value)} }`).join(", ");
|
|
521
|
+
const children = normalizeTextRuns(node.children).map((child) => declaredStaticLiteral(child)).join(", ");
|
|
522
|
+
return `{ kind: "element", localName: ${JSON.stringify(node.tag)}, attributes: [${attributes}], children: [${children}] }`;
|
|
523
|
+
}
|
|
524
|
+
function recipeMap(component) {
|
|
525
|
+
return new Map(component.recipes.map((recipe) => [recipe.id, recipe]));
|
|
526
|
+
}
|
|
527
|
+
function declaredRecipeIdSet(component) {
|
|
528
|
+
const ids = /* @__PURE__ */ new Set();
|
|
529
|
+
for (const resource of component.resources) if (resource.recipeId !== null) ids.add(resource.recipeId);
|
|
530
|
+
return ids;
|
|
531
|
+
}
|
|
532
|
+
function componentOwnsReactiveResources(component) {
|
|
533
|
+
return component.resources.some((resource) => resource.kind === "signal" || resource.kind === "computed");
|
|
534
|
+
}
|
|
535
|
+
/** Fragment roots that mount as one directory on their claim parent. */
|
|
536
|
+
function isDirectoryRootComponent(component) {
|
|
537
|
+
return staticElementDirectory(component.roots) !== null;
|
|
538
|
+
}
|
|
539
|
+
function attributesClaimable(attributes) {
|
|
540
|
+
for (const attribute of attributes) {
|
|
541
|
+
if (attribute.kind === "static") {
|
|
542
|
+
if (!ATTRIBUTE_PATTERN.test(attribute.name)) return false;
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
if (CONSUMED_ATTRIBUTE_CHANNELS.has(attribute.channel)) continue;
|
|
546
|
+
if (CLIENT_ONLY_ATTRIBUTE_CHANNELS.has(attribute.channel)) continue;
|
|
547
|
+
if (!ADMITTED_ATTRIBUTE_CHANNELS.has(attribute.channel)) return false;
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* M07a static leaf, plus M07-1 composition that can adopt an existing sibling
|
|
553
|
+
* list in author order, plus M08-2 condition branches whose nodes were already
|
|
554
|
+
* claimable before the condition itself (text, dynamic-text pairs, attributes).
|
|
555
|
+
*
|
|
556
|
+
* The extra `insideTemplate` flag is the composition boundary: a component
|
|
557
|
+
* reference, insertion site or children projection inside a condition branch is
|
|
558
|
+
* refused (mount-only) because the branch chunk would have to align three
|
|
559
|
+
* ownership layers at once. Elements do not change "inside a template"; a
|
|
560
|
+
* condition is a new chunk for ordinals but not a second claim mechanism.
|
|
561
|
+
*
|
|
562
|
+
* The `context` parameter is the parser context the emitted nodes land in.
|
|
563
|
+
* Conditions write two comments, so a condition under RCDATA/rawtext/template/
|
|
564
|
+
* noscript/foreign/foster/select ancestry is not claimable; the same rule
|
|
565
|
+
* crosses a component reference. This is a claimability decision, never a
|
|
566
|
+
* silent marker emitted inside a context that would not parse it.
|
|
567
|
+
*/
|
|
568
|
+
function nodeClaimable(node, component, ctx, insideTemplate = false, context = { kind: "flow" }) {
|
|
569
|
+
switch (node.kind) {
|
|
570
|
+
case "text":
|
|
571
|
+
case "dynamic-text": return true;
|
|
572
|
+
case "fragment": return node.children.every((child) => nodeClaimable(child, component, ctx, insideTemplate, context));
|
|
573
|
+
case "element": {
|
|
574
|
+
if (!TAG_PATTERN.test(node.tag)) return false;
|
|
575
|
+
if (!attributesClaimable(node.attributes)) return false;
|
|
576
|
+
const childContext = textContextForChild(context, node.tag);
|
|
577
|
+
return node.children.every((child) => nodeClaimable(child, component, ctx, insideTemplate, childContext));
|
|
578
|
+
}
|
|
579
|
+
case "condition":
|
|
580
|
+
if (insideTemplate) return false;
|
|
581
|
+
if (context.kind !== "flow") return false;
|
|
582
|
+
return [node.consequent, ...node.alternate === null ? [] : [node.alternate]].every((branch) => branch.every((child) => nodeClaimable(child, component, ctx, true, context)));
|
|
583
|
+
case "list":
|
|
584
|
+
if (insideTemplate) return false;
|
|
585
|
+
if (context.kind !== "flow") return false;
|
|
586
|
+
return node.template.every((child) => nodeClaimable(child, component, ctx, true, context));
|
|
587
|
+
case "insertion-site": {
|
|
588
|
+
if (insideTemplate) return false;
|
|
589
|
+
if (!declaredRecipeIdSet(component).has(node.recipeId)) return false;
|
|
590
|
+
const recipe = recipeMap(component).get(node.recipeId);
|
|
591
|
+
if (recipe === void 0) return false;
|
|
592
|
+
if (treeHasList([recipe.target])) return false;
|
|
593
|
+
return nodeClaimable(recipe.target, component, ctx, false, context);
|
|
594
|
+
}
|
|
595
|
+
case "children-projection": return !insideTemplate;
|
|
596
|
+
case "component-ref": {
|
|
597
|
+
if (insideTemplate) return false;
|
|
598
|
+
if (node.props.some((prop) => prop.name === "children")) return false;
|
|
599
|
+
if (!attributesClaimable(node.props.filter((prop) => prop.name !== "key"))) return false;
|
|
600
|
+
const target = ctx.componentByName.get(node.name);
|
|
601
|
+
if (target === void 0 || target.propsParam === null) return false;
|
|
602
|
+
if (componentOwnsReactiveResources(target)) return false;
|
|
603
|
+
if (isDirectoryRootComponent(target)) return false;
|
|
604
|
+
if (!componentClaimable(target, ctx, context)) return false;
|
|
605
|
+
if (node.childrenRecipeId !== null) {
|
|
606
|
+
const recipe = recipeMap(component).get(node.childrenRecipeId);
|
|
607
|
+
if (recipe === void 0) return false;
|
|
608
|
+
return nodeClaimable(recipe.target, component, ctx, false, context);
|
|
609
|
+
}
|
|
610
|
+
if (componentProjectsChildren(target)) return false;
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
default: return false;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function componentClaimable(component, ctx, context = { kind: "flow" }) {
|
|
617
|
+
if (ctx.stack.has(component.name)) return false;
|
|
618
|
+
ctx.stack.add(component.name);
|
|
619
|
+
try {
|
|
620
|
+
return component.roots.every((node) => nodeClaimable(node, component, ctx, false, context));
|
|
621
|
+
} finally {
|
|
622
|
+
ctx.stack.delete(component.name);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function treeHasComposition(nodes) {
|
|
626
|
+
for (const node of nodes) switch (node.kind) {
|
|
627
|
+
case "insertion-site":
|
|
628
|
+
case "children-projection":
|
|
629
|
+
case "component-ref": return true;
|
|
630
|
+
case "element":
|
|
631
|
+
case "fragment":
|
|
632
|
+
if (treeHasComposition(node.children)) return true;
|
|
633
|
+
break;
|
|
634
|
+
case "condition":
|
|
635
|
+
if (treeHasComposition(node.consequent)) return true;
|
|
636
|
+
if (node.alternate !== null && treeHasComposition(node.alternate)) return true;
|
|
637
|
+
break;
|
|
638
|
+
case "list": if (treeHasComposition(node.template)) return true;
|
|
639
|
+
}
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* `true` when the node tree contains a list at any depth. Used to keep a list
|
|
644
|
+
* inside a reusable-JSX recipe body out of the claim/SSR surface until that
|
|
645
|
+
* composition has a real consumer test of its own.
|
|
646
|
+
*/
|
|
647
|
+
function treeHasList(nodes) {
|
|
648
|
+
for (const node of nodes) switch (node.kind) {
|
|
649
|
+
case "list": return true;
|
|
650
|
+
case "element":
|
|
651
|
+
case "fragment":
|
|
652
|
+
if (treeHasList(node.children)) return true;
|
|
653
|
+
break;
|
|
654
|
+
case "condition":
|
|
655
|
+
if (treeHasList(node.consequent)) return true;
|
|
656
|
+
if (node.alternate !== null && treeHasList(node.alternate)) return true;
|
|
657
|
+
}
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
function moduleUsesSharedClaimCursor(module, componentByName) {
|
|
661
|
+
const ctx = {
|
|
662
|
+
componentByName,
|
|
663
|
+
stack: /* @__PURE__ */ new Set()
|
|
664
|
+
};
|
|
665
|
+
return module.components.some((component) => componentClaimable(component, ctx) && treeHasComposition(component.roots));
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* The module's STATIC class tokens (deletion prerequisite P-1, 2026-11-21).
|
|
669
|
+
*
|
|
670
|
+
* A utility engine compiles a component's stylesheet from its admitted class
|
|
671
|
+
* candidates, and until now only the class lane, the server function lane (which
|
|
672
|
+
* reuses the class lowering) and packed artifacts produced them. The
|
|
673
|
+
* generated-element lane produced NONE, so a generated shadow component migrated
|
|
674
|
+
* off the class lane silently lost its utilities: the authored `.css` still
|
|
675
|
+
* shipped, the utility classes landed in the document sheet (which a shadow root
|
|
676
|
+
* cannot reach no matter what).
|
|
677
|
+
*
|
|
678
|
+
* The tokens are a MODEL fact, not an emission fact: this walk reads the same
|
|
679
|
+
* `FunctionModelModule` the generator emits, so the set cannot drift from the
|
|
680
|
+
* markup. Dynamic `class` channels are deliberately excluded — an authored
|
|
681
|
+
* expression is not a compile-time candidate, and guessing at one would compile
|
|
682
|
+
* utilities nobody declared. Duplicates are collapsed and the result is sorted,
|
|
683
|
+
* so the registry sees a stable fact.
|
|
684
|
+
*/
|
|
685
|
+
function collectStaticClassCandidates(module) {
|
|
686
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
687
|
+
const visit = (nodes) => {
|
|
688
|
+
for (const node of nodes) switch (node.kind) {
|
|
689
|
+
case "element":
|
|
690
|
+
for (const attribute of node.attributes) {
|
|
691
|
+
if (attribute.kind !== "static" || attribute.name !== "class") continue;
|
|
692
|
+
for (const token of attribute.value.split(/\s+/)) if (token.length > 0) tokens.add(token);
|
|
693
|
+
}
|
|
694
|
+
visit(node.children);
|
|
695
|
+
break;
|
|
696
|
+
case "fragment":
|
|
697
|
+
visit(node.children);
|
|
698
|
+
break;
|
|
699
|
+
case "component-ref": break;
|
|
700
|
+
case "condition":
|
|
701
|
+
visit(node.consequent);
|
|
702
|
+
visit(node.alternate ?? []);
|
|
703
|
+
break;
|
|
704
|
+
case "list": visit(node.template);
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
for (const component of module.components) {
|
|
708
|
+
visit(component.roots);
|
|
709
|
+
for (const recipe of component.recipes) visit([recipe.target]);
|
|
710
|
+
}
|
|
711
|
+
return [...tokens].sort();
|
|
712
|
+
}
|
|
713
|
+
//#endregion
|
|
714
|
+
export { assertTextBoundaryContext, collectStaticClassCandidates, componentClaimable, componentProjectsChildren, declaredRecipeIdSet, declaredStaticLiteral, directoryParentAllowed, emissionNodes, isDirectoryRootComponent, lightSlotAnchorsEnabled, moduleUsesSharedClaimCursor, nodeClaimable, normalizeTextRuns, recipeMap, referencedRecipeIds, slotNameOf, ssrSlotAnchorOrdinals, staticElementDirectory, textOrdinal, textSlotOrdinals, treeHasComposition };
|