@openelement/compiler 1.0.0-alpha.14 → 1.0.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/package.json +4 -2
  2. package/src/compiler.d.ts +12 -6
  3. package/src/compiler.js +11 -6
  4. package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +11 -0
  5. package/src/internal/compiler/compiled-artifact-class-candidates.js +46 -0
  6. package/src/internal/compiler/compiled-artifact-style-requests.d.ts +26 -7
  7. package/src/internal/compiler/compiled-artifact-style-requests.js +57 -9
  8. package/src/internal/compiler/plugin.d.ts +68 -49
  9. package/src/internal/compiler/plugin.js +93 -82
  10. package/src/internal/compiler/semantic-core/analyze-module.d.ts +73 -0
  11. package/src/internal/compiler/semantic-core/analyze-module.js +29 -379
  12. package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
  13. package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
  14. package/src/internal/compiler/semantic-core/diagnostics/index.d.ts +21 -1
  15. package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
  16. package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
  17. package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
  18. package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
  19. package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
  20. package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
  21. package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
  22. package/src/internal/compiler/semantic-core/lower-program.d.ts +220 -0
  23. package/src/internal/compiler/semantic-core/lower-program.js +350 -142
  24. package/src/internal/compiler/semantic-core/module-analysis.d.ts +82 -4
  25. package/src/internal/compiler/semantic-core/module-analysis.js +88 -19
  26. package/src/internal/compiler/semantic-core/parse-module.js +16 -16
  27. package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
  28. package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
  29. package/src/internal/compiler/semantic-core/server-component.d.ts +129 -0
  30. package/src/internal/compiler/semantic-core/server-component.js +587 -0
  31. package/src/internal/compiler/semantic-core/type-check.js +1 -1
  32. package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
  33. package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
  34. package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
  35. package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
  36. package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
  37. package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
  38. package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
  39. package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
  40. package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
  41. package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
  42. package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
  43. package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
  44. package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
  45. package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
  46. package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
  47. package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
  48. package/src/internal/compiler/style-requests.d.ts +35 -7
  49. package/src/internal/compiler/style-requests.js +57 -11
  50. package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
  51. package/src/internal/compiler/tailwind-candidates.js +54 -0
  52. package/src/internal/compiler/semantic-core/compile.d.ts +0 -39
  53. package/src/internal/compiler/semantic-core/compile.js +0 -98
  54. package/src/internal/compiler/semantic-core/emit-module.js +0 -313
  55. package/src/internal/compiler/semantic-core/emit-program.js +0 -121
  56. package/src/internal/compiler/semantic-core/style-imports.js +0 -87
@@ -0,0 +1,129 @@
1
+ import { CompilerFail } from "./compiler-diagnostics.js";
2
+ import { Lowering } from "./lower-program.js";
3
+ import { CompiledElementSourceMap } from "./source-map.js";
4
+ import ts from "typescript";
5
+ import { ProgramTreeNode } from "@openelement/protocol/part-program";
6
+ //#region src/internal/compiler/semantic-core/server-component.d.ts
7
+ /** Authored source with the resolved filename that determines its syntax. */
8
+ export interface ResolvedServerComponentSource {
9
+ readonly fileName: string;
10
+ readonly source: string;
11
+ }
12
+ /** Host-supplied inputs for the server function component compile. */
13
+ export interface ServerComponentCompileOptions {
14
+ /**
15
+ * Resolve one authored import specifier to that module's SOURCE, so a
16
+ * nested server function component composes by direct call to the imported
17
+ * binding (compile-time resolved, deterministic). Absent or returning
18
+ * undefined: importing components from that specifier is a coded rejection.
19
+ * Resolution of specifiers to files stays the host's job — the compiler
20
+ * never reads the filesystem. Supply the resolved filename when resolution
21
+ * can pick a different extension from the authored specifier. A source-only
22
+ * answer uses the specifier as the parser's filename.
23
+ */
24
+ readonly resolveModule?: (specifier: string) => string | ResolvedServerComponentSource | undefined;
25
+ /**
26
+ * The custom-element host tags the host build admitted as @element
27
+ * compiled components: those JSX children ride `__ssr(tag, props)`.
28
+ * Unadmitted hosts (islands, foreign tags) emit their tag as-is.
29
+ */
30
+ readonly compiledTags?: readonly string[];
31
+ }
32
+ /** The compiled server function component module. */
33
+ export interface CompileServerComponentResult {
34
+ /** The generated TS module: verbatim authored content + constructor functions. */
35
+ code: string;
36
+ /** Real Source Map v3 for the generated component functions. */
37
+ map: CompiledElementSourceMap;
38
+ /** The compiled component names, sorted. */
39
+ components: string[];
40
+ /**
41
+ * The statically admitted class tokens (alpha15 S lane), unioned over the
42
+ * compiled components — the host build forwards them to the official
43
+ * Tailwind compiler as explicit candidates.
44
+ */
45
+ classCandidates?: string[];
46
+ }
47
+ /** Resolve the compiler's static source candidates through an asynchronous host. */
48
+ export declare function prepareServerComponentImports(source: string, fileName: string, resolve: (specifier: string) => string | ResolvedServerComponentSource | undefined | Promise<string | ResolvedServerComponentSource | undefined>): Promise<ServerComponentCompileOptions['resolveModule']>;
49
+ /**
50
+ * Compile one authored TSX module's server function components into the
51
+ * generative constructor module. Returns null for modules with no exported
52
+ * JSX-returning function (nothing to admit). Fails closed with a
53
+ * {@link CompiledElementError} carrying the ordered OEC diagnostics.
54
+ */
55
+ export declare function compileServerComponentModule(source: string, fileName: string, options?: ServerComponentCompileOptions): CompileServerComponentResult | null;
56
+ /**
57
+ * The host-build admission bridge: compile `code` through the server function
58
+ * component lane when — and only when — this module belongs to it.
59
+ *
60
+ * - a module carrying a compiled-element decorator (or an unsupported
61
+ * decorator spelling, which the class lane compiles so it fails closed with
62
+ * OEC9027) belongs to the class lane: null;
63
+ * - a module with no admitted server function component and no near-miss
64
+ * exported JSX function has nothing to admit: null;
65
+ * - a near-miss (statements before the return, a block-bodied arrow, or any
66
+ * other exported function/arrow whose body contains JSX but is not the
67
+ * single-return shape) is NOT null: it goes through
68
+ * {@link compileServerComponentModule}, which fails closed with OEC9032.
69
+ * Returning null would hand the authored module to another lane unchanged;
70
+ * - a plain script id never carries the JSX grammar: null;
71
+ * - the cheap `export` + `<` prefilter (the same conservative superset idea
72
+ * the class lane's prefilter uses) keeps plainly inert modules off the
73
+ * parse. A module that does not parse stays null so the host reports the
74
+ * syntax error.
75
+ *
76
+ * Everything else goes through {@link compileServerComponentModule}, whose
77
+ * diagnostics fail the build closed.
78
+ */
79
+ export declare function compileServerComponentIfAdmitted(code: string, id: string, options?: ServerComponentCompileOptions): CompileServerComponentResult | null;
80
+ /**
81
+ * The generated-constructor expression builder: one walk over the lowered
82
+ * tree that turns admitted nodes into `__h`/`__t`/`__ssr`/direct-call code.
83
+ * Static attribute values are compile-time literals; every dynamic value
84
+ * enters through a helper boundary.
85
+ *
86
+ * Code-construction boundary (CodeQL js/bad-code-sanitization #4238, FRM-05):
87
+ * every value this class splices into the generated module is either an
88
+ * `JSON.stringify`-quoted string literal (the ECMAScript QuoteJSONString
89
+ * escaping for a TS string literal) or a name validated by `identifier()`
90
+ * below; ordering-comparison operands are finite numeric literals only
91
+ * (protocol `conditionLiteralAllowed`). The artifact is a standalone TS module
92
+ * returned to the host build's transform — never inlined into HTML — so the
93
+ * query's script-embedding model does not apply. Evidence and the hostile-input
94
+ * regression live in this batch's REL-02 CodeQL disposition record and in the
95
+ * server-component-codegen-boundary regression test.
96
+ */
97
+ declare class ConstructorEmitter {
98
+ private readonly sf;
99
+ private readonly lowering;
100
+ private readonly parameter;
101
+ private readonly fail;
102
+ constructor(sf: ts.SourceFile, lowering: Lowering, parameter: string, fail: CompilerFail);
103
+ /**
104
+ * The codegen identifier boundary: every lowering-produced name the emitter
105
+ * splices into an IDENTIFIER position of the generated module
106
+ * (`props.<signal>`, `item.<field>`, the component binding) must be a plain
107
+ * ES identifier. Anything else would leave its slot and inject arbitrary
108
+ * source into the artifact, so a non-identifier fails the compile CLOSED —
109
+ * same diagnostic shape as the lowering's own "must be a plain identifier"
110
+ * refusals, never a silent fallback or a dropped sink. The lowering
111
+ * validates most names on the way in; this is the one boundary every
112
+ * emitted name passes, so a future lowering change cannot silently widen
113
+ * the splice.
114
+ */
115
+ private identifier;
116
+ emit(root: ProgramTreeNode): string;
117
+ private sinksOf;
118
+ /**
119
+ * The slot-name expression for one child of a `__ssr` host: the child's
120
+ * static `slot` attribute as a literal, else its dynamic attr sink named
121
+ * `slot` (the same props read the emitted attribute takes), else `''` — the
122
+ * default slot. Text and Part children are always default-slot: the class
123
+ * path's own `slotNameOf` reads exactly these sources.
124
+ */
125
+ private slotNameExpressionOf;
126
+ private conditionText;
127
+ private node;
128
+ }
129
+ //#endregion