@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,52 @@
1
+ import ts from "typescript";
2
+ //#region src/internal/compiler/semantic-core/island-policy-statement.ts
3
+ /**
4
+ * The island/component policy sidecar locator — ONE definition for every reader.
5
+ *
6
+ * A generated element declares its platform facts in the sidecar statement
7
+ *
8
+ * `export const openElement = defineIslandConfig({ ... })` (router islands)
9
+ * `export const openElement = defineComponentConfig({ ... })` (ui components)
10
+ *
11
+ * Two independent readers need this shape: the generated-element lane (which
12
+ * validates and reads the config) and the module-semantics fact
13
+ * `hasGeneratedElementSidecar` (which lets the router's auto-admission
14
+ * derivation recognize a generated component module). Duplicating the locator
15
+ * would let them disagree about WHICH statement is the policy — the drift class
16
+ * P6/P8 forbid — so it lives here and both import it.
17
+ *
18
+ * Binding provenance (which local name a host's descriptor binds) is NOT
19
+ * decided here: the host's admission has already answered that question before
20
+ * either reader runs. This is the statement SHAPE only.
21
+ */
22
+ /** The exported name the sidecar statement must bind. */
23
+ const SIDECAR_NAME = "openElement";
24
+ /**
25
+ * Locate the sidecar's config object literal, or `null` when the module has
26
+ * none. Exactly one `export const openElement = <call>({...})` statement is
27
+ * recognized: extra modifiers, a multi-declaration list, a non-identifier name,
28
+ * a non-call initializer or a non-object argument all mean "not the sidecar".
29
+ */
30
+ function islandPolicyObjectLiteral(sourceFile) {
31
+ for (const statement of sourceFile.statements) {
32
+ if (!ts.isVariableStatement(statement)) continue;
33
+ const modifiers = ts.getModifiers(statement) ?? [];
34
+ if (modifiers.length !== 1 || modifiers[0].kind !== ts.SyntaxKind.ExportKeyword) continue;
35
+ const declarations = statement.declarationList.declarations;
36
+ if (declarations.length !== 1) continue;
37
+ const declaration = declarations[0];
38
+ if (!ts.isIdentifier(declaration.name) || declaration.name.text !== SIDECAR_NAME) continue;
39
+ const initializer = declaration.initializer;
40
+ if (initializer === void 0 || !ts.isCallExpression(initializer)) continue;
41
+ if (initializer.arguments.length !== 1) continue;
42
+ const descriptor = initializer.arguments[0];
43
+ if (ts.isObjectLiteralExpression(descriptor)) return descriptor;
44
+ }
45
+ return null;
46
+ }
47
+ /** Whether the module carries the sidecar statement at all. */
48
+ function hasIslandPolicyStatement(sourceFile) {
49
+ return islandPolicyObjectLiteral(sourceFile) !== null;
50
+ }
51
+ //#endregion
52
+ export { hasIslandPolicyStatement, islandPolicyObjectLiteral };
@@ -0,0 +1,4 @@
1
+ //#region src/internal/compiler/semantic-core/jsx-module-id.d.ts
2
+ /** Whether an authored module id has a JSX-bearing source extension. */
3
+ export declare function isJsxModuleId(id: string): boolean;
4
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region src/internal/compiler/semantic-core/jsx-module-id.ts
2
+ /** Whether an authored module id has a JSX-bearing source extension. */
3
+ function isJsxModuleId(id) {
4
+ return /\.[jt]sx$/.test(id.split("?", 1)[0]);
5
+ }
6
+ //#endregion
7
+ export { isJsxModuleId };
@@ -0,0 +1,220 @@
1
+ import { CompiledField } from "./analyze-module.js";
2
+ import ts from "typescript";
3
+ import { ProgramBlockRecord, ProgramDependencyRecord, ProgramEventAction, ProgramLocationRecord, ProgramPart, ProgramSourceRecord, ProgramTreeNode, PropertyValueType } from "@openelement/protocol/part-program";
4
+ //#region src/internal/compiler/semantic-core/lower-program.d.ts
5
+ export interface GeneratedHandler {
6
+ name: string;
7
+ action: ProgramEventAction;
8
+ node: ts.ArrowFunction;
9
+ }
10
+ /**
11
+ * Local name the generated module binds the canonical `computed` import to
12
+ * when a synthesized conditional-class field (#1556) exists but the authored
13
+ * module never imported computed. The synthesized name cannot collide with an
14
+ * authored binding the compiler would have resolved (a canonical computed
15
+ * import is reused by name instead), and the emitter adds the import
16
+ * alongside it.
17
+ */
18
+ declare const SYNTHESIZED_COMPUTED_LOCAL = "__openelementComputed";
19
+ /**
20
+ * The server function component binding surface (alpha15 server lane): when
21
+ * set, the ONE lowering walk reads component state from the component
22
+ * function's `props` parameter instead of `this`, resolves uppercase JSX tags
23
+ * against the imported server function components, and records which
24
+ * custom-element hosts the host build admitted as compiled components
25
+ * (rendered through `__ssr`). Every other rule — attribute-name safety, sink
26
+ * denial, the trustedHtml boundary, the single-return grammar, the OEC
27
+ * diagnostics — is exactly the @element class path's: one semantic authority.
28
+ */
29
+ export interface ServerComponentBindings {
30
+ /** The component function's single parameter (fixed `props` by admission). */
31
+ readonly parameter: string;
32
+ /** JSX identifier tag → the local binding the generated call targets. */
33
+ readonly components: ReadonlyMap<string, string>;
34
+ /** Custom-element host tags the build admitted as compiled components (`__ssr`). */
35
+ readonly compiledTags: ReadonlySet<string>;
36
+ /**
37
+ * Imported server function components whose declaration is `async`.
38
+ * An async parent awaits the direct call; a synchronous parent is refused.
39
+ */
40
+ readonly asyncComponents: ReadonlySet<string>;
41
+ /** This component is itself an async function or async arrow. */
42
+ readonly asyncFunction: boolean;
43
+ /**
44
+ * Props fields whose annotation is `Promise<...>` (M14-2, "a Promise is not
45
+ * a normal child"). Reading one at a text or attribute sink would stringify
46
+ * the pending thenable, so the read is refused; `{await props.<field>}` is
47
+ * the sanctioned spelling and never passes through that guard. Only the
48
+ * `Promise<...>` annotation is recognised — this is not a type checker.
49
+ */
50
+ readonly promiseFields: ReadonlySet<string>;
51
+ }
52
+ /** Lowering inputs beyond the analyzed module shape. */
53
+ export interface LoweringOptions {
54
+ /**
55
+ * The authored module's canonical `computed` local binding (aliases
56
+ * followed), when present. Synthesized conditional-class factories
57
+ * reference it; when null the emitter binds
58
+ * {@linkcode SYNTHESIZED_COMPUTED_LOCAL} and adds the import.
59
+ */
60
+ readonly computedLocal: string | null;
61
+ /**
62
+ * Server function component mode (alpha15 server lane). Absent: the walk
63
+ * behaves byte-identically to the @element class path.
64
+ */
65
+ readonly server?: ServerComponentBindings;
66
+ }
67
+ export declare class Lowering {
68
+ readonly parts: ProgramPart[];
69
+ readonly blocks: ProgramBlockRecord[];
70
+ readonly dependencies: ProgramDependencyRecord[];
71
+ readonly locations: ProgramLocationRecord[];
72
+ readonly sourceRecords: ProgramSourceRecord[];
73
+ readonly generatedHandlers: GeneratedHandler[];
74
+ readonly fieldNames: Set<string>;
75
+ readonly methodNames: Set<string>;
76
+ readonly computedNames: Set<string>;
77
+ readonly fieldTypes: Map<string, PropertyValueType>;
78
+ /**
79
+ * Compiler-synthesized computed fields (#1556): one per inline conditional
80
+ * class. The caller appends them to the analyzed fields after lowering so
81
+ * the metadata, `__compiledProps` and `__computedFields` emission treat
82
+ * them exactly like authored computeds — the Part Program IR itself stays
83
+ * v1 (one class Part bound to the synthesized signal).
84
+ */
85
+ readonly synthesizedFields: CompiledField[];
86
+ /** True when the authored module binds the canonical `computed` import. */
87
+ readonly sourceBindsComputed: boolean;
88
+ /**
89
+ * The component's statically admitted class tokens (alpha15 S lane): every
90
+ * whitespace-separated token of every compile-time `class` value the
91
+ * lowering admits — static literals, primitive-literal attributes, both
92
+ * branches of an admitted conditional class, and `each` item-template
93
+ * literals. The compiler collects them as OPAQUE STRINGS: it never
94
+ * interprets Tailwind's class grammar, and the build layer hands the list
95
+ * to the official Tailwind compiler as explicit candidates.
96
+ */
97
+ readonly classCandidates: Set<string>;
98
+ /**
99
+ * Server mode side tables (alpha15 server lane): the nested server function
100
+ * component calls (element id → the recorded call shape, props entries as
101
+ * verbatim value texts) and the custom-element hosts the build admitted as
102
+ * compiled components (`__ssr`). The tree stays Part Program vocabulary —
103
+ * the code generator consumes these alongside it.
104
+ */
105
+ readonly componentCalls: Map<string, {
106
+ component: string;
107
+ propsEntries: Array<[string, string]>;
108
+ children: ProgramTreeNode[];
109
+ }>;
110
+ readonly ssrCalls: Set<string>;
111
+ /**
112
+ * Server-lane await text slots (element id → the expression the constructor
113
+ * emitter splices in place of a tag). The text is built only from the
114
+ * admitted await grammar, then wrapped in `__t`, so it crosses the one
115
+ * text escape. Absent on the class path.
116
+ */
117
+ readonly serverExpressionSlots: Map<string, string>;
118
+ private readonly server?;
119
+ private readonly plainFieldNames;
120
+ private readonly computedFieldNames;
121
+ private readonly sf;
122
+ private readonly options;
123
+ private elementSerial;
124
+ private conditionalClassSerial;
125
+ constructor(sf: ts.SourceFile, fields: CompiledField[], methodNames: string[], options?: LoweringOptions);
126
+ fail(node: ts.Node, code: string, message: string): never;
127
+ /**
128
+ * Record one compile-time class value's whitespace-separated tokens as
129
+ * Tailwind candidates (alpha15 S lane). The values are provably finite at
130
+ * compile time — the compiler's grammar admits no other shape — so the
131
+ * tokens are FACTS, not guesses: no runtime class interpolation ever
132
+ * contributes, and the compiler attaches no Tailwind semantics to them.
133
+ */
134
+ private collectClassCandidates;
135
+ private addSource;
136
+ private reserveElement;
137
+ private addElement;
138
+ private addPart;
139
+ /** True when the generated server call must be awaited (async child). */
140
+ isServerAsyncComponent(name: string): boolean;
141
+ private expressionContainsAwait;
142
+ /**
143
+ * Emit one admitted `await` operand. The result is spliced into the
144
+ * generated module, so the grammar is closed: a plain call, literal or
145
+ * `props.<field>` arguments, or a `props.<field>` read. Nothing else.
146
+ */
147
+ private serverAwaitExpression;
148
+ private serverAwaitOperand;
149
+ private serverAwaitArgument;
150
+ private fieldAccess;
151
+ /**
152
+ * The M14-2 "a Promise is not a normal child" guard: a props field annotated
153
+ * `Promise<...>` read at a text or attribute sink. The check is on the READ,
154
+ * never on the declaration — `{await props.<field>}` is the sanctioned
155
+ * spelling and splices through {@link serverAwaitExpression}, which never
156
+ * reaches this guard. Server mode only: the class path has no promise-field
157
+ * table, so its diagnostics do not move.
158
+ */
159
+ private refusePromiseField;
160
+ private methodAccess;
161
+ lowerRoot(expr: ts.Expression): ProgramTreeNode;
162
+ private normalizeAttributeName;
163
+ private lowerElement;
164
+ /**
165
+ * The one children walk both the class path and the server component
166
+ * branch share: JSX text cleaning, expression children (field read /
167
+ * literal / when / each), nested elements, and the fragments-and-spreads
168
+ * rejection. `elementPath` is the owning element's own address.
169
+ */
170
+ private lowerChildren;
171
+ /**
172
+ * Server function components: one uppercase JSX tag — a nested server
173
+ * function component reference. The call composes by DIRECT function call
174
+ * to the imported binding: attribute values cross as raw props (literals
175
+ * or `props.<field>` reads — the callee's own compiled body escapes at its
176
+ * sinks), and JSX children compose the `children` prop through the same
177
+ * children walk every other element takes.
178
+ */
179
+ private lowerComponentElement;
180
+ private lowerEvent;
181
+ private eventAction;
182
+ private parseEventMutation;
183
+ /**
184
+ * Inline conditional class (#1556): `class={this.<cond> ? 'a' : 'b'}` is
185
+ * authoring sugar for a computed field bound to the element's class Part —
186
+ * exactly the shape the author would hand-write as
187
+ * `@property({ reflect: false, attribute: false }) x = computed(() => ...)`
188
+ * plus `class={x}`. The lowering therefore reuses the computed-field
189
+ * machinery end to end: the condition validates under the same body grammar
190
+ * (only `this.<declared plain property>` reads; module-scope values pass
191
+ * through), the synthesized factory rides the existing `__computedFields`
192
+ * emission, and the Part Program stays v1 — one `class` Part whose signal
193
+ * is the synthesized computed signal. No runtime or IR shape changes; the
194
+ * serialized class value and its reactivity are the existing class-Part
195
+ * and computed-signal semantics on every execution mode.
196
+ *
197
+ * Both branches must be string literals (the class-attribute text); an
198
+ * empty string is the idiomatic off-branch. Everything else fails closed
199
+ * with OEC9011 — no runtime fallback (P2). A condition reading no declared
200
+ * property would emit a computed entry with an empty dep list, which the
201
+ * wire validator rejects, so it fails here at the source.
202
+ */
203
+ private lowerConditionalClass;
204
+ private lowerDynamicAttribute;
205
+ /**
206
+ * Which refused position a child expression's await actually sits in — the
207
+ * M14-1 message contract. The generic child gate sees one expression; the
208
+ * position decides which clause the author reads: an awaited condition test,
209
+ * an awaited static branch, an awaited list mapper, or the operand itself
210
+ * (a larger expression an await is embedded in). No classifier here admits
211
+ * anything; every branch still fails closed with OEC9032.
212
+ */
213
+ private refusedAwaitChildPosition;
214
+ private lowerExpressionChild;
215
+ private parseCondition;
216
+ private lowerStaticBranch;
217
+ private lowerEach;
218
+ private lowerItemElement;
219
+ }
220
+ //#endregion