@jalvin/compiler 2.0.42 → 2.0.43
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/dist/codegen.d.ts +53 -11
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +831 -339
- package/dist/codegen.js.map +1 -1
- package/dist/diagnostics.d.ts +0 -2
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +1 -3
- package/dist/diagnostics.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/typechecker.d.ts +0 -12
- package/dist/typechecker.d.ts.map +1 -1
- package/dist/typechecker.js +152 -244
- package/dist/typechecker.js.map +1 -1
- package/package.json +1 -1
package/dist/codegen.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as AST from "./ast.js";
|
|
2
2
|
import { JType } from "./typechecker.js";
|
|
3
3
|
export interface CodegenOptions {
|
|
4
|
+
/** Emit .tsx (React JSX) output — set for files containing `component` decls */
|
|
5
|
+
readonly jsx: boolean;
|
|
4
6
|
/** Target module format */
|
|
5
7
|
readonly module: "esm" | "cjs";
|
|
6
8
|
/** Emit type annotations in output (verbose but useful for debugging) */
|
|
@@ -20,18 +22,16 @@ export declare const DEFAULT_CODEGEN_OPTIONS: CodegenOptions;
|
|
|
20
22
|
export interface CodegenResult {
|
|
21
23
|
readonly code: string;
|
|
22
24
|
readonly lineMap: number[];
|
|
23
|
-
/**
|
|
24
|
-
readonly
|
|
25
|
+
/** Whether JSX was emitted (caller should rename output to .tsx) */
|
|
26
|
+
readonly isJsx: boolean;
|
|
25
27
|
}
|
|
26
28
|
export declare class CodeGenerator {
|
|
27
29
|
private readonly w;
|
|
28
30
|
private readonly opts;
|
|
29
31
|
private hasComponents;
|
|
30
32
|
private runtimeSymbolsNeeded;
|
|
31
|
-
/** Names of
|
|
32
|
-
private
|
|
33
|
-
/** Names of all potential components (including UI primitives) — used to detect props-object calls */
|
|
34
|
-
private allComponentLikeNames;
|
|
33
|
+
/** Names of component functions — used to detect component calls and emit them as JSX */
|
|
34
|
+
private componentNames;
|
|
35
35
|
/**
|
|
36
36
|
* Param names for components resolved from imported local .jalvin files.
|
|
37
37
|
* Maps component name → ordered list of param names.
|
|
@@ -39,8 +39,6 @@ export declare class CodeGenerator {
|
|
|
39
39
|
private componentParamNames;
|
|
40
40
|
/** True when the program contains `import @jalvin/ui.*` — used to detect UI primitive calls */
|
|
41
41
|
private hasUiStarImport;
|
|
42
|
-
/** Names of symbols explicitly imported from @jalvin/ui */
|
|
43
|
-
private uiNamedImports;
|
|
44
42
|
/** Operator overload resolutions from the type checker */
|
|
45
43
|
private operatorOverloadMap;
|
|
46
44
|
/** Type map from the type checker */
|
|
@@ -64,23 +62,36 @@ export declare class CodeGenerator {
|
|
|
64
62
|
* Maps module specifier (e.g. "src/views") → sorted list of exported names.
|
|
65
63
|
*/
|
|
66
64
|
private localStarExports;
|
|
67
|
-
private isInClass;
|
|
68
65
|
constructor(opts?: Partial<CodegenOptions>);
|
|
69
66
|
generate(program: AST.Program, operatorOverloads?: Map<AST.BinaryExpr, string>, typeMap?: Map<object, JType>): CodegenResult;
|
|
70
|
-
/** Walk AST to see if it contains any JsxElement nodes */
|
|
71
|
-
private containsJsx;
|
|
72
67
|
private buildPreamble;
|
|
73
68
|
private emitHeader;
|
|
69
|
+
/**
|
|
70
|
+
* Heuristic for non-scoped imports: if the first path segment resolves to an
|
|
71
|
+
* installed package in node_modules, treat the import as npm/ESM and strip
|
|
72
|
+
* the trailing symbol name from the module specifier.
|
|
73
|
+
*/
|
|
74
74
|
private isLikelyNodeModuleImport;
|
|
75
|
+
/** Emit a @deprecated JSDoc block if the declaration has @Nuked. */
|
|
75
76
|
private emitAnnotations;
|
|
76
77
|
private emitTopLevelDecl;
|
|
77
78
|
private emitFunDecl;
|
|
78
79
|
private emitMemberFunDecl;
|
|
79
80
|
private emitComponentDecl;
|
|
81
|
+
/**
|
|
82
|
+
* Emit the body of a `component fun` block.
|
|
83
|
+
* The last statement is emitted in tail position — if it is an expression,
|
|
84
|
+
* an if/else chain, or a when block, the innermost UI call is implicitly
|
|
85
|
+
* returned (implicit return of the last expression).
|
|
86
|
+
*/
|
|
80
87
|
private emitComponentBlock;
|
|
88
|
+
/** Emit a statement in tail position, adding implicit return where applicable. */
|
|
81
89
|
private emitTailStmt;
|
|
90
|
+
/** Emit a block in tail position, treating its last statement as a tail expression. */
|
|
82
91
|
private emitTailBlock;
|
|
92
|
+
/** Like emitIfStmt but with tail-return applied recursively to each branch body. */
|
|
83
93
|
private emitIfStmtWithTailReturn;
|
|
94
|
+
/** Like emitWhenStmt but with tail-return applied recursively to each branch body. */
|
|
84
95
|
private emitWhenStmtWithTailReturn;
|
|
85
96
|
private emitClassDecl;
|
|
86
97
|
private emitDataClassDecl;
|
|
@@ -92,6 +103,11 @@ export declare class CodeGenerator {
|
|
|
92
103
|
private emitTypeAliasDecl;
|
|
93
104
|
private emitExtensionFunDecl;
|
|
94
105
|
private receiverClassName;
|
|
106
|
+
/**
|
|
107
|
+
* Maps a JType to the primitive receiver type name used as a key
|
|
108
|
+
* in `primitiveExtensions` (e.g. JType `{ tag: "string" }` → `"String"`).
|
|
109
|
+
* Returns null for non-primitive / unknown types.
|
|
110
|
+
*/
|
|
95
111
|
private jTypeToReceiverName;
|
|
96
112
|
private classHasInvokeOperator;
|
|
97
113
|
private emitPropertyDecl;
|
|
@@ -114,9 +130,20 @@ export declare class CodeGenerator {
|
|
|
114
130
|
private emitJsxChild;
|
|
115
131
|
private emitStringTemplate;
|
|
116
132
|
private emitCallExpr;
|
|
133
|
+
/**
|
|
134
|
+
* For each non-scoped local import (e.g. `import src.views.MoveCounterView.MoveCounter`),
|
|
135
|
+
* attempt to load and parse the corresponding .jalvin source file. If the named symbol is
|
|
136
|
+
* a `component fun`, register it in `componentNames` and record its param names so that
|
|
137
|
+
* call sites can emit the correct props-object invocation.
|
|
138
|
+
*/
|
|
117
139
|
private resolveLocalComponentImports;
|
|
140
|
+
/** Returns true if a call expression's callee looks like a class constructor.
|
|
141
|
+
* In Jalvin, class names always start with an uppercase letter. */
|
|
118
142
|
private isConstructorCall;
|
|
143
|
+
/** Emit `Column(modifier = ...) { ... }` as `React.createElement(Column, { modifier: ... }, [children])` */
|
|
119
144
|
private emitComponentCall;
|
|
145
|
+
/** Collect each expression statement in a trailing-lambda body as DOM children.
|
|
146
|
+
* For-loop statements are emitted as spread IIFEs so their dynamic output is preserved. */
|
|
120
147
|
private emitLambdaBodyAsDomChildren;
|
|
121
148
|
private emitLambdaExpr;
|
|
122
149
|
private emitIfExpr;
|
|
@@ -131,12 +158,27 @@ export declare class CodeGenerator {
|
|
|
131
158
|
private emitTypeRef;
|
|
132
159
|
private emitTypeParamsStr;
|
|
133
160
|
private emitParamsStr;
|
|
161
|
+
private emitComponentPropsStr;
|
|
134
162
|
private emitSuperTypesStr;
|
|
135
163
|
private exportPrefix;
|
|
136
164
|
private visibilityPrefix;
|
|
137
165
|
private unaryOpStr;
|
|
138
166
|
private binaryOpStr;
|
|
167
|
+
/**
|
|
168
|
+
* Walk the entire program AST and collect all identifier names that are
|
|
169
|
+
* REFERENCED (i.e., used) in the code: NameExpr values and the first name
|
|
170
|
+
* component of SimpleTypeRef / GenericTypeRef nodes.
|
|
171
|
+
*
|
|
172
|
+
* Jalvin primitive type names (String, Boolean, …) that map to TS primitives
|
|
173
|
+
* are excluded from TypeRef collection since they never need an import.
|
|
174
|
+
*/
|
|
139
175
|
private gatherReferencedNames;
|
|
176
|
+
/**
|
|
177
|
+
* Walk the entire program AST and collect all names that are LOCALLY DEFINED:
|
|
178
|
+
* top-level declaration names, non-star import aliases, function/lambda
|
|
179
|
+
* parameters, local val/var bindings, for-loop variables, catch-clause names,
|
|
180
|
+
* when-subject bindings, and type parameter names.
|
|
181
|
+
*/
|
|
140
182
|
private gatherAllLocalBindings;
|
|
141
183
|
}
|
|
142
184
|
export declare function generate(program: AST.Program, opts?: Partial<CodegenOptions>, operatorOverloads?: Map<AST.BinaryExpr, string>, typeMap?: Map<object, JType>): CodegenResult;
|
package/dist/codegen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAoDzC,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAoDzC,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,uBAAuB,EAAE,cAKrC,CAAC;AAEF,MAAM,WAA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