@openelement/compiler 1.0.0-alpha.14 → 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.
Files changed (56) hide show
  1. package/package.json +4 -2
  2. package/src/compiler.d.ts +12 -6
  3. package/src/compiler.js +11 -6
  4. package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +11 -0
  5. package/src/internal/compiler/compiled-artifact-class-candidates.js +46 -0
  6. package/src/internal/compiler/compiled-artifact-style-requests.d.ts +26 -7
  7. package/src/internal/compiler/compiled-artifact-style-requests.js +57 -9
  8. package/src/internal/compiler/plugin.d.ts +68 -49
  9. package/src/internal/compiler/plugin.js +93 -82
  10. package/src/internal/compiler/semantic-core/analyze-module.d.ts +73 -0
  11. package/src/internal/compiler/semantic-core/analyze-module.js +29 -379
  12. package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
  13. package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
  14. package/src/internal/compiler/semantic-core/diagnostics/index.d.ts +21 -1
  15. package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
  16. package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
  17. package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
  18. package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
  19. package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
  20. package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
  21. package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
  22. package/src/internal/compiler/semantic-core/lower-program.d.ts +220 -0
  23. package/src/internal/compiler/semantic-core/lower-program.js +350 -142
  24. package/src/internal/compiler/semantic-core/module-analysis.d.ts +82 -4
  25. package/src/internal/compiler/semantic-core/module-analysis.js +88 -19
  26. package/src/internal/compiler/semantic-core/parse-module.js +16 -16
  27. package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
  28. package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
  29. package/src/internal/compiler/semantic-core/server-component.d.ts +129 -0
  30. package/src/internal/compiler/semantic-core/server-component.js +587 -0
  31. package/src/internal/compiler/semantic-core/type-check.js +1 -1
  32. package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
  33. package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
  34. package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
  35. package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
  36. package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
  37. package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
  38. package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
  39. package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
  40. package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
  41. package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
  42. package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
  43. package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
  44. package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
  45. package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
  46. package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
  47. package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
  48. package/src/internal/compiler/style-requests.d.ts +35 -7
  49. package/src/internal/compiler/style-requests.js +57 -11
  50. package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
  51. package/src/internal/compiler/tailwind-candidates.js +54 -0
  52. package/src/internal/compiler/semantic-core/compile.d.ts +0 -39
  53. package/src/internal/compiler/semantic-core/compile.js +0 -98
  54. package/src/internal/compiler/semantic-core/emit-module.js +0 -313
  55. package/src/internal/compiler/semantic-core/emit-program.js +0 -121
  56. package/src/internal/compiler/semantic-core/style-imports.js +0 -87
@@ -0,0 +1,865 @@
1
+ import { ERROR_REPORT_PROPERTY, INTERNAL_PREFIX, MOUNT_HOST, MOUNT_SCOPE, TRANSACTION_VAR, declareReads, importContextOf, moduleUsesErrorBoundary, push, pushParts, recordFor } from "./emission.js";
2
+ import { componentProjectsChildren, recipeMap, referencedRecipeIds } from "./structure.js";
3
+ //#region src/internal/compiler/semantic-ir/generated-leaf/instance-emission.ts
4
+ /**
5
+ * T3 / 16b-LC-1: the module-local ROOT setup factory name.
6
+ *
7
+ * The emitted CE descriptor's `createInstance` row references exactly this
8
+ * name (the tail appends the row when this declaration exists), and the root
9
+ * mount/claim alias the record it returns instead of re-evaluating the setup
10
+ * initializers. It is compiler-owned generated code, not an author hook and
11
+ * not a package export: the `__oe_` prefix is refused for every authored
12
+ * identifier, and `nextName` always emits a counter suffix, so neither an
13
+ * authored name nor a generator-local name can collide with this fixed
14
+ * module-scope declaration.
15
+ */
16
+ const GENERATED_ROOT_INSTANCE_NAME = `${INTERNAL_PREFIX}rootInstance`;
17
+ /**
18
+ * `16b-LC` option 1a: the compiler-owned key/array name carrying the ROOT's
19
+ * admitted `onConnect` callbacks through the retained instance record.
20
+ *
21
+ * The `__oe_rootInstance` factory pushes every lowered callback into this
22
+ * array and returns it with the setup record; the root mount/claim PROLOGUE
23
+ * replays the array on the per-connection scope the shell handed it and
24
+ * registers each returned cleanup on that same scope. It is not a runtime hook
25
+ * dispatcher and not author syntax: the record field is read by generated code
26
+ * only, the `__oe_` prefix is refused for every authored identifier, and the
27
+ * name is a fixed compiler-owned local, so it cannot collide with an authored
28
+ * name or a `nextName` identifier.
29
+ */
30
+ const GENERATED_ROOT_CONNECT_RECORD = `${INTERNAL_PREFIX}connect`;
31
+ /**
32
+ * `16b-LC` option 1a env form: the compiler-owned retained-record key carrying
33
+ * the callbacks that declare the one `env` parameter. It is a SEPARATE record
34
+ * on purpose: a module whose hooks are all zero-argument keeps the exact
35
+ * pre-env bytes, and the replay for each form is emitted only when that form is
36
+ * present. Like `__oe_connect`, the key is read by generated code only.
37
+ */
38
+ const GENERATED_ROOT_CONNECT_ENV_RECORD = `${INTERNAL_PREFIX}connectEnv`;
39
+ /**
40
+ * The compiler-private host-record property carrying the element a connection
41
+ * belongs to: the generated element itself for the root, and the nearest
42
+ * ancestor generated element for a depth-1 retained hostless child. The shell
43
+ * attaches it as a runtime property (`hostFor`/`instanceHostFor`) — the
44
+ * exported host types are not changed and no exported symbol is added.
45
+ */
46
+ const HOST_ELEMENT_PROPERTY = `${INTERNAL_PREFIX}hostElement`;
47
+ /** Replay locals the root mount/claim prologue uses (all compiler-owned). */
48
+ const LIFECYCLE_HOOKS_VAR = `${INTERNAL_PREFIX}lifecycleHooks`;
49
+ const LIFECYCLE_HOOK_VAR = `${INTERNAL_PREFIX}lifecycleHook`;
50
+ const LIFECYCLE_CLEANUP_VAR = `${INTERNAL_PREFIX}lifecycleCleanup`;
51
+ /** Env-form replay locals (separate from the zero-argument ones). */
52
+ const LIFECYCLE_ENV_HOOKS_VAR = `${INTERNAL_PREFIX}lifecycleEnvHooks`;
53
+ const LIFECYCLE_ENV_HOOK_VAR = `${INTERNAL_PREFIX}lifecycleEnvHook`;
54
+ const LIFECYCLE_ENV_CLEANUP_VAR = `${INTERNAL_PREFIX}lifecycleEnvCleanup`;
55
+ /** The instance-lifetime signal an `onDispose(env)` registration captures. */
56
+ const TEARDOWN_SIGNAL_VAR = `${INTERNAL_PREFIX}teardownSignal`;
57
+ /**
58
+ * The compiler-private host-record property that registers an element-lifetime
59
+ * `onPropertyChange` callback. The shell owns the actual listener list and the
60
+ * env it builds; generated code only registers through this channel, exactly
61
+ * like `__oe_hostElement` is a runtime property and not an exported symbol.
62
+ */
63
+ const PROPERTY_CHANGE_PROPERTY = `${INTERNAL_PREFIX}onPropertyChange`;
64
+ /** The host-record property exposing the element's `CustomStateSet` to the env. */
65
+ const STATES_PROPERTY = `${INTERNAL_PREFIX}states`;
66
+ /**
67
+ * `16b-EB`: the compiler-private host-record property that registers the
68
+ * element-lifetime `onError` handler. The shell owns the capture points and the
69
+ * handler list; generated code only registers through this channel, exactly like
70
+ * `__oe_onPropertyChange`. Registration is FORWARDED through host literals only
71
+ * for modules that use the intrinsic, so every other module keeps its bytes.
72
+ */
73
+ const ERROR_HANDLER_PROPERTY = `${INTERNAL_PREFIX}onError`;
74
+ /**
75
+ * `16b-CTX`: the compiler-private host-record property that exposes the
76
+ * generated element's ONE context scope. The shell owns the service; generated
77
+ * code only calls `provider(token, read)`, `use(token)` and `owner()` through
78
+ * this channel, exactly like `__oe_onPropertyChange` and `__oe_onError` are
79
+ * runtime properties rather than exported symbols.
80
+ */
81
+ const CONTEXT_SCOPE_PROPERTY = `${INTERNAL_PREFIX}context`;
82
+ /**
83
+ * `16b-CTX`: the compiler-owned retained record field carrying THIS component's
84
+ * owner scope channel.
85
+ *
86
+ * A generated element ROOT provides and consumes on the element anchor itself
87
+ * (so every depth-1 child sees its providers). A hostless component is an owner
88
+ * in its own right: its scope is `anchor.owner()`, a CHILD of the anchor, so its
89
+ * provider is invisible to its siblings while its own consumers still resolve
90
+ * the anchor's ancestors. Storing that channel in the retained record is what
91
+ * makes the component's whole subtree — and its own consumers — agree on one
92
+ * scope across a reconnect.
93
+ */
94
+ const GENERATED_CONTEXT_SCOPE_RECORD = `${INTERNAL_PREFIX}contextScope`;
95
+ /**
96
+ * `16b-CTX` — the SSR producer's optional trailing parameter carrying the
97
+ * ENCLOSING render scope channel.
98
+ *
99
+ * It is a PARAMETER, never a module global: two concurrent server renders each
100
+ * own their scope, and a producer that reads one request's value out of module
101
+ * state would share it with the other. A context-using component's producer does
102
+ *
103
+ * `const __oe_contextScope = __oe_ssrContext === undefined
104
+ * ? createRenderContextScope()
105
+ * : __oe_ssrContext.owner();`
106
+ *
107
+ * which is the SERVER spelling of the client's two owner shapes: the module root
108
+ * creates the render's anchor (the host wrapper and the light serializer pass no
109
+ * scope), and a depth-1 child joins it as `anchor.owner()` — the identical rule
110
+ * the client's retained setup factory uses.
111
+ */
112
+ const SSR_CONTEXT_PARAM = `${INTERNAL_PREFIX}ssrContext`;
113
+ /**
114
+ * Whether any component in the module uses a `16b-CTX` intrinsic. The channel is
115
+ * forwarded through the host-record literals only for such a module, so every
116
+ * other module keeps its exact bytes.
117
+ */
118
+ function moduleUsesContext(state) {
119
+ for (const component of state.componentByName.values()) {
120
+ if (component.contextProviders.length > 0) return true;
121
+ if (component.resources.some((resource) => resource.kind === "context")) return true;
122
+ }
123
+ return false;
124
+ }
125
+ /**
126
+ * Whether any component in the module registers an `onPropertyChange`
127
+ * callback. The registration channel is forwarded through the host-record
128
+ * literals only for such a module, so every other module keeps its exact bytes.
129
+ */
130
+ function moduleUsesPropertyChange(state) {
131
+ for (const component of state.componentByName.values()) if (component.lifecycle.some((hook) => hook.kind === "property-change")) return true;
132
+ return false;
133
+ }
134
+ /**
135
+ * Whether any component in the module declares an env-form lifecycle callback.
136
+ * The host-element property is forwarded through the host-record literals only
137
+ * for such a module, so a module that never opts into the env form keeps its
138
+ * exact pre-env bytes (including every hook-free SHA pin).
139
+ */
140
+ /**
141
+ * True when ANY component in the module declares a `useHost()` accessor
142
+ * (`16b-REF`).
143
+ *
144
+ * The lowering is a field read on the setup host record, so the record must
145
+ * carry the element. A generated element ROOT gets it unconditionally (the
146
+ * shell attaches it), but a RETAINED depth-1 hostless child's host literal is
147
+ * built by the parent and only forwards the fields the child actually reads —
148
+ * which is why this fact has to be module-wide, exactly like the env-form
149
+ * lifecycle gate beside it.
150
+ */
151
+ function moduleUsesHostAccess(state) {
152
+ for (const component of state.componentByName.values()) if (component.resources.some((resource) => resource.kind === "host")) return true;
153
+ return false;
154
+ }
155
+ /** True when `component` itself declares a `useHost()` accessor. */
156
+ function componentUsesHostAccess(component) {
157
+ return component.resources.some((resource) => resource.kind === "host");
158
+ }
159
+ function moduleUsesLifecycleEnv(state) {
160
+ for (const component of state.componentByName.values()) if (component.lifecycle.some((hook) => hook.kind !== "property-change" && hook.kind !== "error" && hook.receivesEnv)) return true;
161
+ return false;
162
+ }
163
+ /**
164
+ * The host-element field a RETAINED reference-site host literal forwards to a
165
+ * depth-1 child that declares an env-form lifecycle callback. Empty otherwise,
166
+ * so every other module and reference site keeps its exact bytes.
167
+ */
168
+ function childHostElementField(state, node) {
169
+ const child = state.componentByName.get(node.name);
170
+ if (child === void 0) return "";
171
+ if (!(moduleUsesLifecycleEnv(state) && child.lifecycle.some((hook) => hook.receivesEnv) || componentUsesHostAccess(child))) return "";
172
+ return `, ${HOST_ELEMENT_PROPERTY}: ${state.hostVar}.${HOST_ELEMENT_PROPERTY}, ${STATES_PROPERTY}: ${state.hostVar}.${STATES_PROPERTY}`;
173
+ }
174
+ /** The change channel a retained child setup host forwards (empty otherwise). */
175
+ function childPropertyChangeField(state, node) {
176
+ if (!moduleUsesPropertyChange(state)) return "";
177
+ const child = state.componentByName.get(node.name);
178
+ if (child === void 0 || !child.lifecycle.some((hook) => hook.kind === "property-change")) return "";
179
+ return `, ${PROPERTY_CHANGE_PROPERTY}: ${state.hostVar}.${PROPERTY_CHANGE_PROPERTY}`;
180
+ }
181
+ /**
182
+ * The `16b-CTX` channel a RETAINED reference-site host literal forwards to a
183
+ * depth-1 child that uses a context intrinsic. Empty otherwise, so every other
184
+ * module and reference site keeps its exact bytes. Both the child's setup host
185
+ * (provider registration and consumer construction) and its mount/claim host
186
+ * (the alias the body reads) need it, which is why the same field rides both.
187
+ */
188
+ function childContextField(state, node) {
189
+ if (!moduleUsesContext(state)) return "";
190
+ const child = state.componentByName.get(node.name);
191
+ if (child === void 0) return "";
192
+ if (!(child.contextProviders.length > 0 || child.resources.some((resource) => resource.kind === "context"))) return "";
193
+ return `, ${CONTEXT_SCOPE_PROPERTY}: ${state.hostVar}.${CONTEXT_SCOPE_PROPERTY}`;
194
+ }
195
+ /**
196
+ * The `16b-EB` channels a RETAINED reference-site host literal forwards to a
197
+ * depth-1 child that declares `onError`: the registration channel (so the
198
+ * child's `<Name>__setup` can register on the element's one handler list) and
199
+ * the update-phase sink (so the child's own refresh subscriptions are guarded).
200
+ * Empty otherwise, so every other module and reference site keeps its bytes.
201
+ */
202
+ function childErrorBoundaryField(state, node) {
203
+ if (!moduleUsesErrorBoundary(state)) return "";
204
+ const child = state.componentByName.get(node.name);
205
+ if (child === void 0 || !child.lifecycle.some((hook) => hook.kind === "error")) return "";
206
+ return `, ${ERROR_HANDLER_PROPERTY}: ${state.hostVar}.${ERROR_HANDLER_PROPERTY}, ${ERROR_REPORT_PROPERTY}: ${state.hostVar}.${ERROR_REPORT_PROPERTY}`;
207
+ }
208
+ /**
209
+ * The `16b-EB` update-phase sink alone, for the `__oe_childHost` literal a
210
+ * retained child's MOUNT/CLAIM body reads. Registration belongs to the setup
211
+ * host, but the refresh subscriptions are opened by the mount/claim body, so it
212
+ * needs the sink there too. Without this the child's refresh would call
213
+ * `guardUpdate(fn, undefined)` and propagate — the enclosing element's handler
214
+ * would never see the throw. Empty otherwise, keeping every other site's bytes.
215
+ */
216
+ function childErrorReportField(state, node) {
217
+ if (!moduleUsesErrorBoundary(state)) return "";
218
+ const child = state.componentByName.get(node.name);
219
+ if (child === void 0 || !child.lifecycle.some((hook) => hook.kind === "error")) return "";
220
+ return `, ${ERROR_REPORT_PROPERTY}: ${state.hostVar}.${ERROR_REPORT_PROPERTY}`;
221
+ }
222
+ /**
223
+ * 16b-LC retained-child: the module-local setup factory a RETAINED hostless child exposes to
224
+ * its retaining reference site (`<Name>__setup`). Synthesized from the
225
+ * component's own name, exactly like `<Name>__mount`/`<Name>__claim`, so it can
226
+ * never collide with another component's generated declarations; it adds no
227
+ * descriptor row, no metadata and no diagnostic. The factory runs once on the
228
+ * ledger-owned retained scope and its return value is the retained record the
229
+ * child body aliases.
230
+ */
231
+ const LEAF_SETUP_SUFFIX = "__setup";
232
+ /**
233
+ * The retained-record source property of each generated host record:
234
+ * the ROOT body aliases the shell's retained `bindings` record, while a LEAF
235
+ * body aliases the compiler-private `setup` property of the child host literal
236
+ * the retaining reference site built. One property per body mode; no runtime
237
+ * probing and no fallback branch.
238
+ */
239
+ const ROOT_SETUP_HOST_PROPERTY = "bindings";
240
+ const LEAF_SETUP_HOST_PROPERTY = "setup";
241
+ /**
242
+ * 16b-LC retained-child site key: the ONE authored-span literal emitted by both the mount
243
+ * and the claim reference-site emitters. Identity is the authored span
244
+ * (`IrSpan` UTF-16 start/end), so the same site re-claiming on a new connection
245
+ * reuses the same ledger entry and two distinct sites can never share one. The
246
+ * runtime never parses or derives it.
247
+ */
248
+ function siteKeyLiteral(span) {
249
+ return JSON.stringify(`${span.file}:${span.start}:${span.end}`);
250
+ }
251
+ /**
252
+ * Root mount/claim alias of the retained setup record (`__oe_host.bindings`).
253
+ * Presence is checked with `Object.hasOwn`, so a legitimately `undefined` setup
254
+ * value is retained; the host-binding `__oe_requireBinding` helper keeps its
255
+ * documented undefined-means-missing identity (two records, two deliberate
256
+ * semantics).
257
+ */
258
+ const ROOT_SETUP_RECORD = `${INTERNAL_PREFIX}setup`;
259
+ /** The own-property presence helper used by the root mount/claim aliases. */
260
+ const ROOT_SETUP_REQUIRE = `${INTERNAL_PREFIX}requireRootSetup`;
261
+ function collectComponentRefSites(component, nodes, inRecipe, inList, sink) {
262
+ for (const node of nodes) switch (node.kind) {
263
+ case "component-ref":
264
+ sink.push({
265
+ node,
266
+ owner: component.name,
267
+ inRecipe,
268
+ inList
269
+ });
270
+ break;
271
+ case "element":
272
+ case "fragment":
273
+ collectComponentRefSites(component, node.children, inRecipe, inList, sink);
274
+ break;
275
+ case "condition":
276
+ collectComponentRefSites(component, node.consequent, inRecipe, inList, sink);
277
+ if (node.alternate !== null) collectComponentRefSites(component, node.alternate, inRecipe, inList, sink);
278
+ break;
279
+ case "list": collectComponentRefSites(component, node.template, inRecipe, true, sink);
280
+ }
281
+ }
282
+ /**
283
+ * Collect every emitted component-reference site. `recipes` selects whether
284
+ * unreferenced (never emitted) recipes participate: the eligibility fixpoint
285
+ * only counts emitted bodies, while the root-target guard is a deliberate
286
+ * conservative superset and walks every recipe.
287
+ */
288
+ function collectModuleRefSites(module, recipes) {
289
+ const sites = [];
290
+ for (const component of module.components) {
291
+ collectComponentRefSites(component, component.roots, false, false, sites);
292
+ const emitted = recipes === "all" ? null : referencedRecipeIds(component);
293
+ for (const recipe of component.recipes) {
294
+ if (emitted !== null && !emitted.has(recipe.id)) continue;
295
+ collectComponentRefSites(component, [recipe.target], true, false, sites);
296
+ }
297
+ }
298
+ return sites;
299
+ }
300
+ /**
301
+ * The root-style setup gateway (`generate.ts` `rootSetup` facts, shared here so
302
+ * one body shape per component): a setup local may read props, other setup
303
+ * locals and plain globals only. Any other read is a host-binding read
304
+ * (`declareReads`'s fallback), and the retained setup scope has no bindings
305
+ * record, so such a component stays legacy and its references emit today's
306
+ * inline text.
307
+ */
308
+ function setupReadAllowed(read, setupLocals, imports) {
309
+ if (read.name === "props" || read.binding.name === "props") return true;
310
+ if (setupLocals.has(read.name) || setupLocals.has(read.binding.name)) return true;
311
+ if (read.value === "plain" && read.binding.name === read.name && read.binding.scope.path === "global") return true;
312
+ if (imports !== void 0 && imports.byLocal.has(read.name)) return true;
313
+ return false;
314
+ }
315
+ function setupGatewayPasses(component, records, imports) {
316
+ const hostBindings = new Set(component.resources.filter((resource) => resource.kind === "signal" || resource.kind === "computed").map((r) => r.name));
317
+ const setupLocals = new Set(component.resources.filter((resource) => (resource.kind === "local" || resource.kind === "ref" || resource.kind === "context") && resource.recipeId === null && resource.expression !== null).map((resource) => resource.name));
318
+ for (const hook of component.lifecycle) {
319
+ const record = records.get(hook.callback.id);
320
+ if (record === void 0) return false;
321
+ if (record.lowered.includes("__oe_recipe_ref")) return false;
322
+ if (!record.reads.every((read) => setupReadAllowed(read, setupLocals, imports))) return false;
323
+ }
324
+ for (const provider of component.contextProviders) for (const ref of [provider.token, provider.value]) {
325
+ const record = records.get(ref.id);
326
+ if (record === void 0) return false;
327
+ if (record.lowered.includes("__oe_recipe_ref")) return false;
328
+ if (!record.reads.every((read) => setupReadAllowed(read, setupLocals, imports))) return false;
329
+ }
330
+ for (const resource of component.resources) {
331
+ if (resource.recipeId !== null || resource.expression === null) continue;
332
+ if (resource.kind !== "local" && resource.kind !== "ref" && resource.kind !== "context") continue;
333
+ const record = records.get(resource.expression.id);
334
+ if (record === void 0) return false;
335
+ if (record.lowered.includes("__oe_recipe_ref")) return false;
336
+ for (const read of record.reads) {
337
+ if (read.name === "props" || read.binding.name === "props") continue;
338
+ if (setupLocals.has(read.name) || setupLocals.has(read.binding.name)) continue;
339
+ if (read.value === "plain" && read.binding.name === read.name && read.binding.scope.path === "global") continue;
340
+ if (imports !== void 0 && imports.byLocal.has(read.name)) continue;
341
+ if (hostBindings.has(read.name) || hostBindings.has(read.binding.name)) return false;
342
+ return false;
343
+ }
344
+ }
345
+ return true;
346
+ }
347
+ /**
348
+ * Compute the retention plan, or `null` when this module emits today's bytes
349
+ * exactly (no eligible site, or a root-target reference).
350
+ *
351
+ * Depth-1 vs depth >= 2 is the SAME fixpoint with one more owner class: a site
352
+ * is retention-eligible when its owner emits retain calls (the root, or a
353
+ * retained component that itself retains children). The plan starts at the
354
+ * greatest candidate set and demotes monotonically, so a component referenced
355
+ * from BOTH a retaining body and a legacy/recipe/list body ends up legacy
356
+ * everywhere (one body shape per component, no runtime probing), and the
357
+ * transaction flag is true only when a retained child is itself a retaining
358
+ * body. A depth-1 module therefore keeps its exact pre-change bytes.
359
+ */
360
+ function planRetention(module, componentByName, records, rootName) {
361
+ if (rootName === void 0 || !componentByName.has(rootName)) return null;
362
+ if (collectModuleRefSites(module, "all").some((site) => site.node.name === rootName)) return null;
363
+ const sites = collectModuleRefSites(module, "emitted");
364
+ const byTarget = /* @__PURE__ */ new Map();
365
+ for (const site of sites) {
366
+ const list = byTarget.get(site.node.name);
367
+ if (list === void 0) byTarget.set(site.node.name, [site]);
368
+ else list.push(site);
369
+ }
370
+ const candidates = /* @__PURE__ */ new Set();
371
+ for (const component of module.components) {
372
+ if (component.name === rootName) continue;
373
+ if (setupGatewayPasses(component, records, importContextOf(component))) candidates.add(component.name);
374
+ }
375
+ const retained = new Set(candidates);
376
+ const retaining = /* @__PURE__ */ new Set([rootName, ...retained]);
377
+ let changed = true;
378
+ while (changed) {
379
+ changed = false;
380
+ for (const name of [...retained]) {
381
+ const targetSites = byTarget.get(name) ?? [];
382
+ if (targetSites.length === 0) {
383
+ retained.delete(name);
384
+ retaining.delete(name);
385
+ changed = true;
386
+ continue;
387
+ }
388
+ if (!targetSites.every((site) => !site.inRecipe && !site.inList && retaining.has(site.owner) && (site.owner === rootName || retained.has(site.owner)))) {
389
+ retained.delete(name);
390
+ retaining.delete(name);
391
+ changed = true;
392
+ }
393
+ }
394
+ for (const name of [...retaining]) {
395
+ if (name === rootName) continue;
396
+ if (!sites.some((site) => site.owner === name && !site.inRecipe && !site.inList && retained.has(site.node.name))) {
397
+ retaining.delete(name);
398
+ changed = true;
399
+ }
400
+ }
401
+ }
402
+ const retainedRefs = /* @__PURE__ */ new Set();
403
+ for (const site of sites) {
404
+ if (site.inRecipe || site.inList) continue;
405
+ if (!retaining.has(site.owner)) continue;
406
+ if (site.owner !== rootName && !retained.has(site.owner)) continue;
407
+ if (retained.has(site.node.name)) retainedRefs.add(site.node);
408
+ }
409
+ if (retainedRefs.size === 0) return null;
410
+ const retainingBodies = /* @__PURE__ */ new Set([rootName]);
411
+ for (const site of sites) {
412
+ if (!retainedRefs.has(site.node)) continue;
413
+ if (retained.has(site.owner)) retainingBodies.add(site.owner);
414
+ }
415
+ const transaction = sites.some((site) => retainedRefs.has(site.node) && retainingBodies.has(site.node.name));
416
+ const setupBodies = /* @__PURE__ */ new Set();
417
+ for (const name of retained) {
418
+ const component = componentByName.get(name);
419
+ if (component.lifecycle.length > 0 || component.contextProviders.length > 0 || component.resources.some((resource) => (resource.kind === "local" || resource.kind === "ref" || resource.kind === "context") && resource.recipeId === null)) setupBodies.add(name);
420
+ }
421
+ return {
422
+ rootName,
423
+ retainedRefs,
424
+ leafBodies: retained,
425
+ setupBodies,
426
+ retainingBodies,
427
+ transaction
428
+ };
429
+ }
430
+ /**
431
+ * Collect every `<Child>…</Child>` reference site in one component's roots: the
432
+ * child mount will project that children recipe whenever `<Child>` itself
433
+ * projects `props.children` (M06b2a). Used by `findMountCycle` to add the
434
+ * conservative projection edge `c:<Child> -> r:<defining>:<childrenRecipeId>`,
435
+ * so a component that projects the children of a reference back to itself is
436
+ * refused instead of emitting an unbounded mount.
437
+ */
438
+ function collectChildrenProjectionEdges(component, out) {
439
+ const walk = (nodes) => {
440
+ for (const node of nodes) switch (node.kind) {
441
+ case "component-ref":
442
+ if (node.childrenRecipeId !== null) out.push({
443
+ projectingComponent: node.name,
444
+ definingComponent: component.name,
445
+ recipeId: node.childrenRecipeId,
446
+ span: node.span
447
+ });
448
+ break;
449
+ case "element":
450
+ case "fragment":
451
+ walk(node.children);
452
+ break;
453
+ case "condition":
454
+ walk(node.consequent);
455
+ if (node.alternate !== null) walk(node.alternate);
456
+ break;
457
+ case "list": walk(node.template);
458
+ }
459
+ };
460
+ walk(component.roots);
461
+ }
462
+ /**
463
+ * The `16b-REF` handle expression the retained setup factory emits.
464
+ *
465
+ * A handle is a CALLABLE with one `current` field, which is exactly what the
466
+ * existing intrinsic `ref` channel already accepts: the channel validates
467
+ * `typeof handler === "function"`, calls it with the element on attach, keeps
468
+ * the returned cleanup for detach, and calls it with `null` after that cleanup
469
+ * ran. So the handle IS the channel value — the ref slice adds no sink kind, no
470
+ * second attachment mechanism and no new cleanup ordering; it only makes the
471
+ * handle survive mount/claim/reconnect by building it in the retained factory.
472
+ *
473
+ * Attach order: `current` is populated BEFORE the notification runs, so an
474
+ * author callback observing the handle sees the node. Detach order is the
475
+ * channel's existing one: the notification's cleanup runs first (while
476
+ * `current` still names the node), then this handle is called with `null`,
477
+ * which clears `current` and forwards `null` to the notification.
478
+ */
479
+ function emitSetupBinding(state, local) {
480
+ if (local.kind === "local") {
481
+ if (local.record === null) return;
482
+ pushParts(state, [
483
+ `const ${local.name} = (`,
484
+ { record: local.record },
485
+ ");"
486
+ ], local.span);
487
+ return;
488
+ }
489
+ if (local.kind === "host") {
490
+ push(state, `const ${local.name} = ${state.hostVar}.${HOST_ELEMENT_PROPERTY};`, local.span);
491
+ return;
492
+ }
493
+ if (local.kind === "context") {
494
+ if (local.record === null) return;
495
+ pushParts(state, [
496
+ `const ${local.name} = ${GENERATED_CONTEXT_SCOPE_RECORD}.use((`,
497
+ { record: local.record },
498
+ "));"
499
+ ], local.span);
500
+ return;
501
+ }
502
+ const handle = local.name;
503
+ const tail = ` fn.current = null; return fn; })();`;
504
+ if (local.record === null) {
505
+ pushParts(state, [`const ${handle} = (() => { const fn = (element) => { fn.current = element; };${tail}`], local.span);
506
+ return;
507
+ }
508
+ pushParts(state, [
509
+ `const ${handle} = (() => { const notify = (`,
510
+ { record: local.record },
511
+ `); const fn = (element) => { fn.current = element; return notify(element); };${tail}`
512
+ ], local.span);
513
+ }
514
+ /**
515
+ * `16b-CTX` — emit this component's provider registrations into a retained setup
516
+ * factory.
517
+ *
518
+ * Each admitted `provideContext(token, () => value)` becomes ONE registration on
519
+ * this component's OWNER scope. The owner expression is the channel itself for a
520
+ * generated element ROOT (so a root provider covers every depth-1 child) and
521
+ * `host.<channel>.owner()` for a nested hostless component (so siblings are
522
+ * isolated from each other while both still see the element's ancestors). The
523
+ * thunk is emitted verbatim: the VALUE is re-read on connect and after every
524
+ * declared-property commit — the lane's one change channel — instead of being
525
+ * snapshotted here.
526
+ *
527
+ * `nested` is the placement fact, decided by the same rule that carries the
528
+ * lifecycle hooks (root setup vs retained depth-1 child setup).
529
+ */
530
+ function emitContextProviders(state, providers, records) {
531
+ for (const provider of providers) {
532
+ const token = recordFor(state, provider.token, records);
533
+ const value = recordFor(state, provider.value, records);
534
+ if (token === null || value === null) continue;
535
+ if (!declareReads(state, token)) continue;
536
+ if (!declareReads(state, value)) continue;
537
+ pushParts(state, [
538
+ `${GENERATED_CONTEXT_SCOPE_RECORD}.provider((`,
539
+ { record: token },
540
+ "), (",
541
+ { record: value },
542
+ "));"
543
+ ], provider.span);
544
+ }
545
+ }
546
+ /**
547
+ * `16b-CTX` — emit the component's owner-scope declaration into a retained setup
548
+ * factory.
549
+ *
550
+ * The ROOT owns the element anchor. Every other component is a hostless owner,
551
+ * so its scope is `anchor.owner()` — a child of the anchor. Two sibling hostless
552
+ * children therefore get two distinct scopes and cannot see each other's
553
+ * providers, while both still resolve the element's ancestors, which is exactly
554
+ * the ADR-0182 "nearest owning component, hostless owners included" rule.
555
+ *
556
+ * The declaration is emitted only for a component that uses a context intrinsic,
557
+ * so every other component's bytes are unchanged.
558
+ */
559
+ function emitContextScopeDeclaration(state, component, nested) {
560
+ if (!componentUsesContextIntrinsic(component)) return;
561
+ const channel = `${MOUNT_HOST}.${CONTEXT_SCOPE_PROPERTY}`;
562
+ const expression = nested ? `${channel}.owner()` : channel;
563
+ push(state, `const ${GENERATED_CONTEXT_SCOPE_RECORD} = ${expression};`, component.span);
564
+ }
565
+ /** Does one component itself use `provideContext` or `useContext`? */
566
+ function componentUsesContextIntrinsic(component) {
567
+ return component.contextProviders.length > 0 || component.resources.some((resource) => resource.kind === "context");
568
+ }
569
+ /**
570
+ * `16b-CTX` SERVER side — declare this producer call's owner scope.
571
+ *
572
+ * The scope arrives as a PARAMETER (`__oe_ssrContext`) when an enclosing
573
+ * component reference supplies one, and is created fresh otherwise:
574
+ *
575
+ * - a MODULE ROOT producer (called by the host wrapper or the light serializer
576
+ * with no scope) creates the render's anchor — one per producer call, so two
577
+ * concurrent renders are independent and no request value lives in module
578
+ * state;
579
+ * - a NESTED producer joins the caller as `anchor.owner()`, which is the exact
580
+ * server image of the client's depth-1 hostless owner: a child provider is
581
+ * invisible to the caller's other children while the child still resolves the
582
+ * anchor's providers.
583
+ *
584
+ * The `undefined` guard keeps a hand-written or older caller working: a producer
585
+ * invoked without a scope behaves as the root of its own render rather than
586
+ * reading provider state that does not exist.
587
+ */
588
+ function emitSsrContextScope(state) {
589
+ push(state, `const ${GENERATED_CONTEXT_SCOPE_RECORD} = ${SSR_CONTEXT_PARAM} === undefined ? createRenderContextScope() : ${SSR_CONTEXT_PARAM}.owner();`);
590
+ }
591
+ /**
592
+ * `16b-CTX` SERVER side — does this component's producer need a render scope at
593
+ * all? True when the component itself uses a context intrinsic, or when it
594
+ * renders a component reference whose own producer does (the scope must be
595
+ * threaded down as an argument, never read from module state).
596
+ *
597
+ * A component that neither provides, consumes nor references a scope-using
598
+ * child keeps its exact pre-`16b-CTX` producer bytes: no parameter, no import,
599
+ * no declaration.
600
+ */
601
+ function componentNeedsSsrContextScope(component, componentByName) {
602
+ return ssrScopeNeed(component, componentByName, /* @__PURE__ */ new Set());
603
+ }
604
+ function ssrScopeNeed(component, componentByName, stack) {
605
+ if (componentUsesContextIntrinsic(component)) return true;
606
+ if (stack.has(component.name)) return false;
607
+ stack.add(component.name);
608
+ try {
609
+ return ssrScopeNeedInNodes(component.roots, component, componentByName, stack);
610
+ } finally {
611
+ stack.delete(component.name);
612
+ }
613
+ }
614
+ function ssrScopeNeedInNodes(nodes, component, componentByName, stack) {
615
+ const recipes = recipeMap(component);
616
+ const walk = (list) => {
617
+ for (const node of list) {
618
+ if (node.kind === "fragment" || node.kind === "element") {
619
+ if (walk(node.children)) return true;
620
+ continue;
621
+ }
622
+ if (node.kind === "condition") {
623
+ if (walk(node.consequent)) return true;
624
+ if (node.alternate !== null && walk(node.alternate)) return true;
625
+ continue;
626
+ }
627
+ if (node.kind === "list") {
628
+ if (walk(node.template)) return true;
629
+ continue;
630
+ }
631
+ if (node.kind === "component-ref") {
632
+ const target = componentByName.get(node.name);
633
+ if (target !== void 0 && ssrScopeNeed(target, componentByName, stack)) return true;
634
+ if (node.childrenRecipeId !== null) {
635
+ const recipe = recipes.get(node.childrenRecipeId);
636
+ if (recipe !== void 0 && walk([recipe.target])) return true;
637
+ }
638
+ continue;
639
+ }
640
+ if (node.kind === "insertion-site") {
641
+ const recipe = recipes.get(node.recipeId);
642
+ if (recipe !== void 0 && walk([recipe.target])) return true;
643
+ }
644
+ }
645
+ return false;
646
+ };
647
+ return walk(nodes);
648
+ }
649
+ /**
650
+ * The retained-setup alias prologue (T3 / 16b-LC-1 for the root, 16b-LC retained-child for a
651
+ * leaf instance body).
652
+ *
653
+ * One body shape per component: a body that must NOT re-evaluate its setup
654
+ * reads each setup name from the retained record by OWN-PROPERTY presence
655
+ * instead of re-running the authored initializer. The ROOT body aliases
656
+ * `host.bindings` (the shell's `ensureInstance` publishes it before the recipe
657
+ * is created); a LEAF instance body aliases the compiler-private
658
+ * `host.setup` property of the child host literal its retaining reference site
659
+ * built. Presence, not value, is checked: a setup value that legitimately is
660
+ * `undefined` is retained. A missing key is the coded leaf missing-value
661
+ * failure, thrown before any claim write — the same fail-closed identity the
662
+ * host-binding helper uses for an absent binding.
663
+ */
664
+ function emitSetupAlias(state, localLines, hostProperty) {
665
+ push(state, `const ${ROOT_SETUP_RECORD} = ${state.hostVar}.${hostProperty} ?? {};`);
666
+ push(state, `const ${ROOT_SETUP_REQUIRE} = (name) => { if (!Object.hasOwn(${ROOT_SETUP_RECORD}, name)) throw new Error("OEIR_LEAF_MISSING_VALUE: " + name); return ${ROOT_SETUP_RECORD}[name]; };`);
667
+ if (componentUsesContextIntrinsic(state.component)) push(state, `const ${GENERATED_CONTEXT_SCOPE_RECORD} = ${ROOT_SETUP_REQUIRE}(${JSON.stringify(GENERATED_CONTEXT_SCOPE_RECORD)});`);
668
+ for (const line of localLines) push(state, `const ${line.name} = ${ROOT_SETUP_REQUIRE}(${JSON.stringify(line.name)});`);
669
+ }
670
+ /**
671
+ * `16b-LC` option 1a — replay the retained `onConnect` callbacks on the
672
+ * per-connection scope of the ROOT body that is about to mount or claim.
673
+ *
674
+ * The callbacks were lowered into the compiler-owned
675
+ * `__oe_rootInstance`/`<Name>__setup` factory and carried by the retained instance record, so
676
+ * replaying here never repeats setup. Each callback's optional returned cleanup
677
+ * is registered on the SAME per-connection scope the projection owns, so the
678
+ * shell's existing disconnect/rollback disposal releases it (LIFO, first error
679
+ * surfaced after every cleanup was attempted). Nothing here is a second
680
+ * lifecycle engine: mount and claim call the one retained list, and the
681
+ * intrinsic itself never reaches the emitted module.
682
+ *
683
+ * A throwing callback stops the replay and propagates into the shell's existing
684
+ * connect catch: the projection/connection rollback disposes the entries the
685
+ * earlier callbacks already registered, then the original error surfaces.
686
+ * Absence of the key is the hand-built-descriptor / hook-free shape and is a
687
+ * no-op (never a fabricated subscription).
688
+ */
689
+ function emitLifecycleReplay(hostRecordProperty) {
690
+ return [
691
+ ` const ${LIFECYCLE_HOOKS_VAR} = ${MOUNT_HOST}.${hostRecordProperty}.${GENERATED_ROOT_CONNECT_RECORD};`,
692
+ ` if (${LIFECYCLE_HOOKS_VAR} !== undefined) {`,
693
+ ` for (const ${LIFECYCLE_HOOK_VAR} of ${LIFECYCLE_HOOKS_VAR}) {`,
694
+ ` const ${LIFECYCLE_CLEANUP_VAR} = ${LIFECYCLE_HOOK_VAR}();`,
695
+ ` if (typeof ${LIFECYCLE_CLEANUP_VAR} === "function") ${MOUNT_SCOPE}.add(${LIFECYCLE_CLEANUP_VAR});`,
696
+ " }",
697
+ " }"
698
+ ];
699
+ }
700
+ /**
701
+ * `16b-LC` option 1a, env form — replay the retained `onConnect(env)` callbacks
702
+ * on the per-connection scope of the body that is about to mount or claim.
703
+ *
704
+ * The env argument is built HERE, from data the body already has: the host
705
+ * element the shell attached to the host record (runtime property; no exported
706
+ * type change) and the per-connection scope's own `signal`. `LifetimeScope`
707
+ * aborts that signal at the FIRST step of `dispose()`, before children and
708
+ * before any registered cleanup, so a cleanup that runs at disconnect observes
709
+ * an aborted signal. Each returned cleanup registers on the same scope, exactly
710
+ * like the zero-argument form. The env form has its own retained record and its
711
+ * own replay lines, so a module whose callbacks are all zero-argument keeps its
712
+ * exact pre-env bytes.
713
+ */
714
+ function emitLifecycleEnvReplay(hostRecordProperty) {
715
+ return [
716
+ ` const ${LIFECYCLE_ENV_HOOKS_VAR} = ${MOUNT_HOST}.${hostRecordProperty}.${GENERATED_ROOT_CONNECT_ENV_RECORD};`,
717
+ ` if (${LIFECYCLE_ENV_HOOKS_VAR} !== undefined) {`,
718
+ ` for (const ${LIFECYCLE_ENV_HOOK_VAR} of ${LIFECYCLE_ENV_HOOKS_VAR}) {`,
719
+ ` const ${LIFECYCLE_ENV_CLEANUP_VAR} = ${LIFECYCLE_ENV_HOOK_VAR}({ host: ${MOUNT_HOST}.${HOST_ELEMENT_PROPERTY}, signal: ${MOUNT_SCOPE}.signal, states: ${MOUNT_HOST}.${STATES_PROPERTY} });`,
720
+ ` if (typeof ${LIFECYCLE_ENV_CLEANUP_VAR} === "function") ${MOUNT_SCOPE}.add(${LIFECYCLE_ENV_CLEANUP_VAR});`,
721
+ " }",
722
+ " }"
723
+ ];
724
+ }
725
+ /**
726
+ * Emit `<Name>__claim` for a claimable component. Returns null when the shape
727
+ * is outside the admitted claim slice; the caller then leaves the recipe mount-only.
728
+ */
729
+ /**
730
+ * The depth >= 2 transaction-token field a retained child body joins with, as a
731
+ * fragment of its compiler-private host literal. A target that retains no
732
+ * children gets no field, so every depth-1 host literal keeps its exact bytes.
733
+ * The root body threads its own captured token; a retained body forwards the
734
+ * one it received.
735
+ */
736
+ function retainedTransactionField(state, target) {
737
+ if (state.retention?.retainingBodies.has(target) !== true) return "";
738
+ return `, txn: ${state.retainBody ? TRANSACTION_VAR : `${state.hostVar}.txn`}`;
739
+ }
740
+ /**
741
+ * 16b-LC depth >= 2 (2026-11-21): a retained body that retains its own children
742
+ * joins the root attempt's transaction before any retain call. The token arrives
743
+ * in the compiler-private host literal (`host.txn`); a hand-built fixture host
744
+ * without one emits nothing (such a body would then be legacy-shaped and has no
745
+ * retain calls to coordinate).
746
+ */
747
+ function emitJoinTransaction(state) {
748
+ if (!state.leafBody || !state.retainsChildren) return;
749
+ push(state, `const ${TRANSACTION_VAR} = ${MOUNT_HOST}.txn;`);
750
+ push(state, `if (${TRANSACTION_VAR} !== undefined) joinInstancePass(${MOUNT_HOST}.instance, ${TRANSACTION_VAR});`);
751
+ }
752
+ /** Collect every mount edge under one node tree, in authored order. */
753
+ function collectMountEdges(component, nodes, edges) {
754
+ for (const node of nodes) switch (node.kind) {
755
+ case "component-ref":
756
+ edges.push({
757
+ to: `c:${node.name}`,
758
+ span: node.span
759
+ });
760
+ break;
761
+ case "insertion-site":
762
+ edges.push({
763
+ to: `r:${component.name}:${node.recipeId}`,
764
+ span: node.span
765
+ });
766
+ break;
767
+ case "element":
768
+ case "fragment":
769
+ collectMountEdges(component, node.children, edges);
770
+ break;
771
+ case "condition":
772
+ collectMountEdges(component, node.consequent, edges);
773
+ if (node.alternate !== null) collectMountEdges(component, node.alternate, edges);
774
+ break;
775
+ case "list": collectMountEdges(component, node.template, edges);
776
+ }
777
+ }
778
+ /**
779
+ * Fail closed on mount cycles (M06b1a-2 extends the M06b1a-1 component-cycle
780
+ * DFS): a component reference and a reusable-JSX recipe both mount another
781
+ * mount at instance time, so a cycle would emit self-recursive mounts (unbounded
782
+ * recursion). Recipe targets are walked because a recipe can mount a component,
783
+ * and recipe bodies can insert another recipe. Children recipes (M06b2a) are
784
+ * component recipes too, so their target edges are already in the graph; the
785
+ * projection edge from the child component to the recipe is added conservatively
786
+ * (see the children-projection pass below) because only the runtime instance
787
+ * knows which reference site supplied its `props.children`. The first cycle in
788
+ * authored order is reported with its path and the closing edge's span; a cycle
789
+ * that passes through a recipe node gets `OEIR_LEAF_RECIPE_CYCLE`, a pure
790
+ * component-reference cycle keeps `OEIR_LEAF_COMPONENT_CYCLE`.
791
+ */
792
+ function findMountCycle(module) {
793
+ const edges = /* @__PURE__ */ new Map();
794
+ const labels = /* @__PURE__ */ new Map();
795
+ const addNode = (key, label, collected) => {
796
+ labels.set(key, label);
797
+ edges.set(key, collected);
798
+ };
799
+ for (const component of module.components) {
800
+ const componentEdges = [];
801
+ collectMountEdges(component, component.roots, componentEdges);
802
+ addNode(`c:${component.name}`, component.name, componentEdges);
803
+ for (const recipe of component.recipes) {
804
+ const recipeEdges = [];
805
+ collectMountEdges(component, [recipe.target], recipeEdges);
806
+ addNode(`r:${component.name}:${recipe.id}`, `${component.name}${recipe.id}`, recipeEdges);
807
+ }
808
+ }
809
+ const projectsChildrenByName = new Map(module.components.map((component) => [component.name, componentProjectsChildren(component)]));
810
+ for (const component of module.components) {
811
+ const projectionEdges = [];
812
+ collectChildrenProjectionEdges(component, projectionEdges);
813
+ for (const edge of projectionEdges) {
814
+ if (projectsChildrenByName.get(edge.projectingComponent) !== true) continue;
815
+ const fromEdges = edges.get(`c:${edge.projectingComponent}`);
816
+ const toKey = `r:${edge.definingComponent}:${edge.recipeId}`;
817
+ if (fromEdges === void 0 || !edges.has(toKey)) continue;
818
+ fromEdges.push({
819
+ to: toKey,
820
+ span: edge.span
821
+ });
822
+ }
823
+ }
824
+ const WHITE = 0;
825
+ const GRAY = 1;
826
+ const BLACK = 2;
827
+ const color = /* @__PURE__ */ new Map();
828
+ const path = [];
829
+ const visit = (key) => {
830
+ color.set(key, GRAY);
831
+ path.push(key);
832
+ for (const edge of edges.get(key) ?? []) {
833
+ if (!edges.has(edge.to)) continue;
834
+ const targetColor = color.get(edge.to) ?? WHITE;
835
+ if (targetColor === GRAY) {
836
+ const cycleKeys = path.slice(path.indexOf(edge.to));
837
+ const recipeCycle = cycleKeys.some((entry) => entry.startsWith("r:")) || edge.to.startsWith("r:");
838
+ const cycle = [...cycleKeys, edge.to].map((entry) => labels.get(entry) ?? entry).join(" -> ");
839
+ return {
840
+ severity: "error",
841
+ code: recipeCycle ? "OEIR_LEAF_RECIPE_CYCLE" : "OEIR_LEAF_COMPONENT_CYCLE",
842
+ message: recipeCycle ? `recipe insertion cycle: ${cycle}` : `component reference cycle: ${cycle}`,
843
+ span: edge.span,
844
+ origin: "ir-object"
845
+ };
846
+ }
847
+ if (targetColor === WHITE) {
848
+ const found = visit(edge.to);
849
+ if (found !== null) return found;
850
+ }
851
+ }
852
+ path.pop();
853
+ color.set(key, BLACK);
854
+ return null;
855
+ };
856
+ for (const component of module.components) {
857
+ const key = `c:${component.name}`;
858
+ if ((color.get(key) ?? WHITE) !== WHITE) continue;
859
+ const found = visit(key);
860
+ if (found !== null) return found;
861
+ }
862
+ return null;
863
+ }
864
+ //#endregion
865
+ export { CONTEXT_SCOPE_PROPERTY, ERROR_HANDLER_PROPERTY, GENERATED_CONTEXT_SCOPE_RECORD, GENERATED_ROOT_CONNECT_ENV_RECORD, GENERATED_ROOT_CONNECT_RECORD, GENERATED_ROOT_INSTANCE_NAME, HOST_ELEMENT_PROPERTY, LEAF_SETUP_HOST_PROPERTY, LEAF_SETUP_SUFFIX, PROPERTY_CHANGE_PROPERTY, ROOT_SETUP_HOST_PROPERTY, ROOT_SETUP_RECORD, ROOT_SETUP_REQUIRE, SSR_CONTEXT_PARAM, STATES_PROPERTY, TEARDOWN_SIGNAL_VAR, childContextField, childErrorBoundaryField, childErrorReportField, childHostElementField, childPropertyChangeField, componentNeedsSsrContextScope, componentUsesContextIntrinsic, emitContextProviders, emitContextScopeDeclaration, emitJoinTransaction, emitLifecycleEnvReplay, emitLifecycleReplay, emitSetupAlias, emitSetupBinding, emitSsrContextScope, findMountCycle, moduleUsesContext, moduleUsesHostAccess, moduleUsesLifecycleEnv, moduleUsesPropertyChange, planRetention, retainedTransactionField, siteKeyLiteral };