@openelement/compiler 1.0.0-alpha.15 → 1.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/compiler.d.ts +8 -6
- package/src/compiler.js +7 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +5 -30
- package/src/internal/compiler/compiled-artifact-class-candidates.js +18 -32
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +9 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +9 -7
- package/src/internal/compiler/plugin.d.ts +31 -50
- package/src/internal/compiler/plugin.js +41 -108
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +1 -45
- package/src/internal/compiler/semantic-core/analyze-module.js +10 -405
- package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
- package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
- package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
- package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
- package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
- package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
- package/src/internal/compiler/semantic-core/lower-program.d.ts +51 -0
- package/src/internal/compiler/semantic-core/lower-program.js +186 -90
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +28 -5
- package/src/internal/compiler/semantic-core/module-analysis.js +16 -17
- package/src/internal/compiler/semantic-core/parse-module.js +16 -16
- package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
- package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
- package/src/internal/compiler/semantic-core/server-component.d.ts +22 -7
- package/src/internal/compiler/semantic-core/server-component.js +163 -57
- package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
- package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
- package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
- package/src/internal/compiler/style-requests.d.ts +0 -8
- package/src/internal/compiler/style-requests.js +1 -14
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -47
- package/src/internal/compiler/semantic-core/compile.js +0 -100
- package/src/internal/compiler/semantic-core/emit-module.js +0 -317
- package/src/internal/compiler/semantic-core/emit-program.js +0 -141
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -0,0 +1,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 };
|
|
@@ -33,6 +33,21 @@ export interface ServerComponentBindings {
|
|
|
33
33
|
readonly components: ReadonlyMap<string, string>;
|
|
34
34
|
/** Custom-element host tags the build admitted as compiled components (`__ssr`). */
|
|
35
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>;
|
|
36
51
|
}
|
|
37
52
|
/** Lowering inputs beyond the analyzed module shape. */
|
|
38
53
|
export interface LoweringOptions {
|
|
@@ -93,6 +108,13 @@ export declare class Lowering {
|
|
|
93
108
|
children: ProgramTreeNode[];
|
|
94
109
|
}>;
|
|
95
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>;
|
|
96
118
|
private readonly server?;
|
|
97
119
|
private readonly plainFieldNames;
|
|
98
120
|
private readonly computedFieldNames;
|
|
@@ -114,7 +136,27 @@ export declare class Lowering {
|
|
|
114
136
|
private reserveElement;
|
|
115
137
|
private addElement;
|
|
116
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;
|
|
117
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;
|
|
118
160
|
private methodAccess;
|
|
119
161
|
lowerRoot(expr: ts.Expression): ProgramTreeNode;
|
|
120
162
|
private normalizeAttributeName;
|
|
@@ -160,6 +202,15 @@ export declare class Lowering {
|
|
|
160
202
|
*/
|
|
161
203
|
private lowerConditionalClass;
|
|
162
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;
|
|
163
214
|
private lowerExpressionChild;
|
|
164
215
|
private parseCondition;
|
|
165
216
|
private lowerStaticBranch;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { isSafeAttributeName as isSafeAttributeName$1, literalValue, primitiveText, unwrapExpression, validateComputedExpressionBody } from "./analyze-module.js";
|
|
2
1
|
import { diagnosticAt } from "./diagnostics/index.js";
|
|
3
2
|
import { CompiledElementError, sourceRange } from "./compiler-diagnostics.js";
|
|
3
|
+
import { isSafeAttributeName as isSafeAttributeName$1, literalValue, primitiveText, unwrapExpression, validateComputedExpressionBody } from "./analyze-module.js";
|
|
4
|
+
import { classifyIntrinsicAttribute } from "./attribute-classification.js";
|
|
4
5
|
import ts from "typescript";
|
|
5
6
|
import { forbiddenSinkReason } from "@openelement/protocol/forbidden-sinks";
|
|
6
7
|
import { VOID_TAGS, conditionLiteralAllowed } from "@openelement/protocol/part-program";
|
|
@@ -20,42 +21,6 @@ import { VOID_TAGS, conditionLiteralAllowed } from "@openelement/protocol/part-p
|
|
|
20
21
|
* alongside it.
|
|
21
22
|
*/
|
|
22
23
|
const SYNTHESIZED_COMPUTED_LOCAL = "__openelementComputed";
|
|
23
|
-
const BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
24
|
-
"allowfullscreen",
|
|
25
|
-
"async",
|
|
26
|
-
"autofocus",
|
|
27
|
-
"autoplay",
|
|
28
|
-
"checked",
|
|
29
|
-
"controls",
|
|
30
|
-
"default",
|
|
31
|
-
"defer",
|
|
32
|
-
"disabled",
|
|
33
|
-
"formnovalidate",
|
|
34
|
-
"hidden",
|
|
35
|
-
"inert",
|
|
36
|
-
"ismap",
|
|
37
|
-
"itemscope",
|
|
38
|
-
"loop",
|
|
39
|
-
"multiple",
|
|
40
|
-
"muted",
|
|
41
|
-
"nomodule",
|
|
42
|
-
"open",
|
|
43
|
-
"playsinline",
|
|
44
|
-
"readonly",
|
|
45
|
-
"required",
|
|
46
|
-
"reversed",
|
|
47
|
-
"selected"
|
|
48
|
-
]);
|
|
49
|
-
const DOM_PROPERTY_NAMES = /* @__PURE__ */ new Set([
|
|
50
|
-
"checked",
|
|
51
|
-
"files",
|
|
52
|
-
"indeterminate",
|
|
53
|
-
"readOnly",
|
|
54
|
-
"scrollLeft",
|
|
55
|
-
"scrollTop",
|
|
56
|
-
"selected",
|
|
57
|
-
"value"
|
|
58
|
-
]);
|
|
59
24
|
/**
|
|
60
25
|
* The one boundary sentence every when-branch rejection names (alpha15):
|
|
61
26
|
* a branch element admits `this.<property>` attribute sinks, but event
|
|
@@ -64,6 +29,39 @@ const DOM_PROPERTY_NAMES = /* @__PURE__ */ new Set([
|
|
|
64
29
|
* representable inside it.
|
|
65
30
|
*/
|
|
66
31
|
const BRANCH_BOUNDARY = "Block branches admit attribute bindings; events and refs stay outside blocks";
|
|
32
|
+
/**
|
|
33
|
+
* The stable M14 full-await head sentence (D9 ruling, 2026-11-13): which
|
|
34
|
+
* component admits an await and which two positions do. Every refusal appends
|
|
35
|
+
* exactly one {@link SERVER_AWAIT_POSITION} clause below, so the author reads
|
|
36
|
+
* the boundary they actually met — and the nearest lawful spelling for it —
|
|
37
|
+
* instead of one paragraph listing positions they are not in. The diagnostic
|
|
38
|
+
* code stays OEC9032 for every refusal: this is a message contract, not an
|
|
39
|
+
* admission change.
|
|
40
|
+
*/
|
|
41
|
+
const SERVER_AWAIT_HEAD = "this full-await slice admits await only inside an async server function component, and only as a text child or a nested server-component prop: await load(), await load(<literal or props.field>), or await props.field";
|
|
42
|
+
/**
|
|
43
|
+
* One clause per refused position: the position named, then the nearest
|
|
44
|
+
* lawful spelling today. No clause promises a future position — the admitted
|
|
45
|
+
* set is the two positions in {@link SERVER_AWAIT_HEAD}, and stays there.
|
|
46
|
+
*/
|
|
47
|
+
const SERVER_AWAIT_POSITION = {
|
|
48
|
+
attribute: "the refused position is an attribute value (including a custom-element host prop); await the value into a nested server-component prop, or await it in a text child",
|
|
49
|
+
condition: "the refused position is a condition test; await the value into a nested server-component prop and branch in a sync child component, or await it in a text child first",
|
|
50
|
+
listItem: "the refused position is a list item or mapper body; await the whole list into a nested server-component prop and map it in a sync child component",
|
|
51
|
+
staticBranch: "the refused position is a static branch; await the value into a nested server-component prop, or move the branch into a sync child component",
|
|
52
|
+
componentProp: "the refused position is inside a nested server-component prop, and a prop admits one leading await as its whole value; await the value in its own prop first",
|
|
53
|
+
operand: "the refused shape is the awaited operand or a larger expression; the await must be the whole child and its operand must be await load(), await load(<literal or props.field>), or await props.field",
|
|
54
|
+
reservedCallee: "the refused shape is a reserved callee; that callee belongs to the generated constructor module — await the authored function instead"
|
|
55
|
+
};
|
|
56
|
+
/** The one full-await refusal sentence for one refused position. */
|
|
57
|
+
function serverAwaitRefusal(position) {
|
|
58
|
+
return `${SERVER_AWAIT_HEAD} — ${SERVER_AWAIT_POSITION[position]}`;
|
|
59
|
+
}
|
|
60
|
+
/** The M14-2 defect sentence: a `Promise<...>`-annotated prop read at a sink. */
|
|
61
|
+
function promiseSinkRefusal(read, position) {
|
|
62
|
+
const spelling = position === "child" ? `await it first: {await ${read}}` : `await it into a nested server-component prop (<Child value={await ${read}} />), or render it as a text child`;
|
|
63
|
+
return `a Promise is not a normal ${position === "child" ? "child" : "attribute value"} — ${read} is annotated Promise<...>, so this read would stringify the pending value ("[object Promise]"); ` + spelling;
|
|
64
|
+
}
|
|
67
65
|
function isIdentifier(value) {
|
|
68
66
|
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
|
|
69
67
|
}
|
|
@@ -173,6 +171,13 @@ var Lowering = class {
|
|
|
173
171
|
*/
|
|
174
172
|
componentCalls = /* @__PURE__ */ new Map();
|
|
175
173
|
ssrCalls = /* @__PURE__ */ new Set();
|
|
174
|
+
/**
|
|
175
|
+
* Server-lane await text slots (element id → the expression the constructor
|
|
176
|
+
* emitter splices in place of a tag). The text is built only from the
|
|
177
|
+
* admitted await grammar, then wrapped in `__t`, so it crosses the one
|
|
178
|
+
* text escape. Absent on the class path.
|
|
179
|
+
*/
|
|
180
|
+
serverExpressionSlots = /* @__PURE__ */ new Map();
|
|
176
181
|
server;
|
|
177
182
|
plainFieldNames;
|
|
178
183
|
computedFieldNames;
|
|
@@ -285,12 +290,69 @@ var Lowering = class {
|
|
|
285
290
|
});
|
|
286
291
|
return index;
|
|
287
292
|
}
|
|
293
|
+
/** True when the generated server call must be awaited (async child). */
|
|
294
|
+
isServerAsyncComponent(name) {
|
|
295
|
+
return this.server?.asyncComponents.has(name) === true;
|
|
296
|
+
}
|
|
297
|
+
expressionContainsAwait(node) {
|
|
298
|
+
if (ts.isAwaitExpression(node)) return true;
|
|
299
|
+
return ts.forEachChild(node, (child) => this.expressionContainsAwait(child)) === true;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Emit one admitted `await` operand. The result is spliced into the
|
|
303
|
+
* generated module, so the grammar is closed: a plain call, literal or
|
|
304
|
+
* `props.<field>` arguments, or a `props.<field>` read. Nothing else.
|
|
305
|
+
*/
|
|
306
|
+
serverAwaitExpression(node) {
|
|
307
|
+
if (this.server?.asyncFunction !== true) this.fail(node, "OEC9032", "await is admitted only inside an async server function component");
|
|
308
|
+
return `await ${this.serverAwaitOperand(unwrapExpression(node.expression))}`;
|
|
309
|
+
}
|
|
310
|
+
serverAwaitOperand(expr) {
|
|
311
|
+
const parameter = this.server?.parameter ?? "props";
|
|
312
|
+
if (ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === parameter && isIdentifier(expr.name.text) && this.fieldNames.has(expr.name.text)) return `${parameter}.${expr.name.text}`;
|
|
313
|
+
if (ts.isCallExpression(expr) && expr.questionDotToken === void 0 && expr.typeArguments === void 0 && ts.isIdentifier(expr.expression) && isIdentifier(expr.expression.text)) {
|
|
314
|
+
const callee = expr.expression.text;
|
|
315
|
+
if (callee === "__h" || callee === "__t" || callee === "__ssr" || callee === "eval" || this.server?.components.has(callee) === true) this.fail(expr, "OEC9032", serverAwaitRefusal("reservedCallee"));
|
|
316
|
+
return `${callee}(${expr.arguments.map((argument) => {
|
|
317
|
+
if (ts.isSpreadElement(argument)) this.fail(argument, "OEC9032", serverAwaitRefusal("operand"));
|
|
318
|
+
return this.serverAwaitArgument(argument);
|
|
319
|
+
}).join(", ")})`;
|
|
320
|
+
}
|
|
321
|
+
this.fail(expr, "OEC9032", serverAwaitRefusal("operand"));
|
|
322
|
+
}
|
|
323
|
+
serverAwaitArgument(expr) {
|
|
324
|
+
const value = unwrapExpression(expr);
|
|
325
|
+
if (ts.isStringLiteral(value) || ts.isNoSubstitutionTemplateLiteral(value)) return JSON.stringify(value.text);
|
|
326
|
+
if (value.kind === ts.SyntaxKind.TrueKeyword) return "true";
|
|
327
|
+
if (value.kind === ts.SyntaxKind.FalseKeyword) return "false";
|
|
328
|
+
if (value.kind === ts.SyntaxKind.NullKeyword) return "null";
|
|
329
|
+
if (ts.isNumericLiteral(value) && Number.isFinite(Number(value.text))) return value.text;
|
|
330
|
+
const field = this.fieldAccess(value);
|
|
331
|
+
if (field !== null && this.server !== void 0) return `${this.server.parameter}.${field}`;
|
|
332
|
+
this.fail(expr, "OEC9032", serverAwaitRefusal("operand"));
|
|
333
|
+
}
|
|
288
334
|
fieldAccess(expr) {
|
|
289
335
|
const value = unwrapExpression(expr);
|
|
290
336
|
if (ts.isPropertyAccessExpression(value) && value.expression.kind === ts.SyntaxKind.ThisKeyword && this.fieldNames.has(value.name.text)) return value.name.text;
|
|
291
337
|
if (this.server !== void 0 && ts.isPropertyAccessExpression(value) && ts.isIdentifier(value.expression) && value.expression.text === this.server.parameter && this.fieldNames.has(value.name.text)) return value.name.text;
|
|
292
338
|
return null;
|
|
293
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* The M14-2 "a Promise is not a normal child" guard: a props field annotated
|
|
342
|
+
* `Promise<...>` read at a text or attribute sink. The check is on the READ,
|
|
343
|
+
* never on the declaration — `{await props.<field>}` is the sanctioned
|
|
344
|
+
* spelling and splices through {@link serverAwaitExpression}, which never
|
|
345
|
+
* reaches this guard. Server mode only: the class path has no promise-field
|
|
346
|
+
* table, so its diagnostics do not move.
|
|
347
|
+
*/
|
|
348
|
+
refusePromiseField(expr, node, position) {
|
|
349
|
+
const server = this.server;
|
|
350
|
+
if (server === void 0 || server.promiseFields.size === 0) return;
|
|
351
|
+
const value = unwrapExpression(expr);
|
|
352
|
+
if (!ts.isPropertyAccessExpression(value) || !ts.isIdentifier(value.expression) || value.expression.text !== server.parameter || !server.promiseFields.has(value.name.text)) return;
|
|
353
|
+
const read = `${server.parameter}.${value.name.text}`;
|
|
354
|
+
this.fail(node, "OEC9032", promiseSinkRefusal(read, position));
|
|
355
|
+
}
|
|
294
356
|
methodAccess(expr) {
|
|
295
357
|
const value = unwrapExpression(expr);
|
|
296
358
|
if (ts.isPropertyAccessExpression(value) && value.expression.kind === ts.SyntaxKind.ThisKeyword && this.methodNames.has(value.name.text)) return value.name.text;
|
|
@@ -366,6 +428,7 @@ var Lowering = class {
|
|
|
366
428
|
}, path, prop, elementId);
|
|
367
429
|
continue;
|
|
368
430
|
}
|
|
431
|
+
if (this.server !== void 0 && this.expressionContainsAwait(expr)) this.fail(prop, "OEC9032", serverAwaitRefusal("attribute"));
|
|
369
432
|
if (name === "class" && ts.isConditionalExpression(expr)) {
|
|
370
433
|
if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — an inline conditional class cannot bind inside a branch`);
|
|
371
434
|
if (!isCustomHost) {
|
|
@@ -375,6 +438,7 @@ var Lowering = class {
|
|
|
375
438
|
}
|
|
376
439
|
const field = this.fieldAccess(expr);
|
|
377
440
|
if (field) {
|
|
441
|
+
this.refusePromiseField(expr, prop, "attribute");
|
|
378
442
|
if (name === "innerHTML") {
|
|
379
443
|
this.lowerDynamicAttribute(name, field, tag, path, prop, elementId, trustedHtmlCapability);
|
|
380
444
|
continue;
|
|
@@ -458,6 +522,7 @@ var Lowering = class {
|
|
|
458
522
|
const name = tagNameNode.getText(this.sf);
|
|
459
523
|
const local = this.server.components.get(name);
|
|
460
524
|
if (local === void 0) this.fail(tagNameNode, "OEC9032", `<${name}> is not a server function component — import it from the module that exports it (a server function component composes only by direct call to another server function component; @element components compose by tag name)`);
|
|
525
|
+
if (this.server.asyncComponents.has(local) && this.server.asyncFunction !== true) this.fail(tagNameNode, "OEC9032", `<${name}> is an async server function component — a synchronous parent cannot call it, because HTML is built only after the child settles. Mark the parent async.`);
|
|
461
526
|
const elementId = this.reserveElement(local, path, sourceNode);
|
|
462
527
|
const propsEntries = [];
|
|
463
528
|
for (const prop of attributes.properties) {
|
|
@@ -481,6 +546,11 @@ var Lowering = class {
|
|
|
481
546
|
propsEntries.push([propName, `${this.server.parameter}.${field}`]);
|
|
482
547
|
continue;
|
|
483
548
|
}
|
|
549
|
+
if (ts.isAwaitExpression(expr)) {
|
|
550
|
+
propsEntries.push([propName, this.serverAwaitExpression(expr)]);
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
if (this.expressionContainsAwait(expr)) this.fail(prop, "OEC9032", serverAwaitRefusal("componentProp"));
|
|
484
554
|
const literal = literalValue(expr, this.sf);
|
|
485
555
|
if (literal === void 0) this.fail(prop, "OEC9032", `component prop "${propName}" must be a literal or a props.<field> read — arbitrary expressions are outside the server function grammar`);
|
|
486
556
|
propsEntries.push([propName, JSON.stringify(literal)]);
|
|
@@ -636,66 +706,91 @@ var Lowering = class {
|
|
|
636
706
|
}, path, sourceNode, elementId);
|
|
637
707
|
}
|
|
638
708
|
lowerDynamicAttribute(name, signal, tag, path, sourceNode, elementId, trustedHtmlCapability) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
path
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
709
|
+
switch (classifyIntrinsicAttribute(name, tag)) {
|
|
710
|
+
case "class":
|
|
711
|
+
this.addPart({
|
|
712
|
+
k: "class",
|
|
713
|
+
signal,
|
|
714
|
+
path
|
|
715
|
+
}, path, sourceNode, elementId);
|
|
716
|
+
return;
|
|
717
|
+
case "style":
|
|
718
|
+
this.addPart({
|
|
719
|
+
k: "style",
|
|
720
|
+
signal,
|
|
721
|
+
path
|
|
722
|
+
}, path, sourceNode, elementId);
|
|
723
|
+
return;
|
|
724
|
+
case "html":
|
|
725
|
+
if (this.fieldTypes.get(signal) !== "object") this.fail(sourceNode, "OEC9026", "innerHTML sinks require an Object-typed TrustedHtml property");
|
|
726
|
+
if (!trustedHtmlCapability) this.fail(sourceNode, "OEC9026", "innerHTML sinks require the explicit trustedHtml capability marker");
|
|
727
|
+
if (VOID_TAGS.has(tag)) this.fail(sourceNode, "OEC9026", `void element <${tag}> cannot carry an innerHTML sink — move the sink to a container element (e.g. <div>)`);
|
|
728
|
+
this.addPart({
|
|
729
|
+
k: "html",
|
|
730
|
+
signal,
|
|
731
|
+
path
|
|
732
|
+
}, path, sourceNode, elementId);
|
|
733
|
+
return;
|
|
734
|
+
case "boolean":
|
|
735
|
+
if (forbiddenSinkReason("bool", name) !== null) this.fail(sourceNode, "OEC9011", `attribute name "${name}" is unsafe — names must be valid HTML attribute names, not event handlers (on*) or forbidden sinks; use an admitted attribute name`);
|
|
736
|
+
this.addPart({
|
|
737
|
+
k: "bool",
|
|
738
|
+
signal,
|
|
739
|
+
name,
|
|
740
|
+
path
|
|
741
|
+
}, path, sourceNode, elementId);
|
|
742
|
+
return;
|
|
743
|
+
case "property":
|
|
744
|
+
if (forbiddenSinkReason("prop", name) !== null) this.fail(sourceNode, "OEC9011", `property sink name "${name}" is unsafe — prototype-pollution primitives are on the shared deny list on every boundary; rename the sink`);
|
|
745
|
+
this.addPart({
|
|
746
|
+
k: "prop",
|
|
747
|
+
signal,
|
|
748
|
+
name,
|
|
749
|
+
path
|
|
750
|
+
}, path, sourceNode, elementId);
|
|
751
|
+
return;
|
|
752
|
+
case "event":
|
|
753
|
+
case "key":
|
|
754
|
+
case "ref":
|
|
755
|
+
case "attribute":
|
|
756
|
+
if (forbiddenSinkReason("attr", name) !== null) this.fail(sourceNode, "OEC9011", `attribute name "${name}" is unsafe — names must be valid HTML attribute names, not event handlers (on*) or forbidden sinks; use an admitted attribute name`);
|
|
757
|
+
this.addPart({
|
|
758
|
+
k: "attr",
|
|
759
|
+
signal,
|
|
760
|
+
name,
|
|
761
|
+
path
|
|
762
|
+
}, path, sourceNode, elementId);
|
|
763
|
+
return;
|
|
676
764
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Which refused position a child expression's await actually sits in — the
|
|
768
|
+
* M14-1 message contract. The generic child gate sees one expression; the
|
|
769
|
+
* position decides which clause the author reads: an awaited condition test,
|
|
770
|
+
* an awaited static branch, an awaited list mapper, or the operand itself
|
|
771
|
+
* (a larger expression an await is embedded in). No classifier here admits
|
|
772
|
+
* anything; every branch still fails closed with OEC9032.
|
|
773
|
+
*/
|
|
774
|
+
refusedAwaitChildPosition(expr) {
|
|
775
|
+
if (ts.isConditionalExpression(expr)) return this.expressionContainsAwait(expr.condition) ? "condition" : "staticBranch";
|
|
776
|
+
if (ts.isCallExpression(expr)) {
|
|
777
|
+
const callee = expr.expression;
|
|
778
|
+
return ts.isPropertyAccessExpression(callee) && callee.name.text === "map" ? "listItem" : "operand";
|
|
686
779
|
}
|
|
687
|
-
|
|
688
|
-
this.addPart({
|
|
689
|
-
k: "attr",
|
|
690
|
-
signal,
|
|
691
|
-
name,
|
|
692
|
-
path
|
|
693
|
-
}, path, sourceNode, elementId);
|
|
780
|
+
return "operand";
|
|
694
781
|
}
|
|
695
782
|
lowerExpressionChild(child, staticOnly, path) {
|
|
696
783
|
if (!child.expression) return null;
|
|
697
784
|
const expr = unwrapExpression(child.expression);
|
|
698
785
|
if (this.server !== void 0 && ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === this.server.parameter && expr.name.text === "children" && !this.fieldNames.has("children")) this.fail(child, "OEC9032", `${this.server.parameter}.children is not declared — add \`children?: string\` to the props type: the JSX children a caller nests compose it as one final-HTML string`);
|
|
786
|
+
if (this.server !== void 0 && ts.isAwaitExpression(expr)) {
|
|
787
|
+
if (staticOnly) this.fail(child, "OEC9032", serverAwaitRefusal("staticBranch"));
|
|
788
|
+
const id = this.reserveElement("slot", path, child);
|
|
789
|
+
this.serverExpressionSlots.set(id, `__t(${this.serverAwaitExpression(expr)})`);
|
|
790
|
+
return this.addElement(id, "slot", [], []);
|
|
791
|
+
}
|
|
792
|
+
if (this.server !== void 0 && this.expressionContainsAwait(expr)) this.fail(child, "OEC9032", serverAwaitRefusal(this.refusedAwaitChildPosition(expr)));
|
|
793
|
+
this.refusePromiseField(expr, child, "child");
|
|
699
794
|
const field = this.fieldAccess(expr);
|
|
700
795
|
if (field) {
|
|
701
796
|
if (staticOnly) this.fail(child, "OEC9012", `${BRANCH_BOUNDARY} — a branch cannot interpolate text; bind the value as an attribute (e.g. data-label={this.<property>})`);
|
|
@@ -902,6 +997,7 @@ var Lowering = class {
|
|
|
902
997
|
}
|
|
903
998
|
if (ts.isJsxExpression(child) && child.expression) {
|
|
904
999
|
const expr = unwrapExpression(child.expression);
|
|
1000
|
+
if (this.server !== void 0 && this.expressionContainsAwait(expr)) this.fail(child, "OEC9032", serverAwaitRefusal("listItem"));
|
|
905
1001
|
if (ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === param && isIdentifier(expr.name.text)) {
|
|
906
1002
|
itemFields.push(expr.name.text);
|
|
907
1003
|
children.push({
|
|
@@ -11,7 +11,7 @@ import { ModuleVocabularyDescriptor, ModuleVocabularyDescriptor as ModuleVocabul
|
|
|
11
11
|
export interface ModuleSemanticFacts {
|
|
12
12
|
relativeImports: string[];
|
|
13
13
|
/**
|
|
14
|
-
* Every static import/export specifier
|
|
14
|
+
* Every runtime-capable static import/export specifier, relative or not —
|
|
15
15
|
* present only when the caller asks for it (`collectSpecifiers`), because a
|
|
16
16
|
* host that walks a module graph through its own resolver (S-C1.4's
|
|
17
17
|
* server-rendered style-edge pass) needs the aliased and package specifiers
|
|
@@ -25,8 +25,9 @@ export interface ModuleSemanticFacts {
|
|
|
25
25
|
* default import, conflicting duplicate bindings, or a relative-module
|
|
26
26
|
* re-export). Never set for clearly foreign bindings (third-party packages,
|
|
27
27
|
* local declarations, bare/global spellings) — those modules are simply not
|
|
28
|
-
* OpenElement modules.
|
|
29
|
-
*
|
|
28
|
+
* OpenElement modules. No lane compiles such a module any more, so the fact
|
|
29
|
+
* survives as REFUSAL EVIDENCE: both admission bridges answer null for it
|
|
30
|
+
* instead of compiling a class grammar that no longer has an entry point.
|
|
30
31
|
*/
|
|
31
32
|
unsupportedElementDecorator?: string;
|
|
32
33
|
exportedTagName?: string;
|
|
@@ -67,6 +68,23 @@ export interface ModuleSemanticFacts {
|
|
|
67
68
|
definedCustomElementTags: string[];
|
|
68
69
|
referencedCustomElementTags: string[];
|
|
69
70
|
compilerInteractionEvents: string[];
|
|
71
|
+
/**
|
|
72
|
+
* The module declares a GENERATED element: it carries the island policy
|
|
73
|
+
* sidecar statement (`export const openElement = defineIslandConfig({...})` /
|
|
74
|
+
* `defineComponentConfig({...})`) that the generated-element lane reads.
|
|
75
|
+
*
|
|
76
|
+
* This is the generated lane's counterpart to `definedCustomElementTags`:
|
|
77
|
+
* a generated component never applies the `@element` decorator (its element
|
|
78
|
+
* class is emitted by the compiler), so a consumer that asks "is this module
|
|
79
|
+
* a component module?" must consult BOTH facts. The TAG is deliberately NOT
|
|
80
|
+
* derived here — it stays the manifest's identity (the sidecar does not
|
|
81
|
+
* spell it), and this boolean only answers the module-shape question.
|
|
82
|
+
*
|
|
83
|
+
* The statement shape is read through the compiler's own sidecar locator
|
|
84
|
+
* (`hasIslandPolicyStatement`), so this fact and the generated-element lane
|
|
85
|
+
* cannot disagree about which statement is the policy.
|
|
86
|
+
*/
|
|
87
|
+
hasGeneratedElementSidecar: boolean;
|
|
70
88
|
}
|
|
71
89
|
/**
|
|
72
90
|
* The canonical intrinsic-binding model (#1209, A10.1): compiler intrinsics
|
|
@@ -99,8 +117,6 @@ export interface ModuleSemanticsOptions {
|
|
|
99
117
|
/** Collect {@link ModuleSemanticFacts.moduleSpecifiers} (opt-in). */
|
|
100
118
|
readonly collectSpecifiers?: boolean;
|
|
101
119
|
}
|
|
102
|
-
/** True when `imported` from `module` is a compile-time-only intrinsic binding. */
|
|
103
|
-
declare function isCompileTimeOnlyImport(module: string, imported: string): boolean;
|
|
104
120
|
export interface IntrinsicResolution {
|
|
105
121
|
/** True only for a runtime named import of the intrinsic from its canonical module. */
|
|
106
122
|
readonly canonical: boolean;
|
|
@@ -159,6 +175,13 @@ declare function resolveCanonicalBaseClass(bindings: ModuleIntrinsicBindings, he
|
|
|
159
175
|
* another package.
|
|
160
176
|
*/
|
|
161
177
|
declare function createModuleIntrinsicBindings(sourceFile: ts.SourceFile, options?: SemanticCoreOptions): ModuleIntrinsicBindings;
|
|
178
|
+
/**
|
|
179
|
+
* The compiler's custom-element tag predicate. Exported for the generated-element
|
|
180
|
+
* lane's sidecar `tag` read (`semantic-ir/generated-element/site.ts`): the lane
|
|
181
|
+
* must not carry a second hyphenated-name regex, so the one this module already
|
|
182
|
+
* applies to JSX references is the one the sidecar fact is screened by.
|
|
183
|
+
*/
|
|
184
|
+
declare function isCustomElementTag(value: string): boolean;
|
|
162
185
|
/**
|
|
163
186
|
* The exported name of a function declaration / single-declarator variable
|
|
164
187
|
* statement that {@link isExportedServerComponentDeclaration} admitted.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { hasIslandPolicyStatement } from "./island-policy-statement.js";
|
|
2
|
+
import { isJsxModuleId } from "./jsx-module-id.js";
|
|
1
3
|
import ts from "typescript";
|
|
2
4
|
//#region src/internal/compiler/semantic-core/module-analysis.ts
|
|
3
5
|
/** Bundler-neutral module semantics consumed by compiler and Vite graph adapters. */
|
|
@@ -12,23 +14,13 @@ const INTRINSIC_MODULES = {
|
|
|
12
14
|
/**
|
|
13
15
|
* The core's own vocabulary: empty. The element package exposes no
|
|
14
16
|
* defineElement() factory — compiled registration is the @element decorator
|
|
15
|
-
* on an OpenElement subclass, which the scan recognizes directly.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* on an OpenElement subclass, which the scan recognizes directly. Router's
|
|
18
|
+
* page-definition and registration vocabulary rides host-injected
|
|
19
|
+
* descriptors, and any retired or unrecognized factory name fails closed
|
|
18
20
|
* like any other unrecognized import.
|
|
19
21
|
*/
|
|
20
22
|
const CORE_VOCABULARY = [];
|
|
21
23
|
/**
|
|
22
|
-
* Intrinsics that exist only at compile time: the compiler erases the
|
|
23
|
-
* decorator applications they power, and the runtime packages export no such
|
|
24
|
-
* bindings, so the generated module must not keep importing them.
|
|
25
|
-
*/
|
|
26
|
-
const COMPILE_TIME_ONLY_IMPORTS = { "@openelement/element": ["element", "property"] };
|
|
27
|
-
/** True when `imported` from `module` is a compile-time-only intrinsic binding. */
|
|
28
|
-
function isCompileTimeOnlyImport(module, imported) {
|
|
29
|
-
return COMPILE_TIME_ONLY_IMPORTS[module]?.includes(imported) ?? false;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
24
|
* The compiler's admitted base classes, in resolution order (alpha.13 I2,
|
|
33
25
|
* KR-11): the README documents subclassing `ErrorBoundary`, and the compiler
|
|
34
26
|
* admits that authoring form exactly as it admits `OpenElement` — both must
|
|
@@ -176,6 +168,12 @@ function createModuleIntrinsicBindings(sourceFile, options = {}) {
|
|
|
176
168
|
}
|
|
177
169
|
};
|
|
178
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* The compiler's custom-element tag predicate. Exported for the generated-element
|
|
173
|
+
* lane's sidecar `tag` read (`semantic-ir/generated-element/site.ts`): the lane
|
|
174
|
+
* must not carry a second hyphenated-name regex, so the one this module already
|
|
175
|
+
* applies to JSX references is the one the sidecar fact is screened by.
|
|
176
|
+
*/
|
|
179
177
|
function isCustomElementTag(value) {
|
|
180
178
|
return /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(value);
|
|
181
179
|
}
|
|
@@ -244,14 +242,14 @@ function isCustomElementsRegistry(object, imports) {
|
|
|
244
242
|
* descriptors.
|
|
245
243
|
*/
|
|
246
244
|
function analyzeModuleSemantics(source, fileName, options = {}) {
|
|
247
|
-
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true,
|
|
245
|
+
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, isJsxModuleId(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
248
246
|
const imports = createModuleIntrinsicBindings(sourceFile);
|
|
249
247
|
const vocabulary = [...CORE_VOCABULARY, ...options.vocabulary ?? []];
|
|
250
248
|
const pageDefinitionBindings = vocabulary.filter((descriptor) => descriptor.kind === "page-definition");
|
|
251
249
|
const registrationBindings = vocabulary.filter((descriptor) => descriptor.kind === "element-registration");
|
|
252
250
|
const relativeImports = /* @__PURE__ */ new Set();
|
|
253
251
|
const moduleSpecifiers = /* @__PURE__ */ new Set();
|
|
254
|
-
for (const statement of sourceFile.statements) if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
252
|
+
for (const statement of sourceFile.statements) if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier) && !(ts.isImportDeclaration(statement) ? statement.importClause?.isTypeOnly : statement.isTypeOnly)) {
|
|
255
253
|
moduleSpecifiers.add(statement.moduleSpecifier.text);
|
|
256
254
|
if (statement.moduleSpecifier.text.startsWith(".")) relativeImports.add(statement.moduleSpecifier.text);
|
|
257
255
|
}
|
|
@@ -356,8 +354,9 @@ function analyzeModuleSemantics(source, fileName, options = {}) {
|
|
|
356
354
|
...defaultCompiledTag === void 0 ? {} : { defaultCompiledTag },
|
|
357
355
|
definedCustomElementTags: [...defined].sort(),
|
|
358
356
|
referencedCustomElementTags: [...referenced].sort(),
|
|
359
|
-
compilerInteractionEvents: [...interactionEvents].sort()
|
|
357
|
+
compilerInteractionEvents: [...interactionEvents].sort(),
|
|
358
|
+
hasGeneratedElementSidecar: hasIslandPolicyStatement(sourceFile)
|
|
360
359
|
};
|
|
361
360
|
}
|
|
362
361
|
//#endregion
|
|
363
|
-
export { CANONICAL_BASE_CLASS_INTRINSICS, analyzeModuleSemantics, createModuleIntrinsicBindings,
|
|
362
|
+
export { CANONICAL_BASE_CLASS_INTRINSICS, analyzeModuleSemantics, createModuleIntrinsicBindings, isCustomElementTag, isExportedServerComponentDeclaration, resolveCanonicalBaseClass, serverComponentName };
|