@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.
- package/package.json +4 -2
- package/src/compiler.d.ts +12 -6
- package/src/compiler.js +11 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +11 -0
- package/src/internal/compiler/compiled-artifact-class-candidates.js +46 -0
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +26 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +57 -9
- package/src/internal/compiler/plugin.d.ts +68 -49
- package/src/internal/compiler/plugin.js +93 -82
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +73 -0
- package/src/internal/compiler/semantic-core/analyze-module.js +29 -379
- 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/diagnostics/index.d.ts +21 -1
- package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
- 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 +220 -0
- package/src/internal/compiler/semantic-core/lower-program.js +350 -142
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +82 -4
- package/src/internal/compiler/semantic-core/module-analysis.js +88 -19
- 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 +129 -0
- package/src/internal/compiler/semantic-core/server-component.js +587 -0
- package/src/internal/compiler/semantic-core/type-check.js +1 -1
- 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 +35 -7
- package/src/internal/compiler/style-requests.js +57 -11
- package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
- package/src/internal/compiler/tailwind-candidates.js +54 -0
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -39
- package/src/internal/compiler/semantic-core/compile.js +0 -98
- package/src/internal/compiler/semantic-core/emit-module.js +0 -313
- package/src/internal/compiler/semantic-core/emit-program.js +0 -121
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -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";
|
|
@@ -8,7 +9,7 @@ import { VOID_TAGS, conditionLiteralAllowed } from "@openelement/protocol/part-p
|
|
|
8
9
|
/**
|
|
9
10
|
* JSX → Part Program lowering for the compiled grammar (#1473 split): the
|
|
10
11
|
* {@link Lowering} walk turns
|
|
11
|
-
* the analyzed render() tree into fixed Parts,
|
|
12
|
+
* the analyzed render() tree into fixed Parts, Blocks, locations and source
|
|
12
13
|
* records with stable compiler-owned paths.
|
|
13
14
|
*/
|
|
14
15
|
/**
|
|
@@ -20,47 +21,52 @@ import { VOID_TAGS, conditionLiteralAllowed } from "@openelement/protocol/part-p
|
|
|
20
21
|
* alongside it.
|
|
21
22
|
*/
|
|
22
23
|
const SYNTHESIZED_COMPUTED_LOCAL = "__openelementComputed";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The one boundary sentence every when-branch rejection names (alpha15):
|
|
26
|
+
* a branch element admits `this.<property>` attribute sinks, but event
|
|
27
|
+
* handlers, refs and inline conditional classes stay outside blocks — a
|
|
28
|
+
* branch has no anchor of its own, so only attribute-bound state is
|
|
29
|
+
* representable inside it.
|
|
30
|
+
*/
|
|
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
|
+
}
|
|
59
65
|
function isIdentifier(value) {
|
|
60
66
|
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
|
-
* Token→operator map for when-
|
|
69
|
+
* Token→operator map for when-Block conditions (#1372). Only strict
|
|
64
70
|
* equality tokens are admitted; `==`/`!=` fail closed with OEC9013 so the
|
|
65
71
|
* coercion difference cannot ride in unnoticed.
|
|
66
72
|
*/
|
|
@@ -127,7 +133,7 @@ function hasMeaningfulJsxChild(sf, child) {
|
|
|
127
133
|
}
|
|
128
134
|
var Lowering = class {
|
|
129
135
|
parts = [];
|
|
130
|
-
|
|
136
|
+
blocks = [];
|
|
131
137
|
dependencies = [];
|
|
132
138
|
locations = [];
|
|
133
139
|
sourceRecords = [];
|
|
@@ -146,6 +152,33 @@ var Lowering = class {
|
|
|
146
152
|
synthesizedFields = [];
|
|
147
153
|
/** True when the authored module binds the canonical `computed` import. */
|
|
148
154
|
sourceBindsComputed;
|
|
155
|
+
/**
|
|
156
|
+
* The component's statically admitted class tokens (alpha15 S lane): every
|
|
157
|
+
* whitespace-separated token of every compile-time `class` value the
|
|
158
|
+
* lowering admits — static literals, primitive-literal attributes, both
|
|
159
|
+
* branches of an admitted conditional class, and `each` item-template
|
|
160
|
+
* literals. The compiler collects them as OPAQUE STRINGS: it never
|
|
161
|
+
* interprets Tailwind's class grammar, and the build layer hands the list
|
|
162
|
+
* to the official Tailwind compiler as explicit candidates.
|
|
163
|
+
*/
|
|
164
|
+
classCandidates = /* @__PURE__ */ new Set();
|
|
165
|
+
/**
|
|
166
|
+
* Server mode side tables (alpha15 server lane): the nested server function
|
|
167
|
+
* component calls (element id → the recorded call shape, props entries as
|
|
168
|
+
* verbatim value texts) and the custom-element hosts the build admitted as
|
|
169
|
+
* compiled components (`__ssr`). The tree stays Part Program vocabulary —
|
|
170
|
+
* the code generator consumes these alongside it.
|
|
171
|
+
*/
|
|
172
|
+
componentCalls = /* @__PURE__ */ new Map();
|
|
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();
|
|
181
|
+
server;
|
|
149
182
|
plainFieldNames;
|
|
150
183
|
computedFieldNames;
|
|
151
184
|
sf;
|
|
@@ -162,10 +195,21 @@ var Lowering = class {
|
|
|
162
195
|
this.computedFieldNames = new Set(this.computedNames);
|
|
163
196
|
this.sourceBindsComputed = options.computedLocal !== null;
|
|
164
197
|
this.options = options;
|
|
198
|
+
this.server = options.server;
|
|
165
199
|
}
|
|
166
200
|
fail(node, code, message) {
|
|
167
201
|
throw new CompiledElementError([diagnosticAt(this.sf, node, code, message)]);
|
|
168
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Record one compile-time class value's whitespace-separated tokens as
|
|
205
|
+
* Tailwind candidates (alpha15 S lane). The values are provably finite at
|
|
206
|
+
* compile time — the compiler's grammar admits no other shape — so the
|
|
207
|
+
* tokens are FACTS, not guesses: no runtime class interpolation ever
|
|
208
|
+
* contributes, and the compiler attaches no Tailwind semantics to them.
|
|
209
|
+
*/
|
|
210
|
+
collectClassCandidates(value) {
|
|
211
|
+
for (const token of value.split(/\s+/)) if (token !== "") this.classCandidates.add(token);
|
|
212
|
+
}
|
|
169
213
|
addSource(id, kind, node) {
|
|
170
214
|
if (this.sourceRecords.some((record) => record.id === id)) return;
|
|
171
215
|
this.sourceRecords.push({
|
|
@@ -226,7 +270,7 @@ var Lowering = class {
|
|
|
226
270
|
const sourceKind = part.k === "when" || part.k === "each" ? "region" : "part";
|
|
227
271
|
this.addSource(`p${index}`, sourceKind, node);
|
|
228
272
|
if (part.k === "when" || part.k === "each") {
|
|
229
|
-
this.
|
|
273
|
+
this.blocks.push({
|
|
230
274
|
id: `r${index}`,
|
|
231
275
|
index,
|
|
232
276
|
kind: part.k,
|
|
@@ -246,11 +290,69 @@ var Lowering = class {
|
|
|
246
290
|
});
|
|
247
291
|
return index;
|
|
248
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
|
+
}
|
|
249
334
|
fieldAccess(expr) {
|
|
250
335
|
const value = unwrapExpression(expr);
|
|
251
336
|
if (ts.isPropertyAccessExpression(value) && value.expression.kind === ts.SyntaxKind.ThisKeyword && this.fieldNames.has(value.name.text)) return value.name.text;
|
|
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;
|
|
252
338
|
return null;
|
|
253
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
|
+
}
|
|
254
356
|
methodAccess(expr) {
|
|
255
357
|
const value = unwrapExpression(expr);
|
|
256
358
|
if (ts.isPropertyAccessExpression(value) && value.expression.kind === ts.SyntaxKind.ThisKeyword && this.methodNames.has(value.name.text)) return value.name.text;
|
|
@@ -267,12 +369,14 @@ var Lowering = class {
|
|
|
267
369
|
}
|
|
268
370
|
lowerElement(tagNameNode, attributes, children, path, sourceNode, staticOnly = false) {
|
|
269
371
|
const tag = tagNameNode.getText(this.sf);
|
|
372
|
+
if (this.server !== void 0 && ts.isIdentifier(tagNameNode) && /^[A-Z]/.test(tag)) return this.lowerComponentElement(tagNameNode, attributes, children, path, sourceNode);
|
|
270
373
|
const isCustomHost = /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(tag);
|
|
271
374
|
if (!/^[a-z][a-z0-9]*$/.test(tag) && !isCustomHost) this.fail(tagNameNode, "OEC9010", `component tag <${tag}> is outside the compiler grammar (intrinsic lowercase elements and custom-element hosts only) — custom elements compose by tag name — use the tag string, not the class value`);
|
|
272
375
|
const tagReason = forbiddenSinkReason("tag", tag);
|
|
273
376
|
if (tagReason !== null) this.fail(tagNameNode, "OEC9010", tagReason);
|
|
274
377
|
const attrs = [];
|
|
275
378
|
const elementId = this.reserveElement(tag, path, sourceNode);
|
|
379
|
+
if (this.server !== void 0 && isCustomHost && this.server.compiledTags.has(tag)) this.ssrCalls.add(elementId);
|
|
276
380
|
const attributeNames = /* @__PURE__ */ new Set();
|
|
277
381
|
let trustedHtmlCapability = false;
|
|
278
382
|
for (const prop of attributes.properties) {
|
|
@@ -283,16 +387,17 @@ var Lowering = class {
|
|
|
283
387
|
if (!trustedHtmlCapability) this.fail(prop, "OEC9026", "trustedHtml capability marker must be the literal true");
|
|
284
388
|
}
|
|
285
389
|
for (const prop of attributes.properties) {
|
|
286
|
-
if (ts.isJsxSpreadAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported by the compiler grammar");
|
|
390
|
+
if (ts.isJsxSpreadAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported by the compiler grammar — write each attribute explicitly (a literal or a this.<property> sink)");
|
|
287
391
|
const name = this.normalizeAttributeName(prop.name.getText(this.sf));
|
|
288
392
|
const init = prop.initializer;
|
|
289
393
|
if (name === "trustedHtml") continue;
|
|
290
394
|
const isDynamicEvent = /^on[A-Z]/.test(name) && init !== void 0 && ts.isJsxExpression(init) && init.expression !== void 0;
|
|
291
|
-
if (
|
|
292
|
-
if (
|
|
293
|
-
if (
|
|
395
|
+
if (this.server !== void 0 && /^on[A-Z]/.test(name)) this.fail(prop, "OEC9031", `event handlers are a client-only construct — a server function component renders static HTML and may not carry ${name}; interactivity belongs to an @element island (a compiled component), not to server markup`);
|
|
396
|
+
if (isCustomHost && (isDynamicEvent || /^on[A-Z]/.test(name))) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry event handlers — bind the handler on an intrinsic element, or attach the listener imperatively in a lifecycle method`);
|
|
397
|
+
if (!isSafeAttributeName$1(name) && !isDynamicEvent && name !== "innerHTML") this.fail(prop, "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`);
|
|
398
|
+
if (name === "innerHTML" && !(init !== void 0 && ts.isJsxExpression(init) && init.expression !== void 0 && this.fieldAccess(unwrapExpression(init.expression)) !== null)) this.fail(prop, "OEC9011", "attribute name \"innerHTML\" is unsafe as a static attribute — innerHTML opens only through the trusted-HTML sink: bind an Object-typed trustedHtml(...) property and carry the literal trustedHtml marker");
|
|
294
399
|
const attributeKey = name.toLowerCase();
|
|
295
|
-
if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported`);
|
|
400
|
+
if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported — remove one; an element admits each attribute once`);
|
|
296
401
|
attributeNames.add(attributeKey);
|
|
297
402
|
if (!init) {
|
|
298
403
|
attrs.push([name, ""]);
|
|
@@ -300,18 +405,20 @@ var Lowering = class {
|
|
|
300
405
|
}
|
|
301
406
|
if (ts.isStringLiteral(init)) {
|
|
302
407
|
attrs.push([name, init.text]);
|
|
408
|
+
if (name === "class") this.collectClassCandidates(init.text);
|
|
303
409
|
continue;
|
|
304
410
|
}
|
|
305
411
|
if (!ts.isJsxExpression(init) || !init.expression) this.fail(prop, "OEC9011", `attribute "${name}" must be a literal or a supported expression`);
|
|
306
412
|
const expr = unwrapExpression(init.expression);
|
|
307
413
|
if (/^on[A-Z]/.test(name)) {
|
|
308
|
-
if (staticOnly) this.fail(prop, "OEC9012",
|
|
414
|
+
if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — an event handler cannot bind inside a branch`);
|
|
309
415
|
this.lowerEvent(name, expr, path, prop, elementId);
|
|
310
416
|
continue;
|
|
311
417
|
}
|
|
312
418
|
if (name === "ref") {
|
|
313
|
-
if (
|
|
314
|
-
if (
|
|
419
|
+
if (this.server !== void 0) this.fail(prop, "OEC9031", "refs are a client-only construct — a server function component renders static HTML and may not carry a ref; element access belongs to an @element island (a compiled component), not to server markup");
|
|
420
|
+
if (isCustomHost) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry a ref — query the host imperatively in a lifecycle method (e.g. connectedCallback)`);
|
|
421
|
+
if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — a ref cannot bind inside a branch`);
|
|
315
422
|
const ref = this.fieldAccess(expr);
|
|
316
423
|
if (!ref) this.fail(prop, "OEC9011", "ref must reference this.<field>");
|
|
317
424
|
this.addPart({
|
|
@@ -321,19 +428,23 @@ var Lowering = class {
|
|
|
321
428
|
}, path, prop, elementId);
|
|
322
429
|
continue;
|
|
323
430
|
}
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
|
|
431
|
+
if (this.server !== void 0 && this.expressionContainsAwait(expr)) this.fail(prop, "OEC9032", serverAwaitRefusal("attribute"));
|
|
432
|
+
if (name === "class" && ts.isConditionalExpression(expr)) {
|
|
433
|
+
if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — an inline conditional class cannot bind inside a branch`);
|
|
434
|
+
if (!isCustomHost) {
|
|
435
|
+
this.lowerConditionalClass(expr, path, prop, elementId);
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
327
438
|
}
|
|
328
439
|
const field = this.fieldAccess(expr);
|
|
329
440
|
if (field) {
|
|
330
|
-
|
|
441
|
+
this.refusePromiseField(expr, prop, "attribute");
|
|
331
442
|
if (name === "innerHTML") {
|
|
332
443
|
this.lowerDynamicAttribute(name, field, tag, path, prop, elementId, trustedHtmlCapability);
|
|
333
444
|
continue;
|
|
334
445
|
}
|
|
335
446
|
if (isCustomHost) {
|
|
336
|
-
if (forbiddenSinkReason("prop", name) !== null) this.fail(prop, "OEC9011", `property sink name "${name}" is unsafe`);
|
|
447
|
+
if (forbiddenSinkReason("prop", name) !== null) this.fail(prop, "OEC9011", `property sink name "${name}" is unsafe — prototype-pollution primitives are on the shared deny list on every boundary; rename the attribute`);
|
|
337
448
|
this.addPart({
|
|
338
449
|
k: "prop",
|
|
339
450
|
signal: field,
|
|
@@ -348,16 +459,31 @@ var Lowering = class {
|
|
|
348
459
|
const literal = literalValue(expr, this.sf);
|
|
349
460
|
if (literal === void 0) this.fail(prop, "OEC9011", `attribute "${name}" must be a literal, this.<property>, or a supported expression`);
|
|
350
461
|
const text = primitiveText(literal);
|
|
351
|
-
if (text === null) this.fail(prop, "OEC9011", `attribute "${name}" only accepts primitive literal values`);
|
|
462
|
+
if (text === null) this.fail(prop, "OEC9011", `attribute "${name}" only accepts primitive literal values — use a string, number or boolean literal (objects and arrays have no attribute form)`);
|
|
352
463
|
if (literal === false || literal === null) continue;
|
|
353
464
|
attrs.push([name, literal === true ? "" : text ?? ""]);
|
|
465
|
+
if (name === "class" && literal !== true && text !== null) this.collectClassCandidates(text);
|
|
354
466
|
}
|
|
355
|
-
const hasHtmlSink = this.parts.some((part) => part.k === "html" && part.
|
|
467
|
+
const hasHtmlSink = this.parts.some((part) => part.k === "html" && part.location.node === elementId);
|
|
356
468
|
if (trustedHtmlCapability && !hasHtmlSink) this.fail(sourceNode, "OEC9026", "trustedHtml capability marker requires an innerHTML sink");
|
|
357
469
|
if (!isCustomHost && hasHtmlSink && children.some((child) => hasMeaningfulJsxChild(this.sf, child))) this.fail(sourceNode, "OEC9026", "an innerHTML sink target must be otherwise childless (the sink owns its content)");
|
|
470
|
+
const lowered = this.lowerChildren(children, staticOnly, path);
|
|
471
|
+
if (VOID_TAGS.has(tag)) {
|
|
472
|
+
const child = children.find((candidate) => hasMeaningfulJsxChild(this.sf, candidate));
|
|
473
|
+
if (child) this.fail(child, "OEC9013", `void element <${tag}> may not have children`);
|
|
474
|
+
}
|
|
475
|
+
return this.addElement(elementId, tag, attrs, lowered);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* The one children walk both the class path and the server component
|
|
479
|
+
* branch share: JSX text cleaning, expression children (field read /
|
|
480
|
+
* literal / when / each), nested elements, and the fragments-and-spreads
|
|
481
|
+
* rejection. `elementPath` is the owning element's own address.
|
|
482
|
+
*/
|
|
483
|
+
lowerChildren(children, staticOnly, elementPath) {
|
|
358
484
|
const lowered = [];
|
|
359
485
|
for (const child of children) {
|
|
360
|
-
const childPath = [...
|
|
486
|
+
const childPath = [...elementPath, lowered.length];
|
|
361
487
|
if (ts.isJsxText(child)) {
|
|
362
488
|
const value = cleanJsxText(child.text);
|
|
363
489
|
if (value === "") continue;
|
|
@@ -380,13 +506,62 @@ var Lowering = class {
|
|
|
380
506
|
lowered.push(this.lowerElement(child.tagName, child.attributes, [], childPath, child, staticOnly));
|
|
381
507
|
continue;
|
|
382
508
|
}
|
|
383
|
-
this.fail(child, "OEC9013", "JSX fragments and spreads are outside the compiler grammar");
|
|
509
|
+
this.fail(child, "OEC9013", "JSX fragments and spreads are outside the compiler grammar — wrap the fragment's children in a single element");
|
|
384
510
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
511
|
+
return lowered;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Server function components: one uppercase JSX tag — a nested server
|
|
515
|
+
* function component reference. The call composes by DIRECT function call
|
|
516
|
+
* to the imported binding: attribute values cross as raw props (literals
|
|
517
|
+
* or `props.<field>` reads — the callee's own compiled body escapes at its
|
|
518
|
+
* sinks), and JSX children compose the `children` prop through the same
|
|
519
|
+
* children walk every other element takes.
|
|
520
|
+
*/
|
|
521
|
+
lowerComponentElement(tagNameNode, attributes, children, path, sourceNode) {
|
|
522
|
+
const name = tagNameNode.getText(this.sf);
|
|
523
|
+
const local = this.server.components.get(name);
|
|
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.`);
|
|
526
|
+
const elementId = this.reserveElement(local, path, sourceNode);
|
|
527
|
+
const propsEntries = [];
|
|
528
|
+
for (const prop of attributes.properties) {
|
|
529
|
+
if (ts.isJsxSpreadAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported by the compiler grammar — write each attribute explicitly (a literal or a this.<property> sink)");
|
|
530
|
+
if (!ts.isIdentifier(prop.name)) this.fail(prop, "OEC9032", "component prop names must be plain identifiers");
|
|
531
|
+
const propName = prop.name.text;
|
|
532
|
+
if (/^on[A-Z]/.test(propName)) this.fail(prop, "OEC9031", `event handlers are a client-only construct — a server function component renders static HTML and may not carry ${propName}; interactivity belongs to an @element island (a compiled component), not to server markup`);
|
|
533
|
+
const initializer = prop.initializer;
|
|
534
|
+
if (initializer === void 0) {
|
|
535
|
+
propsEntries.push([propName, "true"]);
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (ts.isStringLiteral(initializer)) {
|
|
539
|
+
propsEntries.push([propName, JSON.stringify(initializer.text)]);
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
if (!ts.isJsxExpression(initializer) || !initializer.expression) this.fail(prop, "OEC9032", `component prop "${propName}" must be a literal or a props.<field> read`);
|
|
543
|
+
const expr = unwrapExpression(initializer.expression);
|
|
544
|
+
const field = this.fieldAccess(expr);
|
|
545
|
+
if (field !== null) {
|
|
546
|
+
propsEntries.push([propName, `${this.server.parameter}.${field}`]);
|
|
547
|
+
continue;
|
|
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"));
|
|
554
|
+
const literal = literalValue(expr, this.sf);
|
|
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`);
|
|
556
|
+
propsEntries.push([propName, JSON.stringify(literal)]);
|
|
388
557
|
}
|
|
389
|
-
|
|
558
|
+
const childNodes = this.lowerChildren(children, false, path);
|
|
559
|
+
this.componentCalls.set(elementId, {
|
|
560
|
+
component: local,
|
|
561
|
+
propsEntries,
|
|
562
|
+
children: childNodes
|
|
563
|
+
});
|
|
564
|
+
return this.addElement(elementId, local, [], []);
|
|
390
565
|
}
|
|
391
566
|
lowerEvent(attributeName, expr, path, sourceNode, elementId) {
|
|
392
567
|
const action = this.eventAction(expr, sourceNode);
|
|
@@ -489,13 +664,14 @@ var Lowering = class {
|
|
|
489
664
|
for (const branch of [expr.whenTrue, expr.whenFalse]) {
|
|
490
665
|
const value = unwrapExpression(branch);
|
|
491
666
|
if (!ts.isStringLiteral(value) && !ts.isNoSubstitutionTemplateLiteral(value)) this.fail(sourceNode, "OEC9011", "conditional class branches must be string literals: class={this.<cond> ? 'a' : 'b'}");
|
|
667
|
+
this.collectClassCandidates(value.text);
|
|
492
668
|
}
|
|
493
669
|
const { deps, bodyText } = validateComputedExpressionBody(expr, this.sf, this.plainFieldNames, this.computedFieldNames, (node, code, message) => this.fail(node, code, message), {
|
|
494
670
|
actor: "conditional class conditions",
|
|
495
671
|
single: "conditional class condition",
|
|
496
672
|
plural: "conditional class conditions"
|
|
497
|
-
});
|
|
498
|
-
if (deps.length === 0) this.fail(sourceNode, "OEC9011",
|
|
673
|
+
}, this.server === void 0 ? void 0 : { parameter: this.server.parameter });
|
|
674
|
+
if (deps.length === 0) this.fail(sourceNode, "OEC9011", `conditional class conditions must read at least one ${this.server === void 0 ? "this" : this.server.parameter}.<property>`);
|
|
499
675
|
const computedName = this.options.computedLocal ?? "__openelementComputed";
|
|
500
676
|
let name = `__compiledClass${this.conditionalClassSerial++}`;
|
|
501
677
|
while (this.methodNames.has(name) || this.fieldNames.has(name)) name = `_${name}`;
|
|
@@ -530,68 +706,94 @@ var Lowering = class {
|
|
|
530
706
|
}, path, sourceNode, elementId);
|
|
531
707
|
}
|
|
532
708
|
lowerDynamicAttribute(name, signal, tag, path, sourceNode, elementId, trustedHtmlCapability) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
path
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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;
|
|
570
764
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
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";
|
|
580
779
|
}
|
|
581
|
-
|
|
582
|
-
this.addPart({
|
|
583
|
-
k: "attr",
|
|
584
|
-
signal,
|
|
585
|
-
name,
|
|
586
|
-
path
|
|
587
|
-
}, path, sourceNode, elementId);
|
|
780
|
+
return "operand";
|
|
588
781
|
}
|
|
589
782
|
lowerExpressionChild(child, staticOnly, path) {
|
|
590
783
|
if (!child.expression) return null;
|
|
591
784
|
const expr = unwrapExpression(child.expression);
|
|
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");
|
|
592
794
|
const field = this.fieldAccess(expr);
|
|
593
795
|
if (field) {
|
|
594
|
-
if (staticOnly) this.fail(child, "OEC9012",
|
|
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>})`);
|
|
595
797
|
const index = this.addPart({
|
|
596
798
|
k: "text",
|
|
597
799
|
signal: field
|
|
@@ -613,7 +815,7 @@ var Lowering = class {
|
|
|
613
815
|
};
|
|
614
816
|
}
|
|
615
817
|
if (ts.isConditionalExpression(expr)) {
|
|
616
|
-
if (staticOnly) this.fail(child, "OEC9012", "nested
|
|
818
|
+
if (staticOnly) this.fail(child, "OEC9012", "nested Blocks are outside the compiler grammar");
|
|
617
819
|
const test = this.parseCondition(expr.condition, child);
|
|
618
820
|
const on = this.lowerStaticBranch(expr.whenTrue, child);
|
|
619
821
|
const off = this.lowerStaticBranch(expr.whenFalse, child);
|
|
@@ -631,7 +833,7 @@ var Lowering = class {
|
|
|
631
833
|
};
|
|
632
834
|
}
|
|
633
835
|
if (ts.isCallExpression(expr)) {
|
|
634
|
-
if (staticOnly) this.fail(child, "OEC9012", "nested
|
|
836
|
+
if (staticOnly) this.fail(child, "OEC9012", "nested Blocks are outside the compiler grammar");
|
|
635
837
|
return this.lowerEach(expr, child, path);
|
|
636
838
|
}
|
|
637
839
|
this.fail(child, "OEC9013", "unsupported dynamic expression; use this.<property>, a supported condition, or this.<array>.map(...)");
|
|
@@ -662,42 +864,44 @@ var Lowering = class {
|
|
|
662
864
|
value
|
|
663
865
|
};
|
|
664
866
|
}
|
|
665
|
-
this.fail(near, "OEC9013", "conditional
|
|
867
|
+
this.fail(near, "OEC9013", "conditional Blocks support this.<property> compared with a numeric literal (>, >=, <, <=), a number/string/boolean equality (===, !==), or a bare this.<property> (optionally negated) truthiness test");
|
|
666
868
|
}
|
|
667
869
|
lowerStaticBranch(expr, near) {
|
|
668
870
|
const branch = unwrapExpression(expr);
|
|
669
|
-
if (ts.isJsxElement(branch)) return this.lowerElement(branch.openingElement.tagName, branch.openingElement.attributes, [...branch.children], [], branch, true);
|
|
670
|
-
if (ts.isJsxSelfClosingElement(branch)) return this.lowerElement(branch.tagName, branch.attributes, [], [], branch, true);
|
|
671
|
-
this.fail(near, "OEC9012", "
|
|
871
|
+
if (ts.isJsxElement(branch)) return this.lowerElement(branch.openingElement.tagName, branch.openingElement.attributes, [...branch.children], [0], branch, true);
|
|
872
|
+
if (ts.isJsxSelfClosingElement(branch)) return this.lowerElement(branch.tagName, branch.attributes, [], [0], branch, true);
|
|
873
|
+
if (ts.isConditionalExpression(branch)) this.fail(near, "OEC9012", "nested ternaries are outside the compiler grammar — one condition per Block; derive the decision in a computed(...) property and branch on it");
|
|
874
|
+
if (literalValue(branch, this.sf) !== void 0) this.fail(near, "OEC9012", "a text-only ternary is not a Block — Blocks swap elements; derive the text in a computed(...) property and interpolate {this.<property>}");
|
|
875
|
+
this.fail(near, "OEC9012", "conditional Block branches must be single static JSX elements — each branch is exactly one element (bind its values as this.<property> attributes)");
|
|
672
876
|
}
|
|
673
877
|
lowerEach(expr, near, path) {
|
|
674
878
|
const callee = expr.expression;
|
|
675
|
-
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "map" || expr.arguments.length !== 1) this.fail(near, "OEC9013", "list
|
|
879
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "map" || expr.arguments.length !== 1) this.fail(near, "OEC9013", "list Blocks support exactly this.<property>.map(...)");
|
|
676
880
|
const signal = this.fieldAccess(callee.expression);
|
|
677
|
-
if (!signal) this.fail(near, "OEC9013", "list
|
|
881
|
+
if (!signal) this.fail(near, "OEC9013", "list Blocks must map over this.<property>");
|
|
678
882
|
const arrow = expr.arguments[0];
|
|
679
|
-
if (!ts.isArrowFunction(arrow) || arrow.parameters.length !== 1 || !ts.isIdentifier(arrow.parameters[0].name)) this.fail(near, "OEC9013", "list
|
|
680
|
-
if (ts.isBlock(arrow.body)) this.fail(near, "OEC9013", "list
|
|
883
|
+
if (!ts.isArrowFunction(arrow) || arrow.parameters.length !== 1 || !ts.isIdentifier(arrow.parameters[0].name)) this.fail(near, "OEC9013", "list Block mapper must be a single-parameter arrow function");
|
|
884
|
+
if (ts.isBlock(arrow.body)) this.fail(near, "OEC9013", "list Block mapper must return one JSX element");
|
|
681
885
|
const body = unwrapExpression(arrow.body);
|
|
682
|
-
if (!ts.isJsxElement(body) && !ts.isJsxSelfClosingElement(body)) this.fail(near, "OEC9013", "list
|
|
886
|
+
if (!ts.isJsxElement(body) && !ts.isJsxSelfClosingElement(body)) this.fail(near, "OEC9013", "list Block mapper must return one JSX element");
|
|
683
887
|
const param = arrow.parameters[0].name.text;
|
|
684
888
|
const attributes = ts.isJsxElement(body) ? body.openingElement.attributes : body.attributes;
|
|
685
889
|
let key = null;
|
|
686
890
|
for (const prop of attributes.properties) {
|
|
687
|
-
if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "list
|
|
891
|
+
if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "list Block items do not support spread attributes — write each attribute explicitly (a literal or {<item>.<field>})");
|
|
688
892
|
if (prop.name.getText(this.sf) !== "key") continue;
|
|
689
|
-
if (key !== null) this.fail(prop, "OEC9014", "list
|
|
893
|
+
if (key !== null) this.fail(prop, "OEC9014", "list Block items may declare key only once");
|
|
690
894
|
if (!prop.initializer || !ts.isJsxExpression(prop.initializer) || !prop.initializer.expression) this.fail(prop, "OEC9014", "key must be key={<item>.<field>}");
|
|
691
895
|
const keyExpr = unwrapExpression(prop.initializer.expression);
|
|
692
896
|
if (ts.isPropertyAccessExpression(keyExpr) && ts.isIdentifier(keyExpr.expression) && keyExpr.expression.text === param && isIdentifier(keyExpr.name.text)) key = keyExpr.name.text;
|
|
693
897
|
else this.fail(prop, "OEC9014", `key must reference ${param}.<field>`);
|
|
694
898
|
}
|
|
695
|
-
if (!key) this.fail(body, "OEC9014", "list
|
|
899
|
+
if (!key) this.fail(body, "OEC9014", "list Block items require key={<item>.<field>}");
|
|
696
900
|
const itemFields = [];
|
|
697
901
|
const itemEvents = [];
|
|
698
902
|
const item = this.lowerItemElement(body, param, itemFields, [], true, itemEvents, "");
|
|
699
903
|
const uniqueFields = [...new Set(itemFields)];
|
|
700
|
-
if (uniqueFields.length === 0) this.fail(body, "OEC9013", "list
|
|
904
|
+
if (uniqueFields.length === 0) this.fail(body, "OEC9013", "list Block items must bind at least one {<item>.<field>} value or attribute slot");
|
|
701
905
|
const index = this.addPart({
|
|
702
906
|
k: "each",
|
|
703
907
|
signal,
|
|
@@ -717,7 +921,7 @@ var Lowering = class {
|
|
|
717
921
|
const attributes = ts.isJsxElement(element) ? element.openingElement.attributes : element.attributes;
|
|
718
922
|
const tag = tagName.getText(this.sf);
|
|
719
923
|
const isCustomHost = /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(tag);
|
|
720
|
-
if (!/^[a-z][a-z0-9]*$/.test(tag) && !isCustomHost) this.fail(tagName, "OEC9010", "list
|
|
924
|
+
if (!/^[a-z][a-z0-9]*$/.test(tag) && !isCustomHost) this.fail(tagName, "OEC9010", "list Block item must be an intrinsic lowercase element or a custom-element host — compose by tag name, not class values");
|
|
721
925
|
const itemTagReason = forbiddenSinkReason("tag", tag);
|
|
722
926
|
if (itemTagReason !== null) this.fail(tagName, "OEC9010", itemTagReason);
|
|
723
927
|
const elementId = this.reserveElement(tag, path, element);
|
|
@@ -725,16 +929,16 @@ var Lowering = class {
|
|
|
725
929
|
const iattrs = [];
|
|
726
930
|
const attributeNames = /* @__PURE__ */ new Set();
|
|
727
931
|
for (const prop of attributes.properties) {
|
|
728
|
-
if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported in item templates");
|
|
932
|
+
if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported in item templates — write each attribute explicitly (a literal or {<item>.<field>})");
|
|
729
933
|
const name = this.normalizeAttributeName(prop.name.getText(this.sf));
|
|
730
934
|
if (name === "key") {
|
|
731
|
-
if (!allowKey) this.fail(prop, "OEC9011", "key is only supported on the list
|
|
935
|
+
if (!allowKey) this.fail(prop, "OEC9011", "key is only supported on the list Block item root");
|
|
732
936
|
continue;
|
|
733
937
|
}
|
|
734
938
|
const isItemEvent = /^on[A-Z]/.test(name) && prop.initializer !== void 0 && ts.isJsxExpression(prop.initializer) && prop.initializer.expression !== void 0;
|
|
735
|
-
if (!isSafeAttributeName$1(name) && !isItemEvent) this.fail(prop, "OEC9011", `attribute name "${name}" is unsafe`);
|
|
939
|
+
if (!isSafeAttributeName$1(name) && !isItemEvent) this.fail(prop, "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
940
|
const attributeKey = name.toLowerCase();
|
|
737
|
-
if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported`);
|
|
941
|
+
if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported — remove one; an element admits each attribute once`);
|
|
738
942
|
attributeNames.add(attributeKey);
|
|
739
943
|
if (!prop.initializer) {
|
|
740
944
|
attrs.push([name, ""]);
|
|
@@ -742,12 +946,14 @@ var Lowering = class {
|
|
|
742
946
|
}
|
|
743
947
|
if (ts.isStringLiteral(prop.initializer)) {
|
|
744
948
|
attrs.push([name, prop.initializer.text]);
|
|
949
|
+
if (name === "class") this.collectClassCandidates(prop.initializer.text);
|
|
745
950
|
continue;
|
|
746
951
|
}
|
|
747
|
-
if (!ts.isJsxExpression(prop.initializer) || !prop.initializer.expression) this.fail(prop, "OEC9011",
|
|
952
|
+
if (!ts.isJsxExpression(prop.initializer) || !prop.initializer.expression) this.fail(prop, "OEC9011", `item template attribute "${name}" must be a static literal or {${param}.<field>}`);
|
|
748
953
|
if (/^on[A-Z]/.test(name)) {
|
|
749
|
-
if (
|
|
750
|
-
if (
|
|
954
|
+
if (this.server !== void 0) this.fail(prop, "OEC9031", `event handlers are a client-only construct — a server function component renders static HTML and may not carry ${name}; interactivity belongs to an @element island (a compiled component), not to server markup`);
|
|
955
|
+
if (isCustomHost) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry event handlers — bind the handler on an intrinsic element, or attach the listener imperatively in a lifecycle method`);
|
|
956
|
+
if (itemEvents === void 0) this.fail(prop, "OEC9012", "event handlers are only supported on list Block item templates");
|
|
751
957
|
const action = this.eventAction(unwrapExpression(prop.initializer.expression), prop);
|
|
752
958
|
itemEvents.push({
|
|
753
959
|
event: name.slice(2).toLowerCase(),
|
|
@@ -766,9 +972,10 @@ var Lowering = class {
|
|
|
766
972
|
const literal = literalValue(prop.initializer.expression, this.sf);
|
|
767
973
|
if (literal === void 0) this.fail(prop, "OEC9011", `item template attribute "${name}" must be a static literal or {${param}.<field>}`);
|
|
768
974
|
const text = primitiveText(literal);
|
|
769
|
-
if (text === null) this.fail(prop, "OEC9011",
|
|
975
|
+
if (text === null) this.fail(prop, "OEC9011", `item template attributes must use primitive literals — use a string, number or boolean literal, or bind {${param}.<field>}`);
|
|
770
976
|
if (literal === false || literal === null) continue;
|
|
771
977
|
attrs.push([name, literal === true ? "" : text ?? ""]);
|
|
978
|
+
if (name === "class" && literal !== true && text !== null) this.collectClassCandidates(text);
|
|
772
979
|
}
|
|
773
980
|
const children = [];
|
|
774
981
|
const rawChildren = ts.isJsxElement(element) ? [...element.children] : [];
|
|
@@ -790,6 +997,7 @@ var Lowering = class {
|
|
|
790
997
|
}
|
|
791
998
|
if (ts.isJsxExpression(child) && child.expression) {
|
|
792
999
|
const expr = unwrapExpression(child.expression);
|
|
1000
|
+
if (this.server !== void 0 && this.expressionContainsAwait(expr)) this.fail(child, "OEC9032", serverAwaitRefusal("listItem"));
|
|
793
1001
|
if (ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression) && expr.expression.text === param && isIdentifier(expr.name.text)) {
|
|
794
1002
|
itemFields.push(expr.name.text);
|
|
795
1003
|
children.push({
|