@openelement/compiler 1.0.0-alpha.14 → 1.0.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/compiler.d.ts +12 -6
- package/src/compiler.js +11 -6
- package/src/internal/compiler/compiled-artifact-class-candidates.d.ts +11 -0
- package/src/internal/compiler/compiled-artifact-class-candidates.js +46 -0
- package/src/internal/compiler/compiled-artifact-style-requests.d.ts +26 -7
- package/src/internal/compiler/compiled-artifact-style-requests.js +57 -9
- package/src/internal/compiler/plugin.d.ts +68 -49
- package/src/internal/compiler/plugin.js +93 -82
- package/src/internal/compiler/semantic-core/analyze-module.d.ts +73 -0
- package/src/internal/compiler/semantic-core/analyze-module.js +29 -379
- package/src/internal/compiler/semantic-core/attribute-classification.js +92 -0
- package/src/internal/compiler/semantic-core/compiler-diagnostics.js +2 -16
- package/src/internal/compiler/semantic-core/diagnostics/index.d.ts +21 -1
- package/src/internal/compiler/semantic-core/diagnostics/index.js +32 -1
- package/src/internal/compiler/semantic-core/expression-lowering.js +469 -0
- package/src/internal/compiler/semantic-core/expression-registry.js +165 -0
- package/src/internal/compiler/semantic-core/function-frontend.js +1229 -0
- package/src/internal/compiler/semantic-core/island-policy-statement.js +52 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.d.ts +4 -0
- package/src/internal/compiler/semantic-core/jsx-module-id.js +7 -0
- package/src/internal/compiler/semantic-core/lower-program.d.ts +220 -0
- package/src/internal/compiler/semantic-core/lower-program.js +350 -142
- package/src/internal/compiler/semantic-core/module-analysis.d.ts +82 -4
- package/src/internal/compiler/semantic-core/module-analysis.js +88 -19
- package/src/internal/compiler/semantic-core/parse-module.js +16 -16
- package/src/internal/compiler/semantic-core/scope-resolution.d.ts +208 -0
- package/src/internal/compiler/semantic-core/scope-resolution.js +1121 -0
- package/src/internal/compiler/semantic-core/server-component.d.ts +129 -0
- package/src/internal/compiler/semantic-core/server-component.js +587 -0
- package/src/internal/compiler/semantic-core/type-check.js +1 -1
- package/src/internal/compiler/semantic-core/type-erasure.js +156 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.d.ts +61 -0
- package/src/internal/compiler/semantic-ir/generated-element/compile.js +137 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.d.ts +201 -0
- package/src/internal/compiler/semantic-ir/generated-element/contract.js +147 -0
- package/src/internal/compiler/semantic-ir/generated-element/emit.js +452 -0
- package/src/internal/compiler/semantic-ir/generated-element/site.js +1195 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/claim-emission.js +1372 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/codegen-literals.js +31 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/component-emission.js +647 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/emission.js +388 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/generate.js +395 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/instance-emission.js +865 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/mount-emission.js +960 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/server-emission.js +1011 -0
- package/src/internal/compiler/semantic-ir/generated-leaf/structure.js +714 -0
- package/src/internal/compiler/style-requests.d.ts +35 -7
- package/src/internal/compiler/style-requests.js +57 -11
- package/src/internal/compiler/tailwind-candidates.d.ts +84 -0
- package/src/internal/compiler/tailwind-candidates.js +54 -0
- package/src/internal/compiler/semantic-core/compile.d.ts +0 -39
- package/src/internal/compiler/semantic-core/compile.js +0 -98
- package/src/internal/compiler/semantic-core/emit-module.js +0 -313
- package/src/internal/compiler/semantic-core/emit-program.js +0 -121
- package/src/internal/compiler/semantic-core/style-imports.js +0 -87
|
@@ -10,6 +10,14 @@ import { ModuleVocabularyDescriptor, ModuleVocabularyDescriptor as ModuleVocabul
|
|
|
10
10
|
*/
|
|
11
11
|
export interface ModuleSemanticFacts {
|
|
12
12
|
relativeImports: string[];
|
|
13
|
+
/**
|
|
14
|
+
* Every runtime-capable static import/export specifier, relative or not —
|
|
15
|
+
* present only when the caller asks for it (`collectSpecifiers`), because a
|
|
16
|
+
* host that walks a module graph through its own resolver (S-C1.4's
|
|
17
|
+
* server-rendered style-edge pass) needs the aliased and package specifiers
|
|
18
|
+
* too, while every other consumer's facts stay exactly as they were.
|
|
19
|
+
*/
|
|
20
|
+
moduleSpecifiers?: string[];
|
|
13
21
|
compiledElementDecorator: boolean;
|
|
14
22
|
/**
|
|
15
23
|
* Set when a class decorator spells the `element` intrinsic through
|
|
@@ -17,8 +25,9 @@ export interface ModuleSemanticFacts {
|
|
|
17
25
|
* default import, conflicting duplicate bindings, or a relative-module
|
|
18
26
|
* re-export). Never set for clearly foreign bindings (third-party packages,
|
|
19
27
|
* local declarations, bare/global spellings) — those modules are simply not
|
|
20
|
-
* OpenElement modules.
|
|
21
|
-
*
|
|
28
|
+
* OpenElement modules. No lane compiles such a module any more, so the fact
|
|
29
|
+
* survives as REFUSAL EVIDENCE: both admission bridges answer null for it
|
|
30
|
+
* instead of compiling a class grammar that no longer has an entry point.
|
|
22
31
|
*/
|
|
23
32
|
unsupportedElementDecorator?: string;
|
|
24
33
|
exportedTagName?: string;
|
|
@@ -28,12 +37,54 @@ export interface ModuleSemanticFacts {
|
|
|
28
37
|
* (no injected vocabulary) never recognizes another package's factories.
|
|
29
38
|
*/
|
|
30
39
|
definePage: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The server function page fact (alpha15 server lane): the first argument
|
|
42
|
+
* of a default-exported `definePage(…)` call when that argument is an
|
|
43
|
+
* identifier resolving to a server function component THIS module
|
|
44
|
+
* declares. A function component never carries a Part Program, so the
|
|
45
|
+
* route cannot be a compiled class page; the host build renders it through
|
|
46
|
+
* the component function. Spread-conditional: absent for class pages and
|
|
47
|
+
* non-page modules. The scan is order-independent (the module's server
|
|
48
|
+
* function components are collected before the page call is judged), so a
|
|
49
|
+
* default export written above its component declaration admits
|
|
50
|
+
* identically. An inline arrow or an unexported local — the shapes whose
|
|
51
|
+
* JSX would otherwise escape to runtime — never records the fact.
|
|
52
|
+
*/
|
|
53
|
+
pageComponentName?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The exported functions whose body is a single return of JSX — the
|
|
56
|
+
* server-only TSX function components this module declares (alpha15 server
|
|
57
|
+
* lane). Discovery is structural and deterministic: `export function`
|
|
58
|
+
* declarations (named, not default) with exactly one return statement of a
|
|
59
|
+
* JSX element, or `export const` arrows with a JSX expression body. The
|
|
60
|
+
* fact is the cheap graph-walker face; admission and lowering stay the
|
|
61
|
+
* compile entry's job (`compileServerComponentModule`), which fails closed
|
|
62
|
+
* on everything this scan only reports. Sorted alphabetically.
|
|
63
|
+
*/
|
|
64
|
+
serverFunctionComponents: string[];
|
|
31
65
|
usesExportedTagName: boolean;
|
|
32
66
|
enhancedForm: boolean;
|
|
33
67
|
defaultCompiledTag?: string;
|
|
34
68
|
definedCustomElementTags: string[];
|
|
35
69
|
referencedCustomElementTags: string[];
|
|
36
70
|
compilerInteractionEvents: string[];
|
|
71
|
+
/**
|
|
72
|
+
* The module declares a GENERATED element: it carries the island policy
|
|
73
|
+
* sidecar statement (`export const openElement = defineIslandConfig({...})` /
|
|
74
|
+
* `defineComponentConfig({...})`) that the generated-element lane reads.
|
|
75
|
+
*
|
|
76
|
+
* This is the generated lane's counterpart to `definedCustomElementTags`:
|
|
77
|
+
* a generated component never applies the `@element` decorator (its element
|
|
78
|
+
* class is emitted by the compiler), so a consumer that asks "is this module
|
|
79
|
+
* a component module?" must consult BOTH facts. The TAG is deliberately NOT
|
|
80
|
+
* derived here — it stays the manifest's identity (the sidecar does not
|
|
81
|
+
* spell it), and this boolean only answers the module-shape question.
|
|
82
|
+
*
|
|
83
|
+
* The statement shape is read through the compiler's own sidecar locator
|
|
84
|
+
* (`hasIslandPolicyStatement`), so this fact and the generated-element lane
|
|
85
|
+
* cannot disagree about which statement is the policy.
|
|
86
|
+
*/
|
|
87
|
+
hasGeneratedElementSidecar: boolean;
|
|
37
88
|
}
|
|
38
89
|
/**
|
|
39
90
|
* The canonical intrinsic-binding model (#1209, A10.1): compiler intrinsics
|
|
@@ -63,9 +114,9 @@ export interface ModuleSemanticsOptions {
|
|
|
63
114
|
* the host injects its descriptor.
|
|
64
115
|
*/
|
|
65
116
|
readonly vocabulary?: readonly ModuleVocabularyDescriptor[];
|
|
117
|
+
/** Collect {@link ModuleSemanticFacts.moduleSpecifiers} (opt-in). */
|
|
118
|
+
readonly collectSpecifiers?: boolean;
|
|
66
119
|
}
|
|
67
|
-
/** True when `imported` from `module` is a compile-time-only intrinsic binding. */
|
|
68
|
-
declare function isCompileTimeOnlyImport(module: string, imported: string): boolean;
|
|
69
120
|
export interface IntrinsicResolution {
|
|
70
121
|
/** True only for a runtime named import of the intrinsic from its canonical module. */
|
|
71
122
|
readonly canonical: boolean;
|
|
@@ -90,6 +141,12 @@ export interface ModuleIntrinsicBindings {
|
|
|
90
141
|
isStaticSidecarCallee(expression: ts.Expression): boolean;
|
|
91
142
|
/** True for a runtime (non-type-only) named import, aliases followed. */
|
|
92
143
|
isRuntimeNamedImport(localName: string, module: string | readonly string[], imported: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* True when the module binds the name itself (top-level local declaration
|
|
146
|
+
* or any import): such a spelling never refers to a platform global. Same
|
|
147
|
+
* top-level-only shadowing discipline the intrinsic resolution uses.
|
|
148
|
+
*/
|
|
149
|
+
hasModuleScopeBinding(localName: string): boolean;
|
|
93
150
|
}
|
|
94
151
|
/**
|
|
95
152
|
* The compiler's admitted base classes, in resolution order (alpha.13 I2,
|
|
@@ -118,6 +175,27 @@ declare function resolveCanonicalBaseClass(bindings: ModuleIntrinsicBindings, he
|
|
|
118
175
|
* another package.
|
|
119
176
|
*/
|
|
120
177
|
declare function createModuleIntrinsicBindings(sourceFile: ts.SourceFile, options?: SemanticCoreOptions): ModuleIntrinsicBindings;
|
|
178
|
+
/**
|
|
179
|
+
* The compiler's custom-element tag predicate. Exported for the generated-element
|
|
180
|
+
* lane's sidecar `tag` read (`semantic-ir/generated-element/site.ts`): the lane
|
|
181
|
+
* must not carry a second hyphenated-name regex, so the one this module already
|
|
182
|
+
* applies to JSX references is the one the sidecar fact is screened by.
|
|
183
|
+
*/
|
|
184
|
+
declare function isCustomElementTag(value: string): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* The exported name of a function declaration / single-declarator variable
|
|
187
|
+
* statement that {@link isExportedServerComponentDeclaration} admitted.
|
|
188
|
+
*/
|
|
189
|
+
declare function serverComponentName(statement: ts.Statement): string;
|
|
190
|
+
/**
|
|
191
|
+
* The structural server function component shapes the fact scan reports:
|
|
192
|
+
* a named `export function` whose body is exactly one `return <jsx>` or an
|
|
193
|
+
* `export const` arrow whose expression body is JSX. The compile entry
|
|
194
|
+
* (`compileServerComponentModule`) re-derives the same shapes with
|
|
195
|
+
* fail-closed diagnostics; this scan only answers "is there something to
|
|
196
|
+
* compile here" for the module graph walker.
|
|
197
|
+
*/
|
|
198
|
+
declare function isExportedServerComponentDeclaration(statement: ts.Statement): boolean;
|
|
121
199
|
/**
|
|
122
200
|
* Parse one module source and report the semantic facts the compiler boundary
|
|
123
201
|
* and the Vite graph adapters branch on. Pure: it never resolves imports from
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { hasIslandPolicyStatement } from "./island-policy-statement.js";
|
|
2
|
+
import { isJsxModuleId } from "./jsx-module-id.js";
|
|
1
3
|
import ts from "typescript";
|
|
2
4
|
//#region src/internal/compiler/semantic-core/module-analysis.ts
|
|
3
5
|
/** Bundler-neutral module semantics consumed by compiler and Vite graph adapters. */
|
|
@@ -12,23 +14,13 @@ const INTRINSIC_MODULES = {
|
|
|
12
14
|
/**
|
|
13
15
|
* The core's own vocabulary: empty. The element package exposes no
|
|
14
16
|
* defineElement() factory — compiled registration is the @element decorator
|
|
15
|
-
* on an OpenElement subclass, which the scan recognizes directly.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* on an OpenElement subclass, which the scan recognizes directly. Router's
|
|
18
|
+
* page-definition and registration vocabulary rides host-injected
|
|
19
|
+
* descriptors, and any retired or unrecognized factory name fails closed
|
|
18
20
|
* like any other unrecognized import.
|
|
19
21
|
*/
|
|
20
22
|
const CORE_VOCABULARY = [];
|
|
21
23
|
/**
|
|
22
|
-
* Intrinsics that exist only at compile time: the compiler erases the
|
|
23
|
-
* decorator applications they power, and the runtime packages export no such
|
|
24
|
-
* bindings, so the generated module must not keep importing them.
|
|
25
|
-
*/
|
|
26
|
-
const COMPILE_TIME_ONLY_IMPORTS = { "@openelement/element": ["element", "property"] };
|
|
27
|
-
/** True when `imported` from `module` is a compile-time-only intrinsic binding. */
|
|
28
|
-
function isCompileTimeOnlyImport(module, imported) {
|
|
29
|
-
return COMPILE_TIME_ONLY_IMPORTS[module]?.includes(imported) ?? false;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
24
|
* The compiler's admitted base classes, in resolution order (alpha.13 I2,
|
|
33
25
|
* KR-11): the README documents subclassing `ErrorBoundary`, and the compiler
|
|
34
26
|
* admits that authoring form exactly as it admits `OpenElement` — both must
|
|
@@ -170,17 +162,76 @@ function createModuleIntrinsicBindings(sourceFile, options = {}) {
|
|
|
170
162
|
const modules = typeof module === "string" ? [module] : module;
|
|
171
163
|
const bindings = imports.get(localName) ?? [];
|
|
172
164
|
return bindings.length === 1 && bindings[0].form === "named" && modules.includes(bindings[0].module) && bindings[0].imported === imported && !bindings[0].typeOnly;
|
|
165
|
+
},
|
|
166
|
+
hasModuleScopeBinding(localName) {
|
|
167
|
+
return locals.has(localName) || imports.has(localName);
|
|
173
168
|
}
|
|
174
169
|
};
|
|
175
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* The compiler's custom-element tag predicate. Exported for the generated-element
|
|
173
|
+
* lane's sidecar `tag` read (`semantic-ir/generated-element/site.ts`): the lane
|
|
174
|
+
* must not carry a second hyphenated-name regex, so the one this module already
|
|
175
|
+
* applies to JSX references is the one the sidecar fact is screened by.
|
|
176
|
+
*/
|
|
176
177
|
function isCustomElementTag(value) {
|
|
177
178
|
return /^[a-z][a-z0-9]*(-[a-z0-9]+)+$/.test(value);
|
|
178
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* The exported name of a function declaration / single-declarator variable
|
|
182
|
+
* statement that {@link isExportedServerComponentDeclaration} admitted.
|
|
183
|
+
*/
|
|
184
|
+
function serverComponentName(statement) {
|
|
185
|
+
if (ts.isFunctionDeclaration(statement)) return statement.name?.text ?? "";
|
|
186
|
+
const declaration = statement.declarationList.declarations[0];
|
|
187
|
+
return ts.isIdentifier(declaration.name) ? declaration.name.text : "";
|
|
188
|
+
}
|
|
189
|
+
function returnsJsx(expression) {
|
|
190
|
+
const value = expression && ts.isParenthesizedExpression(expression) ? expression.expression : expression;
|
|
191
|
+
return value !== void 0 && (ts.isJsxElement(value) || ts.isJsxSelfClosingElement(value));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The structural server function component shapes the fact scan reports:
|
|
195
|
+
* a named `export function` whose body is exactly one `return <jsx>` or an
|
|
196
|
+
* `export const` arrow whose expression body is JSX. The compile entry
|
|
197
|
+
* (`compileServerComponentModule`) re-derives the same shapes with
|
|
198
|
+
* fail-closed diagnostics; this scan only answers "is there something to
|
|
199
|
+
* compile here" for the module graph walker.
|
|
200
|
+
*/
|
|
201
|
+
function isExportedServerComponentDeclaration(statement) {
|
|
202
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) ?? [] : [];
|
|
203
|
+
if (!modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) return false;
|
|
204
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
205
|
+
if (statement.name === void 0 || modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) || statement.body === void 0 || !ts.isBlock(statement.body)) return false;
|
|
206
|
+
const returns = statement.body.statements.filter(ts.isReturnStatement);
|
|
207
|
+
return statement.body.statements.length === 1 && returns.length === 1 && returnsJsx(returns[0].expression);
|
|
208
|
+
}
|
|
209
|
+
if (ts.isVariableStatement(statement)) {
|
|
210
|
+
const declarations = statement.declarationList.declarations;
|
|
211
|
+
if (declarations.length !== 1 || !ts.isIdentifier(declarations[0].name)) return false;
|
|
212
|
+
const initializer = declarations[0].initializer;
|
|
213
|
+
return initializer !== void 0 && ts.isArrowFunction(initializer) && !ts.isBlock(initializer.body) && returnsJsx(initializer.body);
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
179
217
|
function stringArgument(call, index = 0) {
|
|
180
218
|
const argument = call.arguments[index];
|
|
181
219
|
return argument && (ts.isStringLiteral(argument) || ts.isNoSubstitutionTemplateLiteral(argument)) ? argument.text : void 0;
|
|
182
220
|
}
|
|
183
221
|
/**
|
|
222
|
+
* Whether a `.define(...)` callee object is the platform CustomElementRegistry:
|
|
223
|
+
* a bare module-unbound `customElements` global, or the registry reached
|
|
224
|
+
* through an unambiguous unbound global qualifier
|
|
225
|
+
* (`window.`/`globalThis.`/`self.`). Raw text matching misfires both ways — a
|
|
226
|
+
* module-scope `customElements` binding (import or local) is a shadow, not the
|
|
227
|
+
* registry, while a qualified global spelling is the registry and must count.
|
|
228
|
+
*/
|
|
229
|
+
function isCustomElementsRegistry(object, imports) {
|
|
230
|
+
if (ts.isIdentifier(object)) return object.text === "customElements" && !imports.hasModuleScopeBinding(object.text);
|
|
231
|
+
if (ts.isPropertyAccessExpression(object) && object.name.text === "customElements" && ts.isIdentifier(object.expression) && !imports.hasModuleScopeBinding(object.expression.text)) return object.expression.text === "window" || object.expression.text === "globalThis" || object.expression.text === "self";
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
184
235
|
* Parse one module source and report the semantic facts the compiler boundary
|
|
185
236
|
* and the Vite graph adapters branch on. Pure: it never resolves imports from
|
|
186
237
|
* disk and never throws on foreign or invalid syntax — an unparsable module
|
|
@@ -191,30 +242,44 @@ function stringArgument(call, index = 0) {
|
|
|
191
242
|
* descriptors.
|
|
192
243
|
*/
|
|
193
244
|
function analyzeModuleSemantics(source, fileName, options = {}) {
|
|
194
|
-
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true,
|
|
245
|
+
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, isJsxModuleId(fileName) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
195
246
|
const imports = createModuleIntrinsicBindings(sourceFile);
|
|
196
247
|
const vocabulary = [...CORE_VOCABULARY, ...options.vocabulary ?? []];
|
|
197
248
|
const pageDefinitionBindings = vocabulary.filter((descriptor) => descriptor.kind === "page-definition");
|
|
198
249
|
const registrationBindings = vocabulary.filter((descriptor) => descriptor.kind === "element-registration");
|
|
199
250
|
const relativeImports = /* @__PURE__ */ new Set();
|
|
200
|
-
|
|
251
|
+
const moduleSpecifiers = /* @__PURE__ */ new Set();
|
|
252
|
+
for (const statement of sourceFile.statements) if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier) && !(ts.isImportDeclaration(statement) ? statement.importClause?.isTypeOnly : statement.isTypeOnly)) {
|
|
253
|
+
moduleSpecifiers.add(statement.moduleSpecifier.text);
|
|
254
|
+
if (statement.moduleSpecifier.text.startsWith(".")) relativeImports.add(statement.moduleSpecifier.text);
|
|
255
|
+
}
|
|
201
256
|
let exportedTagName;
|
|
202
257
|
let compiledElementDecorator = false;
|
|
203
258
|
let unsupportedElementDecorator;
|
|
204
259
|
let definePage = fileName.endsWith(".mdx");
|
|
260
|
+
let pageComponentName;
|
|
205
261
|
let usesExportedTagName = false;
|
|
206
262
|
let enhancedForm = false;
|
|
207
263
|
let defaultCompiledTag;
|
|
208
264
|
const defined = /* @__PURE__ */ new Set();
|
|
209
265
|
const referenced = /* @__PURE__ */ new Set();
|
|
210
266
|
const interactionEvents = /* @__PURE__ */ new Set();
|
|
267
|
+
const serverComponents = /* @__PURE__ */ new Set();
|
|
268
|
+
for (const statement of sourceFile.statements) if (isExportedServerComponentDeclaration(statement)) serverComponents.add(serverComponentName(statement));
|
|
211
269
|
for (const statement of sourceFile.statements) {
|
|
212
270
|
if (ts.isVariableStatement(statement) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
213
271
|
for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.name.text === "tagName" && declaration.initializer && (ts.isStringLiteral(declaration.initializer) || ts.isNoSubstitutionTemplateLiteral(declaration.initializer))) exportedTagName = declaration.initializer.text;
|
|
214
272
|
}
|
|
215
273
|
if (ts.isExportAssignment(statement) && ts.isCallExpression(statement.expression) && ts.isIdentifier(statement.expression.expression)) {
|
|
216
274
|
const pageFactory = statement.expression.expression.text;
|
|
217
|
-
|
|
275
|
+
const matchedPageBinding = pageDefinitionBindings.find((descriptor) => imports.isRuntimeNamedImport(pageFactory, descriptor.moduleSpecifier, descriptor.exportName));
|
|
276
|
+
if (matchedPageBinding) {
|
|
277
|
+
definePage = true;
|
|
278
|
+
if (matchedPageBinding.kind === "page-definition" && matchedPageBinding.exportName === "definePage") {
|
|
279
|
+
const firstArgument = statement.expression.arguments[0];
|
|
280
|
+
if (firstArgument !== void 0 && ts.isIdentifier(firstArgument) && serverComponents.has(firstArgument.text)) pageComponentName = firstArgument.text;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
218
283
|
}
|
|
219
284
|
if (!ts.isClassDeclaration(statement)) continue;
|
|
220
285
|
const isDefault = statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword);
|
|
@@ -249,7 +314,7 @@ function analyzeModuleSemantics(source, fileName, options = {}) {
|
|
|
249
314
|
const tag = stringArgument(node);
|
|
250
315
|
if (tag && isCustomElementTag(tag)) referenced.add(tag);
|
|
251
316
|
}
|
|
252
|
-
} else if (ts.isPropertyAccessExpression(expression) && expression.
|
|
317
|
+
} else if (ts.isPropertyAccessExpression(expression) && expression.name.text === "define" && isCustomElementsRegistry(expression.expression, imports)) {
|
|
253
318
|
const tag = stringArgument(node);
|
|
254
319
|
if (tag && isCustomElementTag(tag)) defined.add(tag);
|
|
255
320
|
if (tag !== void 0 && tag === exportedTagName) usesExportedTagName = true;
|
|
@@ -277,17 +342,21 @@ function analyzeModuleSemantics(source, fileName, options = {}) {
|
|
|
277
342
|
visit(sourceFile);
|
|
278
343
|
return {
|
|
279
344
|
relativeImports: [...relativeImports],
|
|
345
|
+
...options.collectSpecifiers === true ? { moduleSpecifiers: [...moduleSpecifiers] } : {},
|
|
280
346
|
compiledElementDecorator,
|
|
281
347
|
...unsupportedElementDecorator === void 0 ? {} : { unsupportedElementDecorator },
|
|
282
348
|
...exportedTagName === void 0 ? {} : { exportedTagName },
|
|
283
349
|
definePage,
|
|
350
|
+
...pageComponentName === void 0 ? {} : { pageComponentName },
|
|
351
|
+
serverFunctionComponents: [...serverComponents].sort(),
|
|
284
352
|
usesExportedTagName,
|
|
285
353
|
enhancedForm,
|
|
286
354
|
...defaultCompiledTag === void 0 ? {} : { defaultCompiledTag },
|
|
287
355
|
definedCustomElementTags: [...defined].sort(),
|
|
288
356
|
referencedCustomElementTags: [...referenced].sort(),
|
|
289
|
-
compilerInteractionEvents: [...interactionEvents].sort()
|
|
357
|
+
compilerInteractionEvents: [...interactionEvents].sort(),
|
|
358
|
+
hasGeneratedElementSidecar: hasIslandPolicyStatement(sourceFile)
|
|
290
359
|
};
|
|
291
360
|
}
|
|
292
361
|
//#endregion
|
|
293
|
-
export { CANONICAL_BASE_CLASS_INTRINSICS, analyzeModuleSemantics, createModuleIntrinsicBindings,
|
|
362
|
+
export { CANONICAL_BASE_CLASS_INTRINSICS, analyzeModuleSemantics, createModuleIntrinsicBindings, isCustomElementTag, isExportedServerComponentDeclaration, resolveCanonicalBaseClass, serverComponentName };
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
//#region src/internal/compiler/semantic-core/parse-module.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* JavaScript parsing API (#1473, item 2 of the semantic-core split).
|
|
4
|
+
* TypeScript parsing policy helper for the strict compilation path (#1473).
|
|
6
5
|
*
|
|
7
|
-
* `ParserPort`
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* `ParserPort` returns a TypeScript AST and TypeScript syntax diagnostics; it
|
|
7
|
+
* is not a backend-neutral AST boundary. Other paths, including module analysis
|
|
8
|
+
* and type-check hosts, also parse source. Tolerant discovery and strict
|
|
9
|
+
* compilation have different diagnostic responsibilities and need not share
|
|
10
|
+
* this helper's TSX/ES2022 policy.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* making tsgo's native API the supported parse entry, or
|
|
18
|
-
* 2. oxc's standard-decorators support is declared stable.
|
|
19
|
-
* At that point `typescriptParser` swaps for an oxc/tsgo-backed `ParserPort`
|
|
20
|
-
* implementation; the compiler pipeline and its diagnostics contract stay.
|
|
12
|
+
* A future parser change requires auditing those consumers, AST assumptions,
|
|
13
|
+
* source locations and diagnostics. TypeScript API maintenance or another
|
|
14
|
+
* parser's decorator support may motivate evaluation, but do not establish a
|
|
15
|
+
* drop-in replacement or a one-file backend swap.
|
|
21
16
|
*/
|
|
17
|
+
/** Inline TSX and inline JSX JSDoc annotations feed the same props readers. */
|
|
18
|
+
function authoredPropsType(parameter) {
|
|
19
|
+
const isJavaScriptJsx = parameter.getSourceFile().fileName.split("?", 1)[0].endsWith(".jsx");
|
|
20
|
+
return parameter.type ?? (isJavaScriptJsx ? ts.getJSDocType(parameter) : void 0);
|
|
21
|
+
}
|
|
22
22
|
/** The one TypeScript-backed `ParserPort` implementation. */
|
|
23
23
|
const typescriptParser = { parseModule(source, fileName) {
|
|
24
24
|
return {
|
|
@@ -34,4 +34,4 @@ const typescriptParser = { parseModule(source, fileName) {
|
|
|
34
34
|
};
|
|
35
35
|
} };
|
|
36
36
|
//#endregion
|
|
37
|
-
export { typescriptParser };
|
|
37
|
+
export { authoredPropsType, typescriptParser };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
//#region src/internal/compiler/semantic-core/scope-resolution.d.ts
|
|
3
|
+
/** A half-open authored source range (UTF-16 code units, TS position unit). */
|
|
4
|
+
export interface SourceSpan {
|
|
5
|
+
readonly file: string;
|
|
6
|
+
readonly start: number;
|
|
7
|
+
readonly end: number;
|
|
8
|
+
/** 1-based line of `start`. */
|
|
9
|
+
readonly line: number;
|
|
10
|
+
/** 1-based column of `start`. */
|
|
11
|
+
readonly column: number;
|
|
12
|
+
}
|
|
13
|
+
/** Stable within one compilation; not serialized. */
|
|
14
|
+
export interface ScopeId {
|
|
15
|
+
readonly moduleId: string;
|
|
16
|
+
/** Scope-chain path: `"0.2.1"` = module → second child → first child. */
|
|
17
|
+
readonly path: string;
|
|
18
|
+
}
|
|
19
|
+
/** Binding identity. Never contains a `ValueKind` (§3 rule). */
|
|
20
|
+
export interface BindingId {
|
|
21
|
+
readonly scope: ScopeId;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/**
|
|
24
|
+
* Ordinal among declarations of this name in the scope. `0` for every legal
|
|
25
|
+
* merge (declaration merging keeps one identity); raised only when an illegal
|
|
26
|
+
* duplicate has to be recovered as a second identity.
|
|
27
|
+
*/
|
|
28
|
+
readonly declarationOrder: number;
|
|
29
|
+
}
|
|
30
|
+
/** Syntactic form of one declaration. Immutable once built. */
|
|
31
|
+
export type DeclarationKind = 'var' | 'let' | 'const' | 'function' | 'class' | 'class-name' | 'param' | 'import' | 'catch';
|
|
32
|
+
/** Classification; mutable (a host may learn or refine it later). */
|
|
33
|
+
export type ValueKind = 'signal' | 'computed' | 'prop' | 'plain' | 'unknown';
|
|
34
|
+
/** What an imported symbol *is* — a role, not a value category (§6). */
|
|
35
|
+
export type SymbolRole = 'factory' | 'value' | 'type' | 'namespace' | 'unknown';
|
|
36
|
+
/** Where the binding came from (§3). */
|
|
37
|
+
export type BindingOrigin = {
|
|
38
|
+
readonly form: 'local';
|
|
39
|
+
} |
|
|
40
|
+
/**
|
|
41
|
+
* ONLY the component's original props object parameter. Every name produced
|
|
42
|
+
* by destructuring it is `local` (a snapshot) and must not reuse this form.
|
|
43
|
+
*/
|
|
44
|
+
{
|
|
45
|
+
readonly form: 'prop-param';
|
|
46
|
+
} | {
|
|
47
|
+
readonly form: 'import';
|
|
48
|
+
readonly specifier: string;
|
|
49
|
+
/** `null` means a default import (or a namespace import, §6). */
|
|
50
|
+
readonly importedName: string | null;
|
|
51
|
+
} | {
|
|
52
|
+
readonly form: 'builtin';
|
|
53
|
+
readonly name: string;
|
|
54
|
+
};
|
|
55
|
+
/** One syntactic declaration contributing to a binding. */
|
|
56
|
+
export interface DeclarationRecord {
|
|
57
|
+
readonly kind: DeclarationKind;
|
|
58
|
+
/** Points at the authored binding name (the diagnostic location). */
|
|
59
|
+
readonly span: SourceSpan;
|
|
60
|
+
/** True when this record is the one that carries the initializer/value. */
|
|
61
|
+
readonly initializing: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** Classification provenance: syntax-derived or host-supplied (§3). */
|
|
64
|
+
export type ClassificationSource = 'syntax' | 'host-classifier' | 'unresolved';
|
|
65
|
+
/** One resolved binding: every declaration that merged into it. */
|
|
66
|
+
export interface ResolvedBinding {
|
|
67
|
+
readonly id: BindingId;
|
|
68
|
+
readonly declarations: readonly DeclarationRecord[];
|
|
69
|
+
readonly value: ValueKind;
|
|
70
|
+
readonly origin: BindingOrigin;
|
|
71
|
+
/** Authored declaration sites; the first record's span is canonical. */
|
|
72
|
+
readonly declarationSpan: SourceSpan;
|
|
73
|
+
readonly classifiedBy: ClassificationSource;
|
|
74
|
+
/**
|
|
75
|
+
* §6 symbol role (factory/value/type/namespace/unknown) when known. Kept
|
|
76
|
+
* next to—not inside—`ValueKind` so a factory symbol is never mistaken for
|
|
77
|
+
* the value it produces.
|
|
78
|
+
*/
|
|
79
|
+
readonly role: SymbolRole | null;
|
|
80
|
+
}
|
|
81
|
+
/** What calling a factory produces, when the host knows it. */
|
|
82
|
+
export interface FactoryResult {
|
|
83
|
+
readonly call: 'signal' | 'computed' | 'unknown';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The host-supplied classifier for module symbols (§6). The resolver never
|
|
87
|
+
* infers a role from a name; every cross-module question goes through this
|
|
88
|
+
* interface. A host may omit `classifyMember`; namespace member reads then stay
|
|
89
|
+
* `unknown` (§6.1) and fail closed only where a kind is required.
|
|
90
|
+
*/
|
|
91
|
+
export interface ImportClassifier {
|
|
92
|
+
/** Role of the imported symbol (alias already resolved). */
|
|
93
|
+
classifySymbol(moduleSpecifier: string, importedName: string | null): SymbolRole | undefined;
|
|
94
|
+
/** Value kind of the binding, when the host knows it directly. */
|
|
95
|
+
classifyValue(moduleSpecifier: string, importedName: string | null): ValueKind | undefined;
|
|
96
|
+
/** Result kind of a factory call, when the host knows it. */
|
|
97
|
+
classifyCall(moduleSpecifier: string, importedName: string | null): FactoryResult | undefined;
|
|
98
|
+
/** Optional: classify a namespace member (`ns.x`). */
|
|
99
|
+
classifyMember?(moduleSpecifier: string, memberName: string): SymbolRole | undefined;
|
|
100
|
+
}
|
|
101
|
+
/** When the expression runs. Dependency selection depends on it (§5). */
|
|
102
|
+
export type EvaluationMode = 'setup' | 'inline' | 'handler' | 'derived' | 'per-entry' | 'key';
|
|
103
|
+
/** One identifier an expression reads, resolved to a binding. */
|
|
104
|
+
export interface ResolvedRead {
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly binding: BindingId;
|
|
107
|
+
readonly value: ValueKind;
|
|
108
|
+
readonly span: SourceSpan;
|
|
109
|
+
/** True when the read crosses a function boundary (§5), builtins excepted. */
|
|
110
|
+
readonly capture: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** An identifier an expression reads that resolves to nothing (a diagnostic). */
|
|
113
|
+
export interface UnresolvedRead {
|
|
114
|
+
readonly name: string;
|
|
115
|
+
readonly span: SourceSpan;
|
|
116
|
+
}
|
|
117
|
+
/** §5's four axes for one expression, plus the diagnostics and failures. */
|
|
118
|
+
export interface ExpressionResolution {
|
|
119
|
+
readonly mode: EvaluationMode;
|
|
120
|
+
readonly reads: readonly ResolvedRead[];
|
|
121
|
+
/** Subset of `reads`: lexical captures. */
|
|
122
|
+
readonly captures: readonly BindingId[];
|
|
123
|
+
/** Subset of `reads`: reactive reads in a tracked mode. */
|
|
124
|
+
readonly dependencies: readonly BindingId[];
|
|
125
|
+
readonly unresolvedReads: readonly UnresolvedRead[];
|
|
126
|
+
readonly diagnostics: readonly ScopeDiagnostic[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Where a diagnostic can be located. The resolver reports authored sites, so
|
|
130
|
+
* its findings are `source`; `module` is reserved for a future module-wide
|
|
131
|
+
* finding that has no authored node.
|
|
132
|
+
*/
|
|
133
|
+
export type ScopeDiagnosticOrigin = 'source' | 'module';
|
|
134
|
+
/** A coded, source-located resolver diagnostic. */
|
|
135
|
+
export interface ScopeDiagnostic {
|
|
136
|
+
readonly severity: 'error' | 'warning';
|
|
137
|
+
readonly code: string;
|
|
138
|
+
readonly message: string;
|
|
139
|
+
readonly span: SourceSpan;
|
|
140
|
+
readonly origin: ScopeDiagnosticOrigin;
|
|
141
|
+
}
|
|
142
|
+
export type ScopeKind = 'module' | 'function' | 'block' | 'catch' | 'for' | 'switch' | 'class' |
|
|
143
|
+
/** Synthetic parent of the module scope holding builtin globals. */
|
|
144
|
+
'global';
|
|
145
|
+
/** One lexical scope. Scope paths are internal numbering, not a contract. */
|
|
146
|
+
export interface ScopeRecord {
|
|
147
|
+
readonly id: ScopeId;
|
|
148
|
+
readonly kind: ScopeKind;
|
|
149
|
+
readonly parent: ScopeId | null;
|
|
150
|
+
readonly span: SourceSpan;
|
|
151
|
+
/** Function/arrow/method/static-block scopes are function boundaries. */
|
|
152
|
+
readonly functionBoundary: boolean;
|
|
153
|
+
/** Nesting depth, module = 0 (global = -1). */
|
|
154
|
+
readonly depth: number;
|
|
155
|
+
/** Number of function boundaries on the chain, module = 0. */
|
|
156
|
+
readonly functionDepth: number;
|
|
157
|
+
}
|
|
158
|
+
/** The function-shaped component roots the resolver is asked about. */
|
|
159
|
+
export type ComponentFunction = ts.FunctionDeclaration | ts.FunctionExpression | ts.ArrowFunction;
|
|
160
|
+
/** Options for `resolveModule`. */
|
|
161
|
+
export interface ResolveModuleOptions {
|
|
162
|
+
/**
|
|
163
|
+
* The function components in this module. Their first parameter is the props
|
|
164
|
+
* parameter (§3 `prop-param` origin) and their subtree is checked for the
|
|
165
|
+
* context-sensitive constructs of §4 (`this`, `arguments`, `super`,
|
|
166
|
+
* `new.target`). Omitted: the module is resolved without component
|
|
167
|
+
* provenance, and those diagnostics are not produced.
|
|
168
|
+
*/
|
|
169
|
+
readonly components?: readonly ComponentFunction[];
|
|
170
|
+
/** Host classifier for imported symbols (§6). */
|
|
171
|
+
readonly importClassifier?: ImportClassifier;
|
|
172
|
+
/** Additionally-resolvable global names (the default list is ECMAScript-only). */
|
|
173
|
+
readonly globals?: readonly string[];
|
|
174
|
+
}
|
|
175
|
+
/** A resolved module: bindings, scopes, diagnostics, and the resolution API. */
|
|
176
|
+
export interface ResolvedModule {
|
|
177
|
+
readonly moduleId: string;
|
|
178
|
+
readonly file: string;
|
|
179
|
+
readonly sourceFile: ts.SourceFile;
|
|
180
|
+
/** Declaration/import/unsupported-construct findings. */
|
|
181
|
+
readonly diagnostics: readonly ScopeDiagnostic[];
|
|
182
|
+
/** The scope tree, global scope first. */
|
|
183
|
+
readonly scopes: readonly ScopeRecord[];
|
|
184
|
+
/** Authored bindings only; builtin globals are synthesized on read. */
|
|
185
|
+
readonly bindings: readonly ResolvedBinding[];
|
|
186
|
+
/**
|
|
187
|
+
* Resolve one authored expression on the §5 four axes. `node` must belong to
|
|
188
|
+
* this module's `sourceFile`; the call is pure (returns fresh diagnostics)
|
|
189
|
+
* and reads the final binding classifications built by `resolveModule`.
|
|
190
|
+
*/
|
|
191
|
+
resolveExpression(node: ts.Node, mode: EvaluationMode): ExpressionResolution;
|
|
192
|
+
/**
|
|
193
|
+
* Lexical resolution of one value-position identifier occurrence (no
|
|
194
|
+
* diagnostics). A declaration/property-name occurrence has no meaning here;
|
|
195
|
+
* callers pass expression identifiers.
|
|
196
|
+
*/
|
|
197
|
+
resolveIdentifier(node: ts.Identifier): ResolvedBinding | undefined;
|
|
198
|
+
}
|
|
199
|
+
/** Stable key for a `BindingId` (identity is never serialized, lookups need one). */
|
|
200
|
+
declare function bindingKey(id: BindingId): string;
|
|
201
|
+
/**
|
|
202
|
+
* Resolve the lexical scopes, declarations, reads, captures and dependencies of
|
|
203
|
+
* one module. Pure: the caller hands the parsed source file and the host
|
|
204
|
+
* classifier; the resolver never touches a `ts.Program`, the filesystem or
|
|
205
|
+
* ambient state.
|
|
206
|
+
*/
|
|
207
|
+
declare function resolveModule(sourceFile: ts.SourceFile, options?: ResolveModuleOptions): ResolvedModule;
|
|
208
|
+
//#endregion
|