@ugo-studio/jspp 0.1.4 → 0.1.5
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/analysis/scope.js +17 -0
- package/dist/analysis/typeAnalyzer.js +7 -1
- package/dist/ast/symbols.js +29 -0
- package/dist/ast/types.js +0 -6
- package/dist/cli-utils/args.js +57 -0
- package/dist/cli-utils/colors.js +9 -0
- package/dist/cli-utils/file-utils.js +20 -0
- package/dist/cli-utils/spinner.js +55 -0
- package/dist/cli.js +105 -30
- package/dist/core/codegen/class-handlers.js +10 -6
- package/dist/core/codegen/control-flow-handlers.js +31 -21
- package/dist/core/codegen/declaration-handlers.js +10 -6
- package/dist/core/codegen/expression-handlers.js +202 -60
- package/dist/core/codegen/function-handlers.js +179 -70
- package/dist/core/codegen/helpers.js +107 -17
- package/dist/core/codegen/index.js +9 -8
- package/dist/core/codegen/literal-handlers.js +15 -6
- package/dist/core/codegen/statement-handlers.js +67 -53
- package/dist/core/codegen/visitor.js +3 -1
- package/package.json +1 -1
- package/src/prelude/any_value.hpp +195 -342
- package/src/prelude/any_value_access.hpp +78 -30
- package/src/prelude/any_value_defines.hpp +74 -35
- package/src/prelude/any_value_helpers.hpp +73 -180
- package/src/prelude/exception.hpp +1 -0
- package/src/prelude/exception_helpers.hpp +4 -4
- package/src/prelude/index.hpp +9 -2
- package/src/prelude/library/array.hpp +190 -0
- package/src/prelude/library/console.hpp +6 -5
- package/src/prelude/library/error.hpp +10 -8
- package/src/prelude/library/function.hpp +10 -0
- package/src/prelude/library/global.hpp +20 -0
- package/src/prelude/library/math.hpp +308 -0
- package/src/prelude/library/object.hpp +288 -0
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -0
- package/src/prelude/library/promise.hpp +53 -43
- package/src/prelude/library/symbol.hpp +45 -57
- package/src/prelude/library/timer.hpp +6 -6
- package/src/prelude/types.hpp +48 -0
- package/src/prelude/utils/access.hpp +182 -11
- package/src/prelude/utils/assignment_operators.hpp +99 -0
- package/src/prelude/utils/log_any_value/array.hpp +8 -8
- package/src/prelude/utils/log_any_value/function.hpp +6 -4
- package/src/prelude/utils/log_any_value/object.hpp +41 -24
- package/src/prelude/utils/log_any_value/primitives.hpp +3 -1
- package/src/prelude/utils/operators.hpp +750 -274
- package/src/prelude/utils/well_known_symbols.hpp +12 -0
- package/src/prelude/values/array.hpp +8 -6
- package/src/prelude/values/descriptors.hpp +2 -2
- package/src/prelude/values/function.hpp +71 -62
- package/src/prelude/values/helpers/array.hpp +64 -28
- package/src/prelude/values/helpers/function.hpp +77 -92
- package/src/prelude/values/helpers/iterator.hpp +3 -3
- package/src/prelude/values/helpers/object.hpp +54 -9
- package/src/prelude/values/helpers/promise.hpp +3 -3
- package/src/prelude/values/iterator.hpp +1 -1
- package/src/prelude/values/object.hpp +10 -3
- package/src/prelude/values/promise.hpp +3 -3
- package/src/prelude/values/prototypes/array.hpp +851 -12
- package/src/prelude/values/prototypes/function.hpp +2 -2
- package/src/prelude/values/prototypes/iterator.hpp +5 -5
- package/src/prelude/values/prototypes/number.hpp +153 -0
- package/src/prelude/values/prototypes/object.hpp +2 -2
- package/src/prelude/values/prototypes/promise.hpp +40 -30
- package/src/prelude/values/prototypes/string.hpp +28 -28
- package/src/prelude/values/prototypes/symbol.hpp +20 -3
- package/src/prelude/values/shape.hpp +52 -0
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { DeclaredSymbols } from "../../ast/symbols";
|
|
2
3
|
import { CodeGenerator } from "./";
|
|
4
|
+
import { collectBlockScopedDeclarations, collectFunctionScopedDeclarations, } from "./helpers";
|
|
3
5
|
export function visitSourceFile(node, context) {
|
|
4
6
|
const sourceFile = node;
|
|
5
7
|
let code = "";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// 1. Collect all var declarations (recursively) + top-level let/const
|
|
9
|
+
const varDecls = collectFunctionScopedDeclarations(sourceFile);
|
|
10
|
+
const topLevelLetConst = collectBlockScopedDeclarations(sourceFile.statements);
|
|
9
11
|
const funcDecls = sourceFile.statements.filter(ts.isFunctionDeclaration);
|
|
10
12
|
const classDecls = sourceFile.statements.filter(ts.isClassDeclaration);
|
|
11
|
-
const hoistedSymbols = new
|
|
12
|
-
//
|
|
13
|
+
const hoistedSymbols = new DeclaredSymbols();
|
|
14
|
+
// Hoist function declarations
|
|
13
15
|
funcDecls.forEach((func) => {
|
|
14
16
|
code += this.hoistDeclaration(func, hoistedSymbols);
|
|
15
17
|
});
|
|
@@ -17,19 +19,27 @@ export function visitSourceFile(node, context) {
|
|
|
17
19
|
classDecls.forEach((cls) => {
|
|
18
20
|
code += this.hoistDeclaration(cls, hoistedSymbols);
|
|
19
21
|
});
|
|
20
|
-
// Hoist variable declarations
|
|
22
|
+
// Hoist variable declarations (var)
|
|
21
23
|
varDecls.forEach((decl) => {
|
|
22
24
|
code += this.hoistDeclaration(decl, hoistedSymbols);
|
|
23
25
|
});
|
|
26
|
+
// Hoist top-level let/const
|
|
27
|
+
topLevelLetConst.forEach((decl) => {
|
|
28
|
+
code += this.hoistDeclaration(decl, hoistedSymbols);
|
|
29
|
+
});
|
|
30
|
+
// Compile symbols for other statements (excluding function)
|
|
31
|
+
const topLevelScopeSymbols = this.prepareScopeSymbolsForVisit(context.topLevelScopeSymbols, context.localScopeSymbols);
|
|
32
|
+
const localScopeSymbols = new DeclaredSymbols(hoistedSymbols); // hoistedSymbols becomes new local
|
|
24
33
|
// 2. Assign all hoisted functions first
|
|
25
34
|
const contextForFunctions = {
|
|
26
35
|
...context,
|
|
27
|
-
|
|
36
|
+
localScopeSymbols: new DeclaredSymbols(context.localScopeSymbols, hoistedSymbols),
|
|
28
37
|
};
|
|
29
|
-
hoistedSymbols.forEach((v, k) => contextForFunctions.currentScopeSymbols.set(k, v));
|
|
30
38
|
funcDecls.forEach((stmt) => {
|
|
31
39
|
const funcName = stmt.name?.getText();
|
|
32
40
|
if (funcName) {
|
|
41
|
+
this.markSymbolAsChecked(funcName, contextForFunctions.topLevelScopeSymbols, contextForFunctions.localScopeSymbols);
|
|
42
|
+
this.markSymbolAsChecked(funcName, topLevelScopeSymbols, localScopeSymbols);
|
|
33
43
|
const lambda = this.generateLambda(stmt, contextForFunctions, {
|
|
34
44
|
isAssignment: true,
|
|
35
45
|
});
|
|
@@ -38,8 +48,6 @@ export function visitSourceFile(node, context) {
|
|
|
38
48
|
});
|
|
39
49
|
// 3. Process other statements
|
|
40
50
|
sourceFile.statements.forEach((stmt) => {
|
|
41
|
-
const topLevelScopeSymbols = this.prepareScopeSymbolsForVisit(context.topLevelScopeSymbols, context.currentScopeSymbols);
|
|
42
|
-
const currentScopeSymbols = hoistedSymbols; // hoistedSymbols becomes new local
|
|
43
51
|
if (ts.isFunctionDeclaration(stmt)) {
|
|
44
52
|
// Already handled
|
|
45
53
|
}
|
|
@@ -50,7 +58,7 @@ export function visitSourceFile(node, context) {
|
|
|
50
58
|
const contextForVisit = {
|
|
51
59
|
...context,
|
|
52
60
|
topLevelScopeSymbols,
|
|
53
|
-
|
|
61
|
+
localScopeSymbols,
|
|
54
62
|
isAssignmentOnly: !isLetOrConst,
|
|
55
63
|
};
|
|
56
64
|
const assignments = this.visit(stmt.declarationList, contextForVisit);
|
|
@@ -63,9 +71,7 @@ export function visitSourceFile(node, context) {
|
|
|
63
71
|
...context,
|
|
64
72
|
isFunctionBody: false,
|
|
65
73
|
topLevelScopeSymbols,
|
|
66
|
-
|
|
67
|
-
// currentScopeSymbols: undefined, // clear the currentScopeSymbols for nested visit
|
|
68
|
-
// topLevelScopeSymbols: undefined, // clear the topLevelScopeSymbols for nested visit
|
|
74
|
+
localScopeSymbols,
|
|
69
75
|
});
|
|
70
76
|
}
|
|
71
77
|
});
|
|
@@ -75,12 +81,11 @@ export function visitBlock(node, context) {
|
|
|
75
81
|
let code = "{\n";
|
|
76
82
|
this.indentationLevel++;
|
|
77
83
|
const block = node;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.flatMap((stmt) => stmt.declarationList.declarations);
|
|
84
|
+
// Collect ONLY block-scoped declarations (let/const)
|
|
85
|
+
const blockScopedDecls = collectBlockScopedDeclarations(block.statements);
|
|
81
86
|
const funcDecls = block.statements.filter(ts.isFunctionDeclaration);
|
|
82
87
|
const classDecls = block.statements.filter(ts.isClassDeclaration);
|
|
83
|
-
const hoistedSymbols = new
|
|
88
|
+
const hoistedSymbols = new DeclaredSymbols();
|
|
84
89
|
// 1. Hoist all function declarations
|
|
85
90
|
funcDecls.forEach((func) => {
|
|
86
91
|
code += this.hoistDeclaration(func, hoistedSymbols);
|
|
@@ -89,19 +94,23 @@ export function visitBlock(node, context) {
|
|
|
89
94
|
classDecls.forEach((cls) => {
|
|
90
95
|
code += this.hoistDeclaration(cls, hoistedSymbols);
|
|
91
96
|
});
|
|
92
|
-
// Hoist variable declarations
|
|
93
|
-
|
|
97
|
+
// Hoist variable declarations (let/const only)
|
|
98
|
+
blockScopedDecls.forEach((decl) => {
|
|
94
99
|
code += this.hoistDeclaration(decl, hoistedSymbols);
|
|
95
100
|
});
|
|
101
|
+
// Compile symbols for other statements (excluding function)
|
|
102
|
+
const topLevelScopeSymbols = this.prepareScopeSymbolsForVisit(context.topLevelScopeSymbols, context.localScopeSymbols);
|
|
103
|
+
const localScopeSymbols = new DeclaredSymbols(hoistedSymbols); // hoistedSymbols becomes new local
|
|
96
104
|
// 2. Assign all hoisted functions first
|
|
97
105
|
const contextForFunctions = {
|
|
98
106
|
...context,
|
|
99
|
-
|
|
107
|
+
localScopeSymbols: new DeclaredSymbols(context.localScopeSymbols, hoistedSymbols),
|
|
100
108
|
};
|
|
101
|
-
hoistedSymbols.forEach((v, k) => contextForFunctions.currentScopeSymbols.set(k, v));
|
|
102
109
|
funcDecls.forEach((stmt) => {
|
|
103
110
|
const funcName = stmt.name?.getText();
|
|
104
111
|
if (funcName) {
|
|
112
|
+
this.markSymbolAsChecked(funcName, contextForFunctions.topLevelScopeSymbols, contextForFunctions.localScopeSymbols);
|
|
113
|
+
this.markSymbolAsChecked(funcName, topLevelScopeSymbols, localScopeSymbols);
|
|
105
114
|
const lambda = this.generateLambda(stmt, contextForFunctions, {
|
|
106
115
|
isAssignment: true,
|
|
107
116
|
});
|
|
@@ -110,8 +119,6 @@ export function visitBlock(node, context) {
|
|
|
110
119
|
});
|
|
111
120
|
// 3. Process other statements
|
|
112
121
|
block.statements.forEach((stmt) => {
|
|
113
|
-
const topLevelScopeSymbols = this.prepareScopeSymbolsForVisit(context.topLevelScopeSymbols, context.currentScopeSymbols);
|
|
114
|
-
const currentScopeSymbols = hoistedSymbols; // hoistedSymbols becomes new local
|
|
115
122
|
if (ts.isFunctionDeclaration(stmt)) {
|
|
116
123
|
// Do nothing, already handled
|
|
117
124
|
}
|
|
@@ -122,7 +129,7 @@ export function visitBlock(node, context) {
|
|
|
122
129
|
const contextForVisit = {
|
|
123
130
|
...context,
|
|
124
131
|
topLevelScopeSymbols,
|
|
125
|
-
|
|
132
|
+
localScopeSymbols,
|
|
126
133
|
isAssignmentOnly: !isLetOrConst,
|
|
127
134
|
};
|
|
128
135
|
const assignments = this.visit(stmt.declarationList, contextForVisit);
|
|
@@ -135,16 +142,14 @@ export function visitBlock(node, context) {
|
|
|
135
142
|
...context,
|
|
136
143
|
isFunctionBody: false,
|
|
137
144
|
topLevelScopeSymbols,
|
|
138
|
-
|
|
139
|
-
// currentScopeSymbols: undefined, // clear the currentScopeSymbols for nested visit
|
|
140
|
-
// topLevelScopeSymbols: undefined, // clear the topLevelScopeSymbols for nested visit
|
|
145
|
+
localScopeSymbols,
|
|
141
146
|
});
|
|
142
147
|
}
|
|
143
148
|
});
|
|
144
149
|
if (context.isFunctionBody) {
|
|
145
150
|
const lastStatement = block.statements[block.statements.length - 1];
|
|
146
151
|
if (!lastStatement || !ts.isReturnStatement(lastStatement)) {
|
|
147
|
-
code += `${this.indent()}${this.getReturnCommand(context)} jspp::
|
|
152
|
+
code += `${this.indent()}${this.getReturnCommand(context)} jspp::Constants::UNDEFINED;\n`;
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
this.indentationLevel--;
|
|
@@ -212,7 +217,7 @@ export function visitIfStatement(node, context) {
|
|
|
212
217
|
isFunctionBody: false,
|
|
213
218
|
});
|
|
214
219
|
}
|
|
215
|
-
return `${this.indent()}if ((${condition})
|
|
220
|
+
return `${this.indent()}if (is_truthy(${condition})) ${thenStmt}${elseStmt}`;
|
|
216
221
|
}
|
|
217
222
|
export function visitExpressionStatement(node, context) {
|
|
218
223
|
return (this.indent() +
|
|
@@ -222,7 +227,7 @@ export function visitExpressionStatement(node, context) {
|
|
|
222
227
|
export function visitThrowStatement(node, context) {
|
|
223
228
|
const throwStmt = node;
|
|
224
229
|
const expr = this.visit(throwStmt.expression, context);
|
|
225
|
-
return `${this.indent()}throw jspp::Exception(${expr});
|
|
230
|
+
return `${this.indent()}throw jspp::Exception(${expr});
|
|
226
231
|
`;
|
|
227
232
|
}
|
|
228
233
|
export function visitTryStatement(node, context) {
|
|
@@ -239,18 +244,23 @@ export function visitTryStatement(node, context) {
|
|
|
239
244
|
const hasReturnedFlagName = this.generateUniqueName("__try_has_returned_", declaredSymbols);
|
|
240
245
|
let code = `${this.indent()}{\n`;
|
|
241
246
|
this.indentationLevel++;
|
|
242
|
-
code += `${this.indent()}jspp::AnyValue ${resultVarName}
|
|
243
|
-
|
|
247
|
+
code += `${this.indent()}jspp::AnyValue ${resultVarName};
|
|
248
|
+
`;
|
|
249
|
+
code += `${this.indent()}bool ${hasReturnedFlagName} = false;
|
|
250
|
+
`;
|
|
244
251
|
const finallyBlockCode = this.visit(tryStmt.finallyBlock, {
|
|
245
252
|
...context,
|
|
246
253
|
isFunctionBody: false,
|
|
247
254
|
});
|
|
248
255
|
code +=
|
|
249
|
-
`${this.indent()}auto ${finallyLambdaName} = [=]() ${finallyBlockCode.trim()}
|
|
250
|
-
|
|
256
|
+
`${this.indent()}auto ${finallyLambdaName} = [=]() ${finallyBlockCode.trim()};
|
|
257
|
+
`;
|
|
258
|
+
code += `${this.indent()}try {
|
|
259
|
+
`;
|
|
251
260
|
this.indentationLevel++;
|
|
252
261
|
code +=
|
|
253
|
-
`${this.indent()}${resultVarName} = ([=, &${hasReturnedFlagName}]() -> jspp::AnyValue {
|
|
262
|
+
`${this.indent()}${resultVarName} = ([=, &${hasReturnedFlagName}]() -> jspp::AnyValue {
|
|
263
|
+
`;
|
|
254
264
|
this.indentationLevel++;
|
|
255
265
|
const innerContext = {
|
|
256
266
|
...context,
|
|
@@ -258,7 +268,8 @@ export function visitTryStatement(node, context) {
|
|
|
258
268
|
isInsideTryCatchLambda: true,
|
|
259
269
|
hasReturnedFlag: hasReturnedFlagName,
|
|
260
270
|
};
|
|
261
|
-
code += `${this.indent()}try {
|
|
271
|
+
code += `${this.indent()}try {
|
|
272
|
+
`;
|
|
262
273
|
this.indentationLevel++;
|
|
263
274
|
code += this.visit(tryStmt.tryBlock, innerContext);
|
|
264
275
|
this.indentationLevel--;
|
|
@@ -267,7 +278,8 @@ export function visitTryStatement(node, context) {
|
|
|
267
278
|
const exceptionName = this.generateUniqueExceptionName(tryStmt.catchClause.variableDeclaration?.name.getText());
|
|
268
279
|
const catchContext = { ...innerContext, exceptionName };
|
|
269
280
|
code +=
|
|
270
|
-
`${this.indent()}catch (const std::exception& ${exceptionName}) {
|
|
281
|
+
`${this.indent()}catch (const std::exception& ${exceptionName}) {
|
|
282
|
+
`;
|
|
271
283
|
this.indentationLevel++;
|
|
272
284
|
code += this.visit(tryStmt.catchClause.block, catchContext);
|
|
273
285
|
this.indentationLevel--;
|
|
@@ -276,18 +288,20 @@ export function visitTryStatement(node, context) {
|
|
|
276
288
|
else {
|
|
277
289
|
code += `${this.indent()}catch (...) { throw; }\n`;
|
|
278
290
|
}
|
|
279
|
-
code += `${this.indent()}${this.getReturnCommand(context)} jspp::
|
|
291
|
+
code += `${this.indent()}${this.getReturnCommand(context)} jspp::Constants::UNDEFINED;\n`;
|
|
280
292
|
this.indentationLevel--;
|
|
281
293
|
code += `${this.indent()}})();\n`;
|
|
282
294
|
this.indentationLevel--;
|
|
283
|
-
code += `${this.indent()}} catch (...) {
|
|
295
|
+
code += `${this.indent()}} catch (...) {
|
|
296
|
+
`;
|
|
284
297
|
this.indentationLevel++;
|
|
285
298
|
code += `${this.indent()}${finallyLambdaName}();\n`;
|
|
286
299
|
code += `${this.indent()}throw;\n`;
|
|
287
300
|
this.indentationLevel--;
|
|
288
301
|
code += `${this.indent()}}\n`;
|
|
289
302
|
code += `${this.indent()}${finallyLambdaName}();\n`;
|
|
290
|
-
code += `${this.indent()}if (${hasReturnedFlagName}) {
|
|
303
|
+
code += `${this.indent()}if (${hasReturnedFlagName}) {
|
|
304
|
+
`;
|
|
291
305
|
this.indentationLevel++;
|
|
292
306
|
code += `${this.indent()}return ${resultVarName};\n`;
|
|
293
307
|
this.indentationLevel--;
|
|
@@ -331,7 +345,7 @@ export function visitCatchClause(node, context) {
|
|
|
331
345
|
// Shadow the C++ exception variable *only if* the names don't clash.
|
|
332
346
|
if (varName !== exceptionName) {
|
|
333
347
|
code +=
|
|
334
|
-
`${this.indent()}auto ${exceptionName} = std::make_shared<jspp::AnyValue>(jspp::
|
|
348
|
+
`${this.indent()}auto ${exceptionName} = std::make_shared<jspp::AnyValue>(jspp::Constants::UNDEFINED);\n`;
|
|
335
349
|
}
|
|
336
350
|
code += this.visit(catchClause.block, context);
|
|
337
351
|
this.indentationLevel--;
|
|
@@ -361,7 +375,7 @@ export function visitYieldExpression(node, context) {
|
|
|
361
375
|
if (typeInfo &&
|
|
362
376
|
!typeInfo.isParameter &&
|
|
363
377
|
!typeInfo.isBuiltin) {
|
|
364
|
-
exprText = this.getDerefCode(exprText, this.getJsVarName(expr), typeInfo);
|
|
378
|
+
exprText = this.getDerefCode(exprText, this.getJsVarName(expr), context, typeInfo);
|
|
365
379
|
}
|
|
366
380
|
}
|
|
367
381
|
// Handle `yield*` expression
|
|
@@ -378,23 +392,23 @@ export function visitYieldExpression(node, context) {
|
|
|
378
392
|
code +=
|
|
379
393
|
`${this.indent()}auto ${iterator} = jspp::Access::get_object_value_iterator(${iterableRef}, ${varName});\n`;
|
|
380
394
|
code +=
|
|
381
|
-
`${this.indent()}auto ${nextFunc} = ${iterator}.get_own_property("next")
|
|
395
|
+
`${this.indent()}auto ${nextFunc} = ${iterator}.get_own_property("next");\n`;
|
|
382
396
|
code +=
|
|
383
|
-
`${this.indent()}auto ${nextRes} = ${nextFunc}
|
|
397
|
+
`${this.indent()}auto ${nextRes} = ${nextFunc}.call(${iterator}, {}, "next");\n`;
|
|
384
398
|
code +=
|
|
385
|
-
`${this.indent()}while (
|
|
399
|
+
`${this.indent()}while (!is_truthy(${nextRes}.get_own_property("done"))) {\n`;
|
|
386
400
|
this.indentationLevel++;
|
|
387
401
|
code +=
|
|
388
402
|
`${this.indent()}co_yield ${nextRes}.get_own_property("value");\n`;
|
|
389
403
|
code +=
|
|
390
|
-
`${this.indent()}${nextRes} = ${nextFunc}
|
|
404
|
+
`${this.indent()}${nextRes} = ${nextFunc}.call(${iterator}, {}, "next");\n`;
|
|
391
405
|
this.indentationLevel--;
|
|
392
|
-
code += `${this.indent()}}
|
|
406
|
+
code += `${this.indent()}}\n`;
|
|
393
407
|
return code;
|
|
394
408
|
}
|
|
395
409
|
return `${this.indent()}co_yield ${exprText}`;
|
|
396
410
|
}
|
|
397
|
-
return `${this.indent()}co_yield jspp::
|
|
411
|
+
return `${this.indent()}co_yield jspp::Constants::UNDEFINED`;
|
|
398
412
|
}
|
|
399
413
|
export function visitReturnStatement(node, context) {
|
|
400
414
|
if (context.isMainContext) {
|
|
@@ -418,14 +432,14 @@ export function visitReturnStatement(node, context) {
|
|
|
418
432
|
else if (typeInfo &&
|
|
419
433
|
!typeInfo.isParameter &&
|
|
420
434
|
!typeInfo.isBuiltin) {
|
|
421
|
-
finalExpr = this.getDerefCode(exprText, this.getJsVarName(expr), typeInfo);
|
|
435
|
+
finalExpr = this.getDerefCode(exprText, this.getJsVarName(expr), context, typeInfo);
|
|
422
436
|
}
|
|
423
437
|
}
|
|
424
438
|
returnCode += `${this.indent()}${returnCmd} ${finalExpr};\n`;
|
|
425
439
|
}
|
|
426
440
|
else {
|
|
427
441
|
returnCode +=
|
|
428
|
-
`${this.indent()}${returnCmd} jspp::
|
|
442
|
+
`${this.indent()}${returnCmd} jspp::Constants::UNDEFINED;\n`;
|
|
429
443
|
}
|
|
430
444
|
return returnCode;
|
|
431
445
|
}
|
|
@@ -442,10 +456,10 @@ export function visitReturnStatement(node, context) {
|
|
|
442
456
|
if (typeInfo &&
|
|
443
457
|
!typeInfo.isParameter &&
|
|
444
458
|
!typeInfo.isBuiltin) {
|
|
445
|
-
finalExpr = this.getDerefCode(exprText, this.getJsVarName(expr), typeInfo);
|
|
459
|
+
finalExpr = this.getDerefCode(exprText, this.getJsVarName(expr), context, typeInfo);
|
|
446
460
|
}
|
|
447
461
|
}
|
|
448
462
|
return `${this.indent()}${returnCmd} ${finalExpr};\n`;
|
|
449
463
|
}
|
|
450
|
-
return `${this.indent()}${returnCmd} jspp::
|
|
464
|
+
return `${this.indent()}${returnCmd} jspp::Constants::UNDEFINED;\n`;
|
|
451
465
|
}
|
|
@@ -3,7 +3,7 @@ import { CodeGenerator } from "./";
|
|
|
3
3
|
import { visitClassDeclaration } from "./class-handlers";
|
|
4
4
|
import { visitCaseClause, visitDefaultClause, visitDoStatement, visitForInStatement, visitForOfStatement, visitForStatement, visitSwitchStatement, visitWhileStatement, } from "./control-flow-handlers";
|
|
5
5
|
import { visitVariableDeclaration, visitVariableDeclarationList, } from "./declaration-handlers";
|
|
6
|
-
import { visitArrayLiteralExpression, visitAwaitExpression, visitBinaryExpression, visitCallExpression, visitConditionalExpression, visitElementAccessExpression, visitNewExpression, visitObjectLiteralExpression, visitParenthesizedExpression, visitPostfixUnaryExpression, visitPrefixUnaryExpression, visitPropertyAccessExpression, visitTemplateExpression, visitTypeOfExpression, visitVoidExpression, } from "./expression-handlers";
|
|
6
|
+
import { visitArrayLiteralExpression, visitAwaitExpression, visitBinaryExpression, visitCallExpression, visitConditionalExpression, visitDeleteExpression, visitElementAccessExpression, visitNewExpression, visitObjectLiteralExpression, visitParenthesizedExpression, visitPostfixUnaryExpression, visitPrefixUnaryExpression, visitPropertyAccessExpression, visitTemplateExpression, visitTypeOfExpression, visitVoidExpression, } from "./expression-handlers";
|
|
7
7
|
import { visitArrowFunction, visitFunctionDeclaration, visitFunctionExpression, } from "./function-handlers";
|
|
8
8
|
import { visitFalseKeyword, visitIdentifier, visitNoSubstitutionTemplateLiteral, visitNullKeyword, visitNumericLiteral, visitStringLiteral, visitThisKeyword, visitTrueKeyword, visitUndefinedKeyword, } from "./literal-handlers";
|
|
9
9
|
import { visitBlock, visitBreakStatement, visitCatchClause, visitContinueStatement, visitExpressionStatement, visitIfStatement, visitLabeledStatement, visitReturnStatement, visitSourceFile, visitThrowStatement, visitTryStatement, visitVariableStatement, visitYieldExpression, } from "./statement-handlers";
|
|
@@ -72,6 +72,8 @@ export function visit(node, context) {
|
|
|
72
72
|
return visitBinaryExpression.call(this, node, context);
|
|
73
73
|
case ts.SyntaxKind.ConditionalExpression:
|
|
74
74
|
return visitConditionalExpression.call(this, node, context);
|
|
75
|
+
case ts.SyntaxKind.DeleteExpression:
|
|
76
|
+
return visitDeleteExpression.call(this, node, context);
|
|
75
77
|
case ts.SyntaxKind.ThrowStatement:
|
|
76
78
|
return visitThrowStatement.call(this, node, context);
|
|
77
79
|
case ts.SyntaxKind.TryStatement:
|
package/package.json
CHANGED