@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
@@ -1,24 +1,24 @@
1
1
  import ts from "typescript";
2
2
  //#region src/internal/compiler/semantic-core/parse-module.ts
3
3
  /**
4
- * The compiler's parse seam — the ONE module that depends on the TypeScript
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` is the explicit boundary every parse backend implements:
8
- * authored source in, TS AST plus syntax diagnostics out. The rest of the
9
- * semantic core consumes the resulting AST through read-only type predicates
10
- * and never constructs or transpiles a parse tree itself, so replacing the
11
- * backend is a change to this file's single implementation and nowhere else.
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
- * Retirement conditions (the alpha6 architecture-debt lane, issue #1473): this
14
- * TypeScript-backed implementation is scheduled to be replaced when either
15
- * trigger fires, whichever lands first —
16
- * 1. the TypeScript 6 line ends JavaScript-API maintenance ("JS-API EOL"),
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