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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +3 -2
  2. package/src/compiler.d.ts +8 -6
  3. package/src/compiler.js +7 -6
  4. package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +5 -30
  5. package/src/internal/compiler/compiled-artifact-class-candidates.js +18 -32
  6. package/src/internal/compiler/compiled-artifact-style-requests.d.ts +9 -7
  7. package/src/internal/compiler/compiled-artifact-style-requests.js +9 -7
  8. package/src/internal/compiler/plugin.d.ts +31 -50
  9. package/src/internal/compiler/plugin.js +41 -108
  10. package/src/internal/compiler/semantic-core/analyze-module.d.ts +1 -45
  11. package/src/internal/compiler/semantic-core/analyze-module.js +10 -405
  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/expression-lowering.js +469 -0
  15. package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
  16. package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
  17. package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
  18. package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
  19. package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
  20. package/src/internal/compiler/semantic-core/lower-program.d.ts +51 -0
  21. package/src/internal/compiler/semantic-core/lower-program.js +186 -90
  22. package/src/internal/compiler/semantic-core/module-analysis.d.ts +28 -5
  23. package/src/internal/compiler/semantic-core/module-analysis.js +16 -17
  24. package/src/internal/compiler/semantic-core/parse-module.js +16 -16
  25. package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
  26. package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
  27. package/src/internal/compiler/semantic-core/server-component.d.ts +22 -7
  28. package/src/internal/compiler/semantic-core/server-component.js +163 -57
  29. package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
  30. package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
  31. package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
  32. package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
  33. package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
  34. package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
  35. package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
  36. package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
  37. package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
  38. package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
  39. package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
  40. package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
  41. package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
  42. package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
  43. package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
  44. package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
  45. package/src/internal/compiler/style-requests.d.ts +0 -8
  46. package/src/internal/compiler/style-requests.js +1 -14
  47. package/src/internal/compiler/semantic-core/compile.d.ts +0 -47
  48. package/src/internal/compiler/semantic-core/compile.js +0 -100
  49. package/src/internal/compiler/semantic-core/emit-module.js +0 -317
  50. package/src/internal/compiler/semantic-core/emit-program.js +0 -141
  51. package/src/internal/compiler/semantic-core/style-imports.js +0 -87
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openelement/compiler",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.16",
4
4
  "type": "module",
5
5
  "main": "./src/compiler.js",
6
6
  "types": "./src/compiler.d.ts",
@@ -30,6 +30,7 @@
30
30
  "compiler",
31
31
  "tsx",
32
32
  "vite",
33
+ "vite-plugin",
33
34
  "part-program"
34
35
  ],
35
36
  "engines": {
@@ -45,7 +46,7 @@
45
46
  }
46
47
  },
47
48
  "dependencies": {
48
- "@openelement/protocol": "1.0.0-alpha.15",
49
+ "@openelement/protocol": "1.0.0-alpha.16",
49
50
  "typescript": "6.0.3"
50
51
  }
51
52
  }
package/src/compiler.d.ts CHANGED
@@ -1,13 +1,15 @@
1
- import { ModuleSemanticFacts, ModuleSemanticsOptions, ModuleVocabularyDescriptor, SemanticCoreOptions, StaticSidecarDescriptor, analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
2
1
  import { PluginDiagnosticError, clearCompilerDiagnostics, compilerDiagnosticsToEnvelopes, diagnosticPluginError, recordCompilerDiagnostics, takeCompilerDiagnostics } from "./internal/compiler/semantic-core/diagnostics/index.js";
3
2
  import { CompiledElementError, ElementCompilerDiagnostic } from "./internal/compiler/semantic-core/compiler-diagnostics.js";
4
- import { CompileElementResult, compileElementProgram } from "./internal/compiler/semantic-core/compile.js";
3
+ import { CompileServerComponentResult, ResolvedServerComponentSource, ServerComponentCompileOptions, compileServerComponentIfAdmitted, compileServerComponentModule, prepareServerComponentImports } from "./internal/compiler/semantic-core/server-component.js";
4
+ import { GeneratedElementSite } from "./internal/compiler/semantic-ir/generated-element/contract.js";
5
5
  import { ClassCandidateRegistry, createClassCandidateRegistry } from "./internal/compiler/tailwind-candidates.js";
6
- import { compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, registerStyleEdges, stableModuleId, stripInlineSourceMapComment } from "./internal/compiler/plugin.js";
6
+ import { compiledElementPlugin, registerStyleEdges, stableModuleId } from "./internal/compiler/plugin.js";
7
+ import { isJsxModuleId } from "./internal/compiler/semantic-core/jsx-module-id.js";
7
8
  import { compiledArtifactStyleRequests, readCompiledArtifactStyles } from "./internal/compiler/compiled-artifact-style-requests.js";
8
9
  import { compiledArtifactClassCandidates } from "./internal/compiler/compiled-artifact-class-candidates.js";
9
- import { CompileServerComponentResult, ServerComponentCompileOptions, compileServerComponentIfAdmitted, compileServerComponentModule } from "./internal/compiler/semantic-core/server-component.js";
10
- import { RegisteredStyleRequest, clearStyleRequests, getStyleRequest, hasStyleImporter, lightRootScopeTag, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter } from "./internal/compiler/style-requests.js";
10
+ import { compileGeneratedElementIfAdmitted } from "./internal/compiler/semantic-ir/generated-element/compile.js";
11
+ import { ModuleSemanticFacts, ModuleSemanticsOptions, ModuleVocabularyDescriptor, SemanticCoreOptions, StaticSidecarDescriptor, analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
12
+ import { RegisteredStyleRequest, clearStyleRequests, getStyleRequest, hasStyleImporter, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter } from "./internal/compiler/style-requests.js";
11
13
  import { EmittedModuleDiagnostic, EmittedModuleTypeCheckOptions, emittedModuleTypeChecks, typeCheckEmittedModule } from "./internal/compiler/semantic-core/type-check.js";
12
14
  import { validatePartProgram } from "@openelement/protocol/part-program";
13
- export { type ClassCandidateRegistry, type CompileElementResult, type CompileServerComponentResult, CompiledElementError, type ElementCompilerDiagnostic, type EmittedModuleDiagnostic, type EmittedModuleTypeCheckOptions, type ModuleSemanticFacts, type ModuleSemanticsOptions, type ModuleVocabularyDescriptor, type PluginDiagnosticError, type RegisteredStyleRequest, type SemanticCoreOptions, type ServerComponentCompileOptions, type StaticSidecarDescriptor, analyzeModuleSemantics, clearCompilerDiagnostics, clearStyleRequests, compileElementModule, compileElementProgram, compileServerComponentIfAdmitted, compileServerComponentModule, compiledArtifactClassCandidates, compiledArtifactStyleRequests, compiledElementPlugin, compilerDiagnosticsToEnvelopes, createClassCandidateRegistry, diagnosticPluginError, emittedModuleTypeChecks, getStyleRequest, hasElementDecoratorApplication, hasStyleImporter, isCompiledElementModule, lightRootScopeTag, readCompiledArtifactStyles, recordCompilerDiagnostics, registerStyleEdges, registerStyleRequest, stableModuleId, stripInlineSourceMapComment, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter, takeCompilerDiagnostics, typeCheckEmittedModule, validatePartProgram };
15
+ export { type ClassCandidateRegistry, type CompileServerComponentResult, CompiledElementError, type ElementCompilerDiagnostic, type EmittedModuleDiagnostic, type EmittedModuleTypeCheckOptions, type GeneratedElementSite, type ModuleSemanticFacts, type ModuleSemanticsOptions, type ModuleVocabularyDescriptor, type PluginDiagnosticError, type RegisteredStyleRequest, type ResolvedServerComponentSource, type SemanticCoreOptions, type ServerComponentCompileOptions, type StaticSidecarDescriptor, analyzeModuleSemantics, clearCompilerDiagnostics, clearStyleRequests, compileGeneratedElementIfAdmitted, compileServerComponentIfAdmitted, compileServerComponentModule, compiledArtifactClassCandidates, compiledArtifactStyleRequests, compiledElementPlugin, compilerDiagnosticsToEnvelopes, createClassCandidateRegistry, diagnosticPluginError, emittedModuleTypeChecks, getStyleRequest, hasStyleImporter, isJsxModuleId, prepareServerComponentImports, readCompiledArtifactStyles, recordCompilerDiagnostics, registerStyleEdges, registerStyleRequest, stableModuleId, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter, takeCompilerDiagnostics, typeCheckEmittedModule, validatePartProgram };
package/src/compiler.js CHANGED
@@ -1,13 +1,14 @@
1
- import { analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
2
1
  import { clearCompilerDiagnostics, compilerDiagnosticsToEnvelopes, diagnosticPluginError, recordCompilerDiagnostics, takeCompilerDiagnostics } from "./internal/compiler/semantic-core/diagnostics/index.js";
3
2
  import { CompiledElementError } from "./internal/compiler/semantic-core/compiler-diagnostics.js";
4
- import { compileElementProgram } from "./internal/compiler/semantic-core/compile.js";
5
- import { compileServerComponentIfAdmitted, compileServerComponentModule } from "./internal/compiler/semantic-core/server-component.js";
3
+ import { isJsxModuleId } from "./internal/compiler/semantic-core/jsx-module-id.js";
4
+ import { analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
5
+ import { compileServerComponentIfAdmitted, compileServerComponentModule, prepareServerComponentImports } from "./internal/compiler/semantic-core/server-component.js";
6
+ import { compileGeneratedElementIfAdmitted } from "./internal/compiler/semantic-ir/generated-element/compile.js";
6
7
  import { emittedModuleTypeChecks, typeCheckEmittedModule } from "./internal/compiler/semantic-core/type-check.js";
7
8
  import { compiledArtifactClassCandidates } from "./internal/compiler/compiled-artifact-class-candidates.js";
8
9
  import { compiledArtifactStyleRequests, readCompiledArtifactStyles } from "./internal/compiler/compiled-artifact-style-requests.js";
9
- import { clearStyleRequests, getStyleRequest, hasStyleImporter, lightRootScopeTag, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter } from "./internal/compiler/style-requests.js";
10
- import { compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, registerStyleEdges, stableModuleId, stripInlineSourceMapComment } from "./internal/compiler/plugin.js";
10
+ import { clearStyleRequests, getStyleRequest, hasStyleImporter, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter } from "./internal/compiler/style-requests.js";
11
+ import { compiledElementPlugin, registerStyleEdges, stableModuleId } from "./internal/compiler/plugin.js";
11
12
  import { createClassCandidateRegistry } from "./internal/compiler/tailwind-candidates.js";
12
13
  import { validatePartProgram } from "@openelement/protocol/part-program";
13
- export { CompiledElementError, analyzeModuleSemantics, clearCompilerDiagnostics, clearStyleRequests, compileElementModule, compileElementProgram, compileServerComponentIfAdmitted, compileServerComponentModule, compiledArtifactClassCandidates, compiledArtifactStyleRequests, compiledElementPlugin, compilerDiagnosticsToEnvelopes, createClassCandidateRegistry, diagnosticPluginError, emittedModuleTypeChecks, getStyleRequest, hasElementDecoratorApplication, hasStyleImporter, isCompiledElementModule, lightRootScopeTag, readCompiledArtifactStyles, recordCompilerDiagnostics, registerStyleEdges, registerStyleRequest, stableModuleId, stripInlineSourceMapComment, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter, takeCompilerDiagnostics, typeCheckEmittedModule, validatePartProgram };
14
+ export { CompiledElementError, analyzeModuleSemantics, clearCompilerDiagnostics, clearStyleRequests, compileGeneratedElementIfAdmitted, compileServerComponentIfAdmitted, compileServerComponentModule, compiledArtifactClassCandidates, compiledArtifactStyleRequests, compiledElementPlugin, compilerDiagnosticsToEnvelopes, createClassCandidateRegistry, diagnosticPluginError, emittedModuleTypeChecks, getStyleRequest, hasStyleImporter, isJsxModuleId, prepareServerComponentImports, readCompiledArtifactStyles, recordCompilerDiagnostics, registerStyleEdges, registerStyleRequest, stableModuleId, styleEdgesForFile, styleRequestFile, styleRequestModuleId, styleRequestsForImporter, takeCompilerDiagnostics, typeCheckEmittedModule, validatePartProgram };
@@ -1,36 +1,11 @@
1
1
  //#region src/internal/compiler/compiled-artifact-class-candidates.d.ts
2
- /**
3
- * The class-candidate facts of an already-compiled artifact module (alpha15 S
4
- * lane, S5-B).
5
- *
6
- * Packages ship the compiler's OWN emitted modules. A consumer build that
7
- * resolves one has no authored grammar left to compile, yet the module's
8
- * statically admitted class tokens are exactly the fact the component
9
- * stylesheet needs — they were proven when the package was compiled, and
10
- * re-deriving them from the shipped markup would mean a second parser. The
11
- * compiler therefore emits them as an explicit static
12
- * (`static __oeClassCandidates: readonly string[] = [...]`, alongside the
13
- * `__oeUtilityClasses` flag it has always emitted for shadow-root
14
- * components), and this module recovers them from the artifact text — the
15
- * same second-input shape as the style-edge recovery
16
- * (compiled-artifact-style-requests.ts).
17
- *
18
- * All-or-nothing per module: a candidates member that is not an array of
19
- * string literals is not adopted, so a module outside the emitted shape keeps
20
- * riding the graph's normal channels exactly as before. Never throws, never
21
- * guesses: an artifact without the member contributes nothing.
22
- *
23
- * Root scope is structural: the compiler emits the member ONLY for
24
- * shadow-root components with admitted candidates (light-root candidates never
25
- * need the shadow sheet), so a recovered member is by construction a
26
- * shadow-root fact.
27
- */
2
+ /** Recover the compiler's shadow stylesheet candidates from a packed module. */
3
+ /** Package staging appends the compiler's candidates to the distributable JS. */
4
+ declare function encodeCompiledArtifactClassCandidates(candidates: readonly string[]): string;
28
5
  /**
29
6
  * The admitted class candidates of one compiled artifact module, or undefined
30
- * when the module does not carry the emitted fact. Tolerates both artifact
31
- * forms the pack pipeline produces (the compiler's raw TypeScript emission and
32
- * the packed, type-stripped module) — the parse is ScriptKind.TSX for exactly
33
- * the reason the style-edge recovery documents.
7
+ * when the module does not carry the emitted fact. Generated elements carry
8
+ * a build-only footer, and compiled classes carry their literal static member.
34
9
  */
35
10
  export declare function compiledArtifactClassCandidates(source: string, fileName: string): readonly string[] | undefined;
36
11
  //#endregion
@@ -1,44 +1,30 @@
1
1
  import { typescriptParser } from "./semantic-core/parse-module.js";
2
2
  import ts from "typescript";
3
3
  //#region src/internal/compiler/compiled-artifact-class-candidates.ts
4
- /**
5
- * The class-candidate facts of an already-compiled artifact module (alpha15 S
6
- * lane, S5-B).
7
- *
8
- * Packages ship the compiler's OWN emitted modules. A consumer build that
9
- * resolves one has no authored grammar left to compile, yet the module's
10
- * statically admitted class tokens are exactly the fact the component
11
- * stylesheet needs — they were proven when the package was compiled, and
12
- * re-deriving them from the shipped markup would mean a second parser. The
13
- * compiler therefore emits them as an explicit static
14
- * (`static __oeClassCandidates: readonly string[] = [...]`, alongside the
15
- * `__oeUtilityClasses` flag it has always emitted for shadow-root
16
- * components), and this module recovers them from the artifact text — the
17
- * same second-input shape as the style-edge recovery
18
- * (compiled-artifact-style-requests.ts).
19
- *
20
- * All-or-nothing per module: a candidates member that is not an array of
21
- * string literals is not adopted, so a module outside the emitted shape keeps
22
- * riding the graph's normal channels exactly as before. Never throws, never
23
- * guesses: an artifact without the member contributes nothing.
24
- *
25
- * Root scope is structural: the compiler emits the member ONLY for
26
- * shadow-root components with admitted candidates (light-root candidates never
27
- * need the shadow sheet), so a recovered member is by construction a
28
- * shadow-root fact.
29
- */
30
- /** The emitted static's member name (the cheap prefilter and the lookup key). */
4
+ /** Recover the compiler's shadow stylesheet candidates from a packed module. */
31
5
  const CANDIDATE_MEMBER_NAME = "__oeClassCandidates";
6
+ const GENERATED_CANDIDATE_FOOTER = "// openElement:class-candidates ";
7
+ function generatedCandidateFooter(source, file) {
8
+ const lastComment = ts.getLeadingCommentRanges(source, file.endOfFileToken.getFullStart())?.at(-1);
9
+ if (lastComment?.kind !== ts.SyntaxKind.SingleLineCommentTrivia || !source.startsWith(GENERATED_CANDIDATE_FOOTER, lastComment.pos) || source.slice(lastComment.end).trim() !== "") return;
10
+ return source.slice(lastComment.pos + 32, lastComment.end);
11
+ }
12
+ function decodeGeneratedCandidates(footer) {
13
+ try {
14
+ const value = JSON.parse(footer);
15
+ if (Array.isArray(value) && value.length > 0 && value.every((candidate) => typeof candidate === "string" && /^\S+$/u.test(candidate))) return value;
16
+ } catch {}
17
+ }
32
18
  /**
33
19
  * The admitted class candidates of one compiled artifact module, or undefined
34
- * when the module does not carry the emitted fact. Tolerates both artifact
35
- * forms the pack pipeline produces (the compiler's raw TypeScript emission and
36
- * the packed, type-stripped module) — the parse is ScriptKind.TSX for exactly
37
- * the reason the style-edge recovery documents.
20
+ * when the module does not carry the emitted fact. Generated elements carry
21
+ * a build-only footer, and compiled classes carry their literal static member.
38
22
  */
39
23
  function compiledArtifactClassCandidates(source, fileName) {
40
- if (!source.includes(CANDIDATE_MEMBER_NAME)) return void 0;
24
+ if (!source.includes(CANDIDATE_MEMBER_NAME) && !source.includes(GENERATED_CANDIDATE_FOOTER)) return;
41
25
  const { sourceFile: sf } = typescriptParser.parseModule(source, fileName);
26
+ const footer = generatedCandidateFooter(source, sf);
27
+ if (footer !== void 0) return decodeGeneratedCandidates(footer);
42
28
  let found;
43
29
  const visit = (node) => {
44
30
  if (found !== void 0) return;
@@ -16,13 +16,15 @@
16
16
  * ".../open-button.css"`), because a workspace build compiled the `.tsx`
17
17
  * source and never needed the artifact path.
18
18
  *
19
- * The accepted shape is the ONE style authoring grammar
20
- * (semantic-core/style-imports.ts): a relative `.css` default import arrayed
21
- * in the class's `static styles`. The extraction here is deliberately the
22
- * PERMISSIVE read of that shape: it claims exactly the relative `.css`
23
- * default imports arrayed as plain bindings, and leaves every other member of
24
- * a `static styles` array untouched. Artifacts compiled before #1558
25
- * (legacy inline sheets that referenced a `StyleSheet` built in a plain
19
+ * The accepted shape is the `.css` default-import-arrayed-in-`static styles`
20
+ * form the retired class grammar admitted: a relative `.css` default import
21
+ * claimed by a `static styles` member. This read outlives that grammar
22
+ * deliberately — artifacts already shipped in the packed form carry it, and a
23
+ * packed consumer has no authored source to recompile. The extraction is
24
+ * deliberately PERMISSIVE about that shape: it claims exactly the relative
25
+ * `.css` default imports arrayed as plain bindings, and leaves every other
26
+ * member of a `static styles` array untouched. Artifacts compiled before
27
+ * #1558 (legacy inline sheets that referenced a `StyleSheet` built in a plain
26
28
  * module) therefore keep riding the old path unchanged — a strict admission
27
29
  * here would break every previously-published package for no protocol gain.
28
30
  *
@@ -18,13 +18,15 @@ import ts from "typescript";
18
18
  * ".../open-button.css"`), because a workspace build compiled the `.tsx`
19
19
  * source and never needed the artifact path.
20
20
  *
21
- * The accepted shape is the ONE style authoring grammar
22
- * (semantic-core/style-imports.ts): a relative `.css` default import arrayed
23
- * in the class's `static styles`. The extraction here is deliberately the
24
- * PERMISSIVE read of that shape: it claims exactly the relative `.css`
25
- * default imports arrayed as plain bindings, and leaves every other member of
26
- * a `static styles` array untouched. Artifacts compiled before #1558
27
- * (legacy inline sheets that referenced a `StyleSheet` built in a plain
21
+ * The accepted shape is the `.css` default-import-arrayed-in-`static styles`
22
+ * form the retired class grammar admitted: a relative `.css` default import
23
+ * claimed by a `static styles` member. This read outlives that grammar
24
+ * deliberately — artifacts already shipped in the packed form carry it, and a
25
+ * packed consumer has no authored source to recompile. The extraction is
26
+ * deliberately PERMISSIVE about that shape: it claims exactly the relative
27
+ * `.css` default imports arrayed as plain bindings, and leaves every other
28
+ * member of a `static styles` array untouched. Artifacts compiled before
29
+ * #1558 (legacy inline sheets that referenced a `StyleSheet` built in a plain
28
30
  * module) therefore keep riding the old path unchanged — a strict admission
29
31
  * here would break every previously-published package for no protocol gain.
30
32
  *
@@ -1,43 +1,8 @@
1
- import { SemanticCoreOptions, StaticSidecarDescriptor } from "./semantic-core/module-analysis.js";
2
- import { CompileElementResult } from "./semantic-core/compile.js";
1
+ import { ResolvedServerComponentSource } from "./semantic-core/server-component.js";
2
+ import { GeneratedElementSite } from "./semantic-ir/generated-element/contract.js";
3
3
  import { ClassCandidateRegistry } from "./tailwind-candidates.js";
4
4
  import { Plugin } from "vite";
5
5
  //#region src/internal/compiler/plugin.d.ts
6
- /**
7
- * Cheap first stage only — NOT a recognizer. The match keeps plain modules off
8
- * the AST path and may false-positive (any '@' — inside a string literal,
9
- * comment, or import specifier — matches); binding provenance and admission
10
- * are decided exclusively by the semantic core.
11
- */
12
- export declare function isCompiledElementModule(code: string, id: string): boolean;
13
- /**
14
- * Precise second stage behind the prefilter: a canonically bound
15
- * `@element(...)` decorator application on a class declaration (provenance
16
- * decided by the semantic core's intrinsic-binding model). Modules that only
17
- * mention the marker in a string literal or comment, or spell it through a
18
- * foreign/local binding, do not reach the compiler.
19
- */
20
- export declare function hasElementDecoratorApplication(code: string, id: string): boolean;
21
- /**
22
- * Compile one opted-in module without binding the caller to Vite. The core
23
- * adapter hook and the inline SSR/client builds all use this same function,
24
- * which prevents duplicate compiler implementations from drifting. Returns
25
- * null for modules without a canonically bound @element decorator
26
- * application, so marker-mentioning and foreign-binding modules pass through
27
- * untouched. Modules whose @element spelling carries unsupported or ambiguous
28
- * provenance are compiled anyway so the compiler boundary fails closed with
29
- * the OEC9027 provenance diagnostic. `options.staticSidecars` admits
30
- * host-declared sidecar policy statements; the default core admits none.
31
- */
32
- export declare function compileElementModule(code: string, id: string, options?: SemanticCoreOptions): CompileElementResult | null;
33
- /**
34
- * Strip the inline map comment from a compiled module at the Vite boundary.
35
- * The core artifact embeds its real Source Map v3 inline for standalone
36
- * consumers; the Vite transform returns that same map as its `map` output so
37
- * Vite composes it with the rest of the pipeline — leaving the comment in the
38
- * served code would create a second, conflicting map story (#1210).
39
- */
40
- export declare function stripInlineSourceMapComment(code: string): string;
41
6
  /**
42
7
  * Compile-time source identity for a module: absolute Vite ids are converted
43
8
  * to project-relative POSIX paths so Part Program `metadata.sourceFile` and
@@ -73,13 +38,6 @@ export interface CompiledElementPluginOptions {
73
38
  typeCheckEmitted?: boolean;
74
39
  /** Specifier → candidate files map used when `typeCheckEmitted` is on. */
75
40
  resolutionPaths?: Record<string, string[]>;
76
- /**
77
- * Static-sidecar descriptors the host application admits into the compiled
78
- * module grammar (e.g. its island delivery policy factory). The default
79
- * core knows none: without an injected descriptor a module carrying a
80
- * sidecar policy statement fails closed with OEC9008.
81
- */
82
- staticSidecars?: readonly StaticSidecarDescriptor[];
83
41
  /**
84
42
  * The class-candidate registry this plugin instance writes its compiled
85
43
  * modules' statically admitted class tokens into (alpha15 S lane). The
@@ -92,20 +50,39 @@ export interface CompiledElementPluginOptions {
92
50
  /**
93
51
  * Host-supplied resolver for the server function component lane's nested
94
52
  * imports (`resolveModule` of {@link compileServerComponentModule}): given
95
- * a specifier and the importing module id, return that module's SOURCE so
53
+ * a specifier and the importing module id, return that module's source so
96
54
  * a nested server function component composes by direct call. Omitting it
97
55
  * (or answering undefined) keeps nested composition a coded rejection.
98
56
  * The compiler itself never reads the filesystem — resolution stays the
99
57
  * host's job, so this option carries the host's capability rather than a
100
- * path convention.
58
+ * path convention. The third argument resolves a specifier in the active
59
+ * Vite environment with the actual importing id.
101
60
  */
102
- resolveServerComponentModule?: (specifier: string, importer: string) => string | null;
61
+ resolveServerComponentModule?: (specifier: string, importer: string, resolve: (specifier: string) => Promise<{
62
+ id: string;
63
+ external?: boolean | 'absolute' | 'relative';
64
+ } | null>) => string | ResolvedServerComponentSource | null | undefined | Promise<string | ResolvedServerComponentSource | null | undefined>;
103
65
  /**
104
66
  * The custom-element host tags the host build admitted as @element compiled
105
67
  * components: JSX children in a server function component ride
106
68
  * `__ssr(tag, props)` for those tags and an emitted-as-is tag otherwise.
107
69
  */
108
70
  compiledTags?: readonly string[];
71
+ /**
72
+ * Host-supplied site fact for the generated Native Custom Element lane
73
+ * (M09-1b): return `{ tag }` for a module the host resolved as an island
74
+ * whose registration tag is already decided, and null for every other
75
+ * module. Returning null (or omitting the option) keeps the lane inert and
76
+ * the module with the class/server/passthrough lanes.
77
+ *
78
+ * This is a host capability, never author syntax: the compiler transform
79
+ * runs before the island transform, so the tag cannot be derived here. The
80
+ * router supplies the one production closure
81
+ * (`createGeneratedElementSiteResolver`); the lane itself still requires the
82
+ * island sidecar and a local default-exported function component, and fails
83
+ * closed on a props parameter or a required host binding.
84
+ */
85
+ generatedElementSite?: (moduleId: string) => GeneratedElementSite | null;
109
86
  }
110
87
  /**
111
88
  * Register one module's style edges (the registry's one write path, S-C1.4).
@@ -125,9 +102,13 @@ export declare function registerStyleEdges(id: string, specifiers: readonly stri
125
102
  /**
126
103
  * The `open:compiled-element` Vite plugin: runs at `enforce: 'pre'` so the
127
104
  * compiler sees authored TSX before Vite's own TS/JSX lowering, compiles every
128
- * module with a canonically bound `@element` decorator, and leaves all other
129
- * modules untouched. `workspaceRoot` anchors generated source-map ids for
130
- * linked workspace packages.
105
+ * module one of the two admission lanes owns, and leaves all other modules
106
+ * untouched. `workspaceRoot` anchors generated source-map ids for linked
107
+ * workspace packages.
108
+ *
109
+ * The generated-element site option is a host capability (M09-1b): hosts that
110
+ * resolve islands before the compiler transform supply the tag fact; hosts
111
+ * that do not (a plain standalone build) omit it and the lane stays inert.
131
112
  */
132
113
  export declare function compiledElementPlugin(options?: CompiledElementPluginOptions): Plugin;
133
114
  //#endregion
@@ -1,88 +1,13 @@
1
- import { analyzeModuleSemantics } from "./semantic-core/module-analysis.js";
2
1
  import { diagnosticPluginError, recordCompilerDiagnostics } from "./semantic-core/diagnostics/index.js";
3
2
  import { CompiledElementError } from "./semantic-core/compiler-diagnostics.js";
4
- import { compileElementProgram } from "./semantic-core/compile.js";
5
- import { compileServerComponentIfAdmitted } from "./semantic-core/server-component.js";
3
+ import { compileServerComponentIfAdmitted, prepareServerComponentImports } from "./semantic-core/server-component.js";
4
+ import { compileGeneratedElementIfAdmitted } from "./semantic-ir/generated-element/compile.js";
6
5
  import { typeCheckEmittedModule } from "./semantic-core/type-check.js";
7
6
  import { compiledArtifactClassCandidates } from "./compiled-artifact-class-candidates.js";
8
7
  import { readCompiledArtifactStyles } from "./compiled-artifact-style-requests.js";
9
- import { lightRootScopeTag, registerStyleRequest, styleRequestFile, styleRequestModuleId } from "./style-requests.js";
8
+ import { registerStyleRequest, styleRequestFile, styleRequestModuleId } from "./style-requests.js";
10
9
  //#region src/internal/compiler/plugin.ts
11
10
  /**
12
- * The cheap first stage — NOT a recognizer.
13
- *
14
- * It answers one question: could this module be a compiled element module? The
15
- * one grammar-independent fact every authored form shares is the '@' character
16
- * of its decorator application. Every spelling of the authored form contains
17
- * it — `@element(...)`, an aliased binding (`import { element as
18
- * defineElement }` with `@defineElement(...)`), a Unicode alias
19
- * (`import { element as 元件 }` with `@元件(...)`) — and so does every spelling
20
- * the semantic layer REJECTS but must still see in order to fail closed with
21
- * its provenance diagnostic (the namespace form, OEC9027). JavaScript lexing
22
- * makes any finer shape un-modelable in a prefilter: identifiers are not ASCII
23
- * (Unicode aliases are legal), and the lexer skips comments, so a block comment
24
- * between the decorator name and its argument list is a legal decorator
25
- * application no identifier-shaped regex admits.
26
- *
27
- * The stages this replaced modeled the decorator-application SHAPE — a literal
28
- * `@element(` substring, then an ASCII-identifier-plus-whitespace regex — and
29
- * therefore answered "does this module spell the decorator this way?" instead
30
- * of "could this module be a compiled element module?", narrowing the CONTRACT
31
- * rather than the AST path: legal spellings the semantic core admits never
32
- * reached the layer that admits them. Admission has exactly one authority; a
33
- * prefilter may only decide whether a module is worth parsing. A false positive
34
- * here (any '@' in a string literal, comment, or import specifier) costs one
35
- * parse and nothing else; a false negative hides a legal module from its only
36
- * admission authority.
37
- */
38
- const SUPPORTED_MODULE_ID = /\.tsx(?:\?|$)/;
39
- /**
40
- * Cheap first stage only — NOT a recognizer. The match keeps plain modules off
41
- * the AST path and may false-positive (any '@' — inside a string literal,
42
- * comment, or import specifier — matches); binding provenance and admission
43
- * are decided exclusively by the semantic core.
44
- */
45
- function isCompiledElementModule(code, id) {
46
- return SUPPORTED_MODULE_ID.test(id) && code.includes("@");
47
- }
48
- /**
49
- * Precise second stage behind the prefilter: a canonically bound
50
- * `@element(...)` decorator application on a class declaration (provenance
51
- * decided by the semantic core's intrinsic-binding model). Modules that only
52
- * mention the marker in a string literal or comment, or spell it through a
53
- * foreign/local binding, do not reach the compiler.
54
- */
55
- function hasElementDecoratorApplication(code, id) {
56
- return analyzeModuleSemantics(code, id).compiledElementDecorator;
57
- }
58
- /**
59
- * Compile one opted-in module without binding the caller to Vite. The core
60
- * adapter hook and the inline SSR/client builds all use this same function,
61
- * which prevents duplicate compiler implementations from drifting. Returns
62
- * null for modules without a canonically bound @element decorator
63
- * application, so marker-mentioning and foreign-binding modules pass through
64
- * untouched. Modules whose @element spelling carries unsupported or ambiguous
65
- * provenance are compiled anyway so the compiler boundary fails closed with
66
- * the OEC9027 provenance diagnostic. `options.staticSidecars` admits
67
- * host-declared sidecar policy statements; the default core admits none.
68
- */
69
- function compileElementModule(code, id, options = {}) {
70
- if (!isCompiledElementModule(code, id)) return null;
71
- const facts = analyzeModuleSemantics(code, id);
72
- if (!facts.compiledElementDecorator && facts.unsupportedElementDecorator === void 0) return null;
73
- return compileElementProgram(code, id, options);
74
- }
75
- /**
76
- * Strip the inline map comment from a compiled module at the Vite boundary.
77
- * The core artifact embeds its real Source Map v3 inline for standalone
78
- * consumers; the Vite transform returns that same map as its `map` output so
79
- * Vite composes it with the rest of the pipeline — leaving the comment in the
80
- * served code would create a second, conflicting map story (#1210).
81
- */
82
- function stripInlineSourceMapComment(code) {
83
- return code.replace(/\n\/\/# sourceMappingURL=data:application\/json;base64,[^\n]*(?=\n?$)/, "");
84
- }
85
- /**
86
11
  * Compile-time source identity for a module: absolute Vite ids are converted
87
12
  * to project-relative POSIX paths so Part Program `metadata.sourceFile` and
88
13
  * `sourceMap.file` never embed the build machine's path. Module resolution,
@@ -109,6 +34,18 @@ function stableModuleId(file, root, workspaceRoot) {
109
34
  return clean;
110
35
  }
111
36
  /**
37
+ * The SCOPE of a generated element's class candidates: a shadow descriptor root
38
+ * needs the component stylesheet, a light (or absent) root does not.
39
+ *
40
+ * The site fact the transform received is the host's admission decision, and it
41
+ * carries the root the shell will create. Reading it here — rather than assuming
42
+ * light, the pre-P-1 default — is what keeps a shadow generated island's
43
+ * utilities in the sheet that can actually reach them.
44
+ */
45
+ function generatedSiteRootIsShadow(site) {
46
+ return site?.root === "shadow";
47
+ }
48
+ /**
112
49
  * Register one module's style edges (the registry's one write path, S-C1.4).
113
50
  *
114
51
  * The importing component's root scope is part of every edge it registers
@@ -134,11 +71,18 @@ function registerStyleEdges(id, specifiers, scopeTag) {
134
71
  /**
135
72
  * The `open:compiled-element` Vite plugin: runs at `enforce: 'pre'` so the
136
73
  * compiler sees authored TSX before Vite's own TS/JSX lowering, compiles every
137
- * module with a canonically bound `@element` decorator, and leaves all other
138
- * modules untouched. `workspaceRoot` anchors generated source-map ids for
139
- * linked workspace packages.
74
+ * module one of the two admission lanes owns, and leaves all other modules
75
+ * untouched. `workspaceRoot` anchors generated source-map ids for linked
76
+ * workspace packages.
77
+ *
78
+ * The generated-element site option is a host capability (M09-1b): hosts that
79
+ * resolve islands before the compiler transform supply the tag fact; hosts
80
+ * that do not (a plain standalone build) omit it and the lane stays inert.
140
81
  */
141
82
  function compiledElementPlugin(options = {}) {
83
+ return createCompiledElementPlugin(options);
84
+ }
85
+ function createCompiledElementPlugin(options = {}) {
142
86
  let viteRoot;
143
87
  const workspaceRoot = options.workspaceRoot;
144
88
  return {
@@ -147,24 +91,27 @@ function compiledElementPlugin(options = {}) {
147
91
  viteRoot = config.root;
148
92
  },
149
93
  enforce: "pre",
150
- transform(code, id) {
94
+ async transform(code, id) {
151
95
  try {
152
96
  const moduleId = stableModuleId(id, viteRoot, workspaceRoot);
153
- const compiled = compileElementModule(code, moduleId, { staticSidecars: options.staticSidecars });
154
- const serverCompiled = compiled === null ? compileServerComponentIfAdmitted(code, moduleId, {
155
- ...options.resolveServerComponentModule === void 0 ? {} : { resolveModule: (specifier) => {
156
- return options.resolveServerComponentModule(specifier, moduleId) ?? void 0;
157
- } },
97
+ const generated = options.generatedElementSite !== void 0 ? compileGeneratedElementIfAdmitted(code, moduleId, { site: options.generatedElementSite(moduleId) }) : null;
98
+ const resolveServerModule = options.resolveServerComponentModule;
99
+ const resolveModule = generated === null && resolveServerModule !== void 0 ? await prepareServerComponentImports(code, moduleId, async (specifier) => await resolveServerModule(specifier, moduleId, (target) => this.resolve(target, id)) ?? void 0) : void 0;
100
+ const serverCompiled = generated === null ? compileServerComponentIfAdmitted(code, moduleId, {
101
+ ...resolveModule === void 0 ? {} : { resolveModule },
158
102
  ...options.compiledTags === void 0 ? {} : { compiledTags: options.compiledTags }
159
103
  }) : null;
160
- const artifact = compiled || serverCompiled ? void 0 : readCompiledArtifactStyles(code, id);
161
- const styleRequests = compiled?.styleRequests ?? artifact?.requests;
162
- if (styleRequests !== void 0) registerStyleEdges(id, styleRequests, compiled ? lightRootScopeTag(compiled.program) : artifact?.scopeTag);
104
+ const artifact = generated || serverCompiled ? void 0 : readCompiledArtifactStyles(code, id);
105
+ if (artifact !== void 0) registerStyleEdges(id, artifact.requests, artifact.scopeTag);
163
106
  if (options.candidates !== void 0) {
164
- if (compiled !== null) options.candidates.register(id, compiled.classCandidates ?? [], { shadow: compiled.program.root.kind !== "light" });
165
- else if (serverCompiled !== null) options.candidates.register(id, serverCompiled.classCandidates ?? [], { shadow: false });
107
+ if (serverCompiled !== null) options.candidates.register(id, serverCompiled.classCandidates ?? [], { shadow: false });
108
+ else if (generated !== null) options.candidates.register(id, generated.classCandidates, { shadow: options.generatedElementSite === void 0 ? false : generatedSiteRootIsShadow(options.generatedElementSite(moduleId)) });
166
109
  else options.candidates.register(id, compiledArtifactClassCandidates(code, id) ?? [], { shadow: true });
167
110
  }
111
+ if (generated !== null) return {
112
+ code: generated.code,
113
+ map: generated.map
114
+ };
168
115
  if (serverCompiled !== null) {
169
116
  if (options.typeCheckEmitted) {
170
117
  const diagnostics = typeCheckEmittedModule(serverCompiled.code, moduleId, { paths: options.resolutionPaths });
@@ -184,21 +131,7 @@ function compiledElementPlugin(options = {}) {
184
131
  map: serverCompiled.map
185
132
  };
186
133
  }
187
- if (!compiled) return null;
188
- if (options.typeCheckEmitted) {
189
- const diagnostics = typeCheckEmittedModule(compiled.code, moduleId, { paths: options.resolutionPaths });
190
- const first = diagnostics[0];
191
- if (first) this.error({
192
- id,
193
- loc: {
194
- file: id,
195
- line: first.line,
196
- column: first.character
197
- },
198
- message: `[open:compiled-element] the compiler emitted a module that does not type-check (${diagnostics.length} diagnostic(s); TS${first.code}: ${first.message}). This is a compiler defect — report it with the authored module that triggered it.`
199
- });
200
- }
201
- return compiled.code;
134
+ return null;
202
135
  } catch (error) {
203
136
  if (error instanceof CompiledElementError) {
204
137
  recordCompilerDiagnostics(error.diagnostics);
@@ -210,4 +143,4 @@ function compiledElementPlugin(options = {}) {
210
143
  };
211
144
  }
212
145
  //#endregion
213
- export { compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, registerStyleEdges, stableModuleId, stripInlineSourceMapComment };
146
+ export { compiledElementPlugin, registerStyleEdges, stableModuleId };
@@ -1,8 +1,8 @@
1
- import { ModuleIntrinsicBindings } from "./module-analysis.js";
2
1
  import { CompilerFail } from "./compiler-diagnostics.js";
3
2
  import ts from "typescript";
4
3
  import { PropertyValueType, SerializableValue } from "@openelement/protocol/part-program";
5
4
  //#region src/internal/compiler/semantic-core/analyze-module.d.ts
5
+ /** The property inventory a caller hands the lowering walk. */
6
6
  export interface CompiledField {
7
7
  name: string;
8
8
  reflect: boolean;
@@ -70,48 +70,4 @@ declare function validateComputedExpressionBody(body: ts.Expression, sf: ts.Sour
70
70
  deps: string[];
71
71
  bodyText: string;
72
72
  };
73
- /** The `@element` root ownership mode (alpha.8). */
74
- export type ElementRootKind = 'light' | 'shadow-open' | 'shadow-closed';
75
- /** Everything the lowering and emission stages consume from one authored module. */
76
- export interface AnalyzedModule {
77
- /** Runtime statements admitted as verbatim passthrough (the island policy). */
78
- passthroughStatements: ts.Statement[];
79
- /** The one decorated class. */
80
- classNode: ts.ClassDeclaration;
81
- /** The class's `@element(...)` decorator application. */
82
- decorator: ts.Decorator;
83
- /** The custom-element tag from the decorator's first argument. */
84
- tag: string;
85
- rootKind: ElementRootKind;
86
- delegatesFocus: boolean;
87
- formAssociated: boolean;
88
- /** True when the class is `export default class`. */
89
- isDefaultExport: boolean;
90
- /** The local name the canonical `OpenElement` base binding carries. */
91
- openElementLocalName: string;
92
- className: string;
93
- fields: CompiledField[];
94
- methods: ts.MethodDeclaration[];
95
- render: ts.MethodDeclaration;
96
- stylesText?: string;
97
- stylesNode?: ts.Expression;
98
- stylesTypeText?: string;
99
- /**
100
- * The module's style edges (#1558): the authored `.css` imports the class's
101
- * `static styles` arrays, in authored order. The host build's style-asset
102
- * plugin intercepts these edges and owns the emitted `.css` artifacts; the
103
- * generated module copies the authored imports and initializer verbatim.
104
- */
105
- styleRequests: readonly string[];
106
- }
107
- /**
108
- * Admit one parsed module to the compiled grammar and lift its shape
109
- * (#1473 split): the top-level
110
- * statement admission (OEC9008 fail-closed, island policy passthrough), the
111
- * exactly-one-`@element`-class rule with its decorator options and canonical
112
- * heritage provenance, and the {@link propertyFields} inventory. Component
113
- * styles are admitted in one form only (#1558): `.css` file imports arrayed
114
- * in `static styles` — any inline sheet shape fails closed with OEC9029.
115
- */
116
- declare function analyzeCompiledModule(sf: ts.SourceFile, intrinsics: ModuleIntrinsicBindings, fail: CompilerFail): AnalyzedModule;
117
73
  //#endregion