typenative 0.0.17 → 0.0.18
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/.github/workflows/npm-publish-github-packages.yml +73 -36
- package/CHANGELOG.md +109 -95
- package/LICENSE +21 -21
- package/README.md +154 -152
- package/bin/index.js +133 -126
- package/bin/transpiler.js +258 -15
- package/package.json +63 -59
- package/types/typenative.d.ts +247 -193
package/bin/transpiler.js
CHANGED
|
@@ -36,14 +36,14 @@ export function transpileToNative(code) {
|
|
|
36
36
|
enumBaseTypes.clear();
|
|
37
37
|
const transpiledCode = visit(sourceFile, { addFunctionOutside: true });
|
|
38
38
|
const transpiledCodeOutside = outsideNodes.map((n) => visit(n, { isOutside: true })).join('\n');
|
|
39
|
-
return `package main
|
|
40
|
-
|
|
41
|
-
${[...importedPackages].map((pkg) => `import "${pkg}"`).join('\n')}
|
|
42
|
-
|
|
43
|
-
func main() {
|
|
44
|
-
${transpiledCode.trim()}
|
|
45
|
-
}
|
|
46
|
-
|
|
39
|
+
return `package main
|
|
40
|
+
|
|
41
|
+
${[...importedPackages].map((pkg) => `import "${pkg}"`).join('\n')}
|
|
42
|
+
|
|
43
|
+
func main() {
|
|
44
|
+
${transpiledCode.trim()}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
47
|
${transpiledCodeOutside.trim()}`;
|
|
48
48
|
}
|
|
49
49
|
export function visit(node, options = {}) {
|
|
@@ -237,9 +237,23 @@ export function visit(node, options = {}) {
|
|
|
237
237
|
})}; ${visit(node.incrementor, { inline: true })}${visit(node.statement)}`;
|
|
238
238
|
}
|
|
239
239
|
else if (ts.isForOfStatement(node)) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
const iterExpr = visit(node.expression, { inline: true });
|
|
241
|
+
const iterType = inferExpressionType(node.expression);
|
|
242
|
+
if (iterType && iterType.startsWith('map[')) {
|
|
243
|
+
const valueType = extractMapValueType(iterType);
|
|
244
|
+
const isSet = valueType === 'struct{}';
|
|
245
|
+
const varInfo = getForOfVarNames(node.initializer);
|
|
246
|
+
if (isSet) {
|
|
247
|
+
return `for ${varInfo[0]} := range ${iterExpr}${visit(node.statement)}`;
|
|
248
|
+
}
|
|
249
|
+
else if (varInfo.length >= 2) {
|
|
250
|
+
return `for ${varInfo[0]}, ${varInfo[1]} := range ${iterExpr}${visit(node.statement)}`;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return `for ${varInfo[0]} := range ${iterExpr}${visit(node.statement)}`;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return `for _,${visit(node.initializer, { inline: true })}= range ${iterExpr}${visit(node.statement)}`;
|
|
243
257
|
}
|
|
244
258
|
else if (ts.isWhileStatement(node)) {
|
|
245
259
|
return `for ${visit(node.expression, { inline: true })}${visit(node.statement)}`;
|
|
@@ -281,6 +295,20 @@ export function visit(node, options = {}) {
|
|
|
281
295
|
else if (ts.isBreakStatement(node)) {
|
|
282
296
|
return 'break';
|
|
283
297
|
}
|
|
298
|
+
else if (ts.isThrowStatement(node)) {
|
|
299
|
+
const expr = node.expression;
|
|
300
|
+
if (ts.isNewExpression(expr) &&
|
|
301
|
+
ts.isIdentifier(expr.expression) &&
|
|
302
|
+
expr.expression.text === 'Error') {
|
|
303
|
+
const args = expr.arguments ?? [];
|
|
304
|
+
const msg = args.length > 0 ? visit(args[0]) : '""';
|
|
305
|
+
return `panic(${msg})` + (options.inline ? '' : ';\n\t');
|
|
306
|
+
}
|
|
307
|
+
return `panic(${visit(expr)})` + (options.inline ? '' : ';\n\t');
|
|
308
|
+
}
|
|
309
|
+
else if (ts.isTryStatement(node)) {
|
|
310
|
+
return visitTryStatement(node, options);
|
|
311
|
+
}
|
|
284
312
|
else if (ts.isReturnStatement(node)) {
|
|
285
313
|
// Handle return new Promise(...)
|
|
286
314
|
if (node.expression &&
|
|
@@ -296,26 +324,41 @@ export function visit(node, options = {}) {
|
|
|
296
324
|
outsideNodes.push(node);
|
|
297
325
|
return '';
|
|
298
326
|
}
|
|
299
|
-
const name = visit(node.name, { inline: true });
|
|
300
|
-
const safeName = getSafeName(name);
|
|
301
327
|
const typeParams = getTypeParameters(node.typeParameters);
|
|
302
328
|
const parameterInfo = getFunctionParametersInfo(node.parameters);
|
|
303
|
-
|
|
329
|
+
if (node.body && ts.isBlock(node.body)) {
|
|
330
|
+
prescanVariableDeclarations(node.body);
|
|
331
|
+
}
|
|
332
|
+
const inferredRetType = inferFunctionBodyReturnType(node);
|
|
333
|
+
const returnType = inferredRetType ? ` ${inferredRetType}` : '';
|
|
304
334
|
if (options.isOutside) {
|
|
335
|
+
const name = node.name ? visit(node.name, { inline: true }) : '';
|
|
336
|
+
const safeName = getSafeName(name);
|
|
305
337
|
return `func ${safeName}${typeParams}(${parameterInfo.signature})${returnType} ${visit(node.body, {
|
|
306
338
|
prefixBlockContent: parameterInfo.prefixBlockContent
|
|
307
339
|
})}`;
|
|
308
340
|
}
|
|
341
|
+
if (!node.name) {
|
|
342
|
+
return `func${typeParams}(${parameterInfo.signature})${returnType} ${visit(node.body, {
|
|
343
|
+
prefixBlockContent: parameterInfo.prefixBlockContent
|
|
344
|
+
})}`;
|
|
345
|
+
}
|
|
346
|
+
const name = visit(node.name, { inline: true });
|
|
347
|
+
const safeName = getSafeName(name);
|
|
309
348
|
return `${safeName} := func${typeParams}(${parameterInfo.signature})${returnType} ${visit(node.body, {
|
|
310
349
|
prefixBlockContent: parameterInfo.prefixBlockContent
|
|
311
350
|
})}`;
|
|
312
351
|
}
|
|
313
352
|
else if (ts.isArrowFunction(node)) {
|
|
314
353
|
const parameterInfo = getFunctionParametersInfo(node.parameters);
|
|
315
|
-
const
|
|
354
|
+
const inferredRetType = inferFunctionBodyReturnType(node);
|
|
355
|
+
const returnType = inferredRetType ? ` ${inferredRetType}` : '';
|
|
316
356
|
if (parameterInfo.prefixBlockContent && !ts.isBlock(node.body)) {
|
|
317
357
|
return `func(${parameterInfo.signature})${returnType} {\n\t\t${parameterInfo.prefixBlockContent}return ${visit(node.body)};\n\t}`;
|
|
318
358
|
}
|
|
359
|
+
if (!ts.isBlock(node.body)) {
|
|
360
|
+
return `func(${parameterInfo.signature})${returnType} { return ${visit(node.body)}; }`;
|
|
361
|
+
}
|
|
319
362
|
return `func(${parameterInfo.signature})${returnType} ${visit(node.body, {
|
|
320
363
|
prefixBlockContent: parameterInfo.prefixBlockContent
|
|
321
364
|
})}`;
|
|
@@ -480,6 +523,12 @@ export function visit(node, options = {}) {
|
|
|
480
523
|
}
|
|
481
524
|
return `regexp.MustCompile("")`;
|
|
482
525
|
}
|
|
526
|
+
if (className === 'Map') {
|
|
527
|
+
return visitNewMap(node);
|
|
528
|
+
}
|
|
529
|
+
if (className === 'Set') {
|
|
530
|
+
return visitNewSet(node);
|
|
531
|
+
}
|
|
483
532
|
const typeArgs = getTypeArguments(node.typeArguments);
|
|
484
533
|
const args = node.arguments ? node.arguments.map((a) => visit(a)) : [];
|
|
485
534
|
return `New${className}${typeArgs}(${args.join(', ')})`;
|
|
@@ -571,7 +620,52 @@ function inferExpectedTypeFromContext(node) {
|
|
|
571
620
|
}
|
|
572
621
|
return undefined;
|
|
573
622
|
}
|
|
623
|
+
function prescanVariableDeclarations(block) {
|
|
624
|
+
for (const stmt of block.statements) {
|
|
625
|
+
if (ts.isVariableStatement(stmt)) {
|
|
626
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
627
|
+
if (ts.isIdentifier(decl.name) && !variableGoTypes.has(decl.name.text)) {
|
|
628
|
+
if (decl.type) {
|
|
629
|
+
variableGoTypes.set(decl.name.text, getType(decl.type));
|
|
630
|
+
}
|
|
631
|
+
else if (decl.initializer) {
|
|
632
|
+
const inferredType = inferExpressionType(decl.initializer);
|
|
633
|
+
if (inferredType)
|
|
634
|
+
variableGoTypes.set(decl.name.text, inferredType);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function inferFunctionBodyReturnType(node) {
|
|
642
|
+
if (node.type)
|
|
643
|
+
return getType(node.type);
|
|
644
|
+
if (ts.isArrowFunction(node) && !ts.isBlock(node.body)) {
|
|
645
|
+
return inferExpressionType(node.body);
|
|
646
|
+
}
|
|
647
|
+
if (node.body && ts.isBlock(node.body)) {
|
|
648
|
+
for (const stmt of node.body.statements) {
|
|
649
|
+
if (ts.isReturnStatement(stmt) && stmt.expression) {
|
|
650
|
+
const exprType = inferExpressionType(stmt.expression);
|
|
651
|
+
if (exprType)
|
|
652
|
+
return exprType;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return undefined;
|
|
657
|
+
}
|
|
658
|
+
function inferArrowFunctionGoType(node) {
|
|
659
|
+
const params = node.parameters
|
|
660
|
+
.map((p) => (p.type ? getType(p.type) : 'interface{}'))
|
|
661
|
+
.join(', ');
|
|
662
|
+
const retType = inferFunctionBodyReturnType(node);
|
|
663
|
+
return `func(${params})${retType ? ` ${retType}` : ''}`;
|
|
664
|
+
}
|
|
574
665
|
function inferExpressionType(expr) {
|
|
666
|
+
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
667
|
+
return inferArrowFunctionGoType(expr);
|
|
668
|
+
}
|
|
575
669
|
if (ts.isParenthesizedExpression(expr))
|
|
576
670
|
return inferExpressionType(expr.expression);
|
|
577
671
|
if (ts.isNonNullExpression(expr))
|
|
@@ -599,6 +693,15 @@ function inferExpressionType(expr) {
|
|
|
599
693
|
const firstElementType = inferExpressionType(expr.elements[0]) ?? 'interface{}';
|
|
600
694
|
return `[]${firstElementType}`;
|
|
601
695
|
}
|
|
696
|
+
if (ts.isNewExpression(expr) && ts.isIdentifier(expr.expression)) {
|
|
697
|
+
const ctorName = expr.expression.text;
|
|
698
|
+
if (ctorName === 'Map' && expr.typeArguments && expr.typeArguments.length === 2) {
|
|
699
|
+
return `map[${getType(expr.typeArguments[0])}]${getType(expr.typeArguments[1])}`;
|
|
700
|
+
}
|
|
701
|
+
if (ctorName === 'Set' && expr.typeArguments && expr.typeArguments.length === 1) {
|
|
702
|
+
return `map[${getType(expr.typeArguments[0])}]struct{}`;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
602
705
|
if (ts.isPropertyAccessExpression(expr)) {
|
|
603
706
|
if (ts.isIdentifier(expr.expression) && enumNames.has(expr.expression.text)) {
|
|
604
707
|
const enumType = getSafeName(expr.expression.text);
|
|
@@ -634,6 +737,12 @@ function inferExpressionType(expr) {
|
|
|
634
737
|
if (ts.isCallExpression(expr) && ts.isPropertyAccessExpression(expr.expression)) {
|
|
635
738
|
const methodName = expr.expression.name.text;
|
|
636
739
|
const ownerType = inferExpressionType(expr.expression.expression);
|
|
740
|
+
if (ownerType && ownerType.startsWith('map[')) {
|
|
741
|
+
if (methodName === 'has')
|
|
742
|
+
return 'bool';
|
|
743
|
+
if (methodName === 'get')
|
|
744
|
+
return extractMapValueType(ownerType);
|
|
745
|
+
}
|
|
637
746
|
if (isArrayLikeGoType(ownerType)) {
|
|
638
747
|
const elementType = getArrayElementTypeFromGoType(ownerType);
|
|
639
748
|
if (methodName === 'map') {
|
|
@@ -1026,6 +1135,13 @@ function getType(typeNode, getArrayType = false) {
|
|
|
1026
1135
|
// Non-nullable union or multi-type union → interface{}
|
|
1027
1136
|
return 'interface{}';
|
|
1028
1137
|
}
|
|
1138
|
+
if (ts.isFunctionTypeNode(typeNode)) {
|
|
1139
|
+
const params = typeNode.parameters
|
|
1140
|
+
.map((p) => (p.type ? getType(p.type) : 'interface{}'))
|
|
1141
|
+
.join(', ');
|
|
1142
|
+
const ret = typeNode.type ? ` ${getType(typeNode.type)}` : '';
|
|
1143
|
+
return `func(${params})${ret}`;
|
|
1144
|
+
}
|
|
1029
1145
|
if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {
|
|
1030
1146
|
const name = typeNode.typeName.text;
|
|
1031
1147
|
if (enumNames.has(name)) {
|
|
@@ -1041,6 +1157,15 @@ function getType(typeNode, getArrayType = false) {
|
|
|
1041
1157
|
if (name === 'RegExp') {
|
|
1042
1158
|
return '*regexp.Regexp';
|
|
1043
1159
|
}
|
|
1160
|
+
if (name === 'Map' && typeNode.typeArguments && typeNode.typeArguments.length === 2) {
|
|
1161
|
+
const keyType = getType(typeNode.typeArguments[0]);
|
|
1162
|
+
const valueType = getType(typeNode.typeArguments[1]);
|
|
1163
|
+
return `map[${keyType}]${valueType}`;
|
|
1164
|
+
}
|
|
1165
|
+
if (name === 'Set' && typeNode.typeArguments && typeNode.typeArguments.length === 1) {
|
|
1166
|
+
const elementType = getType(typeNode.typeArguments[0]);
|
|
1167
|
+
return `map[${elementType}]struct{}`;
|
|
1168
|
+
}
|
|
1044
1169
|
const typeArgs = getTypeArguments(typeNode.typeArguments);
|
|
1045
1170
|
if (classNames.has(name)) {
|
|
1046
1171
|
return `*${name}${typeArgs}`;
|
|
@@ -1091,6 +1216,10 @@ function getTypeCategory(typeNode) {
|
|
|
1091
1216
|
}
|
|
1092
1217
|
if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {
|
|
1093
1218
|
const name = typeNode.typeName.text;
|
|
1219
|
+
if (name === 'Map')
|
|
1220
|
+
return 'Map';
|
|
1221
|
+
if (name === 'Set')
|
|
1222
|
+
return 'Set';
|
|
1094
1223
|
if (classNames.has(name))
|
|
1095
1224
|
return 'class';
|
|
1096
1225
|
return name;
|
|
@@ -1131,6 +1260,9 @@ function getAcessString(leftSide, rightSide, objectType) {
|
|
|
1131
1260
|
if (rightSide === 'length' && objectType !== 'class') {
|
|
1132
1261
|
return `float64(len(${leftSide}))`;
|
|
1133
1262
|
}
|
|
1263
|
+
if (rightSide === 'size' && (objectType === 'Map' || objectType === 'Set')) {
|
|
1264
|
+
return `float64(len(${leftSide}))`;
|
|
1265
|
+
}
|
|
1134
1266
|
return `${leftSide}.${rightSide}`;
|
|
1135
1267
|
}
|
|
1136
1268
|
const callHandlers = {
|
|
@@ -1286,6 +1418,25 @@ const arrayMethodHandlers = {
|
|
|
1286
1418
|
return `fmt.Sprintf("%v", ${obj})`;
|
|
1287
1419
|
}
|
|
1288
1420
|
};
|
|
1421
|
+
const mapMethodHandlers = {
|
|
1422
|
+
set: (obj, args) => `${obj}[${args[0]}] = ${args[1]}`,
|
|
1423
|
+
get: (obj, args) => `${obj}[${args[0]}]`,
|
|
1424
|
+
has: (obj, args) => {
|
|
1425
|
+
const tmp = getTempName('ok');
|
|
1426
|
+
return `func() bool { _, ${tmp} := ${obj}[${args[0]}]; return ${tmp} }()`;
|
|
1427
|
+
},
|
|
1428
|
+
delete: (obj, args) => `delete(${obj}, ${args[0]})`,
|
|
1429
|
+
clear: (obj) => `clear(${obj})`
|
|
1430
|
+
};
|
|
1431
|
+
const setMethodHandlers = {
|
|
1432
|
+
add: (obj, args) => `${obj}[${args[0]}] = struct{}{}`,
|
|
1433
|
+
has: (obj, args) => {
|
|
1434
|
+
const tmp = getTempName('ok');
|
|
1435
|
+
return `func() bool { _, ${tmp} := ${obj}[${args[0]}]; return ${tmp} }()`;
|
|
1436
|
+
},
|
|
1437
|
+
delete: (obj, args) => `delete(${obj}, ${args[0]})`,
|
|
1438
|
+
clear: (obj) => `clear(${obj})`
|
|
1439
|
+
};
|
|
1289
1440
|
function getDynamicCallHandler(caller, objectType) {
|
|
1290
1441
|
if (promiseResolveName && caller === promiseResolveName) {
|
|
1291
1442
|
return (_caller, args) => `ch <- ${args[0]}`;
|
|
@@ -1314,6 +1465,12 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
1314
1465
|
else if (objectType === 'RegExp') {
|
|
1315
1466
|
handler = regexpMethodHandlers[methodName];
|
|
1316
1467
|
}
|
|
1468
|
+
else if (objectType === 'Map') {
|
|
1469
|
+
handler = mapMethodHandlers[methodName];
|
|
1470
|
+
}
|
|
1471
|
+
else if (objectType === 'Set') {
|
|
1472
|
+
handler = setMethodHandlers[methodName];
|
|
1473
|
+
}
|
|
1317
1474
|
else {
|
|
1318
1475
|
// Unknown type: try both maps for backward compatibility
|
|
1319
1476
|
handler =
|
|
@@ -1503,3 +1660,89 @@ function visitNewPromise(node) {
|
|
|
1503
1660
|
promiseResolveName = prevResolveName;
|
|
1504
1661
|
return `func() chan ${channelType} {\n\t\tch := make(chan ${channelType})\n\t\tgo func() ${body.trimEnd()}()\n\t\treturn ch;\n\t}()`;
|
|
1505
1662
|
}
|
|
1663
|
+
function extractMapValueType(mapType) {
|
|
1664
|
+
// mapType is "map[K]V" — find the closing bracket of K accounting for nesting
|
|
1665
|
+
if (!mapType.startsWith('map['))
|
|
1666
|
+
return 'interface{}';
|
|
1667
|
+
let depth = 0;
|
|
1668
|
+
for (let i = 4; i < mapType.length; i++) {
|
|
1669
|
+
if (mapType[i] === '[')
|
|
1670
|
+
depth++;
|
|
1671
|
+
else if (mapType[i] === ']') {
|
|
1672
|
+
if (depth === 0)
|
|
1673
|
+
return mapType.substring(i + 1);
|
|
1674
|
+
depth--;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return 'interface{}';
|
|
1678
|
+
}
|
|
1679
|
+
function visitNewMap(node) {
|
|
1680
|
+
let keyType = 'interface{}';
|
|
1681
|
+
let valueType = 'interface{}';
|
|
1682
|
+
if (node.typeArguments && node.typeArguments.length === 2) {
|
|
1683
|
+
keyType = getType(node.typeArguments[0]);
|
|
1684
|
+
valueType = getType(node.typeArguments[1]);
|
|
1685
|
+
}
|
|
1686
|
+
const mapType = `map[${keyType}]${valueType}`;
|
|
1687
|
+
const args = node.arguments;
|
|
1688
|
+
if (!args || args.length === 0 || !ts.isArrayLiteralExpression(args[0])) {
|
|
1689
|
+
return `make(${mapType})`;
|
|
1690
|
+
}
|
|
1691
|
+
const initArg = args[0];
|
|
1692
|
+
const tmp = getTempName('map');
|
|
1693
|
+
const entries = initArg.elements
|
|
1694
|
+
.filter((el) => ts.isArrayLiteralExpression(el) && el.elements.length >= 2)
|
|
1695
|
+
.map((el) => {
|
|
1696
|
+
const pair = el;
|
|
1697
|
+
return `${tmp}[${visit(pair.elements[0])}] = ${visit(pair.elements[1])}`;
|
|
1698
|
+
})
|
|
1699
|
+
.join('; ');
|
|
1700
|
+
return `func() ${mapType} { ${tmp} := make(${mapType}); ${entries}; return ${tmp} }()`;
|
|
1701
|
+
}
|
|
1702
|
+
function visitNewSet(node) {
|
|
1703
|
+
let elementType = 'interface{}';
|
|
1704
|
+
if (node.typeArguments && node.typeArguments.length === 1) {
|
|
1705
|
+
elementType = getType(node.typeArguments[0]);
|
|
1706
|
+
}
|
|
1707
|
+
const setType = `map[${elementType}]struct{}`;
|
|
1708
|
+
const args = node.arguments;
|
|
1709
|
+
if (!args || args.length === 0 || !ts.isArrayLiteralExpression(args[0])) {
|
|
1710
|
+
return `make(${setType})`;
|
|
1711
|
+
}
|
|
1712
|
+
const initArg = args[0];
|
|
1713
|
+
const tmp = getTempName('set');
|
|
1714
|
+
const values = initArg.elements.map((el) => `${tmp}[${visit(el)}] = struct{}{}`).join('; ');
|
|
1715
|
+
return `func() ${setType} { ${tmp} := make(${setType}); ${values}; return ${tmp} }()`;
|
|
1716
|
+
}
|
|
1717
|
+
function getForOfVarNames(initializer) {
|
|
1718
|
+
if (!ts.isVariableDeclarationList(initializer) || initializer.declarations.length === 0) {
|
|
1719
|
+
return ['_'];
|
|
1720
|
+
}
|
|
1721
|
+
const decl = initializer.declarations[0];
|
|
1722
|
+
if (ts.isArrayBindingPattern(decl.name)) {
|
|
1723
|
+
return decl.name.elements.map((el) => {
|
|
1724
|
+
if (ts.isOmittedExpression(el))
|
|
1725
|
+
return '_';
|
|
1726
|
+
return visit(el.name);
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
return [visit(decl.name)];
|
|
1730
|
+
}
|
|
1731
|
+
function visitTryStatement(node, options) {
|
|
1732
|
+
const deferreds = [];
|
|
1733
|
+
// Register finally first (LIFO: runs last after catch)
|
|
1734
|
+
if (node.finallyBlock) {
|
|
1735
|
+
const finallyBody = node.finallyBlock.statements.map((s) => visit(s)).join('\t');
|
|
1736
|
+
deferreds.push(`defer func() {\n\t\t\t${finallyBody}\t\t\t}()`);
|
|
1737
|
+
}
|
|
1738
|
+
// Register catch second (LIFO: runs first, handles panic via recover)
|
|
1739
|
+
if (node.catchClause) {
|
|
1740
|
+
const varDecl = node.catchClause.variableDeclaration;
|
|
1741
|
+
const catchVar = varDecl ? visit(varDecl.name) : '_r';
|
|
1742
|
+
const catchBody = node.catchClause.block.statements.map((s) => visit(s)).join('\t');
|
|
1743
|
+
deferreds.push(`defer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\t${catchVar} := r\n\t\t\t\t_ = ${catchVar}\n\t\t\t\t${catchBody}\t\t\t}\n\t\t\t}()`);
|
|
1744
|
+
}
|
|
1745
|
+
const tryBody = node.tryBlock.statements.map((s) => visit(s)).join('\t');
|
|
1746
|
+
const body = [...deferreds, tryBody].join('\n\t\t\t');
|
|
1747
|
+
return `func() {\n\t\t\t${body}\n\t\t\t}()` + (options.inline ? '' : ';\n\t');
|
|
1748
|
+
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "typenative",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Build native applications using Typescript.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"typenative": "bin/index.js"
|
|
8
|
-
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "tsc",
|
|
11
|
-
"watch": "tsc --watch",
|
|
12
|
-
"test": "node ./test/test-runner test",
|
|
13
|
-
"release": "npm publish",
|
|
14
|
-
"test1": "node ./bin/index --source test/test1.spec.ts --script",
|
|
15
|
-
"test2": "node ./bin/index --source test/test2.spec.ts --script",
|
|
16
|
-
"test3": "node ./bin/index --source test/test3.spec.ts --script",
|
|
17
|
-
"test3_node": "tsc test/test3.spec.ts && node test/test3.spec.js && rimraf test/test3.spec.js",
|
|
18
|
-
"test4": "node ./bin/index --source test/test4.spec.ts --script",
|
|
19
|
-
"test5": "node ./bin/index --source test/test5.spec.ts --script",
|
|
20
|
-
"test6": "node ./bin/index --source test/test6.spec.ts --script",
|
|
21
|
-
"test7": "node ./bin/index --source test/test7.spec.ts --script",
|
|
22
|
-
"test8": "node ./bin/index --source test/test8.spec.ts --script",
|
|
23
|
-
"test9": "node ./bin/index --source test/test9.spec.ts --script",
|
|
24
|
-
"test10": "node ./bin/index --source test/test10.spec.ts --script",
|
|
25
|
-
"test11": "node ./bin/index --source test/test11.spec.ts --script",
|
|
26
|
-
"test12": "node ./bin/index --source test/test12.spec.ts --script",
|
|
27
|
-
"test13": "node ./bin/index --source test/test13.spec.ts --script",
|
|
28
|
-
"test14": "node ./bin/index --source test/test14.spec.ts --script",
|
|
29
|
-
"test15": "node ./bin/index --source test/test15.spec.ts --script",
|
|
30
|
-
"test16": "node ./bin/index --source test/test16.spec.ts --script",
|
|
31
|
-
"test17": "node ./bin/index --source test/test17.spec.ts --script",
|
|
32
|
-
"test18": "node ./bin/index --source test/test18.spec.ts --script",
|
|
33
|
-
"test19": "node ./bin/index --source test/test19.spec.ts --script",
|
|
34
|
-
"test20": "node ./bin/index --source test/Test20.spec.ts --script"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
},
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "typenative",
|
|
3
|
+
"version": "0.0.18",
|
|
4
|
+
"description": "Build native applications using Typescript.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"typenative": "bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"watch": "tsc --watch",
|
|
12
|
+
"test": "node ./test/test-runner test",
|
|
13
|
+
"release": "npm publish",
|
|
14
|
+
"test1": "node ./bin/index --source test/test1.spec.ts --script",
|
|
15
|
+
"test2": "node ./bin/index --source test/test2.spec.ts --script",
|
|
16
|
+
"test3": "node ./bin/index --source test/test3.spec.ts --script",
|
|
17
|
+
"test3_node": "tsc test/test3.spec.ts && node test/test3.spec.js && rimraf test/test3.spec.js",
|
|
18
|
+
"test4": "node ./bin/index --source test/test4.spec.ts --script",
|
|
19
|
+
"test5": "node ./bin/index --source test/test5.spec.ts --script",
|
|
20
|
+
"test6": "node ./bin/index --source test/test6.spec.ts --script",
|
|
21
|
+
"test7": "node ./bin/index --source test/test7.spec.ts --script",
|
|
22
|
+
"test8": "node ./bin/index --source test/test8.spec.ts --script",
|
|
23
|
+
"test9": "node ./bin/index --source test/test9.spec.ts --script",
|
|
24
|
+
"test10": "node ./bin/index --source test/test10.spec.ts --script",
|
|
25
|
+
"test11": "node ./bin/index --source test/test11.spec.ts --script",
|
|
26
|
+
"test12": "node ./bin/index --source test/test12.spec.ts --script",
|
|
27
|
+
"test13": "node ./bin/index --source test/test13.spec.ts --script",
|
|
28
|
+
"test14": "node ./bin/index --source test/test14.spec.ts --script",
|
|
29
|
+
"test15": "node ./bin/index --source test/test15.spec.ts --script",
|
|
30
|
+
"test16": "node ./bin/index --source test/test16.spec.ts --script",
|
|
31
|
+
"test17": "node ./bin/index --source test/test17.spec.ts --script",
|
|
32
|
+
"test18": "node ./bin/index --source test/test18.spec.ts --script",
|
|
33
|
+
"test19": "node ./bin/index --source test/test19.spec.ts --script",
|
|
34
|
+
"test20": "node ./bin/index --source test/Test20.spec.ts --script",
|
|
35
|
+
"test21": "node ./bin/index --source test/Test21.spec.ts --script",
|
|
36
|
+
"test22": "node ./bin/index --source test/Test22.spec.ts --script",
|
|
37
|
+
"test23": "node ./bin/index --source test/Test23.spec.ts --script",
|
|
38
|
+
"test24": "node ./bin/index --source test/Test24.spec.ts --script"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/danisss9/typenative.git"
|
|
43
|
+
},
|
|
44
|
+
"author": "Dani Santos",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/danisss9/typenative/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/danisss9/typenative#readme",
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/fs-extra": "^11.0.4",
|
|
52
|
+
"@types/inquirer": "^9.0.9",
|
|
53
|
+
"@types/node": "^25.2.3",
|
|
54
|
+
"rimraf": "^6.1.2"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"execa": "^9.6.1",
|
|
58
|
+
"fs-extra": "^11.3.3",
|
|
59
|
+
"inquirer": "^13.2.4",
|
|
60
|
+
"nanoid": "^5.1.6",
|
|
61
|
+
"typescript": "^5.9.3"
|
|
62
|
+
}
|
|
63
|
+
}
|