@openelement/compiler 1.0.0-alpha.13 → 1.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/package.json +3 -2
  2. package/src/compiler.d.ts +8 -4
  3. package/src/compiler.js +8 -4
  4. package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +36 -0
  5. package/src/internal/compiler/compiled-artifact-class-candidates.js +60 -0
  6. package/src/internal/compiler/compiled-artifact-style-requests.d.ts +17 -0
  7. package/src/internal/compiler/compiled-artifact-style-requests.js +48 -2
  8. package/src/internal/compiler/plugin.d.ts +47 -9
  9. package/src/internal/compiler/plugin.js +102 -24
  10. package/src/internal/compiler/semantic-core/analyze-module.d.ts +117 -0
  11. package/src/internal/compiler/semantic-core/analyze-module.js +55 -10
  12. package/src/internal/compiler/semantic-core/compile.d.ts +10 -2
  13. package/src/internal/compiler/semantic-core/compile.js +6 -4
  14. package/src/internal/compiler/semantic-core/diagnostics/index.d.ts +21 -1
  15. package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
  16. package/src/internal/compiler/semantic-core/emit-module.js +4 -0
  17. package/src/internal/compiler/semantic-core/emit-program.js +23 -3
  18. package/src/internal/compiler/semantic-core/lower-program.d.ts +169 -0
  19. package/src/internal/compiler/semantic-core/lower-program.js +168 -56
  20. package/src/internal/compiler/semantic-core/module-analysis.d.ts +55 -0
  21. package/src/internal/compiler/semantic-core/module-analysis.js +74 -4
  22. package/src/internal/compiler/semantic-core/server-component.d.ts +114 -0
  23. package/src/internal/compiler/semantic-core/server-component.js +481 -0
  24. package/src/internal/compiler/semantic-core/type-check.js +1 -1
  25. package/src/internal/compiler/style-requests.d.ts +43 -7
  26. package/src/internal/compiler/style-requests.js +70 -11
  27. package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
  28. package/src/internal/compiler/tailwind-candidates.js +54 -0
@@ -8,7 +8,7 @@ import { VOID_TAGS, conditionLiteralAllowed } from "@openelement/protocol/part-p
8
8
  /**
9
9
  * JSX → Part Program lowering for the compiled grammar (#1473 split): the
10
10
  * {@link Lowering} walk turns
11
- * the analyzed render() tree into fixed Parts, Regions, locations and source
11
+ * the analyzed render() tree into fixed Parts, Blocks, locations and source
12
12
  * records with stable compiler-owned paths.
13
13
  */
14
14
  /**
@@ -56,11 +56,19 @@ const DOM_PROPERTY_NAMES = /* @__PURE__ */ new Set([
56
56
  "selected",
57
57
  "value"
58
58
  ]);
59
+ /**
60
+ * The one boundary sentence every when-branch rejection names (alpha15):
61
+ * a branch element admits `this.<property>` attribute sinks, but event
62
+ * handlers, refs and inline conditional classes stay outside blocks — a
63
+ * branch has no anchor of its own, so only attribute-bound state is
64
+ * representable inside it.
65
+ */
66
+ const BRANCH_BOUNDARY = "Block branches admit attribute bindings; events and refs stay outside blocks";
59
67
  function isIdentifier(value) {
60
68
  return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
61
69
  }
62
70
  /**
63
- * Token→operator map for when-Region conditions (#1372). Only strict
71
+ * Token→operator map for when-Block conditions (#1372). Only strict
64
72
  * equality tokens are admitted; `==`/`!=` fail closed with OEC9013 so the
65
73
  * coercion difference cannot ride in unnoticed.
66
74
  */
@@ -127,7 +135,7 @@ function hasMeaningfulJsxChild(sf, child) {
127
135
  }
128
136
  var Lowering = class {
129
137
  parts = [];
130
- regions = [];
138
+ blocks = [];
131
139
  dependencies = [];
132
140
  locations = [];
133
141
  sourceRecords = [];
@@ -146,6 +154,26 @@ var Lowering = class {
146
154
  synthesizedFields = [];
147
155
  /** True when the authored module binds the canonical `computed` import. */
148
156
  sourceBindsComputed;
157
+ /**
158
+ * The component's statically admitted class tokens (alpha15 S lane): every
159
+ * whitespace-separated token of every compile-time `class` value the
160
+ * lowering admits — static literals, primitive-literal attributes, both
161
+ * branches of an admitted conditional class, and `each` item-template
162
+ * literals. The compiler collects them as OPAQUE STRINGS: it never
163
+ * interprets Tailwind's class grammar, and the build layer hands the list
164
+ * to the official Tailwind compiler as explicit candidates.
165
+ */
166
+ classCandidates = /* @__PURE__ */ new Set();
167
+ /**
168
+ * Server mode side tables (alpha15 server lane): the nested server function
169
+ * component calls (element id → the recorded call shape, props entries as
170
+ * verbatim value texts) and the custom-element hosts the build admitted as
171
+ * compiled components (`__ssr`). The tree stays Part Program vocabulary —
172
+ * the code generator consumes these alongside it.
173
+ */
174
+ componentCalls = /* @__PURE__ */ new Map();
175
+ ssrCalls = /* @__PURE__ */ new Set();
176
+ server;
149
177
  plainFieldNames;
150
178
  computedFieldNames;
151
179
  sf;
@@ -162,10 +190,21 @@ var Lowering = class {
162
190
  this.computedFieldNames = new Set(this.computedNames);
163
191
  this.sourceBindsComputed = options.computedLocal !== null;
164
192
  this.options = options;
193
+ this.server = options.server;
165
194
  }
166
195
  fail(node, code, message) {
167
196
  throw new CompiledElementError([diagnosticAt(this.sf, node, code, message)]);
168
197
  }
198
+ /**
199
+ * Record one compile-time class value's whitespace-separated tokens as
200
+ * Tailwind candidates (alpha15 S lane). The values are provably finite at
201
+ * compile time — the compiler's grammar admits no other shape — so the
202
+ * tokens are FACTS, not guesses: no runtime class interpolation ever
203
+ * contributes, and the compiler attaches no Tailwind semantics to them.
204
+ */
205
+ collectClassCandidates(value) {
206
+ for (const token of value.split(/\s+/)) if (token !== "") this.classCandidates.add(token);
207
+ }
169
208
  addSource(id, kind, node) {
170
209
  if (this.sourceRecords.some((record) => record.id === id)) return;
171
210
  this.sourceRecords.push({
@@ -226,7 +265,7 @@ var Lowering = class {
226
265
  const sourceKind = part.k === "when" || part.k === "each" ? "region" : "part";
227
266
  this.addSource(`p${index}`, sourceKind, node);
228
267
  if (part.k === "when" || part.k === "each") {
229
- this.regions.push({
268
+ this.blocks.push({
230
269
  id: `r${index}`,
231
270
  index,
232
271
  kind: part.k,
@@ -249,6 +288,7 @@ var Lowering = class {
249
288
  fieldAccess(expr) {
250
289
  const value = unwrapExpression(expr);
251
290
  if (ts.isPropertyAccessExpression(value) && value.expression.kind === ts.SyntaxKind.ThisKeyword && this.fieldNames.has(value.name.text)) return value.name.text;
291
+ 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
292
  return null;
253
293
  }
254
294
  methodAccess(expr) {
@@ -267,12 +307,14 @@ var Lowering = class {
267
307
  }
268
308
  lowerElement(tagNameNode, attributes, children, path, sourceNode, staticOnly = false) {
269
309
  const tag = tagNameNode.getText(this.sf);
310
+ if (this.server !== void 0 && ts.isIdentifier(tagNameNode) && /^[A-Z]/.test(tag)) return this.lowerComponentElement(tagNameNode, attributes, children, path, sourceNode);
270
311
  const isCustomHost = /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(tag);
271
312
  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
313
  const tagReason = forbiddenSinkReason("tag", tag);
273
314
  if (tagReason !== null) this.fail(tagNameNode, "OEC9010", tagReason);
274
315
  const attrs = [];
275
316
  const elementId = this.reserveElement(tag, path, sourceNode);
317
+ if (this.server !== void 0 && isCustomHost && this.server.compiledTags.has(tag)) this.ssrCalls.add(elementId);
276
318
  const attributeNames = /* @__PURE__ */ new Set();
277
319
  let trustedHtmlCapability = false;
278
320
  for (const prop of attributes.properties) {
@@ -283,16 +325,17 @@ var Lowering = class {
283
325
  if (!trustedHtmlCapability) this.fail(prop, "OEC9026", "trustedHtml capability marker must be the literal true");
284
326
  }
285
327
  for (const prop of attributes.properties) {
286
- if (ts.isJsxSpreadAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported by the compiler grammar");
328
+ 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
329
  const name = this.normalizeAttributeName(prop.name.getText(this.sf));
288
330
  const init = prop.initializer;
289
331
  if (name === "trustedHtml") continue;
290
332
  const isDynamicEvent = /^on[A-Z]/.test(name) && init !== void 0 && ts.isJsxExpression(init) && init.expression !== void 0;
291
- if (isCustomHost && (isDynamicEvent || /^on[A-Z]/.test(name))) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry event handlers`);
292
- if (!isSafeAttributeName$1(name) && !isDynamicEvent && name !== "innerHTML") this.fail(prop, "OEC9011", `attribute name "${name}" is unsafe`);
293
- 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 "${name}" is unsafe`);
333
+ 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`);
334
+ 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`);
335
+ 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`);
336
+ 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
337
  const attributeKey = name.toLowerCase();
295
- if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported`);
338
+ if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported — remove one; an element admits each attribute once`);
296
339
  attributeNames.add(attributeKey);
297
340
  if (!init) {
298
341
  attrs.push([name, ""]);
@@ -300,18 +343,20 @@ var Lowering = class {
300
343
  }
301
344
  if (ts.isStringLiteral(init)) {
302
345
  attrs.push([name, init.text]);
346
+ if (name === "class") this.collectClassCandidates(init.text);
303
347
  continue;
304
348
  }
305
349
  if (!ts.isJsxExpression(init) || !init.expression) this.fail(prop, "OEC9011", `attribute "${name}" must be a literal or a supported expression`);
306
350
  const expr = unwrapExpression(init.expression);
307
351
  if (/^on[A-Z]/.test(name)) {
308
- if (staticOnly) this.fail(prop, "OEC9012", "Region branches must be fully static");
352
+ if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — an event handler cannot bind inside a branch`);
309
353
  this.lowerEvent(name, expr, path, prop, elementId);
310
354
  continue;
311
355
  }
312
356
  if (name === "ref") {
313
- if (isCustomHost) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry a ref`);
314
- if (staticOnly) this.fail(prop, "OEC9012", "Region branches must be fully static");
357
+ 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");
358
+ 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)`);
359
+ if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — a ref cannot bind inside a branch`);
315
360
  const ref = this.fieldAccess(expr);
316
361
  if (!ref) this.fail(prop, "OEC9011", "ref must reference this.<field>");
317
362
  this.addPart({
@@ -321,19 +366,21 @@ var Lowering = class {
321
366
  }, path, prop, elementId);
322
367
  continue;
323
368
  }
324
- if (name === "class" && !staticOnly && !isCustomHost && ts.isConditionalExpression(expr)) {
325
- this.lowerConditionalClass(expr, path, prop, elementId);
326
- continue;
369
+ if (name === "class" && ts.isConditionalExpression(expr)) {
370
+ if (staticOnly) this.fail(prop, "OEC9012", `${BRANCH_BOUNDARY} — an inline conditional class cannot bind inside a branch`);
371
+ if (!isCustomHost) {
372
+ this.lowerConditionalClass(expr, path, prop, elementId);
373
+ continue;
374
+ }
327
375
  }
328
376
  const field = this.fieldAccess(expr);
329
377
  if (field) {
330
- if (staticOnly) this.fail(prop, "OEC9012", "Region branches must be fully static");
331
378
  if (name === "innerHTML") {
332
379
  this.lowerDynamicAttribute(name, field, tag, path, prop, elementId, trustedHtmlCapability);
333
380
  continue;
334
381
  }
335
382
  if (isCustomHost) {
336
- if (forbiddenSinkReason("prop", name) !== null) this.fail(prop, "OEC9011", `property sink name "${name}" is unsafe`);
383
+ 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
384
  this.addPart({
338
385
  k: "prop",
339
386
  signal: field,
@@ -348,16 +395,31 @@ var Lowering = class {
348
395
  const literal = literalValue(expr, this.sf);
349
396
  if (literal === void 0) this.fail(prop, "OEC9011", `attribute "${name}" must be a literal, this.<property>, or a supported expression`);
350
397
  const text = primitiveText(literal);
351
- if (text === null) this.fail(prop, "OEC9011", `attribute "${name}" only accepts primitive literal values`);
398
+ 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
399
  if (literal === false || literal === null) continue;
353
400
  attrs.push([name, literal === true ? "" : text ?? ""]);
401
+ if (name === "class" && literal !== true && text !== null) this.collectClassCandidates(text);
354
402
  }
355
- const hasHtmlSink = this.parts.some((part) => part.k === "html" && part.path.length === path.length && part.path.every((value, index) => value === path[index]));
403
+ const hasHtmlSink = this.parts.some((part) => part.k === "html" && part.location.node === elementId);
356
404
  if (trustedHtmlCapability && !hasHtmlSink) this.fail(sourceNode, "OEC9026", "trustedHtml capability marker requires an innerHTML sink");
357
405
  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)");
406
+ const lowered = this.lowerChildren(children, staticOnly, path);
407
+ if (VOID_TAGS.has(tag)) {
408
+ const child = children.find((candidate) => hasMeaningfulJsxChild(this.sf, candidate));
409
+ if (child) this.fail(child, "OEC9013", `void element <${tag}> may not have children`);
410
+ }
411
+ return this.addElement(elementId, tag, attrs, lowered);
412
+ }
413
+ /**
414
+ * The one children walk both the class path and the server component
415
+ * branch share: JSX text cleaning, expression children (field read /
416
+ * literal / when / each), nested elements, and the fragments-and-spreads
417
+ * rejection. `elementPath` is the owning element's own address.
418
+ */
419
+ lowerChildren(children, staticOnly, elementPath) {
358
420
  const lowered = [];
359
421
  for (const child of children) {
360
- const childPath = [...path, lowered.length];
422
+ const childPath = [...elementPath, lowered.length];
361
423
  if (ts.isJsxText(child)) {
362
424
  const value = cleanJsxText(child.text);
363
425
  if (value === "") continue;
@@ -380,13 +442,56 @@ var Lowering = class {
380
442
  lowered.push(this.lowerElement(child.tagName, child.attributes, [], childPath, child, staticOnly));
381
443
  continue;
382
444
  }
383
- this.fail(child, "OEC9013", "JSX fragments and spreads are outside the compiler grammar");
445
+ this.fail(child, "OEC9013", "JSX fragments and spreads are outside the compiler grammar — wrap the fragment's children in a single element");
384
446
  }
385
- if (VOID_TAGS.has(tag)) {
386
- const child = children.find((candidate) => hasMeaningfulJsxChild(this.sf, candidate));
387
- if (child) this.fail(child, "OEC9013", `void element <${tag}> may not have children`);
447
+ return lowered;
448
+ }
449
+ /**
450
+ * Server function components: one uppercase JSX tag — a nested server
451
+ * function component reference. The call composes by DIRECT function call
452
+ * to the imported binding: attribute values cross as raw props (literals
453
+ * or `props.<field>` reads — the callee's own compiled body escapes at its
454
+ * sinks), and JSX children compose the `children` prop through the same
455
+ * children walk every other element takes.
456
+ */
457
+ lowerComponentElement(tagNameNode, attributes, children, path, sourceNode) {
458
+ const name = tagNameNode.getText(this.sf);
459
+ const local = this.server.components.get(name);
460
+ 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)`);
461
+ const elementId = this.reserveElement(local, path, sourceNode);
462
+ const propsEntries = [];
463
+ for (const prop of attributes.properties) {
464
+ 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)");
465
+ if (!ts.isIdentifier(prop.name)) this.fail(prop, "OEC9032", "component prop names must be plain identifiers");
466
+ const propName = prop.name.text;
467
+ 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`);
468
+ const initializer = prop.initializer;
469
+ if (initializer === void 0) {
470
+ propsEntries.push([propName, "true"]);
471
+ continue;
472
+ }
473
+ if (ts.isStringLiteral(initializer)) {
474
+ propsEntries.push([propName, JSON.stringify(initializer.text)]);
475
+ continue;
476
+ }
477
+ if (!ts.isJsxExpression(initializer) || !initializer.expression) this.fail(prop, "OEC9032", `component prop "${propName}" must be a literal or a props.<field> read`);
478
+ const expr = unwrapExpression(initializer.expression);
479
+ const field = this.fieldAccess(expr);
480
+ if (field !== null) {
481
+ propsEntries.push([propName, `${this.server.parameter}.${field}`]);
482
+ continue;
483
+ }
484
+ const literal = literalValue(expr, this.sf);
485
+ 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
+ propsEntries.push([propName, JSON.stringify(literal)]);
388
487
  }
389
- return this.addElement(elementId, tag, attrs, lowered);
488
+ const childNodes = this.lowerChildren(children, false, path);
489
+ this.componentCalls.set(elementId, {
490
+ component: local,
491
+ propsEntries,
492
+ children: childNodes
493
+ });
494
+ return this.addElement(elementId, local, [], []);
390
495
  }
391
496
  lowerEvent(attributeName, expr, path, sourceNode, elementId) {
392
497
  const action = this.eventAction(expr, sourceNode);
@@ -489,13 +594,14 @@ var Lowering = class {
489
594
  for (const branch of [expr.whenTrue, expr.whenFalse]) {
490
595
  const value = unwrapExpression(branch);
491
596
  if (!ts.isStringLiteral(value) && !ts.isNoSubstitutionTemplateLiteral(value)) this.fail(sourceNode, "OEC9011", "conditional class branches must be string literals: class={this.<cond> ? 'a' : 'b'}");
597
+ this.collectClassCandidates(value.text);
492
598
  }
493
599
  const { deps, bodyText } = validateComputedExpressionBody(expr, this.sf, this.plainFieldNames, this.computedFieldNames, (node, code, message) => this.fail(node, code, message), {
494
600
  actor: "conditional class conditions",
495
601
  single: "conditional class condition",
496
602
  plural: "conditional class conditions"
497
- });
498
- if (deps.length === 0) this.fail(sourceNode, "OEC9011", "conditional class conditions must read at least one this.<property>");
603
+ }, this.server === void 0 ? void 0 : { parameter: this.server.parameter });
604
+ 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
605
  const computedName = this.options.computedLocal ?? "__openelementComputed";
500
606
  let name = `__compiledClass${this.conditionalClassSerial++}`;
501
607
  while (this.methodNames.has(name) || this.fieldNames.has(name)) name = `_${name}`;
@@ -550,7 +656,7 @@ var Lowering = class {
550
656
  if (name === "innerHTML") {
551
657
  if (this.fieldTypes.get(signal) !== "object") this.fail(sourceNode, "OEC9026", "innerHTML sinks require an Object-typed TrustedHtml property");
552
658
  if (!trustedHtmlCapability) this.fail(sourceNode, "OEC9026", "innerHTML sinks require the explicit trustedHtml capability marker");
553
- if (VOID_TAGS.has(tag)) this.fail(sourceNode, "OEC9026", `void element <${tag}> cannot carry an innerHTML sink`);
659
+ 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>)`);
554
660
  this.addPart({
555
661
  k: "html",
556
662
  signal,
@@ -559,7 +665,7 @@ var Lowering = class {
559
665
  return;
560
666
  }
561
667
  if (BOOLEAN_ATTRIBUTES.has(lowerName)) {
562
- if (forbiddenSinkReason("bool", name) !== null) this.fail(sourceNode, "OEC9011", `attribute name "${name}" is unsafe`);
668
+ 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`);
563
669
  this.addPart({
564
670
  k: "bool",
565
671
  signal,
@@ -569,7 +675,7 @@ var Lowering = class {
569
675
  return;
570
676
  }
571
677
  if (name === "value" || DOM_PROPERTY_NAMES.has(name) || tag === "input" && name === "value") {
572
- if (forbiddenSinkReason("prop", name) !== null) this.fail(sourceNode, "OEC9011", `property sink name "${name}" is unsafe`);
678
+ 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`);
573
679
  this.addPart({
574
680
  k: "prop",
575
681
  signal,
@@ -578,7 +684,7 @@ var Lowering = class {
578
684
  }, path, sourceNode, elementId);
579
685
  return;
580
686
  }
581
- if (forbiddenSinkReason("attr", name) !== null) this.fail(sourceNode, "OEC9011", `attribute name "${name}" is unsafe`);
687
+ 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`);
582
688
  this.addPart({
583
689
  k: "attr",
584
690
  signal,
@@ -589,9 +695,10 @@ var Lowering = class {
589
695
  lowerExpressionChild(child, staticOnly, path) {
590
696
  if (!child.expression) return null;
591
697
  const expr = unwrapExpression(child.expression);
698
+ 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`);
592
699
  const field = this.fieldAccess(expr);
593
700
  if (field) {
594
- if (staticOnly) this.fail(child, "OEC9012", "Region branches must be fully static");
701
+ 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
702
  const index = this.addPart({
596
703
  k: "text",
597
704
  signal: field
@@ -613,7 +720,7 @@ var Lowering = class {
613
720
  };
614
721
  }
615
722
  if (ts.isConditionalExpression(expr)) {
616
- if (staticOnly) this.fail(child, "OEC9012", "nested Regions are outside the compiler grammar");
723
+ if (staticOnly) this.fail(child, "OEC9012", "nested Blocks are outside the compiler grammar");
617
724
  const test = this.parseCondition(expr.condition, child);
618
725
  const on = this.lowerStaticBranch(expr.whenTrue, child);
619
726
  const off = this.lowerStaticBranch(expr.whenFalse, child);
@@ -631,7 +738,7 @@ var Lowering = class {
631
738
  };
632
739
  }
633
740
  if (ts.isCallExpression(expr)) {
634
- if (staticOnly) this.fail(child, "OEC9012", "nested Regions are outside the compiler grammar");
741
+ if (staticOnly) this.fail(child, "OEC9012", "nested Blocks are outside the compiler grammar");
635
742
  return this.lowerEach(expr, child, path);
636
743
  }
637
744
  this.fail(child, "OEC9013", "unsupported dynamic expression; use this.<property>, a supported condition, or this.<array>.map(...)");
@@ -662,42 +769,44 @@ var Lowering = class {
662
769
  value
663
770
  };
664
771
  }
665
- this.fail(near, "OEC9013", "conditional Regions support this.<property> compared with a numeric literal (>, >=, <, <=), a number/string/boolean equality (===, !==), or a bare this.<property> (optionally negated) truthiness test");
772
+ 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
773
  }
667
774
  lowerStaticBranch(expr, near) {
668
775
  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", "conditional Region branches must be single static JSX elements");
776
+ if (ts.isJsxElement(branch)) return this.lowerElement(branch.openingElement.tagName, branch.openingElement.attributes, [...branch.children], [0], branch, true);
777
+ if (ts.isJsxSelfClosingElement(branch)) return this.lowerElement(branch.tagName, branch.attributes, [], [0], branch, true);
778
+ 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");
779
+ 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>}");
780
+ 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
781
  }
673
782
  lowerEach(expr, near, path) {
674
783
  const callee = expr.expression;
675
- if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "map" || expr.arguments.length !== 1) this.fail(near, "OEC9013", "list Regions support exactly this.<property>.map(...)");
784
+ if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "map" || expr.arguments.length !== 1) this.fail(near, "OEC9013", "list Blocks support exactly this.<property>.map(...)");
676
785
  const signal = this.fieldAccess(callee.expression);
677
- if (!signal) this.fail(near, "OEC9013", "list Regions must map over this.<property>");
786
+ if (!signal) this.fail(near, "OEC9013", "list Blocks must map over this.<property>");
678
787
  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 Region mapper must be a single-parameter arrow function");
680
- if (ts.isBlock(arrow.body)) this.fail(near, "OEC9013", "list Region mapper must return one JSX element");
788
+ 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");
789
+ if (ts.isBlock(arrow.body)) this.fail(near, "OEC9013", "list Block mapper must return one JSX element");
681
790
  const body = unwrapExpression(arrow.body);
682
- if (!ts.isJsxElement(body) && !ts.isJsxSelfClosingElement(body)) this.fail(near, "OEC9013", "list Region mapper must return one JSX element");
791
+ if (!ts.isJsxElement(body) && !ts.isJsxSelfClosingElement(body)) this.fail(near, "OEC9013", "list Block mapper must return one JSX element");
683
792
  const param = arrow.parameters[0].name.text;
684
793
  const attributes = ts.isJsxElement(body) ? body.openingElement.attributes : body.attributes;
685
794
  let key = null;
686
795
  for (const prop of attributes.properties) {
687
- if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "list Region items do not support spread attributes");
796
+ 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
797
  if (prop.name.getText(this.sf) !== "key") continue;
689
- if (key !== null) this.fail(prop, "OEC9014", "list Region items may declare key only once");
798
+ if (key !== null) this.fail(prop, "OEC9014", "list Block items may declare key only once");
690
799
  if (!prop.initializer || !ts.isJsxExpression(prop.initializer) || !prop.initializer.expression) this.fail(prop, "OEC9014", "key must be key={<item>.<field>}");
691
800
  const keyExpr = unwrapExpression(prop.initializer.expression);
692
801
  if (ts.isPropertyAccessExpression(keyExpr) && ts.isIdentifier(keyExpr.expression) && keyExpr.expression.text === param && isIdentifier(keyExpr.name.text)) key = keyExpr.name.text;
693
802
  else this.fail(prop, "OEC9014", `key must reference ${param}.<field>`);
694
803
  }
695
- if (!key) this.fail(body, "OEC9014", "list Region items require key={<item>.<field>}");
804
+ if (!key) this.fail(body, "OEC9014", "list Block items require key={<item>.<field>}");
696
805
  const itemFields = [];
697
806
  const itemEvents = [];
698
807
  const item = this.lowerItemElement(body, param, itemFields, [], true, itemEvents, "");
699
808
  const uniqueFields = [...new Set(itemFields)];
700
- if (uniqueFields.length === 0) this.fail(body, "OEC9013", "list Region items must bind at least one {<item>.<field>} value or attribute slot");
809
+ if (uniqueFields.length === 0) this.fail(body, "OEC9013", "list Block items must bind at least one {<item>.<field>} value or attribute slot");
701
810
  const index = this.addPart({
702
811
  k: "each",
703
812
  signal,
@@ -717,7 +826,7 @@ var Lowering = class {
717
826
  const attributes = ts.isJsxElement(element) ? element.openingElement.attributes : element.attributes;
718
827
  const tag = tagName.getText(this.sf);
719
828
  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 Region item must be an intrinsic lowercase element");
829
+ 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
830
  const itemTagReason = forbiddenSinkReason("tag", tag);
722
831
  if (itemTagReason !== null) this.fail(tagName, "OEC9010", itemTagReason);
723
832
  const elementId = this.reserveElement(tag, path, element);
@@ -725,16 +834,16 @@ var Lowering = class {
725
834
  const iattrs = [];
726
835
  const attributeNames = /* @__PURE__ */ new Set();
727
836
  for (const prop of attributes.properties) {
728
- if (!ts.isJsxAttribute(prop)) this.fail(prop, "OEC9011", "spread attributes are not supported in item templates");
837
+ 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
838
  const name = this.normalizeAttributeName(prop.name.getText(this.sf));
730
839
  if (name === "key") {
731
- if (!allowKey) this.fail(prop, "OEC9011", "key is only supported on the list Region item root");
840
+ if (!allowKey) this.fail(prop, "OEC9011", "key is only supported on the list Block item root");
732
841
  continue;
733
842
  }
734
843
  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`);
844
+ 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
845
  const attributeKey = name.toLowerCase();
737
- if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported`);
846
+ if (attributeNames.has(attributeKey)) this.fail(prop, "OEC9011", `duplicate attribute "${name}" is unsupported — remove one; an element admits each attribute once`);
738
847
  attributeNames.add(attributeKey);
739
848
  if (!prop.initializer) {
740
849
  attrs.push([name, ""]);
@@ -742,12 +851,14 @@ var Lowering = class {
742
851
  }
743
852
  if (ts.isStringLiteral(prop.initializer)) {
744
853
  attrs.push([name, prop.initializer.text]);
854
+ if (name === "class") this.collectClassCandidates(prop.initializer.text);
745
855
  continue;
746
856
  }
747
- if (!ts.isJsxExpression(prop.initializer) || !prop.initializer.expression) this.fail(prop, "OEC9011", "item template attributes must be static literals");
857
+ 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
858
  if (/^on[A-Z]/.test(name)) {
749
- if (isCustomHost) this.fail(prop, "OEC9017", `custom-element host <${tag}> may not carry event handlers`);
750
- if (itemEvents === void 0) this.fail(prop, "OEC9012", "event handlers are only supported on list Region item templates");
859
+ 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`);
860
+ 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`);
861
+ if (itemEvents === void 0) this.fail(prop, "OEC9012", "event handlers are only supported on list Block item templates");
751
862
  const action = this.eventAction(unwrapExpression(prop.initializer.expression), prop);
752
863
  itemEvents.push({
753
864
  event: name.slice(2).toLowerCase(),
@@ -766,9 +877,10 @@ var Lowering = class {
766
877
  const literal = literalValue(prop.initializer.expression, this.sf);
767
878
  if (literal === void 0) this.fail(prop, "OEC9011", `item template attribute "${name}" must be a static literal or {${param}.<field>}`);
768
879
  const text = primitiveText(literal);
769
- if (text === null) this.fail(prop, "OEC9011", "item template attributes must use primitive literals");
880
+ 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
881
  if (literal === false || literal === null) continue;
771
882
  attrs.push([name, literal === true ? "" : text ?? ""]);
883
+ if (name === "class" && literal !== true && text !== null) this.collectClassCandidates(text);
772
884
  }
773
885
  const children = [];
774
886
  const rawChildren = ts.isJsxElement(element) ? [...element.children] : [];
@@ -10,6 +10,14 @@ import { ModuleVocabularyDescriptor, ModuleVocabularyDescriptor as ModuleVocabul
10
10
  */
11
11
  export interface ModuleSemanticFacts {
12
12
  relativeImports: string[];
13
+ /**
14
+ * Every static import/export specifier the module spells, relative or not —
15
+ * present only when the caller asks for it (`collectSpecifiers`), because a
16
+ * host that walks a module graph through its own resolver (S-C1.4's
17
+ * server-rendered style-edge pass) needs the aliased and package specifiers
18
+ * too, while every other consumer's facts stay exactly as they were.
19
+ */
20
+ moduleSpecifiers?: string[];
13
21
  compiledElementDecorator: boolean;
14
22
  /**
15
23
  * Set when a class decorator spells the `element` intrinsic through
@@ -28,6 +36,31 @@ export interface ModuleSemanticFacts {
28
36
  * (no injected vocabulary) never recognizes another package's factories.
29
37
  */
30
38
  definePage: boolean;
39
+ /**
40
+ * The server function page fact (alpha15 server lane): the first argument
41
+ * of a default-exported `definePage(…)` call when that argument is an
42
+ * identifier resolving to a server function component THIS module
43
+ * declares. A function component never carries a Part Program, so the
44
+ * route cannot be a compiled class page; the host build renders it through
45
+ * the component function. Spread-conditional: absent for class pages and
46
+ * non-page modules. The scan is order-independent (the module's server
47
+ * function components are collected before the page call is judged), so a
48
+ * default export written above its component declaration admits
49
+ * identically. An inline arrow or an unexported local — the shapes whose
50
+ * JSX would otherwise escape to runtime — never records the fact.
51
+ */
52
+ pageComponentName?: string;
53
+ /**
54
+ * The exported functions whose body is a single return of JSX — the
55
+ * server-only TSX function components this module declares (alpha15 server
56
+ * lane). Discovery is structural and deterministic: `export function`
57
+ * declarations (named, not default) with exactly one return statement of a
58
+ * JSX element, or `export const` arrows with a JSX expression body. The
59
+ * fact is the cheap graph-walker face; admission and lowering stay the
60
+ * compile entry's job (`compileServerComponentModule`), which fails closed
61
+ * on everything this scan only reports. Sorted alphabetically.
62
+ */
63
+ serverFunctionComponents: string[];
31
64
  usesExportedTagName: boolean;
32
65
  enhancedForm: boolean;
33
66
  defaultCompiledTag?: string;
@@ -63,6 +96,8 @@ export interface ModuleSemanticsOptions {
63
96
  * the host injects its descriptor.
64
97
  */
65
98
  readonly vocabulary?: readonly ModuleVocabularyDescriptor[];
99
+ /** Collect {@link ModuleSemanticFacts.moduleSpecifiers} (opt-in). */
100
+ readonly collectSpecifiers?: boolean;
66
101
  }
67
102
  /** True when `imported` from `module` is a compile-time-only intrinsic binding. */
68
103
  declare function isCompileTimeOnlyImport(module: string, imported: string): boolean;
@@ -90,6 +125,12 @@ export interface ModuleIntrinsicBindings {
90
125
  isStaticSidecarCallee(expression: ts.Expression): boolean;
91
126
  /** True for a runtime (non-type-only) named import, aliases followed. */
92
127
  isRuntimeNamedImport(localName: string, module: string | readonly string[], imported: string): boolean;
128
+ /**
129
+ * True when the module binds the name itself (top-level local declaration
130
+ * or any import): such a spelling never refers to a platform global. Same
131
+ * top-level-only shadowing discipline the intrinsic resolution uses.
132
+ */
133
+ hasModuleScopeBinding(localName: string): boolean;
93
134
  }
94
135
  /**
95
136
  * The compiler's admitted base classes, in resolution order (alpha.13 I2,
@@ -118,6 +159,20 @@ declare function resolveCanonicalBaseClass(bindings: ModuleIntrinsicBindings, he
118
159
  * another package.
119
160
  */
120
161
  declare function createModuleIntrinsicBindings(sourceFile: ts.SourceFile, options?: SemanticCoreOptions): ModuleIntrinsicBindings;
162
+ /**
163
+ * The exported name of a function declaration / single-declarator variable
164
+ * statement that {@link isExportedServerComponentDeclaration} admitted.
165
+ */
166
+ declare function serverComponentName(statement: ts.Statement): string;
167
+ /**
168
+ * The structural server function component shapes the fact scan reports:
169
+ * a named `export function` whose body is exactly one `return <jsx>` or an
170
+ * `export const` arrow whose expression body is JSX. The compile entry
171
+ * (`compileServerComponentModule`) re-derives the same shapes with
172
+ * fail-closed diagnostics; this scan only answers "is there something to
173
+ * compile here" for the module graph walker.
174
+ */
175
+ declare function isExportedServerComponentDeclaration(statement: ts.Statement): boolean;
121
176
  /**
122
177
  * Parse one module source and report the semantic facts the compiler boundary
123
178
  * and the Vite graph adapters branch on. Pure: it never resolves imports from