@jalvin/compiler 2.0.43 → 2.0.44
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 +11 -53
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +339 -831
- package/dist/codegen.js.map +1 -1
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +3 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/typechecker.d.ts +12 -0
- package/dist/typechecker.d.ts.map +1 -1
- package/dist/typechecker.js +244 -152
- package/dist/typechecker.js.map +1 -1
- package/package.json +1 -1
package/dist/codegen.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
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;
|
|
6
4
|
/** Target module format */
|
|
7
5
|
readonly module: "esm" | "cjs";
|
|
8
6
|
/** Emit type annotations in output (verbose but useful for debugging) */
|
|
@@ -22,16 +20,18 @@ export declare const DEFAULT_CODEGEN_OPTIONS: CodegenOptions;
|
|
|
22
20
|
export interface CodegenResult {
|
|
23
21
|
readonly code: string;
|
|
24
22
|
readonly lineMap: number[];
|
|
25
|
-
/**
|
|
26
|
-
readonly
|
|
23
|
+
/** True if the program contains component declarations or UI imports. */
|
|
24
|
+
readonly hasComponents: boolean;
|
|
27
25
|
}
|
|
28
26
|
export declare class CodeGenerator {
|
|
29
27
|
private readonly w;
|
|
30
28
|
private readonly opts;
|
|
31
29
|
private hasComponents;
|
|
32
30
|
private runtimeSymbolsNeeded;
|
|
33
|
-
/** Names of
|
|
34
|
-
private
|
|
31
|
+
/** Names of true Jalvin components — used to detect functional calls */
|
|
32
|
+
private userComponentNames;
|
|
33
|
+
/** Names of all potential components (including UI primitives) — used to detect props-object calls */
|
|
34
|
+
private allComponentLikeNames;
|
|
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,6 +39,8 @@ 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;
|
|
42
44
|
/** Operator overload resolutions from the type checker */
|
|
43
45
|
private operatorOverloadMap;
|
|
44
46
|
/** Type map from the type checker */
|
|
@@ -62,36 +64,23 @@ export declare class CodeGenerator {
|
|
|
62
64
|
* Maps module specifier (e.g. "src/views") → sorted list of exported names.
|
|
63
65
|
*/
|
|
64
66
|
private localStarExports;
|
|
67
|
+
private isInClass;
|
|
65
68
|
constructor(opts?: Partial<CodegenOptions>);
|
|
66
69
|
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;
|
|
67
72
|
private buildPreamble;
|
|
68
73
|
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. */
|
|
76
75
|
private emitAnnotations;
|
|
77
76
|
private emitTopLevelDecl;
|
|
78
77
|
private emitFunDecl;
|
|
79
78
|
private emitMemberFunDecl;
|
|
80
79
|
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
|
-
*/
|
|
87
80
|
private emitComponentBlock;
|
|
88
|
-
/** Emit a statement in tail position, adding implicit return where applicable. */
|
|
89
81
|
private emitTailStmt;
|
|
90
|
-
/** Emit a block in tail position, treating its last statement as a tail expression. */
|
|
91
82
|
private emitTailBlock;
|
|
92
|
-
/** Like emitIfStmt but with tail-return applied recursively to each branch body. */
|
|
93
83
|
private emitIfStmtWithTailReturn;
|
|
94
|
-
/** Like emitWhenStmt but with tail-return applied recursively to each branch body. */
|
|
95
84
|
private emitWhenStmtWithTailReturn;
|
|
96
85
|
private emitClassDecl;
|
|
97
86
|
private emitDataClassDecl;
|
|
@@ -103,11 +92,6 @@ export declare class CodeGenerator {
|
|
|
103
92
|
private emitTypeAliasDecl;
|
|
104
93
|
private emitExtensionFunDecl;
|
|
105
94
|
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
|
-
*/
|
|
111
95
|
private jTypeToReceiverName;
|
|
112
96
|
private classHasInvokeOperator;
|
|
113
97
|
private emitPropertyDecl;
|
|
@@ -130,20 +114,9 @@ export declare class CodeGenerator {
|
|
|
130
114
|
private emitJsxChild;
|
|
131
115
|
private emitStringTemplate;
|
|
132
116
|
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
|
-
*/
|
|
139
117
|
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. */
|
|
142
118
|
private isConstructorCall;
|
|
143
|
-
/** Emit `Column(modifier = ...) { ... }` as `React.createElement(Column, { modifier: ... }, [children])` */
|
|
144
119
|
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. */
|
|
147
120
|
private emitLambdaBodyAsDomChildren;
|
|
148
121
|
private emitLambdaExpr;
|
|
149
122
|
private emitIfExpr;
|
|
@@ -158,27 +131,12 @@ export declare class CodeGenerator {
|
|
|
158
131
|
private emitTypeRef;
|
|
159
132
|
private emitTypeParamsStr;
|
|
160
133
|
private emitParamsStr;
|
|
161
|
-
private emitComponentPropsStr;
|
|
162
134
|
private emitSuperTypesStr;
|
|
163
135
|
private exportPrefix;
|
|
164
136
|
private visibilityPrefix;
|
|
165
137
|
private unaryOpStr;
|
|
166
138
|
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
|
-
*/
|
|
175
139
|
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
|
-
*/
|
|
182
140
|
private gatherAllLocalBindings;
|
|
183
141
|
}
|
|
184
142
|
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,
|
|
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,cAIrC,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAgB;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,oBAAoB,CAAqB;IACjD,wEAAwE;I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