@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openelement/compiler",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "type": "module",
5
5
  "main": "./src/compiler.js",
6
6
  "types": "./src/compiler.d.ts",
@@ -23,12 +23,14 @@
23
23
  "homepage": "https://openelement.org",
24
24
  "bugs": "https://github.com/open-element/openelement/issues",
25
25
  "license": "MIT",
26
+ "description": "Build-time compiler for OpenElement: transforms TSX with @element decorators into Part Program modules.",
26
27
  "keywords": [
27
28
  "openelement",
28
29
  "web-components",
29
30
  "compiler",
30
31
  "tsx",
31
32
  "vite",
33
+ "vite-plugin",
32
34
  "part-program"
33
35
  ],
34
36
  "engines": {
@@ -44,7 +46,7 @@
44
46
  }
45
47
  },
46
48
  "dependencies": {
47
- "@openelement/protocol": "1.0.0-alpha.14",
49
+ "@openelement/protocol": "1.0.0-alpha.16",
48
50
  "typescript": "6.0.3"
49
51
  }
50
52
  }
package/src/compiler.d.ts CHANGED
@@ -1,9 +1,15 @@
1
- import { ModuleSemanticFacts, ModuleSemanticsOptions, ModuleVocabularyDescriptor, SemanticCoreOptions, StaticSidecarDescriptor, analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
1
+ import { PluginDiagnosticError, clearCompilerDiagnostics, compilerDiagnosticsToEnvelopes, diagnosticPluginError, recordCompilerDiagnostics, takeCompilerDiagnostics } from "./internal/compiler/semantic-core/diagnostics/index.js";
2
2
  import { CompiledElementError, ElementCompilerDiagnostic } from "./internal/compiler/semantic-core/compiler-diagnostics.js";
3
- import { CompileElementResult, compileElementProgram } from "./internal/compiler/semantic-core/compile.js";
4
- import { COMPILED_ELEMENT_MARKER, compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, stableModuleId, stripInlineSourceMapComment } from "./internal/compiler/plugin.js";
5
- import { compiledArtifactStyleRequests } from "./internal/compiler/compiled-artifact-style-requests.js";
6
- import { RegisteredStyleRequest, clearStyleRequests, getStyleRequest, hasStyleImporter, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId } from "./internal/compiler/style-requests.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
+ import { ClassCandidateRegistry, createClassCandidateRegistry } from "./internal/compiler/tailwind-candidates.js";
6
+ import { compiledElementPlugin, registerStyleEdges, stableModuleId } from "./internal/compiler/plugin.js";
7
+ import { isJsxModuleId } from "./internal/compiler/semantic-core/jsx-module-id.js";
8
+ import { compiledArtifactStyleRequests, readCompiledArtifactStyles } from "./internal/compiler/compiled-artifact-style-requests.js";
9
+ import { compiledArtifactClassCandidates } from "./internal/compiler/compiled-artifact-class-candidates.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";
7
13
  import { EmittedModuleDiagnostic, EmittedModuleTypeCheckOptions, emittedModuleTypeChecks, typeCheckEmittedModule } from "./internal/compiler/semantic-core/type-check.js";
8
14
  import { validatePartProgram } from "@openelement/protocol/part-program";
9
- export { COMPILED_ELEMENT_MARKER, type CompileElementResult, CompiledElementError, type ElementCompilerDiagnostic, type EmittedModuleDiagnostic, type EmittedModuleTypeCheckOptions, type ModuleSemanticFacts, type ModuleSemanticsOptions, type ModuleVocabularyDescriptor, type RegisteredStyleRequest, type SemanticCoreOptions, type StaticSidecarDescriptor, analyzeModuleSemantics, clearStyleRequests, compileElementModule, compileElementProgram, compiledArtifactStyleRequests, compiledElementPlugin, emittedModuleTypeChecks, getStyleRequest, hasElementDecoratorApplication, hasStyleImporter, isCompiledElementModule, registerStyleRequest, stableModuleId, stripInlineSourceMapComment, styleEdgesForFile, styleRequestFile, styleRequestModuleId, 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,9 +1,14 @@
1
- import { analyzeModuleSemantics } from "./internal/compiler/semantic-core/module-analysis.js";
1
+ import { clearCompilerDiagnostics, compilerDiagnosticsToEnvelopes, diagnosticPluginError, recordCompilerDiagnostics, takeCompilerDiagnostics } from "./internal/compiler/semantic-core/diagnostics/index.js";
2
2
  import { CompiledElementError } from "./internal/compiler/semantic-core/compiler-diagnostics.js";
3
- import { compileElementProgram } from "./internal/compiler/semantic-core/compile.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";
4
7
  import { emittedModuleTypeChecks, typeCheckEmittedModule } from "./internal/compiler/semantic-core/type-check.js";
5
- import { compiledArtifactStyleRequests } from "./internal/compiler/compiled-artifact-style-requests.js";
6
- import { clearStyleRequests, getStyleRequest, hasStyleImporter, registerStyleRequest, styleEdgesForFile, styleRequestFile, styleRequestModuleId } from "./internal/compiler/style-requests.js";
7
- import { COMPILED_ELEMENT_MARKER, compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, stableModuleId, stripInlineSourceMapComment } from "./internal/compiler/plugin.js";
8
+ import { compiledArtifactClassCandidates } from "./internal/compiler/compiled-artifact-class-candidates.js";
9
+ import { compiledArtifactStyleRequests, readCompiledArtifactStyles } from "./internal/compiler/compiled-artifact-style-requests.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";
12
+ import { createClassCandidateRegistry } from "./internal/compiler/tailwind-candidates.js";
8
13
  import { validatePartProgram } from "@openelement/protocol/part-program";
9
- export { COMPILED_ELEMENT_MARKER, CompiledElementError, analyzeModuleSemantics, clearStyleRequests, compileElementModule, compileElementProgram, compiledArtifactStyleRequests, compiledElementPlugin, emittedModuleTypeChecks, getStyleRequest, hasElementDecoratorApplication, hasStyleImporter, isCompiledElementModule, registerStyleRequest, stableModuleId, stripInlineSourceMapComment, styleEdgesForFile, styleRequestFile, styleRequestModuleId, 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 };
@@ -0,0 +1,11 @@
1
+ //#region src/internal/compiler/compiled-artifact-class-candidates.d.ts
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;
5
+ /**
6
+ * The admitted class candidates of one compiled artifact module, or undefined
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.
9
+ */
10
+ export declare function compiledArtifactClassCandidates(source: string, fileName: string): readonly string[] | undefined;
11
+ //#endregion
@@ -0,0 +1,46 @@
1
+ import { typescriptParser } from "./semantic-core/parse-module.js";
2
+ import ts from "typescript";
3
+ //#region src/internal/compiler/compiled-artifact-class-candidates.ts
4
+ /** Recover the compiler's shadow stylesheet candidates from a packed module. */
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
+ }
18
+ /**
19
+ * The admitted class candidates of one compiled artifact module, or undefined
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.
22
+ */
23
+ function compiledArtifactClassCandidates(source, fileName) {
24
+ if (!source.includes(CANDIDATE_MEMBER_NAME) && !source.includes(GENERATED_CANDIDATE_FOOTER)) return;
25
+ const { sourceFile: sf } = typescriptParser.parseModule(source, fileName);
26
+ const footer = generatedCandidateFooter(source, sf);
27
+ if (footer !== void 0) return decodeGeneratedCandidates(footer);
28
+ let found;
29
+ const visit = (node) => {
30
+ if (found !== void 0) return;
31
+ if (ts.isPropertyDeclaration(node) && node.name !== void 0 && ts.isIdentifier(node.name) && node.name.text === CANDIDATE_MEMBER_NAME && node.initializer !== void 0 && ts.isArrayLiteralExpression(node.initializer)) {
32
+ const tokens = [];
33
+ for (const element of node.initializer.elements) {
34
+ if (!ts.isStringLiteral(element)) return;
35
+ tokens.push(element.text);
36
+ }
37
+ found = tokens.length === 0 ? void 0 : tokens;
38
+ return;
39
+ }
40
+ ts.forEachChild(node, visit);
41
+ };
42
+ ts.forEachChild(sf, visit);
43
+ return found;
44
+ }
45
+ //#endregion
46
+ export { compiledArtifactClassCandidates };
@@ -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
  *
@@ -30,6 +32,15 @@
30
32
  * compiled-element transform's host binding) registers them, exactly as it
31
33
  * registers an authored compile's `styleRequests`.
32
34
  */
35
+ /**
36
+ * What one compiled artifact module declares about its style edges: the
37
+ * relative `.css` specifiers in authored order, and the light-root scope tag
38
+ * the module's Part Program names (undefined for a shadow-root artifact).
39
+ */
40
+ export interface CompiledArtifactStyleRead {
41
+ readonly requests: readonly string[];
42
+ readonly scopeTag?: string;
43
+ }
33
44
  /**
34
45
  * The `.css` style edges of one compiled artifact module, in authored order —
35
46
  * or undefined when the module is not a shape this recovery adopts. Never
@@ -47,4 +58,12 @@
47
58
  * extension would refuse the raw form and silently drop its edges.
48
59
  */
49
60
  export declare function compiledArtifactStyleRequests(source: string, fileName: string): readonly string[] | undefined;
61
+ /**
62
+ * The same recovery, read once for both facts an artifact states: its edges
63
+ * and its root scope (alpha15 S lane, S-C1.2). The scope comes from the
64
+ * module's own Part Program literal — the emitter writes it verbatim, so the
65
+ * packed form needs no second source of truth and no assumption about which
66
+ * root kind a shipped package used.
67
+ */
68
+ export declare function readCompiledArtifactStyles(source: string, fileName: string): CompiledArtifactStyleRead | undefined;
50
69
  //#endregion
@@ -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
  *
@@ -86,6 +88,16 @@ function collectSheetBindings(sf) {
86
88
  * extension would refuse the raw form and silently drop its edges.
87
89
  */
88
90
  function compiledArtifactStyleRequests(source, fileName) {
91
+ return readCompiledArtifactStyles(source, fileName)?.requests;
92
+ }
93
+ /**
94
+ * The same recovery, read once for both facts an artifact states: its edges
95
+ * and its root scope (alpha15 S lane, S-C1.2). The scope comes from the
96
+ * module's own Part Program literal — the emitter writes it verbatim, so the
97
+ * packed form needs no second source of truth and no assumption about which
98
+ * root kind a shipped package used.
99
+ */
100
+ function readCompiledArtifactStyles(source, fileName) {
89
101
  if (!source.includes(COMPILED_ARTIFACT_MARKER)) return void 0;
90
102
  if (!CSS_SPECIFIER_HINT.test(source)) return void 0;
91
103
  const { sourceFile: sf } = typescriptParser.parseModule(source, fileName);
@@ -104,7 +116,9 @@ function compiledArtifactStyleRequests(source, fileName) {
104
116
  return true;
105
117
  };
106
118
  let shapeFollowed = true;
119
+ let program;
107
120
  const visit = (node) => {
121
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === PART_PROGRAM_BINDING && node.initializer !== void 0) program = node.initializer;
108
122
  if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) for (const member of node.members) {
109
123
  if (!ts.isPropertyDeclaration(member)) continue;
110
124
  if (!ts.isIdentifier(member.name) || member.name.text !== STYLES_MEMBER_NAME) continue;
@@ -123,7 +137,41 @@ function compiledArtifactStyleRequests(source, fileName) {
123
137
  };
124
138
  visit(sf);
125
139
  if (!shapeFollowed || claimed.size !== sheetBindings.size) return void 0;
126
- return edges.length === 0 ? void 0 : edges;
140
+ if (edges.length === 0) return void 0;
141
+ const scopeTag = programScopeTag(program);
142
+ return scopeTag === void 0 ? { requests: edges } : {
143
+ requests: edges,
144
+ scopeTag
145
+ };
146
+ }
147
+ /** The Part Program's module-local binding, as the emitter writes it. */
148
+ const PART_PROGRAM_BINDING = "__partProgram";
149
+ /**
150
+ * The light-root scope tag inside an artifact's Part Program literal. Only a
151
+ * statically visible `tag` string with `root.kind === "light"` counts; every
152
+ * other shape (a computed literal, a shadow root, a missing field) reads as
153
+ * "no scope", which is the shadow-root default.
154
+ */
155
+ function programScopeTag(program) {
156
+ if (program === void 0) return void 0;
157
+ let expression = program;
158
+ while (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression)) expression = expression.expression;
159
+ if (!ts.isObjectLiteralExpression(expression)) return void 0;
160
+ const tag = propertyOf(expression, "tag");
161
+ const root = propertyOf(expression, "root");
162
+ if (tag === void 0 || !ts.isStringLiteral(tag) || tag.text === "") return void 0;
163
+ if (root === void 0 || !ts.isObjectLiteralExpression(root)) return void 0;
164
+ const kind = propertyOf(root, "kind");
165
+ if (kind === void 0 || !ts.isStringLiteral(kind) || kind.text !== "light") return void 0;
166
+ return tag.text;
167
+ }
168
+ /** One property's initializer of an object literal, or undefined. */
169
+ function propertyOf(object, name) {
170
+ for (const property of object.properties) {
171
+ if (!ts.isPropertyAssignment(property)) continue;
172
+ if (ts.isIdentifier(property.name) && property.name.text === name) return property.initializer;
173
+ if (ts.isStringLiteral(property.name) && property.name.text === name) return property.initializer;
174
+ }
127
175
  }
128
176
  //#endregion
129
- export { compiledArtifactStyleRequests };
177
+ export { compiledArtifactStyleRequests, readCompiledArtifactStyles };
@@ -1,46 +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
+ import { ClassCandidateRegistry } from "./tailwind-candidates.js";
3
4
  import { Plugin } from "vite";
4
5
  //#region src/internal/compiler/plugin.d.ts
5
- /** The authored substring every compiled element module contains (`@element(`), used as the cheap prefilter. */
6
- export declare const COMPILED_ELEMENT_MARKER = "@element(";
7
- /**
8
- * Cheap first stage only — NOT a recognizer. The substring match exists to
9
- * keep plain modules off the AST path and may false-positive (string literals
10
- * and comments match); it may also false-negative on namespace-qualified
11
- * spellings (`@ns.element(...)`), which are unsupported by the grammar anyway
12
- * (#1209). Binding provenance and admission are decided exclusively by the
13
- * semantic core.
14
- */
15
- export declare function isCompiledElementModule(code: string, id: string): boolean;
16
- /**
17
- * Precise second stage behind the substring prefilter: a canonically bound
18
- * `@element(...)` decorator application on a class declaration (provenance
19
- * decided by the semantic core's intrinsic-binding model). Modules that only
20
- * mention the marker in a string literal or comment, or spell it through a
21
- * foreign/local binding, do not reach the compiler.
22
- */
23
- export declare function hasElementDecoratorApplication(code: string, id: string): boolean;
24
- /**
25
- * Compile one opted-in module without binding the caller to Vite. The core
26
- * adapter hook and the inline SSR/client builds all use this same function,
27
- * which prevents duplicate compiler implementations from drifting. Returns
28
- * null for modules without a canonically bound @element decorator
29
- * application, so marker-mentioning and foreign-binding modules pass through
30
- * untouched. Modules whose @element spelling carries unsupported or ambiguous
31
- * provenance are compiled anyway so the compiler boundary fails closed with
32
- * the OEC9027 provenance diagnostic. `options.staticSidecars` admits
33
- * host-declared sidecar policy statements; the default core admits none.
34
- */
35
- export declare function compileElementModule(code: string, id: string, options?: SemanticCoreOptions): CompileElementResult | null;
36
- /**
37
- * Strip the inline map comment from a compiled module at the Vite boundary.
38
- * The core artifact embeds its real Source Map v3 inline for standalone
39
- * consumers; the Vite transform returns that same map as its `map` output so
40
- * Vite composes it with the rest of the pipeline — leaving the comment in the
41
- * served code would create a second, conflicting map story (#1210).
42
- */
43
- export declare function stripInlineSourceMapComment(code: string): string;
44
6
  /**
45
7
  * Compile-time source identity for a module: absolute Vite ids are converted
46
8
  * to project-relative POSIX paths so Part Program `metadata.sourceFile` and
@@ -77,19 +39,76 @@ export interface CompiledElementPluginOptions {
77
39
  /** Specifier → candidate files map used when `typeCheckEmitted` is on. */
78
40
  resolutionPaths?: Record<string, string[]>;
79
41
  /**
80
- * Static-sidecar descriptors the host application admits into the compiled
81
- * module grammar (e.g. its island delivery policy factory). The default
82
- * core knows none: without an injected descriptor a module carrying a
83
- * sidecar policy statement fails closed with OEC9008.
42
+ * The class-candidate registry this plugin instance writes its compiled
43
+ * modules' statically admitted class tokens into (alpha15 S lane). The
44
+ * registry is OWNED by the host that created it — one per build, one per dev
45
+ * server — so two live builds in one process never inherit each other's
46
+ * facts (defect C). Omitted: this instance collects no candidates, which is
47
+ * the right shape for a build that consumes none (e.g. the SSR half).
48
+ */
49
+ candidates?: ClassCandidateRegistry;
50
+ /**
51
+ * Host-supplied resolver for the server function component lane's nested
52
+ * imports (`resolveModule` of {@link compileServerComponentModule}): given
53
+ * a specifier and the importing module id, return that module's source so
54
+ * a nested server function component composes by direct call. Omitting it
55
+ * (or answering undefined) keeps nested composition a coded rejection.
56
+ * The compiler itself never reads the filesystem — resolution stays the
57
+ * host's job, so this option carries the host's capability rather than a
58
+ * path convention. The third argument resolves a specifier in the active
59
+ * Vite environment with the actual importing id.
84
60
  */
85
- staticSidecars?: readonly StaticSidecarDescriptor[];
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>;
65
+ /**
66
+ * The custom-element host tags the host build admitted as @element compiled
67
+ * components: JSX children in a server function component ride
68
+ * `__ssr(tag, props)` for those tags and an emitted-as-is tag otherwise.
69
+ */
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;
86
86
  }
87
+ /**
88
+ * Register one module's style edges (the registry's one write path, S-C1.4).
89
+ *
90
+ * The importing component's root scope is part of every edge it registers
91
+ * (alpha15 S lane, S-C1.2): a light-root component's sheets leave the build
92
+ * wrapped in `@scope (<tag>)`, so the tag travels to the intercept through the
93
+ * registry key. A shipped artifact states the same fact in its Part Program
94
+ * literal.
95
+ *
96
+ * The Vite transform is the caller for a module the bundler processes; a build
97
+ * host that admits a module for its ADMISSION FACTS alone (a Page or Layout the
98
+ * server renders and no island imports) calls the same step with the same
99
+ * compiled program — no second writer, no second registry.
100
+ */
101
+ export declare function registerStyleEdges(id: string, specifiers: readonly string[], scopeTag: string | undefined): void;
87
102
  /**
88
103
  * The `open:compiled-element` Vite plugin: runs at `enforce: 'pre'` so the
89
104
  * compiler sees authored TSX before Vite's own TS/JSX lowering, compiles every
90
- * module with a canonically bound `@element` decorator, and leaves all other
91
- * modules untouched. `workspaceRoot` anchors generated source-map ids for
92
- * 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.
93
112
  */
94
113
  export declare function compiledElementPlugin(options?: CompiledElementPluginOptions): Plugin;
95
114
  //#endregion
@@ -1,61 +1,12 @@
1
- import { analyzeModuleSemantics } from "./semantic-core/module-analysis.js";
2
- import { diagnosticPluginError } from "./semantic-core/diagnostics/index.js";
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";
3
+ import { compileServerComponentIfAdmitted, prepareServerComponentImports } from "./semantic-core/server-component.js";
4
+ import { compileGeneratedElementIfAdmitted } from "./semantic-ir/generated-element/compile.js";
5
5
  import { typeCheckEmittedModule } from "./semantic-core/type-check.js";
6
- import { compiledArtifactStyleRequests } from "./compiled-artifact-style-requests.js";
6
+ import { compiledArtifactClassCandidates } from "./compiled-artifact-class-candidates.js";
7
+ import { readCompiledArtifactStyles } from "./compiled-artifact-style-requests.js";
7
8
  import { registerStyleRequest, styleRequestFile, styleRequestModuleId } from "./style-requests.js";
8
9
  //#region src/internal/compiler/plugin.ts
9
- /** The authored substring every compiled element module contains (`@element(`), used as the cheap prefilter. */
10
- const COMPILED_ELEMENT_MARKER = "@element(";
11
- /**
12
- * Cheap first stage only — NOT a recognizer. The substring match exists to
13
- * keep plain modules off the AST path and may false-positive (string literals
14
- * and comments match); it may also false-negative on namespace-qualified
15
- * spellings (`@ns.element(...)`), which are unsupported by the grammar anyway
16
- * (#1209). Binding provenance and admission are decided exclusively by the
17
- * semantic core.
18
- */
19
- function isCompiledElementModule(code, id) {
20
- return /\.tsx(?:\?|$)/.test(id) && code.includes("@element(");
21
- }
22
- /**
23
- * Precise second stage behind the substring prefilter: a canonically bound
24
- * `@element(...)` decorator application on a class declaration (provenance
25
- * decided by the semantic core's intrinsic-binding model). Modules that only
26
- * mention the marker in a string literal or comment, or spell it through a
27
- * foreign/local binding, do not reach the compiler.
28
- */
29
- function hasElementDecoratorApplication(code, id) {
30
- return analyzeModuleSemantics(code, id).compiledElementDecorator;
31
- }
32
- /**
33
- * Compile one opted-in module without binding the caller to Vite. The core
34
- * adapter hook and the inline SSR/client builds all use this same function,
35
- * which prevents duplicate compiler implementations from drifting. Returns
36
- * null for modules without a canonically bound @element decorator
37
- * application, so marker-mentioning and foreign-binding modules pass through
38
- * untouched. Modules whose @element spelling carries unsupported or ambiguous
39
- * provenance are compiled anyway so the compiler boundary fails closed with
40
- * the OEC9027 provenance diagnostic. `options.staticSidecars` admits
41
- * host-declared sidecar policy statements; the default core admits none.
42
- */
43
- function compileElementModule(code, id, options = {}) {
44
- if (!isCompiledElementModule(code, id)) return null;
45
- const facts = analyzeModuleSemantics(code, id);
46
- if (!facts.compiledElementDecorator && facts.unsupportedElementDecorator === void 0) return null;
47
- return compileElementProgram(code, id, options);
48
- }
49
- /**
50
- * Strip the inline map comment from a compiled module at the Vite boundary.
51
- * The core artifact embeds its real Source Map v3 inline for standalone
52
- * consumers; the Vite transform returns that same map as its `map` output so
53
- * Vite composes it with the rest of the pipeline — leaving the comment in the
54
- * served code would create a second, conflicting map story (#1210).
55
- */
56
- function stripInlineSourceMapComment(code) {
57
- return code.replace(/\n\/\/# sourceMappingURL=data:application\/json;base64,[^\n]*(?=\n?$)/, "");
58
- }
59
10
  /**
60
11
  * Compile-time source identity for a module: absolute Vite ids are converted
61
12
  * to project-relative POSIX paths so Part Program `metadata.sourceFile` and
@@ -83,13 +34,55 @@ function stableModuleId(file, root, workspaceRoot) {
83
34
  return clean;
84
35
  }
85
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
+ /**
49
+ * Register one module's style edges (the registry's one write path, S-C1.4).
50
+ *
51
+ * The importing component's root scope is part of every edge it registers
52
+ * (alpha15 S lane, S-C1.2): a light-root component's sheets leave the build
53
+ * wrapped in `@scope (<tag>)`, so the tag travels to the intercept through the
54
+ * registry key. A shipped artifact states the same fact in its Part Program
55
+ * literal.
56
+ *
57
+ * The Vite transform is the caller for a module the bundler processes; a build
58
+ * host that admits a module for its ADMISSION FACTS alone (a Page or Layout the
59
+ * server renders and no island imports) calls the same step with the same
60
+ * compiled program — no second writer, no second registry.
61
+ */
62
+ function registerStyleEdges(id, specifiers, scopeTag) {
63
+ for (const specifier of specifiers) registerStyleRequest({
64
+ moduleId: styleRequestModuleId(id, specifier, scopeTag),
65
+ importer: id,
66
+ specifier,
67
+ file: styleRequestFile(id, specifier),
68
+ ...scopeTag === void 0 ? {} : { scopeTag }
69
+ });
70
+ }
71
+ /**
86
72
  * The `open:compiled-element` Vite plugin: runs at `enforce: 'pre'` so the
87
73
  * compiler sees authored TSX before Vite's own TS/JSX lowering, compiles every
88
- * module with a canonically bound `@element` decorator, and leaves all other
89
- * modules untouched. `workspaceRoot` anchors generated source-map ids for
90
- * 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.
91
81
  */
92
82
  function compiledElementPlugin(options = {}) {
83
+ return createCompiledElementPlugin(options);
84
+ }
85
+ function createCompiledElementPlugin(options = {}) {
93
86
  let viteRoot;
94
87
  const workspaceRoot = options.workspaceRoot;
95
88
  return {
@@ -98,38 +91,56 @@ function compiledElementPlugin(options = {}) {
98
91
  viteRoot = config.root;
99
92
  },
100
93
  enforce: "pre",
101
- transform(code, id) {
94
+ async transform(code, id) {
102
95
  try {
103
96
  const moduleId = stableModuleId(id, viteRoot, workspaceRoot);
104
- const compiled = compileElementModule(code, moduleId, { staticSidecars: options.staticSidecars });
105
- const styleRequests = compiled?.styleRequests ?? compiledArtifactStyleRequests(code, id);
106
- if (styleRequests !== void 0) for (const specifier of styleRequests) registerStyleRequest({
107
- moduleId: styleRequestModuleId(id, specifier),
108
- importer: id,
109
- specifier,
110
- file: styleRequestFile(id, specifier)
111
- });
112
- if (!compiled) return null;
113
- if (options.typeCheckEmitted) {
114
- const diagnostics = typeCheckEmittedModule(compiled.code, moduleId, { paths: options.resolutionPaths });
115
- const first = diagnostics[0];
116
- if (first) this.error({
117
- id,
118
- loc: {
119
- file: id,
120
- line: first.line - 1,
121
- column: first.character - 1
122
- },
123
- 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.`
124
- });
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 },
102
+ ...options.compiledTags === void 0 ? {} : { compiledTags: options.compiledTags }
103
+ }) : null;
104
+ const artifact = generated || serverCompiled ? void 0 : readCompiledArtifactStyles(code, id);
105
+ if (artifact !== void 0) registerStyleEdges(id, artifact.requests, artifact.scopeTag);
106
+ if (options.candidates !== void 0) {
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)) });
109
+ else options.candidates.register(id, compiledArtifactClassCandidates(code, id) ?? [], { shadow: true });
110
+ }
111
+ if (generated !== null) return {
112
+ code: generated.code,
113
+ map: generated.map
114
+ };
115
+ if (serverCompiled !== null) {
116
+ if (options.typeCheckEmitted) {
117
+ const diagnostics = typeCheckEmittedModule(serverCompiled.code, moduleId, { paths: options.resolutionPaths });
118
+ const first = diagnostics[0];
119
+ if (first) this.error({
120
+ id,
121
+ loc: {
122
+ file: id,
123
+ line: first.line,
124
+ column: first.character
125
+ },
126
+ message: `[open:compiled-element] the server component lane 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.`
127
+ });
128
+ }
129
+ return {
130
+ code: serverCompiled.code,
131
+ map: serverCompiled.map
132
+ };
125
133
  }
126
- return compiled.code;
134
+ return null;
127
135
  } catch (error) {
128
- if (error instanceof CompiledElementError) this.error(diagnosticPluginError(error.diagnostics, code, id) ?? error.message);
136
+ if (error instanceof CompiledElementError) {
137
+ recordCompilerDiagnostics(error.diagnostics);
138
+ this.error(diagnosticPluginError(error.diagnostics, code, id) ?? error.message);
139
+ }
129
140
  throw error;
130
141
  }
131
142
  }
132
143
  };
133
144
  }
134
145
  //#endregion
135
- export { COMPILED_ELEMENT_MARKER, compileElementModule, compiledElementPlugin, hasElementDecoratorApplication, isCompiledElementModule, stableModuleId, stripInlineSourceMapComment };
146
+ export { compiledElementPlugin, registerStyleEdges, stableModuleId };