@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.
Files changed (51) hide show
  1. package/package.json +3 -2
  2. package/src/compiler.d.ts +8 -6
  3. package/src/compiler.js +7 -6
  4. package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +5 -30
  5. package/src/internal/compiler/compiled-artifact-class-candidates.js +18 -32
  6. package/src/internal/compiler/compiled-artifact-style-requests.d.ts +9 -7
  7. package/src/internal/compiler/compiled-artifact-style-requests.js +9 -7
  8. package/src/internal/compiler/plugin.d.ts +31 -50
  9. package/src/internal/compiler/plugin.js +41 -108
  10. package/src/internal/compiler/semantic-core/analyze-module.d.ts +1 -45
  11. package/src/internal/compiler/semantic-core/analyze-module.js +10 -405
  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/expression-lowering.js +469 -0
  15. package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
  16. package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
  17. package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
  18. package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
  19. package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
  20. package/src/internal/compiler/semantic-core/lower-program.d.ts +51 -0
  21. package/src/internal/compiler/semantic-core/lower-program.js +186 -90
  22. package/src/internal/compiler/semantic-core/module-analysis.d.ts +28 -5
  23. package/src/internal/compiler/semantic-core/module-analysis.js +16 -17
  24. package/src/internal/compiler/semantic-core/parse-module.js +16 -16
  25. package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
  26. package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
  27. package/src/internal/compiler/semantic-core/server-component.d.ts +22 -7
  28. package/src/internal/compiler/semantic-core/server-component.js +163 -57
  29. package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
  30. package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
  31. package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
  32. package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
  33. package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
  34. package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
  35. package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
  36. package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
  37. package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
  38. package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
  39. package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
  40. package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
  41. package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
  42. package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
  43. package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
  44. package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
  45. package/src/internal/compiler/style-requests.d.ts +0 -8
  46. package/src/internal/compiler/style-requests.js +1 -14
  47. package/src/internal/compiler/semantic-core/compile.d.ts +0 -47
  48. package/src/internal/compiler/semantic-core/compile.js +0 -100
  49. package/src/internal/compiler/semantic-core/emit-module.js +0 -317
  50. package/src/internal/compiler/semantic-core/emit-program.js +0 -141
  51. package/src/internal/compiler/semantic-core/style-imports.js +0 -87
@@ -0,0 +1,1195 @@
1
+ import { hasIslandPolicyStatement as hasIslandPolicyStatement$1, islandPolicyObjectLiteral as islandPolicyObjectLiteral$1 } from "../../semantic-core/island-policy-statement.js";
2
+ import { createModuleIntrinsicBindings, isCustomElementTag } from "../../semantic-core/module-analysis.js";
3
+ import { literalValue } from "../../semantic-core/analyze-module.js";
4
+ import { authoredPropsType } from "../../semantic-core/parse-module.js";
5
+ import { GENERATED_ELEMENT_DIAGNOSTIC } from "./contract.js";
6
+ import ts from "typescript";
7
+ import { camelToKebab, forbiddenSinkReason, isSafeAttributeName } from "@openelement/protocol/forbidden-sinks";
8
+ //#region src/internal/compiler/semantic-ir/generated-element/site.ts
9
+ /**
10
+ * M09-1a — site admission for the generated native element lane.
11
+ *
12
+ * The lane runs inside the compiler transform, before the router's island
13
+ * transform. It therefore cannot see `__tagName` and cannot derive the tag; the
14
+ * host passes one {@link GeneratedElementSite} fact for a module it has already
15
+ * resolved under `islandsDir`. This module supplies the rest of the admission
16
+ * from the authored AST — the one explicit "Native Export" marker, a local
17
+ * default-exported function component, and the M09-1a fail-closed gates.
18
+ *
19
+ * It re-derives no semantic model: the default-export fact is a small syntax
20
+ * walk over the same `typescriptParser` AST, matched by name against
21
+ * `FunctionModelModule.components` (decision D4a's smaller-diff alternative —
22
+ * adding `isDefaultExport` to the M03 model — would touch the parity surface).
23
+ *
24
+ * Structural opt-outs stay silent (the lane returns null and the module falls
25
+ * through to the class lane or the existing passthrough):
26
+ *
27
+ * - no default export;
28
+ * - `export default class` (the retiring class lane owns it);
29
+ * - `export default <expression>`, including a `definePage(...)` call;
30
+ * - a re-export (`export { default } from './x.tsx'`), including the
31
+ * `export { default } from '../site-ui/...'` island shape. Resolving
32
+ * re-exported function islands is M09-2/M11 work (residual R11);
33
+ * - an anonymous default function.
34
+ *
35
+ * A local default-exported function is admitted structurally, then the lane
36
+ * compiles it through the real function frontend. If the frontend does not
37
+ * model it as a component, this module refuses with
38
+ * `OEIR_GENERATED_ELEMENT_NOT_A_COMPONENT` instead of silently shipping a
39
+ * non-constructor default export.
40
+ */
41
+ function spanOf(sourceFile, node) {
42
+ const start = node.getStart(sourceFile);
43
+ const end = node.getEnd();
44
+ const position = sourceFile.getLineAndCharacterOfPosition(start);
45
+ return {
46
+ file: sourceFile.fileName,
47
+ start,
48
+ end,
49
+ line: position.line + 1,
50
+ column: position.character + 1
51
+ };
52
+ }
53
+ function diagnosticAt(sourceFile, node, code, message) {
54
+ return {
55
+ severity: "error",
56
+ code,
57
+ message,
58
+ span: node === null ? {
59
+ file: sourceFile.fileName,
60
+ start: 0,
61
+ end: 0,
62
+ line: 1,
63
+ column: 1
64
+ } : spanOf(sourceFile, node),
65
+ origin: "module"
66
+ };
67
+ }
68
+ function tagDiagnostic(sourceFile, node, message) {
69
+ return diagnosticAt(sourceFile, node, GENERATED_ELEMENT_DIAGNOSTIC.TAG_INVALID, message);
70
+ }
71
+ function hasModifier(node, kind) {
72
+ if (!ts.canHaveModifiers(node)) return false;
73
+ return (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);
74
+ }
75
+ /**
76
+ * The island policy statement locator lives in `semantic-core/island-policy-statement.ts`
77
+ * — ONE definition shared with the module-semantics fact
78
+ * `hasGeneratedElementSidecar`, so the two readers cannot disagree about which
79
+ * statement is the policy. Re-exported through explicit forwarding bindings (not
80
+ * `export { ... } from`) because the bundler's re-export handling of a name this
81
+ * module ALSO imports left the inner call site unbound.
82
+ */
83
+ const hasIslandPolicyStatement = (sourceFile) => hasIslandPolicyStatement$1(sourceFile);
84
+ const islandPolicyObjectLiteral = islandPolicyObjectLiteral$1;
85
+ /**
86
+ * The static string entries of a `styles` initializer. A non-array initializer
87
+ * or a non-literal element contributes nothing here: the router scan refuses
88
+ * that shape with its own coded diagnostic, so this reader never becomes a
89
+ * second validator and never invents a specifier.
90
+ */
91
+ function staticStyleSpecifiers(initializer) {
92
+ if (!ts.isArrayLiteralExpression(initializer)) return [];
93
+ const specifiers = [];
94
+ for (const element of initializer.elements) if (ts.isStringLiteralLike(element)) specifiers.push(element.text);
95
+ return specifiers;
96
+ }
97
+ /** The static property name of a key/value pair, or null when unreadable. */
98
+ function staticPropertyName(name) {
99
+ if (ts.isIdentifier(name)) return name.text;
100
+ if (ts.isStringLiteral(name) && name.text.length > 0) return name.text;
101
+ return null;
102
+ }
103
+ function rootDiagnostic(sourceFile, node, message) {
104
+ return diagnosticAt(sourceFile, node, GENERATED_ELEMENT_DIAGNOSTIC.ROOT_INVALID, message);
105
+ }
106
+ function delegatesFocusDiagnostic(sourceFile, node, message) {
107
+ return diagnosticAt(sourceFile, node, GENERATED_ELEMENT_DIAGNOSTIC.DELEGATES_FOCUS_INVALID, message);
108
+ }
109
+ function propertyDiagnostic(sourceFile, node, message, code = GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID) {
110
+ return diagnosticAt(sourceFile, node, code, message);
111
+ }
112
+ /** The identifier spelling the generated props record / accessors can expose. */
113
+ const IDENTIFIER_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
114
+ const ISLAND_PROPERTY_FIELDS = /* @__PURE__ */ new Set([
115
+ "reflect",
116
+ "attribute",
117
+ "default"
118
+ ]);
119
+ /**
120
+ * Resolve one declared attribute name the way the shell will: a missing
121
+ * `attribute` key derives `camelToKebab(name)`, `false` means no attribute
122
+ * channel, and a string is lowercased and screened by the canonical safe
123
+ * attribute predicate. The scanner applies the identical rule; the drift
124
+ * guard compares the resolved forms.
125
+ */
126
+ function resolveDeclaredAttribute(name, raw) {
127
+ if (raw.kind === ts.SyntaxKind.FalseKeyword) return null;
128
+ return (ts.isStringLiteral(raw) ? raw.text : name).toLowerCase();
129
+ }
130
+ /**
131
+ * The bounded depth of an admitted literal default graph. The graph is known
132
+ * at compile time; the bound keeps the generated factory small and prevents a
133
+ * pathological nested default from becoming a build hazard.
134
+ */
135
+ const PROPERTY_DEFAULT_MAX_DEPTH = 8;
136
+ function defaultGraphDepthOk(value, depth) {
137
+ if (depth > PROPERTY_DEFAULT_MAX_DEPTH) return false;
138
+ if (value === null) return true;
139
+ if (typeof value === "string" || typeof value === "boolean") return true;
140
+ if (typeof value === "number") return Number.isFinite(value);
141
+ if (Array.isArray(value)) return value.every((entry) => defaultGraphDepthOk(entry, depth + 1));
142
+ if (typeof value === "object") return Object.values(value).every((entry) => defaultGraphDepthOk(entry, depth + 1));
143
+ return false;
144
+ }
145
+ /**
146
+ * Every recursively literal default-graph key must pass the canonical
147
+ * property-sink predicate. Three surfaces read one authored default graph — the
148
+ * compiler, the static scanner and the runtime authoring face — and all three
149
+ * use `forbiddenSinkReason('prop', key)` rather than a private deny list:
150
+ * `__proto__` would re-prototype an object built from the graph, while
151
+ * `constructor`/`prototype` are the canonical property-sink names the repo
152
+ * refuses for compiled property declarations as well.
153
+ */
154
+ function defaultGraphKeysAdmissible(value) {
155
+ if (Array.isArray(value)) return value.every(defaultGraphKeysAdmissible);
156
+ if (value !== null && typeof value === "object") return Object.entries(value).every(([key, entry]) => forbiddenSinkReason("prop", key) === null && defaultGraphKeysAdmissible(entry));
157
+ return true;
158
+ }
159
+ /**
160
+ * The canonical trustedHtml TYPE provenance (design §3.3): exactly a named
161
+ * `TrustedHtml` import from '@openelement/element', no alias, not shadowed by
162
+ * a same-module declaration. Checked syntactically; the compiler does not
163
+ * import the element package.
164
+ */
165
+ function canonicalTrustedHtmlTypeName(sourceFile) {
166
+ let imported = false;
167
+ let shadowed = false;
168
+ for (const statement of sourceFile.statements) {
169
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || statement.moduleSpecifier.text !== "@openelement/element") continue;
170
+ const clause = statement.importClause;
171
+ if (clause === void 0 || clause.namedBindings === void 0) continue;
172
+ if (!ts.isNamedImports(clause.namedBindings)) continue;
173
+ for (const element of clause.namedBindings.elements) if (element.propertyName === void 0 && element.name.text === "TrustedHtml") imported = true;
174
+ }
175
+ for (const statement of sourceFile.statements) {
176
+ if ((ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement)) && statement.name?.text === "TrustedHtml") shadowed = true;
177
+ if (ts.isVariableStatement(statement)) {
178
+ for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.name.text === "TrustedHtml") shadowed = true;
179
+ }
180
+ }
181
+ return imported && !shadowed;
182
+ }
183
+ /**
184
+ * Read one sidecar `default` initializer into the proven default vocabulary.
185
+ *
186
+ * Accepted forms: a static primitive, a bounded recursively literal
187
+ * array/object graph (`literalValue`; spreads/identifiers/functions and
188
+ * `__proto__` already refuse there), or a `trustedHtml('<literal>')` call whose
189
+ * callee is the canonical runtime import (the class-lane provenance rule).
190
+ * Every recursive object key in the graph is additionally checked with the
191
+ * canonical `forbiddenSinkReason('prop', …)` predicate — the same rule the
192
+ * scanner and the runtime authoring face apply — so `__proto__`,
193
+ * `constructor` and `prototype` are refused at any depth. Anything else
194
+ * refuses with a source-located message.
195
+ */
196
+ function readPropertyDefault(sourceFile, initializer, context) {
197
+ const literal = literalValue(initializer, sourceFile);
198
+ if (literal !== void 0 && defaultGraphDepthOk(literal, 0)) {
199
+ if (literal === null) return {
200
+ kind: "refused",
201
+ message: `openElement.properties.${context} must not be null; declare an explicit literal default`
202
+ };
203
+ if (!defaultGraphKeysAdmissible(literal)) return {
204
+ kind: "refused",
205
+ message: `openElement.properties.${context}.default must not contain a property-sink key ("__proto__", "constructor" or "prototype") at any depth; use an ordinary data key`
206
+ };
207
+ return {
208
+ kind: "read",
209
+ value: {
210
+ kind: "literal",
211
+ value: literal
212
+ }
213
+ };
214
+ }
215
+ if (ts.isCallExpression(initializer)) {
216
+ if (!createModuleIntrinsicBindings(sourceFile).resolveIntrinsic(initializer.expression, "trustedHtml").canonical) return {
217
+ kind: "refused",
218
+ message: `openElement.properties.${context} must be created by the canonical \`trustedHtml(...)\` import from '@openelement/element'; a same-name or aliased callee is not admitted`
219
+ };
220
+ if (initializer.arguments.length !== 1) return {
221
+ kind: "refused",
222
+ message: `openElement.properties.${context} trustedHtml(...) takes exactly one literal string`
223
+ };
224
+ const html = initializer.arguments[0];
225
+ if (!ts.isStringLiteral(html) && !ts.isNoSubstitutionTemplateLiteral(html)) return {
226
+ kind: "refused",
227
+ message: `openElement.properties.${context} trustedHtml(...) requires a literal string argument`
228
+ };
229
+ return {
230
+ kind: "read",
231
+ value: {
232
+ kind: "trustedHtml",
233
+ html: html.text
234
+ }
235
+ };
236
+ }
237
+ return {
238
+ kind: "refused",
239
+ message: `openElement.properties.${context} must be a static string, number, or boolean literal, a recursively literal array/object graph, or trustedHtml(<literal string>)`
240
+ };
241
+ }
242
+ /**
243
+ * Read the sidecar's `properties` table from the authored AST.
244
+ *
245
+ * The shape is the platform-fact complement of the typed props parameter:
246
+ * an object map keyed by member name, each entry carrying `reflect`,
247
+ * `attribute` and `default` only. It is deliberately narrower than the
248
+ * scanner's parser in one direction (it needs the same facts) and identical
249
+ * in the other (fail closed on anything not provable from literal text). The
250
+ * type/name cross-check is the admission's job because only it sees the root
251
+ * component's parameter.
252
+ */
253
+ function readIslandPropertyTable(sourceFile, node) {
254
+ const refuse = (at, message) => ({
255
+ kind: "refused",
256
+ diagnostic: propertyDiagnostic(sourceFile, at, message)
257
+ });
258
+ if (!ts.isObjectLiteralExpression(node)) return refuse(node, "openElement.properties must be an object of static property entries");
259
+ const declarations = [];
260
+ const names = /* @__PURE__ */ new Set();
261
+ const attributes = /* @__PURE__ */ new Set();
262
+ for (const entry of node.properties) {
263
+ if (!ts.isPropertyAssignment(entry)) return refuse(entry, `openElement.properties must contain only static property entries; "${entry.getText(sourceFile)}" cannot be read statically`);
264
+ const name = staticPropertyName(entry.name);
265
+ if (name === null) return refuse(entry.name, `the openElement.properties key "${entry.name.getText(sourceFile)}" is not a static property name`);
266
+ if (!IDENTIFIER_NAME.test(name)) return refuse(entry.name, `openElement.properties key "${name}" must be an identifier naming a typed props member`);
267
+ const sinkReason = forbiddenSinkReason("prop", name);
268
+ if (sinkReason !== null) return refuse(entry.name, `openElement.properties key "${name}" is not an admissible property name: ${sinkReason}`);
269
+ if (names.has(name)) return refuse(entry.name, `openElement.properties declares property "${name}" more than once`);
270
+ names.add(name);
271
+ const table = entry.initializer;
272
+ if (!ts.isObjectLiteralExpression(table)) return refuse(table, `openElement.properties.${name} must be an object`);
273
+ const seenFields = /* @__PURE__ */ new Set();
274
+ let reflect = false;
275
+ let attribute;
276
+ let attributeExplicit = false;
277
+ let defaultValue;
278
+ for (const field of table.properties) {
279
+ if (!ts.isPropertyAssignment(field)) return refuse(field, `openElement.properties.${name} must contain only static key/value pairs; "${field.getText(sourceFile)}" cannot be read statically`);
280
+ const fieldName = staticPropertyName(field.name);
281
+ if (fieldName === null || !ISLAND_PROPERTY_FIELDS.has(fieldName)) return refuse(field.name, `openElement.properties.${name} does not accept "${field.name.getText(sourceFile)}" — admitted options are reflect, attribute, and default (the property type comes from the typed props parameter)`);
282
+ if (seenFields.has(fieldName)) return refuse(field, `openElement.properties.${name} declares ${fieldName} more than once`);
283
+ seenFields.add(fieldName);
284
+ if (fieldName === "reflect") {
285
+ if (field.initializer.kind !== ts.SyntaxKind.TrueKeyword && field.initializer.kind !== ts.SyntaxKind.FalseKeyword) return refuse(field.initializer, `openElement.properties.${name}.reflect must be a static boolean literal`);
286
+ reflect = field.initializer.kind === ts.SyntaxKind.TrueKeyword;
287
+ } else if (fieldName === "attribute") {
288
+ if (field.initializer.kind !== ts.SyntaxKind.FalseKeyword && !ts.isStringLiteral(field.initializer)) return refuse(field.initializer, `openElement.properties.${name}.attribute must be a static string literal or false`);
289
+ attribute = resolveDeclaredAttribute(name, field.initializer);
290
+ attributeExplicit = true;
291
+ if (attribute !== null) {
292
+ if (attribute.length === 0 || !isSafeAttributeName(attribute)) return refuse(field.initializer, `openElement.properties.${name}.attribute "${attribute}" is not a safe HTML attribute name`);
293
+ }
294
+ } else {
295
+ const parsed = readPropertyDefault(sourceFile, field.initializer, `${name}.default`);
296
+ if (parsed.kind === "refused") return refuse(field.initializer, parsed.message);
297
+ defaultValue = parsed.value;
298
+ }
299
+ }
300
+ if (reflect && attribute === null) return refuse(entry, `openElement.properties.${name} cannot reflect without an attribute channel (attribute: false)`);
301
+ const effectiveAttribute = attribute === void 0 ? camelToKebab(name) : attribute;
302
+ if (effectiveAttribute !== null) {
303
+ if (attributes.has(effectiveAttribute)) return refuse(entry, `openElement.properties declares attribute "${effectiveAttribute}" more than once`);
304
+ attributes.add(effectiveAttribute);
305
+ }
306
+ declarations.push({
307
+ name,
308
+ attribute: effectiveAttribute,
309
+ attributeExplicit,
310
+ reflect,
311
+ ...defaultValue === void 0 ? {} : { default: defaultValue },
312
+ node: entry
313
+ });
314
+ }
315
+ return {
316
+ kind: "read",
317
+ declarations
318
+ };
319
+ }
320
+ /**
321
+ * Read the sidecar's platform facts (`root`, `delegatesFocus`) from the
322
+ * authored AST (D-root-source, 2026-11-13).
323
+ *
324
+ * The router's static scanner is the authority for the sidecar's accepted
325
+ * shape, its accepted key set and its error text; this reader exists because
326
+ * the compiler lane must not carry these facts across the host boundary. It is
327
+ * deliberately narrower than the scanner: it reads the keys it needs, and it
328
+ * refuses — instead of guessing — whenever a value cannot be proven from the
329
+ * literal text (`OEIR_GENERATED_ELEMENT_ROOT_INVALID` /
330
+ * `OEIR_GENERATED_ELEMENT_DELEGATES_FOCUS_INVALID`, source-located).
331
+ *
332
+ * The author-facing vocabulary is the sidecar's `'light' | 'shadow'`; the
333
+ * descriptor's `'shadow'` is the DSD default, which the shell spells
334
+ * `shadow-open`. Closed roots have no author spelling (`D-closed`), so no
335
+ * mapping to `shadow-closed` exists here. `delegatesFocus: true` requires
336
+ * `root: 'shadow'`, exactly as the scanner and the runtime authoring surface
337
+ * enforce it: a light root has no shadow boundary to delegate focus through.
338
+ *
339
+ * `tag` is the sidecar's EXPLICIT custom-element identity. It is read here so
340
+ * the host site resolver can admit a module that is neither an island nor a
341
+ * package declaration (a page-local component under `app/site-ui/`); the
342
+ * descriptor still takes its tag from the host site fact, so this read is the
343
+ * resolver's input, never a second emitter source.
344
+ */
345
+ function readIslandMetadata(sourceFile) {
346
+ const descriptor = islandPolicyObjectLiteral(sourceFile);
347
+ if (descriptor === null) return { kind: "absent" };
348
+ let seenRoot = false;
349
+ let declaredRoot = null;
350
+ let seenSsr = false;
351
+ /**
352
+ * The sidecar's explicit `ssr` boolean, or undefined when it pins none. The
353
+ * CLIENT-ONLY fact below is the same resolution the router scanner applies
354
+ * (`resolveIslandSsrDsd`): explicit `false` OR `hydrate: 'only'`, which
355
+ * forces `ssr` off. Two readers, one phase decision.
356
+ */
357
+ let ssrExplicit;
358
+ let hydrateOnly = false;
359
+ let seenDelegatesFocus = false;
360
+ let delegatesFocus = false;
361
+ let delegatesFocusSpan = null;
362
+ let declaresStyles = false;
363
+ let styles = [];
364
+ let seenFormAssociated = false;
365
+ let formAssociated = false;
366
+ let seenProperties = false;
367
+ let properties;
368
+ let seenTag = false;
369
+ let tag;
370
+ for (const property of descriptor.properties) {
371
+ if (!ts.isPropertyAssignment(property)) return {
372
+ kind: "refused",
373
+ diagnostic: rootDiagnostic(sourceFile, property, `the openElement sidecar must contain only static key/value pairs; "${property.getText(sourceFile)}" cannot be read statically, so the platform facts cannot be established`)
374
+ };
375
+ const name = staticPropertyName(property.name);
376
+ if (name === null) return {
377
+ kind: "refused",
378
+ diagnostic: rootDiagnostic(sourceFile, property.name, `the openElement sidecar key "${property.name.getText(sourceFile)}" is not a static property name, so the platform facts cannot be established`)
379
+ };
380
+ if (name === "root") {
381
+ if (seenRoot) return {
382
+ kind: "refused",
383
+ diagnostic: rootDiagnostic(sourceFile, property, "the openElement sidecar declares root more than once, so the root fact is ambiguous")
384
+ };
385
+ seenRoot = true;
386
+ const initializer = property.initializer;
387
+ if (!ts.isStringLiteral(initializer)) return {
388
+ kind: "refused",
389
+ diagnostic: rootDiagnostic(sourceFile, initializer, `openElement.root must be a static literal, got dynamic value "${initializer.getText(sourceFile)}"`)
390
+ };
391
+ if (initializer.text !== "light" && initializer.text !== "shadow" && initializer.text !== "closed") return {
392
+ kind: "refused",
393
+ diagnostic: rootDiagnostic(sourceFile, initializer, `openElement.root has unsupported value "${initializer.text}"; use "light", "shadow" or "closed"`)
394
+ };
395
+ declaredRoot = initializer.text;
396
+ continue;
397
+ }
398
+ if (name === "ssr") {
399
+ if (seenSsr) return {
400
+ kind: "refused",
401
+ diagnostic: diagnosticAt(sourceFile, property, GENERATED_ELEMENT_DIAGNOSTIC.SSR_INVALID, "the openElement sidecar declares ssr more than once, so the delivery phase is ambiguous")
402
+ };
403
+ seenSsr = true;
404
+ const initializer = property.initializer;
405
+ if (initializer.kind !== ts.SyntaxKind.TrueKeyword && initializer.kind !== ts.SyntaxKind.FalseKeyword) return {
406
+ kind: "refused",
407
+ diagnostic: diagnosticAt(sourceFile, initializer, GENERATED_ELEMENT_DIAGNOSTIC.SSR_INVALID, `openElement.ssr must be a static literal, got dynamic value "${initializer.getText(sourceFile)}"`)
408
+ };
409
+ ssrExplicit = initializer.kind === ts.SyntaxKind.TrueKeyword;
410
+ continue;
411
+ }
412
+ if (name === "hydrate") {
413
+ if (ts.isStringLiteral(property.initializer) && property.initializer.text === "only") hydrateOnly = true;
414
+ continue;
415
+ }
416
+ if (name === "styles") {
417
+ declaresStyles = true;
418
+ styles = staticStyleSpecifiers(property.initializer);
419
+ continue;
420
+ }
421
+ if (name === "properties") {
422
+ if (seenProperties) return {
423
+ kind: "refused",
424
+ diagnostic: propertyDiagnostic(sourceFile, property, "the openElement sidecar declares properties more than once, so the property table is ambiguous")
425
+ };
426
+ seenProperties = true;
427
+ const read = readIslandPropertyTable(sourceFile, property.initializer);
428
+ if (read.kind === "refused") return read;
429
+ properties = read.declarations;
430
+ continue;
431
+ }
432
+ if (name === "tag") {
433
+ if (seenTag) return {
434
+ kind: "refused",
435
+ diagnostic: tagDiagnostic(sourceFile, property, "the openElement sidecar declares tag more than once, so the tag fact is ambiguous")
436
+ };
437
+ seenTag = true;
438
+ const initializer = property.initializer;
439
+ if (!ts.isStringLiteral(initializer)) return {
440
+ kind: "refused",
441
+ diagnostic: tagDiagnostic(sourceFile, initializer, `openElement.tag must be a static literal, got dynamic value "${initializer.getText(sourceFile)}"`)
442
+ };
443
+ if (!isCustomElementTag(initializer.text)) return {
444
+ kind: "refused",
445
+ diagnostic: tagDiagnostic(sourceFile, initializer, `openElement.tag "${initializer.text}" is not a valid custom-element name; use a lowercase hyphenated name such as "open-page-rail"`)
446
+ };
447
+ tag = initializer.text;
448
+ continue;
449
+ }
450
+ if (name === "formAssociated") {
451
+ if (seenFormAssociated) return {
452
+ kind: "refused",
453
+ diagnostic: diagnosticAt(sourceFile, property, GENERATED_ELEMENT_DIAGNOSTIC.FORM_ASSOCIATED_INVALID, "the openElement sidecar declares formAssociated more than once, so the form fact is ambiguous")
454
+ };
455
+ seenFormAssociated = true;
456
+ const initializer = property.initializer;
457
+ if (initializer.kind !== ts.SyntaxKind.TrueKeyword && initializer.kind !== ts.SyntaxKind.FalseKeyword) return {
458
+ kind: "refused",
459
+ diagnostic: diagnosticAt(sourceFile, initializer, GENERATED_ELEMENT_DIAGNOSTIC.FORM_ASSOCIATED_INVALID, `openElement.formAssociated must be a static literal, got dynamic value "${initializer.getText(sourceFile)}"`)
460
+ };
461
+ formAssociated = initializer.kind === ts.SyntaxKind.TrueKeyword;
462
+ continue;
463
+ }
464
+ if (name !== "delegatesFocus") continue;
465
+ if (seenDelegatesFocus) return {
466
+ kind: "refused",
467
+ diagnostic: delegatesFocusDiagnostic(sourceFile, property, "the openElement sidecar declares delegatesFocus more than once, so the focus fact is ambiguous")
468
+ };
469
+ seenDelegatesFocus = true;
470
+ delegatesFocusSpan = property;
471
+ const initializer = property.initializer;
472
+ if (initializer.kind !== ts.SyntaxKind.TrueKeyword && initializer.kind !== ts.SyntaxKind.FalseKeyword) return {
473
+ kind: "refused",
474
+ diagnostic: delegatesFocusDiagnostic(sourceFile, initializer, `openElement.delegatesFocus must be a static literal, got dynamic value "${initializer.getText(sourceFile)}"`)
475
+ };
476
+ delegatesFocus = initializer.kind === ts.SyntaxKind.TrueKeyword;
477
+ }
478
+ const root = declaredRoot === null ? void 0 : declaredRoot === "light" ? "light" : declaredRoot === "closed" ? "shadow-closed" : "shadow-open";
479
+ if (delegatesFocus && root !== "shadow-open") return {
480
+ kind: "refused",
481
+ diagnostic: diagnosticAt(sourceFile, delegatesFocusSpan ?? descriptor, GENERATED_ELEMENT_DIAGNOSTIC.DELEGATES_FOCUS_WITHOUT_SHADOW, "openElement.delegatesFocus requires root: \"shadow\" — a light root has no shadow boundary to delegate focus through")
482
+ };
483
+ return {
484
+ kind: "read",
485
+ facts: {
486
+ tag,
487
+ root,
488
+ clientOnly: ssrExplicit === false || hydrateOnly,
489
+ delegatesFocus,
490
+ formAssociated,
491
+ declaresStyles,
492
+ styles,
493
+ properties
494
+ }
495
+ };
496
+ }
497
+ /**
498
+ * Property names that would replace platform/lifecycle surface on the element
499
+ * prototype. The shell owns this list (`generated-element/shell.ts`
500
+ * `RESERVED_PROPERTY_NAMES`) and refuses a descriptor that names one; the
501
+ * compiler lane refuses earlier so the author gets a source-located build
502
+ * error. The copy is a fast-fail SUBSET: the properties suite asserts every
503
+ * name here is refused by the shell too (an over-refusal is the drift that
504
+ * matters); a new shell-reserved name this list misses still fails closed at
505
+ * class creation, so no unguarded silent failure exists.
506
+ */
507
+ const RESERVED_GENERATED_ELEMENT_PROPERTY_NAMES = /* @__PURE__ */ new Set([
508
+ "constructor",
509
+ "connectedCallback",
510
+ "disconnectedCallback",
511
+ "attributeChangedCallback",
512
+ "adoptedCallback",
513
+ "observedAttributes",
514
+ "dispose",
515
+ "formAssociatedCallback",
516
+ "formResetCallback",
517
+ "formStateRestoreCallback",
518
+ "formDisabledCallback"
519
+ ]);
520
+ /** The type's zero value, matching the shell's `normalizeProperty` default. */
521
+ function zeroPropertyValue(type) {
522
+ if (type === "boolean") return false;
523
+ if (type === "number") return 0;
524
+ return "";
525
+ }
526
+ /** Same-module `interface`/`type` declarations with the given name. */
527
+ function propsTypeDeclarations(sourceFile, name) {
528
+ const declarations = [];
529
+ for (const statement of sourceFile.statements) if ((ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) && statement.name.text === name) declarations.push(statement);
530
+ return declarations;
531
+ }
532
+ /**
533
+ * Resolve a props annotation to its member list without a type checker.
534
+ *
535
+ * Two local, statically provable shapes are admitted: an inline object type
536
+ * literal, and a same-module non-generic `type`/`interface` alias of one
537
+ * (an interface with heritage clauses is refused because its member list is
538
+ * not provable from this file). An imported, generic, union or otherwise
539
+ * computed type refuses: the generated props record cannot be cross-checked
540
+ * against a declaration this module does not own.
541
+ *
542
+ * Two author-reachable shapes that a naive first-match walk gets wrong are
543
+ * refused here, not guessed:
544
+ *
545
+ * - a cyclic alias chain (`type A = A`, `type A = B; type B = A`, longer
546
+ * cycles). The visited-name set turns the walk into a finite proof and the
547
+ * cycle refuses with `PROPS_TYPE_UNSUPPORTED` instead of overflowing the
548
+ * compiler stack (B1);
549
+ * - a props name with more than one same-module declaration (TypeScript
550
+ * declaration merging). Reading only the first declaration would either
551
+ * refuse a legal merged interface or silently emit rows for half of it, so
552
+ * the merged shape is refused as unprovable (D1).
553
+ */
554
+ function resolvePropsTypeMembers(sourceFile, typeNode, visited = /* @__PURE__ */ new Set()) {
555
+ if (ts.isParenthesizedTypeNode(typeNode)) return resolvePropsTypeMembers(sourceFile, typeNode.type, visited);
556
+ if (ts.isTypeLiteralNode(typeNode)) return { members: typeNode.members };
557
+ if (!ts.isTypeReferenceNode(typeNode) || !ts.isIdentifier(typeNode.typeName)) return {
558
+ reason: `the props type "${typeNode.getText(sourceFile)}" is not an object type literal`,
559
+ node: typeNode
560
+ };
561
+ if (typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0) return {
562
+ reason: `the props type "${typeNode.getText(sourceFile)}" is generic`,
563
+ node: typeNode
564
+ };
565
+ const name = typeNode.typeName.text;
566
+ if (visited.has(name)) return {
567
+ reason: `the props type "${name}" is cyclic/self-referential; the lane cannot prove a member list from it — declare the members inline or in an acyclic local alias`,
568
+ node: typeNode
569
+ };
570
+ const declarations = propsTypeDeclarations(sourceFile, name);
571
+ if (declarations.length === 0) return {
572
+ reason: `the props type "${name}" is not declared in this module; the generated element lane admits an inline object type literal or a local type/interface alias`,
573
+ node: typeNode
574
+ };
575
+ if (declarations.length > 1) return {
576
+ reason: `the props type "${name}" is declared more than once in this module (merged declarations are not admitted); declare one interface or type alias so its member list is provable`,
577
+ node: declarations[1].name
578
+ };
579
+ const nextVisited = new Set(visited);
580
+ nextVisited.add(name);
581
+ const declaration = declarations[0];
582
+ if (ts.isInterfaceDeclaration(declaration)) {
583
+ if (declaration.typeParameters !== void 0) return {
584
+ reason: `the props interface "${name}" is generic`,
585
+ node: declaration.name
586
+ };
587
+ if ((declaration.heritageClauses ?? []).length > 0) return {
588
+ reason: `the props interface "${name}" has extends clauses this lane cannot prove`,
589
+ node: declaration.name
590
+ };
591
+ return { members: declaration.members };
592
+ }
593
+ if (declaration.typeParameters !== void 0) return {
594
+ reason: `the props type alias "${name}" is generic`,
595
+ node: declaration.name
596
+ };
597
+ return resolvePropsTypeMembers(sourceFile, declaration.type, nextVisited);
598
+ }
599
+ /**
600
+ * Prove that a type node denotes an opaque object shape: an inline type
601
+ * literal, or a same-module single, non-generic, heritage-free, acyclic
602
+ * interface/type alias chain that ends in one. Members of the object are NOT
603
+ * inspected (the design keeps the shape opaque); only the default literal graph
604
+ * is checked.
605
+ */
606
+ function proveObjectShape(sourceFile, typeNode, visited = /* @__PURE__ */ new Set()) {
607
+ if (ts.isParenthesizedTypeNode(typeNode)) return proveObjectShape(sourceFile, typeNode.type, visited);
608
+ if (ts.isTypeLiteralNode(typeNode)) return { ok: true };
609
+ if (!ts.isTypeReferenceNode(typeNode) || !ts.isIdentifier(typeNode.typeName)) return {
610
+ ok: false,
611
+ reason: `the value type "${typeNode.getText(sourceFile)}" is not an object type literal`,
612
+ node: typeNode
613
+ };
614
+ if (typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0) return {
615
+ ok: false,
616
+ reason: `the value type "${typeNode.getText(sourceFile)}" is generic`,
617
+ node: typeNode
618
+ };
619
+ const name = typeNode.typeName.text;
620
+ if (visited.has(name)) return {
621
+ ok: false,
622
+ reason: `the value type "${name}" is cyclic/self-referential; the lane cannot prove a literal default graph for it`,
623
+ node: typeNode
624
+ };
625
+ const declarations = propsTypeDeclarations(sourceFile, name);
626
+ if (declarations.length === 0) return {
627
+ ok: false,
628
+ reason: `the value type "${name}" is not declared in this module; only an inline object type literal or a local type/interface alias is admitted`,
629
+ node: typeNode
630
+ };
631
+ if (declarations.length > 1) return {
632
+ ok: false,
633
+ reason: `the value type "${name}" is declared more than once in this module (merged declarations are not admitted)`,
634
+ node: declarations[1].name
635
+ };
636
+ const nextVisited = new Set(visited);
637
+ nextVisited.add(name);
638
+ const declaration = declarations[0];
639
+ if (ts.isInterfaceDeclaration(declaration)) {
640
+ if (declaration.typeParameters !== void 0) return {
641
+ ok: false,
642
+ reason: `the value interface "${name}" is generic`,
643
+ node: declaration.name
644
+ };
645
+ if ((declaration.heritageClauses ?? []).length > 0) return {
646
+ ok: false,
647
+ reason: `the value interface "${name}" has extends clauses this lane cannot prove`,
648
+ node: declaration.name
649
+ };
650
+ return { ok: true };
651
+ }
652
+ if (declaration.typeParameters !== void 0) return {
653
+ ok: false,
654
+ reason: `the value type alias "${name}" is generic`,
655
+ node: declaration.name
656
+ };
657
+ return proveObjectShape(sourceFile, declaration.type, nextVisited);
658
+ }
659
+ /** Is this exactly the canonical `TrustedHtml` type reference? */
660
+ function isCanonicalTrustedHtmlType(sourceFile, typeNode) {
661
+ if (!ts.isTypeReferenceNode(typeNode) || !ts.isIdentifier(typeNode.typeName)) return false;
662
+ if (typeNode.typeName.text !== "TrustedHtml") return false;
663
+ if (typeNode.typeArguments !== void 0 && typeNode.typeArguments.length > 0) return false;
664
+ return canonicalTrustedHtmlTypeName(sourceFile);
665
+ }
666
+ /**
667
+ * The admitted value type of one props member:
668
+ * primitive keyword, `T[]`/`Array<T>` (primitive or opaque object element),
669
+ * opaque object shape, or the canonical TrustedHtml type. `ReadonlyArray`,
670
+ * tuples, nested arrays, nested TrustedHtml and imported non-brand types refuse.
671
+ */
672
+ /**
673
+ * Local names bound to the canonical `TrustedHtml` type import, including
674
+ * aliases. Used only by the defensive nested-brand scan below; top-level type
675
+ * admission still requires the exact canonical name.
676
+ */
677
+ function trustedHtmlTypeLocalNames(sourceFile) {
678
+ const names = /* @__PURE__ */ new Set();
679
+ for (const statement of sourceFile.statements) {
680
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || statement.moduleSpecifier.text !== "@openelement/element") continue;
681
+ const clause = statement.importClause;
682
+ if (clause?.namedBindings === void 0 || !ts.isNamedImports(clause.namedBindings)) continue;
683
+ for (const element of clause.namedBindings.elements) if ((element.propertyName?.text ?? element.name.text) === "TrustedHtml") names.add(element.name.text);
684
+ }
685
+ return names;
686
+ }
687
+ /**
688
+ * Defensive nested-brand scan for opaque object shapes (design §3.3: nested
689
+ * `TrustedHtml` refuses until a type-honest nested carrier exists). The object
690
+ * shape stays opaque for ordinary members, but a type reference to the
691
+ * canonical `TrustedHtml` (or a canonical aliased import / local alias chain
692
+ * that resolves to it) anywhere inside the shape is rejected. Imported types
693
+ * that hide the brand behind an alias not visible in this module remain the
694
+ * documented opaque boundary.
695
+ */
696
+ function findNestedTrustedHtml(sourceFile, node, brandLocals, visited = /* @__PURE__ */ new Set()) {
697
+ if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName)) {
698
+ const name = node.typeName.text;
699
+ if (brandLocals.has(name)) return node;
700
+ const declarations = propsTypeDeclarations(sourceFile, name);
701
+ if (declarations.length === 1 && !visited.has(name)) {
702
+ const nextVisited = new Set(visited);
703
+ nextVisited.add(name);
704
+ const declaration = declarations[0];
705
+ if (ts.isInterfaceDeclaration(declaration)) {
706
+ for (const member of declaration.members) {
707
+ const found = findNestedTrustedHtml(sourceFile, member, brandLocals, nextVisited);
708
+ if (found !== null) return found;
709
+ }
710
+ return null;
711
+ }
712
+ if (ts.isTypeAliasDeclaration(declaration)) return findNestedTrustedHtml(sourceFile, declaration.type, brandLocals, nextVisited);
713
+ }
714
+ }
715
+ let found = null;
716
+ ts.forEachChild(node, (child) => {
717
+ if (found !== null) return;
718
+ found = findNestedTrustedHtml(sourceFile, child, brandLocals, visited);
719
+ });
720
+ return found;
721
+ }
722
+ function resolveValueMemberType(sourceFile, typeNode) {
723
+ const brandLocals = trustedHtmlTypeLocalNames(sourceFile);
724
+ const primitive = typeNode.kind === ts.SyntaxKind.StringKeyword ? "string" : typeNode.kind === ts.SyntaxKind.NumberKeyword ? "number" : typeNode.kind === ts.SyntaxKind.BooleanKeyword ? "boolean" : null;
725
+ if (primitive !== null) return {
726
+ kind: "primitive",
727
+ type: primitive
728
+ };
729
+ if (isCanonicalTrustedHtmlType(sourceFile, typeNode)) return {
730
+ kind: "trustedHtml",
731
+ type: "trustedHtml"
732
+ };
733
+ if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "TrustedHtml") return {
734
+ reason: "TrustedHtml must be exactly the canonical named type import from '@openelement/element' (no alias, no local rebinding/shadowing)",
735
+ node: typeNode
736
+ };
737
+ const arrayElement = (element) => {
738
+ if (element.kind === ts.SyntaxKind.StringKeyword || element.kind === ts.SyntaxKind.NumberKeyword || element.kind === ts.SyntaxKind.BooleanKeyword) return { ok: true };
739
+ return proveObjectShape(sourceFile, element);
740
+ };
741
+ if (ts.isTupleTypeNode(typeNode)) return {
742
+ reason: `the props member type "${typeNode.getText(sourceFile)}" is a tuple; this lane admits T[] or Array<T> with a primitive or opaque object element`,
743
+ node: typeNode
744
+ };
745
+ if (ts.isArrayTypeNode(typeNode)) {
746
+ const element = arrayElement(typeNode.elementType);
747
+ if (!element.ok) return {
748
+ reason: `the array element type "${typeNode.elementType.getText(sourceFile)}" is not admitted (${element.reason})`,
749
+ node: element.node ?? typeNode.elementType
750
+ };
751
+ const nestedBrand = findNestedTrustedHtml(sourceFile, typeNode.elementType, brandLocals);
752
+ if (nestedBrand !== null) return {
753
+ reason: "a nested TrustedHtml inside an opaque array element is not admitted; declare a top-level property-only trustedHtml member instead",
754
+ node: nestedBrand
755
+ };
756
+ return {
757
+ kind: "array",
758
+ type: "array"
759
+ };
760
+ }
761
+ if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {
762
+ const referenceName = typeNode.typeName.text;
763
+ if (referenceName === "ReadonlyArray") return {
764
+ reason: `the props member type "${typeNode.getText(sourceFile)}" uses ReadonlyArray; this lane admits T[] or Array<T>`,
765
+ node: typeNode
766
+ };
767
+ if (referenceName === "Array") {
768
+ const args = typeNode.typeArguments;
769
+ if (args === void 0 || args.length !== 1) return {
770
+ reason: `the props member type "${typeNode.getText(sourceFile)}" must have exactly one type argument`,
771
+ node: typeNode
772
+ };
773
+ const element = arrayElement(args[0]);
774
+ if (!element.ok) return {
775
+ reason: `the array element type "${args[0].getText(sourceFile)}" is not admitted (${element.reason})`,
776
+ node: element.node ?? args[0]
777
+ };
778
+ const nestedBrand = findNestedTrustedHtml(sourceFile, args[0], brandLocals);
779
+ if (nestedBrand !== null) return {
780
+ reason: "a nested TrustedHtml inside an opaque array element is not admitted; declare a top-level property-only trustedHtml member instead",
781
+ node: nestedBrand
782
+ };
783
+ return {
784
+ kind: "array",
785
+ type: "array"
786
+ };
787
+ }
788
+ }
789
+ const objectShape = proveObjectShape(sourceFile, typeNode);
790
+ if (objectShape.ok) {
791
+ const nestedBrand = findNestedTrustedHtml(sourceFile, typeNode, brandLocals);
792
+ if (nestedBrand !== null) return {
793
+ reason: "a nested TrustedHtml inside an opaque object shape is not admitted; declare a top-level property-only trustedHtml member instead",
794
+ node: nestedBrand
795
+ };
796
+ return {
797
+ kind: "object",
798
+ type: "object"
799
+ };
800
+ }
801
+ return {
802
+ reason: `the props member type "${typeNode.getText(sourceFile)}" is not an admitted value type (${objectShape.reason}); this lane admits string/number/boolean, T[] or Array<T> of a primitive or opaque object, an opaque object shape, or the canonical TrustedHtml type`,
803
+ node: objectShape.node ?? typeNode
804
+ };
805
+ }
806
+ /**
807
+ * Read the root component's typed props parameter as an admitted member list.
808
+ *
809
+ * The parameter must be a named identifier (the generated props record is
810
+ * exposed as `props.<member>`; a destructured parameter has no name to read)
811
+ * and its annotation must resolve to local object type members. Only
812
+ * `string`/`number`/`boolean` members are admitted. An optional member is
813
+ * refused because the generated record always supplies a declared value, so
814
+ * the annotation would understate the runtime surface; that is this lane's
815
+ * fail-closed admission choice, not a platform constraint (a future decision
816
+ * could admit optional members by mapping absence to the declared default).
817
+ */
818
+ function readTypedProps(sourceFile, node) {
819
+ const parameter = node.parameters[0];
820
+ if (parameter === void 0) return { kind: "none" };
821
+ if (!ts.isIdentifier(parameter.name)) return {
822
+ kind: "refused",
823
+ diagnostic: propertyDiagnostic(sourceFile, parameter, "the root component declares properties, but its props parameter is destructured; the generated element reads a named props record — use `props: { … }` and `props.member`", GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
824
+ };
825
+ const annotation = authoredPropsType(parameter);
826
+ if (annotation === void 0) return {
827
+ kind: "refused",
828
+ diagnostic: propertyDiagnostic(sourceFile, parameter, `the root component's props parameter "${parameter.name.text}" has no type annotation; declare its primitive members inline (\`props: { label: string }\` in TSX or \`@param {{ label: string }} props\` in JSX) so the sidecar property table can be cross-checked`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
829
+ };
830
+ const resolved = resolvePropsTypeMembers(sourceFile, annotation);
831
+ if ("reason" in resolved) return {
832
+ kind: "refused",
833
+ diagnostic: propertyDiagnostic(sourceFile, resolved.node ?? annotation, resolved.reason, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
834
+ };
835
+ const members = [];
836
+ const seen = /* @__PURE__ */ new Set();
837
+ for (const member of resolved.members) {
838
+ if (!ts.isPropertySignature(member)) return {
839
+ kind: "refused",
840
+ diagnostic: propertyDiagnostic(sourceFile, member, `the props type must contain only primitive property signatures; "${member.getText(sourceFile)}" is not one`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
841
+ };
842
+ const name = ts.isIdentifier(member.name) ? member.name.text : ts.isStringLiteral(member.name) ? member.name.text : null;
843
+ if (name === null || !IDENTIFIER_NAME.test(name)) return {
844
+ kind: "refused",
845
+ diagnostic: propertyDiagnostic(sourceFile, member.name, `the props member "${member.name.getText(sourceFile)}" is not an identifier the generated props record can expose`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
846
+ };
847
+ const sinkReason = forbiddenSinkReason("prop", name);
848
+ if (sinkReason !== null) return {
849
+ kind: "refused",
850
+ diagnostic: propertyDiagnostic(sourceFile, member.name, `the props member "${name}" is not an admissible property name: ${sinkReason}`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
851
+ };
852
+ if (seen.has(name)) return {
853
+ kind: "refused",
854
+ diagnostic: propertyDiagnostic(sourceFile, member.name, `the props type declares "${name}" more than once`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
855
+ };
856
+ seen.add(name);
857
+ if (member.questionToken !== void 0) return {
858
+ kind: "refused",
859
+ diagnostic: propertyDiagnostic(sourceFile, member.name, `the props member "${name}" is optional; this lane requires the declared type to match the runtime surface (the generated element always supplies a value), so declare the member required and put the initial value in the sidecar default. This is a lane admission rule, not a platform requirement.`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
860
+ };
861
+ const typeNode = member.type;
862
+ if (typeNode === void 0) return {
863
+ kind: "refused",
864
+ diagnostic: propertyDiagnostic(sourceFile, member, `the props member "${name}" has no type annotation; declare one so the sidecar property table can be cross-checked`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
865
+ };
866
+ const resolvedType = resolveValueMemberType(sourceFile, typeNode);
867
+ if ("reason" in resolvedType) return {
868
+ kind: "refused",
869
+ diagnostic: propertyDiagnostic(sourceFile, resolvedType.node, `the props member "${name}" is not admitted: ${resolvedType.reason}`, GENERATED_ELEMENT_DIAGNOSTIC.PROPS_TYPE_UNSUPPORTED)
870
+ };
871
+ members.push({
872
+ name,
873
+ kind: resolvedType.kind,
874
+ type: resolvedType.type,
875
+ node: member
876
+ });
877
+ }
878
+ return {
879
+ kind: "read",
880
+ parameter,
881
+ members
882
+ };
883
+ }
884
+ /**
885
+ * Cross-check the sidecar declaration against the typed props parameter and
886
+ * resolve the descriptor rows.
887
+ *
888
+ * `none` means the sidecar declares no `properties` table at all: the M09-1a
889
+ * behavior stands (a props parameter is refused by the later gate). A declared
890
+ * table is a contract in BOTH directions — every typed member needs an entry
891
+ * (so the shell's props record exposes it with a declared type/default) and
892
+ * every entry needs a typed member (so a typo or a stale entry cannot silently
893
+ * produce an attribute nobody reads). Nothing is inferred silently in either
894
+ * direction; `properties: {}` with a type-literal `{}` parameter is the one
895
+ * empty-match shape and emits `properties: []`.
896
+ */
897
+ function admitGeneratedElementProperties(sourceFile, node, declared) {
898
+ if (declared === void 0) return { kind: "none" };
899
+ const typed = readTypedProps(sourceFile, node);
900
+ if (typed.kind === "refused") return {
901
+ kind: "refused",
902
+ diagnostics: [typed.diagnostic]
903
+ };
904
+ if (typed.kind === "none") {
905
+ if (declared.length === 0) return {
906
+ kind: "admitted",
907
+ properties: []
908
+ };
909
+ return {
910
+ kind: "refused",
911
+ diagnostics: [propertyDiagnostic(sourceFile, node, "the openElement sidecar declares properties, but the root component takes no props parameter; add `props` with the same primitive members", GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_MISMATCH)]
912
+ };
913
+ }
914
+ const declaredNames = new Set(declared.map((entry) => entry.name));
915
+ const typedNames = new Set(typed.members.map((member) => member.name));
916
+ const missing = typed.members.filter((member) => !declaredNames.has(member.name)).map((member) => member.name);
917
+ const extra = declared.filter((entry) => !typedNames.has(entry.name)).map((entry) => entry.name);
918
+ if (missing.length > 0 || extra.length > 0) {
919
+ const parts = [];
920
+ if (missing.length > 0) parts.push(`typed member(s) without a sidecar entry: ${missing.map((n) => `"${n}"`).join(", ")}`);
921
+ if (extra.length > 0) parts.push(`sidecar entry(ies) without a typed member: ${extra.map((n) => `"${n}"`).join(", ")}`);
922
+ return {
923
+ kind: "refused",
924
+ diagnostics: [propertyDiagnostic(sourceFile, typed.parameter, "the openElement properties table and the typed props parameter disagree — " + parts.join("; ") + ". Every declared attribute must have a typed member that reads it, and every typed primitive member must be declared so the element exposes it.", GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_MISMATCH)]
925
+ };
926
+ }
927
+ const byName = new Map(typed.members.map((member) => [member.name, member]));
928
+ const properties = [];
929
+ for (const declaration of declared) {
930
+ const member = byName.get(declaration.name);
931
+ if (RESERVED_GENERATED_ELEMENT_PROPERTY_NAMES.has(declaration.name)) return {
932
+ kind: "refused",
933
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the property name "${declaration.name}" collides with the element lifecycle surface; rename the props member and its sidecar entry`)]
934
+ };
935
+ if (member.kind === "primitive") {
936
+ const literalDefault = declaration.default !== void 0 && declaration.default.kind === "literal" ? declaration.default.value : void 0;
937
+ const declaredDefault = typeof literalDefault === "string" || typeof literalDefault === "number" || typeof literalDefault === "boolean" ? literalDefault : void 0;
938
+ const defaultValue = declaredDefault === void 0 ? zeroPropertyValue(member.type) : declaredDefault;
939
+ if (declaration.default !== void 0 && declaredDefault === void 0) return {
940
+ kind: "refused",
941
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, declaration.default.kind === "trustedHtml" ? `the primitive property "${declaration.name}" cannot default to trustedHtml(...)` : `the property "${declaration.name}" default must be a static ${member.type} literal to match the typed member; array/object defaults belong to property-only non-primitive members`)]
942
+ };
943
+ if (typeof defaultValue !== member.type) return {
944
+ kind: "refused",
945
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the property "${declaration.name}" default must be a ${member.type} literal to match the typed member, got ${typeof defaultValue}`)]
946
+ };
947
+ properties.push({
948
+ name: declaration.name,
949
+ attribute: declaration.attribute,
950
+ type: member.type,
951
+ reflect: declaration.reflect,
952
+ default: defaultValue
953
+ });
954
+ continue;
955
+ }
956
+ if (!declaration.attributeExplicit || declaration.attribute !== null) return {
957
+ kind: "refused",
958
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the non-primitive property "${declaration.name}" must declare attribute: false explicitly: no attribute or JSON wire carries it`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
959
+ };
960
+ if (declaration.reflect) return {
961
+ kind: "refused",
962
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the non-primitive property "${declaration.name}" cannot reflect: it has no attribute channel`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
963
+ };
964
+ if (declaration.default === void 0) return {
965
+ kind: "refused",
966
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the non-primitive property "${declaration.name}" requires an explicit literal default (array/object literal graph or trustedHtml(<literal string>))`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
967
+ };
968
+ if (member.kind === "trustedHtml") {
969
+ if (declaration.default.kind !== "trustedHtml") return {
970
+ kind: "refused",
971
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the trustedHtml property "${declaration.name}" must default to the canonical trustedHtml(<literal string>) value`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
972
+ };
973
+ properties.push({
974
+ name: declaration.name,
975
+ attribute: null,
976
+ type: member.type,
977
+ reflect: false,
978
+ default: declaration.default.html
979
+ });
980
+ continue;
981
+ }
982
+ if (declaration.default.kind !== "literal") return {
983
+ kind: "refused",
984
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the ${member.kind} property "${declaration.name}" cannot default to trustedHtml(...)`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
985
+ };
986
+ const graph = declaration.default.value;
987
+ if (!(member.kind === "array" ? Array.isArray(graph) : typeof graph === "object" && graph !== null && !Array.isArray(graph))) return {
988
+ kind: "refused",
989
+ diagnostics: [propertyDiagnostic(sourceFile, declaration.node, `the ${member.kind} property "${declaration.name}" default must be a recursively literal ${member.kind === "array" ? "array" : "object"} graph`, GENERATED_ELEMENT_DIAGNOSTIC.PROPERTY_INVALID)]
990
+ };
991
+ properties.push({
992
+ name: declaration.name,
993
+ attribute: null,
994
+ type: member.type,
995
+ reflect: false,
996
+ defaultGraph: graph
997
+ });
998
+ }
999
+ return {
1000
+ kind: "admitted",
1001
+ properties
1002
+ };
1003
+ }
1004
+ function localFunctionDeclaration(sourceFile, name) {
1005
+ for (const statement of sourceFile.statements) {
1006
+ if (ts.isFunctionDeclaration(statement) && statement.name?.text === name) return statement;
1007
+ if (!ts.isVariableStatement(statement)) continue;
1008
+ for (const declaration of statement.declarationList.declarations) {
1009
+ if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name) continue;
1010
+ const initializer = declaration.initializer;
1011
+ if (initializer !== void 0 && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))) return initializer;
1012
+ return null;
1013
+ }
1014
+ }
1015
+ return null;
1016
+ }
1017
+ function localFunctionFact(sourceFile, name, node) {
1018
+ return {
1019
+ kind: "local-function",
1020
+ name,
1021
+ node,
1022
+ span: spanOf(sourceFile, node)
1023
+ };
1024
+ }
1025
+ /**
1026
+ * Classify the module's default export without compiling anything.
1027
+ *
1028
+ * `export default Name` is resolved against local top-level declarations only:
1029
+ * an imported or re-exported name is not a local function the lane can model,
1030
+ * and the design records that residual instead of guessing.
1031
+ */
1032
+ function findDefaultExport(sourceFile) {
1033
+ for (const statement of sourceFile.statements) {
1034
+ if (ts.isExportAssignment(statement)) {
1035
+ const expression = statement.expression;
1036
+ if (!ts.isIdentifier(expression)) return { kind: "expression" };
1037
+ const local = localFunctionDeclaration(sourceFile, expression.text);
1038
+ return local === null ? { kind: "expression" } : localFunctionFact(sourceFile, expression.text, local);
1039
+ }
1040
+ if (ts.isFunctionDeclaration(statement) && hasModifier(statement, ts.SyntaxKind.DefaultKeyword)) {
1041
+ const name = statement.name?.text;
1042
+ if (name === void 0) return { kind: "anonymous" };
1043
+ return localFunctionFact(sourceFile, name, statement);
1044
+ }
1045
+ if (ts.isClassDeclaration(statement) && hasModifier(statement, ts.SyntaxKind.DefaultKeyword)) return { kind: "class" };
1046
+ if (ts.isExportDeclaration(statement)) {
1047
+ const clause = statement.exportClause;
1048
+ if (clause !== void 0 && ts.isNamedExports(clause)) {
1049
+ for (const element of clause.elements) if (element.name.text === "default") return { kind: "expression" };
1050
+ }
1051
+ }
1052
+ }
1053
+ return null;
1054
+ }
1055
+ function propsParameterOf(node) {
1056
+ const parameter = node.parameters[0];
1057
+ if (parameter === void 0) return null;
1058
+ if (ts.isIdentifier(parameter.name)) return parameter.name.text;
1059
+ return node.getSourceFile().text.slice(parameter.name.getStart(), parameter.name.getEnd());
1060
+ }
1061
+ /**
1062
+ * Admit one module to the generated-element lane. `site` is the host's fact;
1063
+ * this function never derives a tag and never reads the filesystem.
1064
+ */
1065
+ function admitGeneratedElementSite(sourceFile, site) {
1066
+ const fact = findDefaultExport(sourceFile);
1067
+ if (fact === null || fact.kind === "class" || fact.kind === "expression" || fact.kind === "anonymous") return { kind: "declined" };
1068
+ if (!hasIslandPolicyStatement(sourceFile)) return {
1069
+ kind: "refused",
1070
+ diagnostics: [diagnosticAt(sourceFile, fact.node, GENERATED_ELEMENT_DIAGNOSTIC.MISSING_SITE_MARKER, `the generated element site "${site.tag}" requires the island policy statement \`export const openElement = defineIslandConfig({ ... })\` in the same module`)]
1071
+ };
1072
+ const metadata = readIslandMetadata(sourceFile);
1073
+ if (metadata.kind === "refused") return {
1074
+ kind: "refused",
1075
+ diagnostics: [metadata.diagnostic]
1076
+ };
1077
+ const facts = metadata.kind === "read" ? metadata.facts : {
1078
+ root: void 0,
1079
+ clientOnly: false,
1080
+ delegatesFocus: false,
1081
+ formAssociated: false,
1082
+ declaresStyles: false,
1083
+ styles: [],
1084
+ properties: void 0,
1085
+ tag: void 0
1086
+ };
1087
+ const propertiesAdmission = admitGeneratedElementProperties(sourceFile, fact.node, facts.properties);
1088
+ if (propertiesAdmission.kind === "refused") return {
1089
+ kind: "refused",
1090
+ diagnostics: propertiesAdmission.diagnostics
1091
+ };
1092
+ const properties = propertiesAdmission.kind === "admitted" ? propertiesAdmission.properties : [];
1093
+ const formDiagnostics = admitGeneratedElementForm(sourceFile, fact.node, facts.formAssociated, facts.properties, properties);
1094
+ if (formDiagnostics.length > 0) return {
1095
+ kind: "refused",
1096
+ diagnostics: formDiagnostics
1097
+ };
1098
+ return {
1099
+ kind: "admitted",
1100
+ admission: {
1101
+ componentName: fact.name,
1102
+ defaultExportSpan: fact.span,
1103
+ root: facts.root,
1104
+ clientOnly: facts.clientOnly,
1105
+ delegatesFocus: facts.delegatesFocus,
1106
+ formAssociated: facts.formAssociated,
1107
+ declaresStyles: facts.declaresStyles,
1108
+ styles: facts.styles,
1109
+ propertiesDeclared: propertiesAdmission.kind === "admitted",
1110
+ properties,
1111
+ propsParameter: propsParameterOf(fact.node)
1112
+ }
1113
+ };
1114
+ }
1115
+ /**
1116
+ * The bounded M09-2d form mapping gate (two shapes).
1117
+ *
1118
+ * The shape is derived from the declared rows — no separate `formValue` field
1119
+ * or shape field is invented:
1120
+ *
1121
+ * - **value shape** — `formAssociated: true` plus the ordinary declared string
1122
+ * `value` property, which is the form value source. Optional declared boolean
1123
+ * `required`/`disabled` properties enable the required→valueMissing mirror
1124
+ * and the fieldset-disabled state. A reflected `disabled` row is refused
1125
+ * because the shell deliberately writes the property, not the attribute, so
1126
+ * the fieldset/authored state stays reversible (#1226).
1127
+ * - **button shape** — `formAssociated: true` without a declared `value` row
1128
+ * (the open-button contract): the element stays form-associated (it is listed
1129
+ * in `form.elements` and an external `form=<id>` association resolves), but
1130
+ * it publishes no form value, makes no validity claim, and its declared
1131
+ * boolean `disabled` row MAY reflect. `required` mirrors valueMissing on the
1132
+ * form value, so it has nothing to mirror here and is refused.
1133
+ *
1134
+ * Both shapes require the optional `required`/`disabled` rows to be boolean.
1135
+ */
1136
+ function admitGeneratedElementForm(sourceFile, defaultExport, formAssociated, declarations, properties) {
1137
+ if (!formAssociated) return [];
1138
+ const refuse = (node, message) => diagnosticAt(sourceFile, node, GENERATED_ELEMENT_DIAGNOSTIC.FORM_VALUE_UNSUPPORTED, message);
1139
+ const byName = new Map(properties.map((property) => [property.name, property]));
1140
+ const declarationByName = new Map((declarations ?? []).map((declaration) => [declaration.name, declaration]));
1141
+ for (const name of ["required", "disabled"]) {
1142
+ const property = byName.get(name);
1143
+ if (property === void 0) continue;
1144
+ if (property.type !== "boolean") return [refuse(declarationByName.get(name)?.node ?? defaultExport, `the optional form property "${name}" must be a boolean, got ${property.type}`)];
1145
+ }
1146
+ const value = byName.get("value");
1147
+ if (value === void 0) {
1148
+ if (byName.get("required") !== void 0) return [refuse(declarationByName.get("required")?.node ?? defaultExport, "the optional form property \"required\" mirrors valueMissing on the declared form value; a form-associated element without a declared \"value\" property publishes no form value, so \"required\" has nothing to mirror")];
1149
+ return [];
1150
+ }
1151
+ if (value.type !== "string") return [refuse(declarationByName.get("value")?.node ?? defaultExport, `the form value property "value" must be a string, got ${value.type}`)];
1152
+ if (byName.get("disabled")?.reflect) return [refuse(declarationByName.get("disabled")?.node ?? defaultExport, "the form property \"disabled\" must not reflect to its attribute: the fieldset/authored disabled state must stay reversible")];
1153
+ return [];
1154
+ }
1155
+ /**
1156
+ * The M09-1a props gate. `component.propsParam` names an identifier parameter;
1157
+ * the admission's AST fact also catches a destructured parameter, which the
1158
+ * model spells as null. Both are the same authoring fact: the root takes props.
1159
+ */
1160
+ function gateGeneratedElementRootProps(admission, component) {
1161
+ if (admission.propertiesDeclared) return [];
1162
+ if (admission.propsParameter === null && component.propsParam === null) return [];
1163
+ const parameter = component.propsParam ?? admission.propsParameter ?? "props";
1164
+ return [{
1165
+ severity: "error",
1166
+ code: GENERATED_ELEMENT_DIAGNOSTIC.UNDECLARED_PROPS,
1167
+ message: `the generated element root component takes a props parameter "${parameter}", but M09-1 cannot declare attributes or property conversion yet; remove the parameter or pass props through an admitted binding source`,
1168
+ span: component.span,
1169
+ origin: "module"
1170
+ }];
1171
+ }
1172
+ /**
1173
+ * The M09-1a bindings gate. The generated body reads `host.bindings[*]`; no
1174
+ * production binding source exists for a function island in this slice, so a
1175
+ * non-empty requirement fails closed instead of mounting with a missing value.
1176
+ */
1177
+ function gateGeneratedElementBindings(file, leaf) {
1178
+ if (leaf.requiredBindings.length === 0) return [];
1179
+ if (leaf.rootInstanceFactory !== null) return [];
1180
+ return [{
1181
+ severity: "error",
1182
+ code: GENERATED_ELEMENT_DIAGNOSTIC.UNBOUND_BINDING,
1183
+ message: `the generated element root requires host binding(s) ${leaf.requiredBindings.map((name) => `"${name}"`).join(", ")}, but no production binding source exists in M09-1; pass the values as module imports or wait for the binding import channel`,
1184
+ span: {
1185
+ file,
1186
+ start: 0,
1187
+ end: 0,
1188
+ line: 1,
1189
+ column: 1
1190
+ },
1191
+ origin: "module"
1192
+ }];
1193
+ }
1194
+ //#endregion
1195
+ export { RESERVED_GENERATED_ELEMENT_PROPERTY_NAMES, admitGeneratedElementSite, findDefaultExport, gateGeneratedElementBindings, gateGeneratedElementRootProps, hasIslandPolicyStatement, islandPolicyObjectLiteral, readIslandMetadata };