@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,156 @@
1
+ import ts from "typescript";
2
+ //#region src/internal/compiler/semantic-core/type-erasure.ts
3
+ /**
4
+ * M03-I-3 — TypeScript-only syntax erasure for lowered expression text.
5
+ *
6
+ * Design authority: `docs/architecture/m03-expression-identity.md` (M03-B) §3
7
+ * Route 3 step 2a and §8 rule 2. The erasure visitor is the one place where
8
+ * this design takes on work TypeScript's own emitter would otherwise do, which
9
+ * is exactly why §10 keeps a differential `ts.transpileModule` oracle: the
10
+ * oracle checks this visitor, it is never the mechanism.
11
+ *
12
+ * Scope (the admitted erasure set):
13
+ * - wrappers: `as`, `satisfies`, non-null `!`, angle-bracket type assertions and
14
+ * instantiation expressions (`f<string>` as a value) are replaced by their
15
+ * inner expression;
16
+ * - type arguments on `call`/`new` sites are dropped;
17
+ * - annotations on function-like nodes are dropped (type parameters, return
18
+ * types, parameter types and their optional `?`); a `this` parameter is
19
+ * removed; this covers arrows/function expressions, object-literal methods
20
+ * and accessors, and nested function declarations;
21
+ * - property declarations only need their type/`?`/`!` erased, but they occur
22
+ * inside class expressions, which this model refuses (see below).
23
+ *
24
+ * Outside the admitted erasure set this module fails closed: class declarations
25
+ * and class expressions are outside the function-component expression model
26
+ * (class authoring retires; M03-B §6), so they are refused with
27
+ * `OEIR_ERASURE_UNSUPPORTED` rather than half-lowered. Context-sensitive
28
+ * constructs (`this`/`arguments`/`super`/`new.target`/`await`/`yield`/`eval`)
29
+ * stay refused by the caller's context matrix.
30
+ *
31
+ * The visitor preserves authored positions on every rebuilt node
32
+ * (`ts.setTextRange`), so the A2 marker/anchor pipeline keeps reporting node
33
+ * starts for the surviving nodes: erasure changes the printed text, never the
34
+ * provenance arithmetic.
35
+ */
36
+ function withAuthoredRange(updated, original) {
37
+ return ts.setTextRange(updated, original);
38
+ }
39
+ /** Type-assert a visited child back to the factory's expected child type. */
40
+ function visitAs(visit, node) {
41
+ return visit(node);
42
+ }
43
+ function isThisParameter(parameter) {
44
+ return ts.isIdentifier(parameter.name) && parameter.name.text === "this";
45
+ }
46
+ function parameterNeedsErasure(parameter) {
47
+ return parameter.type !== void 0 || parameter.questionToken !== void 0;
48
+ }
49
+ /** Erase parameter annotations, optional markers and `this` parameters. */
50
+ function eraseParameters(parameters, visit) {
51
+ const erased = [];
52
+ for (const parameter of parameters) {
53
+ if (isThisParameter(parameter)) continue;
54
+ const initializer = parameter.initializer === void 0 ? void 0 : visitAs(visit, parameter.initializer);
55
+ if (!parameterNeedsErasure(parameter) && initializer === parameter.initializer) {
56
+ erased.push(parameter);
57
+ continue;
58
+ }
59
+ erased.push(withAuthoredRange(ts.factory.updateParameterDeclaration(parameter, parameter.modifiers, parameter.dotDotDotToken, parameter.name, void 0, void 0, initializer), parameter));
60
+ }
61
+ return erased;
62
+ }
63
+ function eraseArrow(node, visit) {
64
+ return withAuthoredRange(ts.factory.updateArrowFunction(node, node.modifiers, void 0, eraseParameters(node.parameters, visit), void 0, node.equalsGreaterThanToken, visitAs(visit, node.body)), node);
65
+ }
66
+ function eraseFunctionExpression(node, visit) {
67
+ return withAuthoredRange(ts.factory.updateFunctionExpression(node, node.modifiers, node.asteriskToken, node.name, void 0, eraseParameters(node.parameters, visit), void 0, visitAs(visit, node.body)), node);
68
+ }
69
+ function eraseFunctionDeclaration(node, visit) {
70
+ return withAuthoredRange(ts.factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, node.name, void 0, eraseParameters(node.parameters, visit), void 0, node.body === void 0 ? void 0 : visitAs(visit, node.body)), node);
71
+ }
72
+ function eraseMethodDeclaration(node, visit) {
73
+ return withAuthoredRange(ts.factory.updateMethodDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.questionToken, void 0, eraseParameters(node.parameters, visit), void 0, node.body === void 0 ? void 0 : visitAs(visit, node.body)), node);
74
+ }
75
+ function eraseGetAccessor(node, visit) {
76
+ return withAuthoredRange(ts.factory.updateGetAccessorDeclaration(node, node.modifiers, node.name, eraseParameters(node.parameters, visit), void 0, node.body === void 0 ? void 0 : visitAs(visit, node.body)), node);
77
+ }
78
+ function eraseSetAccessor(node, visit) {
79
+ return withAuthoredRange(ts.factory.updateSetAccessorDeclaration(node, node.modifiers, node.name, eraseParameters(node.parameters, visit), node.body === void 0 ? void 0 : visitAs(visit, node.body)), node);
80
+ }
81
+ /**
82
+ * Erase TypeScript-only syntax at this node. Returns the replacement, or
83
+ * `undefined` when this node is not erased here and the caller should continue
84
+ * with its normal child traversal (`ts.visitEachChild`).
85
+ */
86
+ function eraseTypeScriptSyntax(node, visit) {
87
+ if (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node) || ts.isTypeAssertionExpression(node)) return visit(node.expression);
88
+ if (ts.isExpressionWithTypeArguments(node)) return visitAs(visit, node.expression);
89
+ if (ts.isCallExpression(node)) {
90
+ if (node.typeArguments === void 0 || node.typeArguments.length === 0) return void 0;
91
+ return withAuthoredRange(ts.factory.updateCallExpression(node, visitAs(visit, node.expression), void 0, node.arguments.map((argument) => visitAs(visit, argument))), node);
92
+ }
93
+ if (ts.isNewExpression(node)) {
94
+ if (node.typeArguments === void 0 || node.typeArguments.length === 0) return void 0;
95
+ return withAuthoredRange(ts.factory.updateNewExpression(node, visitAs(visit, node.expression), void 0, node.arguments === void 0 ? void 0 : node.arguments.map((argument) => visitAs(visit, argument))), node);
96
+ }
97
+ if (ts.isVariableDeclaration(node)) {
98
+ if (node.type === void 0 && node.exclamationToken === void 0) return void 0;
99
+ return withAuthoredRange(ts.factory.updateVariableDeclaration(node, node.name, void 0, void 0, node.initializer === void 0 ? void 0 : visitAs(visit, node.initializer)), node);
100
+ }
101
+ if (ts.isArrowFunction(node)) return eraseArrow(node, visit);
102
+ if (ts.isFunctionExpression(node)) return eraseFunctionExpression(node, visit);
103
+ if (ts.isFunctionDeclaration(node)) return eraseFunctionDeclaration(node, visit);
104
+ if (ts.isMethodDeclaration(node)) return eraseMethodDeclaration(node, visit);
105
+ if (ts.isGetAccessorDeclaration(node)) return eraseGetAccessor(node, visit);
106
+ if (ts.isSetAccessorDeclaration(node)) return eraseSetAccessor(node, visit);
107
+ }
108
+ /** A source-located erasure refusal. */
109
+ function refusal(sourceFile, node, code, message) {
110
+ const start = node.getStart(sourceFile);
111
+ const position = sourceFile.getLineAndCharacterOfPosition(start);
112
+ return {
113
+ severity: "error",
114
+ code,
115
+ message,
116
+ span: {
117
+ file: sourceFile.fileName,
118
+ start,
119
+ end: node.getEnd(),
120
+ line: position.line + 1,
121
+ column: position.character + 1
122
+ },
123
+ origin: "source"
124
+ };
125
+ }
126
+ /**
127
+ * Fail closed on TypeScript syntax outside the admitted erasure set. Class
128
+ * authoring retires (M03-B §6), so a class declaration/expression inside the
129
+ * lowered expression is refused instead of half-lowered. JSX subtrees are
130
+ * recipe interiors and are not inspected.
131
+ */
132
+ function collectErasureBoundaryRefusals(sourceFile, root, diagnostics) {
133
+ const visit = (node) => {
134
+ if (node !== root && ts.isJsxElement(node)) return;
135
+ if (ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)) return;
136
+ if (ts.isClassExpression(node) || ts.isClassDeclaration(node)) {
137
+ diagnostics.push(refusal(sourceFile, node, "OEIR_ERASURE_UNSUPPORTED", "class authoring is outside the function-component expression model; fail closed rather than print a half-erased class"));
138
+ return;
139
+ }
140
+ if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isEnumDeclaration(node) || ts.isModuleDeclaration(node)) {
141
+ diagnostics.push(refusal(sourceFile, node, "OEIR_ERASURE_UNSUPPORTED", "type-only declarations inside a lowered expression are outside the erasure set; fail closed rather than print TypeScript-only declarations as JavaScript"));
142
+ return;
143
+ }
144
+ if (ts.canHaveModifiers(node)) {
145
+ const declare = ts.getModifiers(node)?.find((modifier) => modifier.kind === ts.SyntaxKind.DeclareKeyword);
146
+ if (declare !== void 0) {
147
+ diagnostics.push(refusal(sourceFile, declare, "OEIR_ERASURE_UNSUPPORTED", "`declare` is outside the admitted erasure set; fail closed"));
148
+ return;
149
+ }
150
+ }
151
+ ts.forEachChild(node, visit);
152
+ };
153
+ visit(root);
154
+ }
155
+ //#endregion
156
+ export { collectErasureBoundaryRefusals, eraseTypeScriptSyntax };
@@ -0,0 +1,61 @@
1
+ import { CompiledElementSourceMap } from "../../semantic-core/source-map.js";
2
+ import { GeneratedElementSite } from "./contract.js";
3
+ //#region src/internal/compiler/semantic-ir/generated-element/compile.d.ts
4
+ /** Host-supplied inputs for one generated-element compile. */
5
+ export interface CompileGeneratedElementOptions {
6
+ /** The host's site fact; null keeps the lane inert. */
7
+ readonly site: GeneratedElementSite | null;
8
+ /** The authored source for the emitted module's source map. */
9
+ readonly authoredSource?: string;
10
+ }
11
+ /** The compiled generated-element module (text plus the leaf's unchanged map). */
12
+ export interface CompiledGeneratedElement {
13
+ readonly code: string;
14
+ /** The leaf source map, unchanged; the appended CE tail has no segments. */
15
+ readonly map: CompiledElementSourceMap | null;
16
+ readonly tag: string;
17
+ readonly component: string;
18
+ /**
19
+ * The emitted host-wrapper export name (`<component>__ssrHost`), or null when
20
+ * the emitter appended no host producer. It is the compiler-owned emitted
21
+ * export identity (M11 review §4.1/S1), produced by the same emitter
22
+ * `hostWrapper` decision that appends the function and returned here as
23
+ * build metadata: `null` means "this module has no host producer" (a light or
24
+ * absent root, a leaf without `<component>__ssr`, or a hostless/refused
25
+ * module), not an error. `code` is byte-identical whether or not the field is
26
+ * read; callers must not re-derive the name from the emitted text.
27
+ */
28
+ readonly ssrHostExport: string | null;
29
+ /** Whether emission attached the light-root SSR producer to the constructor. */
30
+ readonly lightSsr: boolean;
31
+ /**
32
+ * The module's admitted STATIC class tokens (deletion prerequisite P-1): the
33
+ * component stylesheet's candidate set, collected from the same function model
34
+ * the module was emitted from. Empty when every class channel is dynamic.
35
+ */
36
+ readonly classCandidates: readonly string[];
37
+ /**
38
+ * Whether this module's tree contains a `when`/`each` Block — the blocks axis of
39
+ * the runtime-shape floor table (ADR-0166), which picks the `./no-blocks` entry
40
+ * when no island in the app uses one.
41
+ *
42
+ * This replaces the class lane's `program.blocks`: the router's scan used to read
43
+ * that Part Program field, and with the class lane gone it had no fact at all.
44
+ * Answered from the SAME function model this compile already lowered, so it is a
45
+ * fact of the compilation and not a second derivation.
46
+ */
47
+ readonly usesBlocks: boolean;
48
+ }
49
+ /**
50
+ * Compile one module through the generated native element lane when — and only
51
+ * when — the host supplied a site fact for it.
52
+ *
53
+ * Admission order (design §4.2): site fact → class-lane ownership → syntactic
54
+ * default-export/sidecar admission (the root and focus facts and the property
55
+ * table included: the lane reads them from the sidecar, D-root-source /
56
+ * D-delegatesFocus / D-props) → props parameter/type cross-check → leaf
57
+ * generation → bindings requirement. The final emitter step is append-only over the leaf text, so
58
+ * every refusal happens before a half-built module can be returned.
59
+ */
60
+ export declare function compileGeneratedElementIfAdmitted(code: string, id: string, options: CompileGeneratedElementOptions): CompiledGeneratedElement | null;
61
+ //#endregion
@@ -0,0 +1,137 @@
1
+ import { CompiledElementError } from "../../semantic-core/compiler-diagnostics.js";
2
+ import { isJsxModuleId } from "../../semantic-core/jsx-module-id.js";
3
+ import { analyzeModuleSemantics } from "../../semantic-core/module-analysis.js";
4
+ import { typescriptParser } from "../../semantic-core/parse-module.js";
5
+ import { compileFunctionModule } from "../../semantic-core/function-frontend.js";
6
+ import { GENERATED_ELEMENT_DIAGNOSTIC, GENERATED_ELEMENT_IMPORT_CLASSIFIER } from "./contract.js";
7
+ import { generateElementModule } from "./emit.js";
8
+ import { admitGeneratedElementSite, gateGeneratedElementBindings, gateGeneratedElementRootProps } from "./site.js";
9
+ //#region src/internal/compiler/semantic-ir/generated-element/compile.ts
10
+ /**
11
+ * M09-1a — the generated-element lane entry.
12
+ *
13
+ * Mirrors `compileServerComponentIfAdmitted`: returns null for a module the
14
+ * lane does not own (no host site fact, non-JSX-bearing, or the class lane's decorator
15
+ * grammar) and fails closed with the single compiler error dialect when it does
16
+ * own a module it must refuse. The host calls it between the class lane and the
17
+ * server function lane in `compiledElementPlugin.transform`.
18
+ *
19
+ * The lane is inert in a real build: no production host passes a
20
+ * `generatedElementSite` option in M09-1a, so every real module returns null at
21
+ * the first gate. The router wiring that supplies a site is M09-1b.
22
+ */
23
+ /**
24
+ * Whether one lowered component's tree contains a `when` or `each` Block.
25
+ *
26
+ * The walk descends conditions and list templates because a Block nested inside one
27
+ * still needs the block builders at runtime. Component references are NOT followed:
28
+ * a child component's Blocks are its own module's business, and the router's scan
29
+ * asks every island module separately — following them here would make one island's
30
+ * answer depend on another's, which is exactly the coupling the per-module scan
31
+ * avoids.
32
+ */
33
+ function componentUsesBlocks(component) {
34
+ let found = false;
35
+ const visit = (nodes) => {
36
+ for (const node of nodes) {
37
+ if (found) return;
38
+ if (node.kind === "condition") {
39
+ found = true;
40
+ return;
41
+ }
42
+ if (node.kind === "list") {
43
+ found = true;
44
+ return;
45
+ }
46
+ if (node.kind === "element" || node.kind === "fragment") visit(node.children);
47
+ }
48
+ };
49
+ visit(component.roots);
50
+ return found;
51
+ }
52
+ function toCompilerDiagnostic(diagnostic) {
53
+ return {
54
+ code: diagnostic.code,
55
+ message: diagnostic.message,
56
+ file: diagnostic.span.file,
57
+ line: diagnostic.span.line,
58
+ character: diagnostic.span.column,
59
+ start: diagnostic.span.start,
60
+ end: diagnostic.span.end
61
+ };
62
+ }
63
+ function notAComponent(componentName, moduleFile) {
64
+ return {
65
+ severity: "error",
66
+ code: GENERATED_ELEMENT_DIAGNOSTIC.NOT_A_COMPONENT,
67
+ message: `the default export "${componentName}" is a function, but the function frontend did not admit it as a component (a component returns JSX); M09-1 will not ship a non-constructor default export for an island`,
68
+ span: {
69
+ file: moduleFile,
70
+ start: 0,
71
+ end: 0,
72
+ line: 1,
73
+ column: 1
74
+ },
75
+ origin: "module"
76
+ };
77
+ }
78
+ /**
79
+ * Compile one module through the generated native element lane when — and only
80
+ * when — the host supplied a site fact for it.
81
+ *
82
+ * Admission order (design §4.2): site fact → class-lane ownership → syntactic
83
+ * default-export/sidecar admission (the root and focus facts and the property
84
+ * table included: the lane reads them from the sidecar, D-root-source /
85
+ * D-delegatesFocus / D-props) → props parameter/type cross-check → leaf
86
+ * generation → bindings requirement. The final emitter step is append-only over the leaf text, so
87
+ * every refusal happens before a half-built module can be returned.
88
+ */
89
+ function compileGeneratedElementIfAdmitted(code, id, options) {
90
+ if (options.site === null) return null;
91
+ if (!isJsxModuleId(id)) return null;
92
+ const classFacts = analyzeModuleSemantics(code, id);
93
+ if (classFacts.compiledElementDecorator || classFacts.unsupportedElementDecorator !== void 0) return null;
94
+ const parsed = typescriptParser.parseModule(code, id);
95
+ if (parsed.syntaxDiagnostics.length > 0) return null;
96
+ const siteAdmission = admitGeneratedElementSite(parsed.sourceFile, options.site);
97
+ if (siteAdmission.kind === "declined") return null;
98
+ if (siteAdmission.kind === "refused") throw new CompiledElementError(siteAdmission.diagnostics.map(toCompilerDiagnostic));
99
+ const admission = siteAdmission.admission;
100
+ const frontend = compileFunctionModule(code, id, {
101
+ importClassifier: GENERATED_ELEMENT_IMPORT_CLASSIFIER,
102
+ lifecycleAdmission: { admission: "module" }
103
+ });
104
+ if (frontend.module === null) throw new CompiledElementError([...frontend.diagnostics]);
105
+ const root = frontend.module.components.find((component) => component.name === admission.componentName);
106
+ if (root === void 0) throw new CompiledElementError([toCompilerDiagnostic(notAComponent(admission.componentName, id))]);
107
+ const propsDiagnostics = gateGeneratedElementRootProps(admission, root);
108
+ if (propsDiagnostics.length > 0) throw new CompiledElementError(propsDiagnostics.map(toCompilerDiagnostic));
109
+ const emitted = generateElementModule(frontend.module, options.site, {
110
+ rootComponent: root.name,
111
+ allowDirectShadowDriver: admission.propsParameter === null,
112
+ ...admission.root === void 0 ? {} : { root: admission.root },
113
+ ...admission.delegatesFocus ? { delegatesFocus: true } : {},
114
+ ...admission.formAssociated ? { formAssociated: true } : {},
115
+ ...admission.properties.length === 0 ? {} : { properties: admission.properties },
116
+ ...admission.declaresStyles && admission.root === "shadow-open" ? { styleLinkPrefix: true } : {},
117
+ clientOnly: admission.clientOnly,
118
+ ...admission.declaresStyles ? { styles: admission.styles } : {},
119
+ ...options.authoredSource === void 0 ? {} : { authoredSource: options.authoredSource }
120
+ });
121
+ if (emitted.diagnostics.length > 0) throw new CompiledElementError(emitted.diagnostics.map(toCompilerDiagnostic));
122
+ const bindingDiagnostics = gateGeneratedElementBindings(id, emitted);
123
+ if (bindingDiagnostics.length > 0) throw new CompiledElementError(bindingDiagnostics.map(toCompilerDiagnostic));
124
+ if (emitted.module === null) throw new CompiledElementError([toCompilerDiagnostic(notAComponent(admission.componentName, id))]);
125
+ return {
126
+ code: emitted.module,
127
+ map: emitted.sourceMap,
128
+ tag: options.site.tag,
129
+ component: root.name,
130
+ ssrHostExport: emitted.ssrHostExport,
131
+ lightSsr: emitted.lightSsr,
132
+ classCandidates: emitted.classCandidates,
133
+ usesBlocks: componentUsesBlocks(root)
134
+ };
135
+ }
136
+ //#endregion
137
+ export { compileGeneratedElementIfAdmitted };
@@ -0,0 +1,201 @@
1
+ import { ImportClassifier } from "../../semantic-core/scope-resolution.js";
2
+ //#region src/internal/compiler/semantic-ir/generated-element/contract.d.ts
3
+ /**
4
+ * The internal shell specifier the emitted CE module imports.
5
+ *
6
+ * Deliberately NOT a package `exports` subpath in M09-1a: the directory is
7
+ * still excluded from `@openelement/element`'s packed `files` set, and the
8
+ * compiler lane has no production caller. M09-1b deletes the exclusion, adds
9
+ * the export subpath, and points the emitted module at the exported spelling.
10
+ * Source-level M09-1a tests alias this specifier to the workspace source; the
11
+ * unresolved spelling cannot reach a real build because no production host
12
+ * passes a site fact yet.
13
+ */
14
+ declare const GENERATED_ELEMENT_SHELL_SPECIFIER = "@openelement/element/internal/compiled/generated-element/shell";
15
+ /**
16
+ * The host-supplied fact that admits one module to the generated-element lane.
17
+ * It is an internal compiler option value, never author syntax: the router
18
+ * derives it from the island path (M09-1b) and the compiler cannot derive it
19
+ * itself because the island transform runs after this compiler plugin.
20
+ *
21
+ * The fact carries the TAG only. The root used to ride here too; D-root-source
22
+ * (2026-11-13) moved it to the compiler lane's own read of the authored
23
+ * sidecar (`site.ts` `readIslandRoot`), so one stale host scan can no longer
24
+ * pin a root that the source no longer declares.
25
+ */
26
+ export interface GeneratedElementSite {
27
+ /** The custom-element tag the host's island pipeline will register. */
28
+ readonly tag: string;
29
+ /**
30
+ * The descriptor root the host will create, when the host already knows it
31
+ * (P-1, 2026-11-21). The router resolves this from the island's OWN
32
+ * declaration — the same fact the DSD link list and the shell's `root` come
33
+ * from — so a shadow generated island's statically admitted class tokens can
34
+ * be registered as SHADOW candidates (the component stylesheet) rather than
35
+ * light ones (the document sheet, which a shadow root never sees).
36
+ *
37
+ * Optional and defaulting to the pre-P-1 answer (`light`): a host that does
38
+ * not know the root keeps today's behaviour, and the compiler never infers it
39
+ * from the sidecar here — the host owns the site fact.
40
+ */
41
+ readonly root?: 'light' | 'shadow' | 'closed';
42
+ }
43
+ /** Host hook for the site fact; returning null keeps the lane inert. */
44
+ type GeneratedElementSiteResolver = (moduleId: string) => GeneratedElementSite | null;
45
+ /** The three primitive property types the generated-element shell admits. */
46
+ export type GeneratedElementPrimitiveType = 'string' | 'number' | 'boolean';
47
+ /**
48
+ * The property-only non-primitive types this lane retains (plan §14): no
49
+ * attribute channel, no JSON wire, no converter. `trustedHtml` is the existing
50
+ * brand; array/object values are caller-owned references.
51
+ */
52
+ export type GeneratedElementNonPrimitiveType = 'array' | 'object' | 'trustedHtml';
53
+ /** Every property type a descriptor row may declare. */
54
+ export type GeneratedElementPlatformPropertyType = GeneratedElementPrimitiveType | GeneratedElementNonPrimitiveType;
55
+ /**
56
+ * The literal default graph an array/object row may carry: JSON-safe values
57
+ * only (the emitter renders it as a fresh-literal factory; the shell never
58
+ * clones caller writes). `trustedHtml` calls are not part of this graph; a
59
+ * trustedHtml default is the literal HTML string carried separately.
60
+ */
61
+ export type GeneratedElementDefaultGraph = string | number | boolean | null | readonly GeneratedElementDefaultGraph[] | {
62
+ readonly [key: string]: GeneratedElementDefaultGraph;
63
+ };
64
+ /**
65
+ * One resolved property row the emitter writes into the descriptor.
66
+ *
67
+ * This is the compiler-side mirror of the shell's landed
68
+ * `GeneratedElementProperty`: the same five facts, already resolved from the
69
+ * sidecar table and the typed props member (attribute name, primitive type,
70
+ * reflection, declared/zero default). `attribute: null` is a property-only
71
+ * channel; the shell derives observedAttributes from the non-null rows.
72
+ *
73
+ * It is deliberately NOT `GeneratedElementProperty` itself: the compiler lane
74
+ * must not import the browser runtime shell (the emitted module is the only
75
+ * consumer of the shell specifier), so the descriptor ABI stays a structural
76
+ * contract on both sides of the boundary.
77
+ */
78
+ interface GeneratedElementPlatformProperty {
79
+ /** JS property name and the key the generated props record exposes. */
80
+ readonly name: string;
81
+ /** Resolved attribute name, or null for a property-only channel. */
82
+ readonly attribute: string | null;
83
+ readonly type: GeneratedElementPlatformPropertyType;
84
+ /** Reflect property writes back to the attribute. */
85
+ readonly reflect: boolean;
86
+ /**
87
+ * Declared initial value. Primitive rows carry the value; a `trustedHtml`
88
+ * row carries the literal HTML string the shell brands per materialisation;
89
+ * array/object rows carry the generated fresh-literal factory NAME in
90
+ * `defaultFactory` instead (the emitter declares one module-level factory),
91
+ * so the descriptor never holds a mutable module-level default graph.
92
+ */
93
+ readonly default?: string | number | boolean;
94
+ /**
95
+ * Emitted module-level factory for an array/object default. Re-evaluating it
96
+ * builds a deep-fresh literal graph; the shell calls it once per element
97
+ * instance and the SSR resolver once per render.
98
+ */
99
+ readonly defaultFactory?: string;
100
+ /** The literal graph the emitted factory returns (array/object rows). */
101
+ readonly defaultGraph?: GeneratedElementDefaultGraph;
102
+ }
103
+ /**
104
+ * The internal diagnostic codes this lane can raise. They follow the shell's
105
+ * `OEIR_*` convention and are deliberately absent from the public error
106
+ * catalogue and the interface snapshot.
107
+ */
108
+ declare const GENERATED_ELEMENT_DIAGNOSTIC: {
109
+ /** A site module default-exports a function that is not an admitted component. */
110
+ readonly NOT_A_COMPONENT: "OEIR_GENERATED_ELEMENT_NOT_A_COMPONENT";
111
+ /** The root component takes a props parameter; M09-1a cannot declare attributes. */
112
+ readonly UNDECLARED_PROPS: "OEIR_GENERATED_ELEMENT_UNDECLARED_PROPS";
113
+ /** The generated body reads `host.bindings[*]` and no binding source exists. */
114
+ readonly UNBOUND_BINDING: "OEIR_GENERATED_ELEMENT_UNBOUND_BINDING";
115
+ /** A fixed CE-tail identifier already occurs in the leaf text. */
116
+ readonly NAME_COLLISION: "OEIR_GENERATED_ELEMENT_NAME_COLLISION";
117
+ /** The host admitted the module but the island sidecar is absent. */
118
+ readonly MISSING_SITE_MARKER: "OEIR_GENERATED_ELEMENT_MISSING_SITE_MARKER";
119
+ /**
120
+ * The sidecar's `root` cannot be read as one of `'light' | 'shadow'`
121
+ * (a dynamic value, another literal, a duplicate key, or a config object
122
+ * whose key set is not static). The router scanner's `ISLAND_METADATA_ERROR`
123
+ * remains the author-facing authority; this code is the lane's own
124
+ * fail-closed verdict inside the compiler.
125
+ */
126
+ readonly ROOT_INVALID: "OEIR_GENERATED_ELEMENT_ROOT_INVALID";
127
+ /**
128
+ * The sidecar's `delegatesFocus` cannot be read as one boolean literal (a
129
+ * dynamic value, a duplicate key, or a config object whose key set is not
130
+ * static). Like `ROOT_INVALID`, this is the lane's fail-closed verdict; the
131
+ * router scanner's `ISLAND_METADATA_ERROR` remains the author-facing
132
+ * authority and the two readers are held together by the seam drift guard.
133
+ */
134
+ readonly DELEGATES_FOCUS_INVALID: "OEIR_GENERATED_ELEMENT_DELEGATES_FOCUS_INVALID";
135
+ /**
136
+ * The sidecar declares `delegatesFocus: true` without `root: 'shadow'`. A
137
+ * light root has no shadow boundary to delegate focus through; the shell's
138
+ * descriptor validation refuses the pair too, so the lane refuses before a
139
+ * module exists instead of shipping a class that throws on evaluation.
140
+ */
141
+ readonly DELEGATES_FOCUS_WITHOUT_SHADOW: "OEIR_GENERATED_ELEMENT_DELEGATES_FOCUS_WITHOUT_SHADOW";
142
+ /**
143
+ * The root component's props parameter cannot be read as a typed primitive
144
+ * member list: no annotation, a destructured/rest parameter, an imported or
145
+ * generic type, a non-property member, an optional member or a non-primitive
146
+ * member type. The generated element's props record is a fixed
147
+ * string/number/boolean table; anything it cannot express fails closed
148
+ * instead of being silently dropped from the attribute channel.
149
+ */
150
+ readonly PROPS_TYPE_UNSUPPORTED: "OEIR_GENERATED_ELEMENT_PROPS_TYPE_UNSUPPORTED";
151
+ /**
152
+ * The sidecar `properties` table and the typed props member list disagree
153
+ * (a declared key with no typed member or a typed member with no entry, or a
154
+ * declaration without a props parameter). The two declarations are
155
+ * cross-checked, never inferred one from the other.
156
+ */
157
+ readonly PROPERTY_MISMATCH: "OEIR_GENERATED_ELEMENT_PROPERTY_MISMATCH";
158
+ /**
159
+ * One sidecar property entry is not representable: an unknown option, a
160
+ * non-literal default, an unsafe attribute name, a duplicate attribute, a
161
+ * reflected property with no attribute channel, a reserved lifecycle name, or
162
+ * a default whose literal type does not match the typed member.
163
+ */
164
+ readonly PROPERTY_INVALID: "OEIR_GENERATED_ELEMENT_PROPERTY_INVALID";
165
+ /** The sidecar's `formAssociated` is not one boolean literal. */
166
+ readonly FORM_ASSOCIATED_INVALID: "OEIR_GENERATED_ELEMENT_FORM_ASSOCIATED_INVALID";
167
+ /**
168
+ * The sidecar's `tag` is not one static string literal, or it is not a valid
169
+ * custom-element name. The lane refuses rather than admitting a module whose
170
+ * identity it cannot prove: the tag is the one host fact the compiler cannot
171
+ * derive, so a dynamic or malformed spelling would either admit the wrong
172
+ * module or register a name the platform rejects.
173
+ */
174
+ readonly TAG_INVALID: "OEIR_GENERATED_ELEMENT_TAG_INVALID";
175
+ /**
176
+ * The form-associated declaration cannot be mapped to the bounded mechanics:
177
+ * no declared string `value` property, a non-boolean `required`/`disabled`,
178
+ * or a reflected `disabled` row (the fieldset state must stay reversible).
179
+ */
180
+ readonly FORM_VALUE_UNSUPPORTED: "OEIR_GENERATED_ELEMENT_FORM_VALUE_UNSUPPORTED";
181
+ /**
182
+ * The sidecar's `ssr` cannot be read as one boolean literal (a dynamic value
183
+ * or a duplicate key). Only the EXPLICIT literal `false` is the client-only
184
+ * fact; `true` and an absent key are the same case, so a value this reader
185
+ * cannot prove must refuse instead of guessing the delivery phase.
186
+ */
187
+ readonly SSR_INVALID: "OEIR_GENERATED_ELEMENT_SSR_INVALID";
188
+ /**
189
+ * A client-only island declares `styles`, but no static `.css` specifier
190
+ * reached the emitter. A client-only island has no DSD template to carry the
191
+ * marked `<link>`, so the sheet can only arrive through a real module-graph
192
+ * import; emitting the descriptor without one would render unstyled. This is
193
+ * the build-time half of the shim #24 failure closure, kept by the client
194
+ * style slice.
195
+ */
196
+ readonly CLIENT_STYLES_UNWIRED: "OEIR_GENERATED_ELEMENT_CLIENT_STYLES_UNWIRED";
197
+ /** The appended tail did not parse (an emitter invariant, not author input). */
198
+ readonly INVALID_ARTIFACT: "OEIR_GENERATED_ELEMENT_INVALID_ARTIFACT";
199
+ };
200
+ declare const GENERATED_ELEMENT_IMPORT_CLASSIFIER: ImportClassifier;
201
+ //#endregion