@runtime-type-inspector/transpiler 2.2.0 → 2.2.2
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/index.cjs +138 -37
- package/index.mjs +133 -32
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -345,6 +345,13 @@
|
|
|
345
345
|
elements: elements.map(expandTypeDepFree)
|
|
346
346
|
};
|
|
347
347
|
}
|
|
348
|
+
if (type.startsWith('typeof ')) {
|
|
349
|
+
var argument = expandTypeDepFree(type.substring(7));
|
|
350
|
+
return {
|
|
351
|
+
type: 'typeof',
|
|
352
|
+
argument: argument
|
|
353
|
+
};
|
|
354
|
+
}
|
|
348
355
|
if (type === 'object' || type === 'Object') {
|
|
349
356
|
return {
|
|
350
357
|
type: 'object',
|
|
@@ -541,6 +548,9 @@
|
|
|
541
548
|
} else {
|
|
542
549
|
warn("not an extensible type", lastTypedef);
|
|
543
550
|
}
|
|
551
|
+
} else if (line.startsWith('@callback')) {
|
|
552
|
+
var _name2 = line.substring(9).trim();
|
|
553
|
+
typedefs[_name2] = 'Function';
|
|
544
554
|
}
|
|
545
555
|
}
|
|
546
556
|
} catch (err) {
|
|
@@ -646,6 +656,14 @@
|
|
|
646
656
|
if (dedicatedLine) {
|
|
647
657
|
out += spaces;
|
|
648
658
|
}
|
|
659
|
+
var multiLine = loc.start.line !== loc.end.line;
|
|
660
|
+
if (multiLine) {
|
|
661
|
+
var _this$parents$at;
|
|
662
|
+
if (((_this$parents$at = this.parents.at(-2)) === null || _this$parents$at === void 0 ? void 0 : _this$parents$at.type) === 'AssignmentExpression') {
|
|
663
|
+
spaces += ' ';
|
|
664
|
+
}
|
|
665
|
+
out += '\n' + spaces;
|
|
666
|
+
}
|
|
649
667
|
out += '/*';
|
|
650
668
|
if (value.includes('\n')) {
|
|
651
669
|
value = trimEndSpaces(value.replace(/^\s*\*/gm, '*')).split('\n').filter(function (_) {
|
|
@@ -1021,12 +1039,21 @@
|
|
|
1021
1039
|
id = node.id,
|
|
1022
1040
|
params = node.params;
|
|
1023
1041
|
var out = '';
|
|
1042
|
+
if (node.leadingComments) {
|
|
1043
|
+
if (this.parentType === 'AssignmentExpression') {
|
|
1044
|
+
this.numSpaces++;
|
|
1045
|
+
}
|
|
1046
|
+
out += '\n' + this.spaces;
|
|
1047
|
+
}
|
|
1024
1048
|
if (async) {
|
|
1025
1049
|
out += 'async ';
|
|
1026
1050
|
}
|
|
1027
1051
|
var star = generator ? '*' : '';
|
|
1028
1052
|
out += 'function' + star + ' ' + this.toSource(id) + this.FunctionDeclarationParams(params);
|
|
1029
1053
|
out += this.toSource(body);
|
|
1054
|
+
if (node.leadingComments && this.parentType === 'AssignmentExpression') {
|
|
1055
|
+
this.numSpaces--;
|
|
1056
|
+
}
|
|
1030
1057
|
return out;
|
|
1031
1058
|
}
|
|
1032
1059
|
}, {
|
|
@@ -1426,26 +1453,51 @@
|
|
|
1426
1453
|
value: function ExportAllDeclaration(node) {
|
|
1427
1454
|
return "export * from ".concat(node.source.extra.raw, ";");
|
|
1428
1455
|
}
|
|
1456
|
+
}, {
|
|
1457
|
+
key: "ExportNamespaceSpecifier",
|
|
1458
|
+
value: function ExportNamespaceSpecifier(node) {
|
|
1459
|
+
var exported = node.exported;
|
|
1460
|
+
return '* as ' + this.toSource(exported);
|
|
1461
|
+
}
|
|
1429
1462
|
}, {
|
|
1430
1463
|
key: "ExportNamedDeclaration",
|
|
1431
1464
|
value: function ExportNamedDeclaration(node) {
|
|
1432
1465
|
var _this3 = this;
|
|
1433
1466
|
var declaration = node.declaration,
|
|
1434
1467
|
source = node.source,
|
|
1435
|
-
specifiers = node.specifiers
|
|
1468
|
+
specifiers = node.specifiers,
|
|
1469
|
+
loc = node.loc;
|
|
1436
1470
|
var out = this.spaces;
|
|
1437
1471
|
if (specifiers.length) {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
out += "
|
|
1472
|
+
if (!source) {
|
|
1473
|
+
console.warn("ExportNamedDeclaration> no source given");
|
|
1474
|
+
}
|
|
1475
|
+
if (specifiers.length === 1 && specifiers[0].type === 'ExportNamespaceSpecifier') {
|
|
1476
|
+
out += 'export ';
|
|
1477
|
+
out += this.toSource(specifiers[0]);
|
|
1478
|
+
out += ' from ';
|
|
1479
|
+
out += this.toSource(source);
|
|
1480
|
+
out += ";";
|
|
1481
|
+
} else {
|
|
1482
|
+
var sameLine = loc.start.line === loc.end.line;
|
|
1483
|
+
if (sameLine) {
|
|
1484
|
+
out += 'export {';
|
|
1485
|
+
out += this.mapToSource(specifiers).join(', ');
|
|
1486
|
+
out += '}';
|
|
1487
|
+
} else {
|
|
1488
|
+
out += 'export {\n';
|
|
1489
|
+
out += this.mapToSource(specifiers).map(function (_) {
|
|
1490
|
+
return " ".concat(_this3.spaces).concat(_);
|
|
1491
|
+
}).join(',\n');
|
|
1492
|
+
out += '\n';
|
|
1493
|
+
out += this.spaces;
|
|
1494
|
+
out += '}';
|
|
1495
|
+
}
|
|
1496
|
+
if (source) {
|
|
1497
|
+
out += " from " + this.toSource(source);
|
|
1498
|
+
}
|
|
1499
|
+
out += ";\n";
|
|
1447
1500
|
}
|
|
1448
|
-
out += ";\n";
|
|
1449
1501
|
} else if (declaration) {
|
|
1450
1502
|
out += 'export ' + this.toSource(declaration);
|
|
1451
1503
|
} else {
|
|
@@ -2000,9 +2052,6 @@
|
|
|
2000
2052
|
i--;
|
|
2001
2053
|
while (i >= 0) {
|
|
2002
2054
|
parent = parents[i];
|
|
2003
|
-
if (parent.type === 'CallExpression') {
|
|
2004
|
-
break;
|
|
2005
|
-
}
|
|
2006
2055
|
if (nodeIsFunction(parent)) {
|
|
2007
2056
|
break;
|
|
2008
2057
|
}
|
|
@@ -2021,37 +2070,49 @@
|
|
|
2021
2070
|
}
|
|
2022
2071
|
(_console = console).warn.apply(_console, arguments);
|
|
2023
2072
|
}
|
|
2073
|
+
}, {
|
|
2074
|
+
key: "getLeadingCommentsNodeForFunctionExpression",
|
|
2075
|
+
value: function getLeadingCommentsNodeForFunctionExpression(node) {
|
|
2076
|
+
var parents = this.parents;
|
|
2077
|
+
var i = parents.findLastIndex(function (_) {
|
|
2078
|
+
return _ === node;
|
|
2079
|
+
});
|
|
2080
|
+
var parent = parents[i];
|
|
2081
|
+
if (parent.leadingComments) {
|
|
2082
|
+
return parent;
|
|
2083
|
+
}
|
|
2084
|
+
i--;
|
|
2085
|
+
while (i >= 0) {
|
|
2086
|
+
parent = parents[i];
|
|
2087
|
+
if (nodeIsFunction(parent)) {
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2090
|
+
if (parent.leadingComments) {
|
|
2091
|
+
return parent;
|
|
2092
|
+
}
|
|
2093
|
+
i--;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2024
2096
|
}, {
|
|
2025
2097
|
key: "getJSDoc",
|
|
2026
2098
|
value: function getJSDoc(node) {
|
|
2027
2099
|
if (node.type === 'BlockStatement') {
|
|
2028
2100
|
node = this.parent;
|
|
2029
2101
|
}
|
|
2030
|
-
if (node.type === 'FunctionExpression') {
|
|
2031
|
-
if (node.leadingComments) {
|
|
2032
|
-
this.warn("Case of FunctionExpression containing its own leadingComments is not handled");
|
|
2033
|
-
return;
|
|
2034
|
-
}
|
|
2035
|
-
node = this.findParentOfType(node, 'ExpressionStatement');
|
|
2036
|
-
if (!node) {
|
|
2037
|
-
node = this.parents.findLast(function (_) {
|
|
2038
|
-
return _.type === 'VariableDeclaration';
|
|
2039
|
-
});
|
|
2040
|
-
if (!node) {
|
|
2041
|
-
return;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
2102
|
var _node = node,
|
|
2046
2103
|
leadingComments = _node.leadingComments;
|
|
2104
|
+
if (node.type === 'FunctionExpression') {
|
|
2105
|
+
var tmp = this.getLeadingCommentsNodeForFunctionExpression(node);
|
|
2106
|
+
leadingComments = tmp === null || tmp === void 0 ? void 0 : tmp.leadingComments;
|
|
2107
|
+
}
|
|
2047
2108
|
if (!leadingComments) {
|
|
2048
2109
|
if (node.type === 'FunctionDeclaration') {
|
|
2049
2110
|
var exportNamedDeclaration = this.findParentOfType(node, 'ExportNamedDeclaration');
|
|
2050
2111
|
leadingComments = exportNamedDeclaration === null || exportNamedDeclaration === void 0 ? void 0 : exportNamedDeclaration.leadingComments;
|
|
2051
2112
|
}
|
|
2052
2113
|
if (node.type === 'ArrowFunctionExpression') {
|
|
2053
|
-
var
|
|
2054
|
-
leadingComments =
|
|
2114
|
+
var _tmp = this.getLeadingCommentsNodeForArrowFunctionExpression(node);
|
|
2115
|
+
leadingComments = _tmp === null || _tmp === void 0 ? void 0 : _tmp.leadingComments;
|
|
2055
2116
|
}
|
|
2056
2117
|
}
|
|
2057
2118
|
if (leadingComments && leadingComments.length) {
|
|
@@ -2279,6 +2340,23 @@
|
|
|
2279
2340
|
}
|
|
2280
2341
|
return out;
|
|
2281
2342
|
}
|
|
2343
|
+
}, {
|
|
2344
|
+
key: "getNameForFunctionExpression",
|
|
2345
|
+
value: function getNameForFunctionExpression(node) {
|
|
2346
|
+
var objectProperty = this.findParentOfType(node, 'ObjectProperty');
|
|
2347
|
+
if (objectProperty) {
|
|
2348
|
+
return this.toSource(objectProperty.key);
|
|
2349
|
+
}
|
|
2350
|
+
var expressionStatement = this.findParentOfType(node, 'ExpressionStatement');
|
|
2351
|
+
if (expressionStatement) {
|
|
2352
|
+
var left = expressionStatement.expression.left;
|
|
2353
|
+
if (left) {
|
|
2354
|
+
return this.toSource(left);
|
|
2355
|
+
}
|
|
2356
|
+
console.warn("Asserter#getNameForFunctionExpression> expression without left");
|
|
2357
|
+
}
|
|
2358
|
+
return 'unnamed function expression';
|
|
2359
|
+
}
|
|
2282
2360
|
}, {
|
|
2283
2361
|
key: "getName",
|
|
2284
2362
|
value: function getName(node) {
|
|
@@ -2308,11 +2386,7 @@
|
|
|
2308
2386
|
if (id) {
|
|
2309
2387
|
return toSource(id);
|
|
2310
2388
|
}
|
|
2311
|
-
|
|
2312
|
-
if (!expressionStatement) {
|
|
2313
|
-
return 'unnamed function expression';
|
|
2314
|
-
}
|
|
2315
|
-
return toSource(expressionStatement.expression.left);
|
|
2389
|
+
return this.getNameForFunctionExpression(node);
|
|
2316
2390
|
case 'ArrowFunctionExpression':
|
|
2317
2391
|
var parent = this.findParentOfType(node, 'VariableDeclarator');
|
|
2318
2392
|
if (parent) {
|
|
@@ -2491,7 +2565,11 @@
|
|
|
2491
2565
|
ConditionalType = _ts$SyntaxKind.ConditionalType,
|
|
2492
2566
|
IndexedAccessType = _ts$SyntaxKind.IndexedAccessType,
|
|
2493
2567
|
RestType = _ts$SyntaxKind.RestType,
|
|
2494
|
-
|
|
2568
|
+
TypeQuery = _ts$SyntaxKind.TypeQuery,
|
|
2569
|
+
TypeOperator = _ts$SyntaxKind.TypeOperator,
|
|
2570
|
+
KeyOfKeyword = _ts$SyntaxKind.KeyOfKeyword,
|
|
2571
|
+
ConstructorType = _ts$SyntaxKind.ConstructorType,
|
|
2572
|
+
NamedTupleMember = _ts$SyntaxKind.NamedTupleMember;
|
|
2495
2573
|
switch (node.kind) {
|
|
2496
2574
|
case BigIntKeyword:
|
|
2497
2575
|
return {
|
|
@@ -2565,6 +2643,21 @@
|
|
|
2565
2643
|
};
|
|
2566
2644
|
}
|
|
2567
2645
|
return ret;
|
|
2646
|
+
case TypeQuery:
|
|
2647
|
+
var argument = toSourceTS(node.exprName);
|
|
2648
|
+
return {
|
|
2649
|
+
type: 'typeof',
|
|
2650
|
+
argument: argument
|
|
2651
|
+
};
|
|
2652
|
+
case TypeOperator:
|
|
2653
|
+
if (node.operator === KeyOfKeyword) {
|
|
2654
|
+
var _argument = toSourceTS(node.type);
|
|
2655
|
+
return {
|
|
2656
|
+
type: 'keyof',
|
|
2657
|
+
argument: _argument
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
console.warn("unimplemented TypeOperator", node);
|
|
2568
2661
|
case TypeReference:
|
|
2569
2662
|
{
|
|
2570
2663
|
if ((typeName.text === 'Object' || typeName.text === 'Record') && (typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length) === 2) {
|
|
@@ -2626,6 +2719,8 @@
|
|
|
2626
2719
|
return node.getText();
|
|
2627
2720
|
case NumberKeyword:
|
|
2628
2721
|
return node.getText();
|
|
2722
|
+
case NamedTupleMember:
|
|
2723
|
+
return toSourceTS(node.type);
|
|
2629
2724
|
case IntersectionType:
|
|
2630
2725
|
return {
|
|
2631
2726
|
type: 'intersection',
|
|
@@ -2845,6 +2940,12 @@
|
|
|
2845
2940
|
return toSourceBabelTS(node.type);
|
|
2846
2941
|
case 'LastTypeNode':
|
|
2847
2942
|
return toSourceBabelTS(node.qualifier);
|
|
2943
|
+
case 'TSTypeQuery':
|
|
2944
|
+
var argument = toSourceBabelTS(node.exprName);
|
|
2945
|
+
return {
|
|
2946
|
+
type: 'typeof',
|
|
2947
|
+
argument: argument
|
|
2948
|
+
};
|
|
2848
2949
|
default:
|
|
2849
2950
|
console.warn('toSourceBabelTS> unhandled type', node.type, node);
|
|
2850
2951
|
debugger;
|
package/index.mjs
CHANGED
|
@@ -81,6 +81,13 @@ function expandTypeDepFree(type) {
|
|
|
81
81
|
elements: elements.map(expandTypeDepFree)
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
if (type.startsWith('typeof ')) {
|
|
85
|
+
const argument = expandTypeDepFree(type.substring(7));
|
|
86
|
+
return {
|
|
87
|
+
type: 'typeof',
|
|
88
|
+
argument
|
|
89
|
+
};
|
|
90
|
+
}
|
|
84
91
|
if (type === 'object' || type === 'Object') {
|
|
85
92
|
return {
|
|
86
93
|
type: 'object',
|
|
@@ -270,6 +277,9 @@ function parseJSDocTypedef(typedefs, warn, comment, expandType) {
|
|
|
270
277
|
} else {
|
|
271
278
|
warn("not an extensible type", lastTypedef);
|
|
272
279
|
}
|
|
280
|
+
} else if (line.startsWith('@callback')) {
|
|
281
|
+
const name = line.substring(9).trim();
|
|
282
|
+
typedefs[name] = 'Function';
|
|
273
283
|
}
|
|
274
284
|
}
|
|
275
285
|
}
|
|
@@ -363,7 +373,7 @@ class Stringifier {
|
|
|
363
373
|
return '';
|
|
364
374
|
}
|
|
365
375
|
this.lastCommentBlockIndex = loc.start.index;
|
|
366
|
-
|
|
376
|
+
let {
|
|
367
377
|
spaces
|
|
368
378
|
} = this;
|
|
369
379
|
let out = '';
|
|
@@ -371,6 +381,14 @@ class Stringifier {
|
|
|
371
381
|
if (dedicatedLine) {
|
|
372
382
|
out += spaces;
|
|
373
383
|
}
|
|
384
|
+
const multiLine = loc.start.line !== loc.end.line;
|
|
385
|
+
if (multiLine) {
|
|
386
|
+
var _this$parents$at;
|
|
387
|
+
if (((_this$parents$at = this.parents.at(-2)) == null ? void 0 : _this$parents$at.type) === 'AssignmentExpression') {
|
|
388
|
+
spaces += ' ';
|
|
389
|
+
}
|
|
390
|
+
out += '\n' + spaces;
|
|
391
|
+
}
|
|
374
392
|
out += '/*';
|
|
375
393
|
if (value.includes('\n')) {
|
|
376
394
|
value = trimEndSpaces(value.replace(/^\s*\*/gm, '*')).split('\n').filter(_ => _.length).map((line, i) => (i ? spaces + ' ' : '') + line).join('\n');
|
|
@@ -709,12 +727,21 @@ class Stringifier {
|
|
|
709
727
|
params
|
|
710
728
|
} = node;
|
|
711
729
|
let out = '';
|
|
730
|
+
if (node.leadingComments) {
|
|
731
|
+
if (this.parentType === 'AssignmentExpression') {
|
|
732
|
+
this.numSpaces++;
|
|
733
|
+
}
|
|
734
|
+
out += '\n' + this.spaces;
|
|
735
|
+
}
|
|
712
736
|
if (async) {
|
|
713
737
|
out += 'async ';
|
|
714
738
|
}
|
|
715
739
|
const star = generator ? '*' : '';
|
|
716
740
|
out += 'function' + star + ' ' + this.toSource(id) + this.FunctionDeclarationParams(params);
|
|
717
741
|
out += this.toSource(body);
|
|
742
|
+
if (node.leadingComments && this.parentType === 'AssignmentExpression') {
|
|
743
|
+
this.numSpaces--;
|
|
744
|
+
}
|
|
718
745
|
return out;
|
|
719
746
|
}
|
|
720
747
|
ArrowFunctionExpression(node) {
|
|
@@ -1112,23 +1139,48 @@ class Stringifier {
|
|
|
1112
1139
|
ExportAllDeclaration(node) {
|
|
1113
1140
|
return `export * from ${node.source.extra.raw};`;
|
|
1114
1141
|
}
|
|
1142
|
+
ExportNamespaceSpecifier(node) {
|
|
1143
|
+
const {
|
|
1144
|
+
exported
|
|
1145
|
+
} = node;
|
|
1146
|
+
return '* as ' + this.toSource(exported);
|
|
1147
|
+
}
|
|
1115
1148
|
ExportNamedDeclaration(node) {
|
|
1116
1149
|
const {
|
|
1117
1150
|
declaration,
|
|
1118
1151
|
source,
|
|
1119
|
-
specifiers
|
|
1152
|
+
specifiers,
|
|
1153
|
+
loc
|
|
1120
1154
|
} = node;
|
|
1121
1155
|
let out = this.spaces;
|
|
1122
1156
|
if (specifiers.length) {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
out +=
|
|
1157
|
+
if (!source) {
|
|
1158
|
+
console.warn("ExportNamedDeclaration> no source given");
|
|
1159
|
+
}
|
|
1160
|
+
if (specifiers.length === 1 && specifiers[0].type === 'ExportNamespaceSpecifier') {
|
|
1161
|
+
out += 'export ';
|
|
1162
|
+
out += this.toSource(specifiers[0]);
|
|
1163
|
+
out += ' from ';
|
|
1164
|
+
out += this.toSource(source);
|
|
1165
|
+
out += ";";
|
|
1166
|
+
} else {
|
|
1167
|
+
const sameLine = loc.start.line === loc.end.line;
|
|
1168
|
+
if (sameLine) {
|
|
1169
|
+
out += 'export {';
|
|
1170
|
+
out += this.mapToSource(specifiers).join(', ');
|
|
1171
|
+
out += '}';
|
|
1172
|
+
} else {
|
|
1173
|
+
out += 'export {\n';
|
|
1174
|
+
out += this.mapToSource(specifiers).map(_ => ` ${this.spaces}${_}`).join(',\n');
|
|
1175
|
+
out += '\n';
|
|
1176
|
+
out += this.spaces;
|
|
1177
|
+
out += '}';
|
|
1178
|
+
}
|
|
1179
|
+
if (source) {
|
|
1180
|
+
out += " from " + this.toSource(source);
|
|
1181
|
+
}
|
|
1182
|
+
out += ";\n";
|
|
1130
1183
|
}
|
|
1131
|
-
out += ";\n";
|
|
1132
1184
|
} else if (declaration) {
|
|
1133
1185
|
out += 'export ' + this.toSource(declaration);
|
|
1134
1186
|
} else {
|
|
@@ -1666,9 +1718,6 @@ class Asserter extends Stringifier {
|
|
|
1666
1718
|
i--;
|
|
1667
1719
|
while (i >= 0) {
|
|
1668
1720
|
parent = parents[i];
|
|
1669
|
-
if (parent.type === 'CallExpression') {
|
|
1670
|
-
break;
|
|
1671
|
-
}
|
|
1672
1721
|
if (nodeIsFunction(parent)) {
|
|
1673
1722
|
break;
|
|
1674
1723
|
}
|
|
@@ -1684,26 +1733,38 @@ class Asserter extends Stringifier {
|
|
|
1684
1733
|
}
|
|
1685
1734
|
console.warn(...args);
|
|
1686
1735
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1736
|
+
getLeadingCommentsNodeForFunctionExpression(node) {
|
|
1737
|
+
const {
|
|
1738
|
+
parents
|
|
1739
|
+
} = this;
|
|
1740
|
+
let i = parents.findLastIndex(_ => _ === node);
|
|
1741
|
+
let parent = parents[i];
|
|
1742
|
+
if (parent.leadingComments) {
|
|
1743
|
+
return parent;
|
|
1690
1744
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1745
|
+
i--;
|
|
1746
|
+
while (i >= 0) {
|
|
1747
|
+
parent = parents[i];
|
|
1748
|
+
if (nodeIsFunction(parent)) {
|
|
1749
|
+
break;
|
|
1695
1750
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
node = this.parents.findLast(_ => _.type === 'VariableDeclaration');
|
|
1699
|
-
if (!node) {
|
|
1700
|
-
return;
|
|
1701
|
-
}
|
|
1751
|
+
if (parent.leadingComments) {
|
|
1752
|
+
return parent;
|
|
1702
1753
|
}
|
|
1754
|
+
i--;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
getJSDoc(node) {
|
|
1758
|
+
if (node.type === 'BlockStatement') {
|
|
1759
|
+
node = this.parent;
|
|
1703
1760
|
}
|
|
1704
1761
|
let {
|
|
1705
1762
|
leadingComments
|
|
1706
1763
|
} = node;
|
|
1764
|
+
if (node.type === 'FunctionExpression') {
|
|
1765
|
+
const tmp = this.getLeadingCommentsNodeForFunctionExpression(node);
|
|
1766
|
+
leadingComments = tmp == null ? void 0 : tmp.leadingComments;
|
|
1767
|
+
}
|
|
1707
1768
|
if (!leadingComments) {
|
|
1708
1769
|
if (node.type === 'FunctionDeclaration') {
|
|
1709
1770
|
const exportNamedDeclaration = this.findParentOfType(node, 'ExportNamedDeclaration');
|
|
@@ -1918,6 +1979,23 @@ class Asserter extends Stringifier {
|
|
|
1918
1979
|
}
|
|
1919
1980
|
return out;
|
|
1920
1981
|
}
|
|
1982
|
+
getNameForFunctionExpression(node) {
|
|
1983
|
+
const objectProperty = this.findParentOfType(node, 'ObjectProperty');
|
|
1984
|
+
if (objectProperty) {
|
|
1985
|
+
return this.toSource(objectProperty.key);
|
|
1986
|
+
}
|
|
1987
|
+
const expressionStatement = this.findParentOfType(node, 'ExpressionStatement');
|
|
1988
|
+
if (expressionStatement) {
|
|
1989
|
+
const {
|
|
1990
|
+
left
|
|
1991
|
+
} = expressionStatement.expression;
|
|
1992
|
+
if (left) {
|
|
1993
|
+
return this.toSource(left);
|
|
1994
|
+
}
|
|
1995
|
+
console.warn("Asserter#getNameForFunctionExpression> expression without left");
|
|
1996
|
+
}
|
|
1997
|
+
return 'unnamed function expression';
|
|
1998
|
+
}
|
|
1921
1999
|
getName(node) {
|
|
1922
2000
|
const toSource = this.toSource.bind(this);
|
|
1923
2001
|
if (node.type === 'BlockStatement') {
|
|
@@ -1944,11 +2022,7 @@ class Asserter extends Stringifier {
|
|
|
1944
2022
|
if (id) {
|
|
1945
2023
|
return toSource(id);
|
|
1946
2024
|
}
|
|
1947
|
-
|
|
1948
|
-
if (!expressionStatement) {
|
|
1949
|
-
return 'unnamed function expression';
|
|
1950
|
-
}
|
|
1951
|
-
return toSource(expressionStatement.expression.left);
|
|
2025
|
+
return this.getNameForFunctionExpression(node);
|
|
1952
2026
|
case 'ArrowFunctionExpression':
|
|
1953
2027
|
const parent = this.findParentOfType(node, 'VariableDeclarator');
|
|
1954
2028
|
if (parent) {
|
|
@@ -2118,7 +2192,11 @@ function toSourceTS(node) {
|
|
|
2118
2192
|
ConditionalType,
|
|
2119
2193
|
IndexedAccessType,
|
|
2120
2194
|
RestType,
|
|
2121
|
-
|
|
2195
|
+
TypeQuery,
|
|
2196
|
+
TypeOperator,
|
|
2197
|
+
KeyOfKeyword,
|
|
2198
|
+
ConstructorType,
|
|
2199
|
+
NamedTupleMember
|
|
2122
2200
|
} = ts.SyntaxKind;
|
|
2123
2201
|
switch (node.kind) {
|
|
2124
2202
|
case BigIntKeyword:
|
|
@@ -2193,6 +2271,21 @@ function toSourceTS(node) {
|
|
|
2193
2271
|
};
|
|
2194
2272
|
}
|
|
2195
2273
|
return ret;
|
|
2274
|
+
case TypeQuery:
|
|
2275
|
+
const argument = toSourceTS(node.exprName);
|
|
2276
|
+
return {
|
|
2277
|
+
type: 'typeof',
|
|
2278
|
+
argument
|
|
2279
|
+
};
|
|
2280
|
+
case TypeOperator:
|
|
2281
|
+
if (node.operator === KeyOfKeyword) {
|
|
2282
|
+
const _argument = toSourceTS(node.type);
|
|
2283
|
+
return {
|
|
2284
|
+
type: 'keyof',
|
|
2285
|
+
argument: _argument
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
console.warn("unimplemented TypeOperator", node);
|
|
2196
2289
|
case TypeReference:
|
|
2197
2290
|
{
|
|
2198
2291
|
if ((typeName.text === 'Object' || typeName.text === 'Record') && (typeArguments == null ? void 0 : typeArguments.length) === 2) {
|
|
@@ -2254,6 +2347,8 @@ function toSourceTS(node) {
|
|
|
2254
2347
|
return node.getText();
|
|
2255
2348
|
case NumberKeyword:
|
|
2256
2349
|
return node.getText();
|
|
2350
|
+
case NamedTupleMember:
|
|
2351
|
+
return toSourceTS(node.type);
|
|
2257
2352
|
case IntersectionType:
|
|
2258
2353
|
return {
|
|
2259
2354
|
type: 'intersection',
|
|
@@ -2473,6 +2568,12 @@ function toSourceBabelTS(node) {
|
|
|
2473
2568
|
return toSourceBabelTS(node.type);
|
|
2474
2569
|
case 'LastTypeNode':
|
|
2475
2570
|
return toSourceBabelTS(node.qualifier);
|
|
2571
|
+
case 'TSTypeQuery':
|
|
2572
|
+
const argument = toSourceBabelTS(node.exprName);
|
|
2573
|
+
return {
|
|
2574
|
+
type: 'typeof',
|
|
2575
|
+
argument
|
|
2576
|
+
};
|
|
2476
2577
|
default:
|
|
2477
2578
|
console.warn('toSourceBabelTS> unhandled type', node.type, node);
|
|
2478
2579
|
debugger;
|
package/package.json
CHANGED