@openrewrite/rewrite 0.23.1 → 0.25.0
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/LICENSE.md +87 -0
- package/dist/src/core/parser.js +17 -7
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/tree.d.ts +1 -1
- package/dist/src/core/tree.d.ts.map +1 -1
- package/dist/src/java/markers.d.ts +2 -2
- package/dist/src/java/markers.d.ts.map +1 -1
- package/dist/src/java/remote/receiver.js +17 -7
- package/dist/src/java/remote/receiver.js.map +1 -1
- package/dist/src/java/remote/sender.js +17 -7
- package/dist/src/java/remote/sender.js.map +1 -1
- package/dist/src/java/tree/support_types.d.ts +1 -1
- package/dist/src/java/tree/support_types.d.ts.map +1 -1
- package/dist/src/java/tree/tree.d.ts +70 -70
- package/dist/src/java/tree/tree.d.ts.map +1 -1
- package/dist/src/java/tree/tree.js +17 -7
- package/dist/src/java/tree/tree.js.map +1 -1
- package/dist/src/java/visitor.js +17 -7
- package/dist/src/java/visitor.js.map +1 -1
- package/dist/src/javascript/extensions.js +17 -7
- package/dist/src/javascript/extensions.js.map +1 -1
- package/dist/src/javascript/parser.d.ts +24 -20
- package/dist/src/javascript/parser.d.ts.map +1 -1
- package/dist/src/javascript/parser.js +149 -76
- package/dist/src/javascript/parser.js.map +1 -1
- package/dist/src/javascript/parserUtils.d.ts +1 -1
- package/dist/src/javascript/parserUtils.js +17 -7
- package/dist/src/javascript/parserUtils.js.map +1 -1
- package/dist/src/javascript/projectParser.js +17 -7
- package/dist/src/javascript/projectParser.js.map +1 -1
- package/dist/src/javascript/remote/receiver.d.ts.map +1 -1
- package/dist/src/javascript/remote/receiver.js +219 -15
- package/dist/src/javascript/remote/receiver.js.map +1 -1
- package/dist/src/javascript/remote/remote_extensions.js +17 -7
- package/dist/src/javascript/remote/remote_extensions.js.map +1 -1
- package/dist/src/javascript/remote/sender.d.ts.map +1 -1
- package/dist/src/javascript/remote/sender.js +167 -11
- package/dist/src/javascript/remote/sender.js.map +1 -1
- package/dist/src/javascript/tree/extensions.js +17 -7
- package/dist/src/javascript/tree/extensions.js.map +1 -1
- package/dist/src/javascript/tree/support_types.d.ts +53 -7
- package/dist/src/javascript/tree/support_types.d.ts.map +1 -1
- package/dist/src/javascript/tree/support_types.js +63 -7
- package/dist/src/javascript/tree/support_types.js.map +1 -1
- package/dist/src/javascript/tree/tree.d.ts +916 -89
- package/dist/src/javascript/tree/tree.d.ts.map +1 -1
- package/dist/src/javascript/tree/tree.js +1755 -613
- package/dist/src/javascript/tree/tree.js.map +1 -1
- package/dist/src/javascript/typeMapping.js +17 -7
- package/dist/src/javascript/typeMapping.js.map +1 -1
- package/dist/src/javascript/visitor.d.ts +17 -1
- package/dist/src/javascript/visitor.d.ts.map +1 -1
- package/dist/src/javascript/visitor.js +225 -10
- package/dist/src/javascript/visitor.js.map +1 -1
- package/dist/src/json/tree.d.ts +1 -1
- package/dist/src/json/tree.d.ts.map +1 -1
- package/dist/src/json/visitor.js +17 -7
- package/dist/src/json/visitor.js.map +1 -1
- package/dist/src/yaml/tree/support_types.d.ts +1 -1
- package/dist/src/yaml/tree/support_types.d.ts.map +1 -1
- package/dist/src/yaml/tree/tree.d.ts +11 -11
- package/package.json +1 -1
- package/LICENSE +0 -201
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -35,6 +45,7 @@ const core_1 = require("../core");
|
|
|
35
45
|
const parserUtils_1 = require("./parserUtils");
|
|
36
46
|
const typeMapping_1 = require("./typeMapping");
|
|
37
47
|
const node_path_1 = __importDefault(require("node:path"));
|
|
48
|
+
const _1 = require(".");
|
|
38
49
|
class JavaScriptParser extends core_1.Parser {
|
|
39
50
|
constructor() {
|
|
40
51
|
super();
|
|
@@ -235,12 +246,17 @@ class JavaScriptParserVisitor {
|
|
|
235
246
|
var _a, _b, _c, _d;
|
|
236
247
|
if (ts.isVariableStatement(node) || ts.isModuleDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node)
|
|
237
248
|
|| ts.isInterfaceDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)
|
|
238
|
-
|| ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node)
|
|
249
|
+
|| ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node)
|
|
250
|
+
|| ts.isIndexSignatureDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isExportDeclaration(node)
|
|
251
|
+
|| ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node)) {
|
|
239
252
|
return node.modifiers ? (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
240
253
|
}
|
|
241
|
-
else if (ts.
|
|
242
|
-
|
|
243
|
-
|
|
254
|
+
else if (ts.isExportAssignment(node)) {
|
|
255
|
+
const defaultModifier = this.findChildNode(node, ts.SyntaxKind.DefaultKeyword);
|
|
256
|
+
return [
|
|
257
|
+
...node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.filter(ts.isModifier).map(this.mapModifier) : [],
|
|
258
|
+
...defaultModifier && ts.isModifier(defaultModifier) ? [this.mapModifier(defaultModifier)] : []
|
|
259
|
+
];
|
|
244
260
|
}
|
|
245
261
|
else if (ts.isVariableDeclarationList(node)) {
|
|
246
262
|
let modifier;
|
|
@@ -300,7 +316,8 @@ class JavaScriptParserVisitor {
|
|
|
300
316
|
}
|
|
301
317
|
for (let heritageClause of node.heritageClauses) {
|
|
302
318
|
if (heritageClause.token == ts.SyntaxKind.ExtendsKeyword) {
|
|
303
|
-
|
|
319
|
+
const expression = this.visit(heritageClause.types[0]);
|
|
320
|
+
return this.leftPadded(this.prefix(heritageClause.getFirstToken()), new _1.TypeTreeExpression((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, expression));
|
|
304
321
|
}
|
|
305
322
|
}
|
|
306
323
|
return null;
|
|
@@ -371,6 +388,15 @@ class JavaScriptParserVisitor {
|
|
|
371
388
|
visitNullKeyword(node) {
|
|
372
389
|
return this.mapLiteral(node, null);
|
|
373
390
|
}
|
|
391
|
+
visitNeverKeyword(node) {
|
|
392
|
+
return this.mapIdentifier(node, 'never');
|
|
393
|
+
}
|
|
394
|
+
visitSymbolKeyword(node) {
|
|
395
|
+
return this.mapIdentifier(node, 'symbol');
|
|
396
|
+
}
|
|
397
|
+
visitBigIntKeyword(node) {
|
|
398
|
+
return this.mapIdentifier(node, 'bigint');
|
|
399
|
+
}
|
|
374
400
|
mapLiteral(node, value) {
|
|
375
401
|
return new J.Literal((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, value, node.getText(), null, this.mapPrimitiveType(node));
|
|
376
402
|
}
|
|
@@ -399,9 +425,6 @@ class JavaScriptParserVisitor {
|
|
|
399
425
|
return this.mapLiteral(node, node.text);
|
|
400
426
|
}
|
|
401
427
|
visitIdentifier(node) {
|
|
402
|
-
if (node.text === 'undefined') {
|
|
403
|
-
return this.mapLiteral(node, undefined);
|
|
404
|
-
}
|
|
405
428
|
return this.mapIdentifier(node, node.text);
|
|
406
429
|
}
|
|
407
430
|
mapIdentifier(node, name, withType = true) {
|
|
@@ -429,16 +452,16 @@ class JavaScriptParserVisitor {
|
|
|
429
452
|
}
|
|
430
453
|
visitParameter(node) {
|
|
431
454
|
if (node.questionToken) {
|
|
432
|
-
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
455
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
433
456
|
}
|
|
434
457
|
if (node.dotDotDotToken) {
|
|
435
|
-
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
458
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.visit(node.name), this.mapType(node)), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
436
459
|
}
|
|
437
460
|
const nameExpression = this.visit(node.name);
|
|
438
461
|
if (nameExpression instanceof J.Identifier) {
|
|
439
|
-
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
462
|
+
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
440
463
|
}
|
|
441
|
-
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
464
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
442
465
|
}
|
|
443
466
|
visitDecorator(node) {
|
|
444
467
|
let annotationType;
|
|
@@ -464,17 +487,26 @@ class JavaScriptParserVisitor {
|
|
|
464
487
|
if (node.questionToken) {
|
|
465
488
|
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
466
489
|
}
|
|
467
|
-
|
|
490
|
+
const nameExpression = this.visit(node.name);
|
|
491
|
+
if (nameExpression instanceof J.Identifier) {
|
|
492
|
+
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
496
|
+
}
|
|
468
497
|
}
|
|
469
498
|
visitPropertyDeclaration(node) {
|
|
470
499
|
if (node.questionToken) {
|
|
471
|
-
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
500
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
501
|
+
}
|
|
502
|
+
if (node.exclamationToken) {
|
|
503
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.name), JS.Unary.Type.Exclamation), this.visit(node.name), this.mapType(node)), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
472
504
|
}
|
|
473
505
|
const nameExpression = this.visit(node.name);
|
|
474
506
|
if (nameExpression instanceof J.Identifier) {
|
|
475
|
-
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
507
|
+
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
476
508
|
}
|
|
477
|
-
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
509
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
478
510
|
}
|
|
479
511
|
visitMethodSignature(node) {
|
|
480
512
|
if (node.questionToken) {
|
|
@@ -486,13 +518,18 @@ class JavaScriptParserVisitor {
|
|
|
486
518
|
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(node.name ? this.visit(node.name) : this.mapIdentifier(node, ""), []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, null, null, this.mapMethodType(node));
|
|
487
519
|
}
|
|
488
520
|
visitMethodDeclaration(node) {
|
|
489
|
-
if (node.questionToken) {
|
|
490
|
-
|
|
521
|
+
if (node.questionToken || node.asteriskToken) {
|
|
522
|
+
let methodName = node.questionToken ? this.getOptionalUnary(node) : this.visit(node.name);
|
|
523
|
+
if (node.asteriskToken) {
|
|
524
|
+
methodName = new JS.Unary((0, core_1.randomId)(), this.prefix(node.asteriskToken), core_1.Markers.EMPTY, this.leftPadded(this.prefix(node.name), JS.Unary.Type.Asterisk), methodName, this.mapType(node));
|
|
525
|
+
}
|
|
526
|
+
return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), methodName, this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
|
|
491
527
|
}
|
|
492
|
-
|
|
493
|
-
|
|
528
|
+
const name = node.name ? this.visit(node.name) : this.mapIdentifier(node, "");
|
|
529
|
+
if (!(name instanceof J.Identifier)) {
|
|
530
|
+
return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), name, this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
|
|
494
531
|
}
|
|
495
|
-
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(
|
|
532
|
+
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(name, []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
|
|
496
533
|
}
|
|
497
534
|
mapTypeInfo(node) {
|
|
498
535
|
return node.type ? new JS.TypeInfo((0, core_1.randomId)(), this.prefix(node.getChildAt(node.getChildren().indexOf(node.type) - 1)), core_1.Markers.EMPTY, this.visit(node.type)) : null;
|
|
@@ -522,7 +559,7 @@ class JavaScriptParserVisitor {
|
|
|
522
559
|
return new JS.IndexSignatureDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.mapCommaSeparatedList(this.getParameterListNodes(node, ts.SyntaxKind.OpenBracketToken)), this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.type) - 1)), this.convert(node.type)), this.mapType(node));
|
|
523
560
|
}
|
|
524
561
|
visitTypePredicate(node) {
|
|
525
|
-
return this.
|
|
562
|
+
return new JS.TypePredicate((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.assertsModifier ? this.leftPadded(this.prefix(node.assertsModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), this.visit(node.parameterName), node.type ? this.leftPadded(this.suffix(node.parameterName), this.convert(node.type)) : null, this.mapType(node));
|
|
526
563
|
}
|
|
527
564
|
visitTypeReference(node) {
|
|
528
565
|
if (node.typeArguments) {
|
|
@@ -531,10 +568,10 @@ class JavaScriptParserVisitor {
|
|
|
531
568
|
return this.visit(node.typeName);
|
|
532
569
|
}
|
|
533
570
|
visitFunctionType(node) {
|
|
534
|
-
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), new java_1.JContainer(this.prefix(node), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
571
|
+
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
535
572
|
}
|
|
536
573
|
visitConstructorType(node) {
|
|
537
|
-
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword))), new java_1.JContainer(this.prefix(node), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
574
|
+
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword))), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
538
575
|
}
|
|
539
576
|
visitTypeQuery(node) {
|
|
540
577
|
return new JS.TypeQuery((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.exprName), this.mapType(node));
|
|
@@ -578,13 +615,13 @@ class JavaScriptParserVisitor {
|
|
|
578
615
|
return new JS.ConditionalType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.checkType), new java_1.JContainer(this.prefix(this.findChildNode(node, ts.SyntaxKind.ExtendsKeyword)), [this.rightPadded(new J.Ternary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.convert(node.extendsType), this.leftPadded(this.suffix(node.extendsType), this.convert(node.trueType)), this.leftPadded(this.suffix(node.trueType), this.convert(node.falseType)), this.mapType(node)), java_1.Space.EMPTY)], core_1.Markers.EMPTY), this.mapType(node));
|
|
579
616
|
}
|
|
580
617
|
visitInferType(node) {
|
|
581
|
-
return this.
|
|
618
|
+
return new JS.InferType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, this.convert(node.typeParameter)), this.mapType(node));
|
|
582
619
|
}
|
|
583
620
|
visitParenthesizedType(node) {
|
|
584
|
-
return this.
|
|
621
|
+
return new J.ParenthesizedTypeTree((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], new J.Parentheses((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.type), this.prefix(node.getLastToken()))));
|
|
585
622
|
}
|
|
586
623
|
visitThisType(node) {
|
|
587
|
-
return this.
|
|
624
|
+
return this.mapIdentifier(node, 'this');
|
|
588
625
|
}
|
|
589
626
|
visitTypeOperator(node) {
|
|
590
627
|
function mapTypeOperator(operator) {
|
|
@@ -593,21 +630,39 @@ class JavaScriptParserVisitor {
|
|
|
593
630
|
return JS.TypeOperator.Type.KeyOf;
|
|
594
631
|
case ts.SyntaxKind.ReadonlyKeyword:
|
|
595
632
|
return JS.TypeOperator.Type.ReadOnly;
|
|
633
|
+
case ts.SyntaxKind.UniqueKeyword:
|
|
634
|
+
return JS.TypeOperator.Type.Unique;
|
|
596
635
|
}
|
|
597
636
|
}
|
|
598
637
|
return new JS.TypeOperator((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, mapTypeOperator(node.operator), this.leftPadded(this.prefix(node.type), this.visit(node.type)));
|
|
599
638
|
}
|
|
600
639
|
visitIndexedAccessType(node) {
|
|
601
|
-
return this.
|
|
640
|
+
return new JS.IndexedAccessType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.objectType), new JS.IndexedAccessType.IndexType((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.indexType), this.suffix(node.indexType)), this.mapType(node.indexType)), this.mapType(node));
|
|
602
641
|
}
|
|
603
642
|
visitMappedType(node) {
|
|
604
|
-
|
|
643
|
+
function hasPrefixToken(readonlyToken) {
|
|
644
|
+
return !!(readonlyToken && (readonlyToken.kind == ts.SyntaxKind.PlusToken || readonlyToken.kind == ts.SyntaxKind.MinusToken));
|
|
645
|
+
}
|
|
646
|
+
function hasSuffixToken(questionToken) {
|
|
647
|
+
return !!(questionToken && (questionToken.kind == ts.SyntaxKind.PlusToken || questionToken.kind == ts.SyntaxKind.MinusToken));
|
|
648
|
+
}
|
|
649
|
+
return new JS.MappedType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, hasPrefixToken(node.readonlyToken) ? this.leftPadded(this.prefix(node.readonlyToken), new J.Literal((0, core_1.randomId)(), this.prefix(node.readonlyToken), core_1.Markers.EMPTY, null, node.readonlyToken.getText(), null, this.mapPrimitiveType(node.readonlyToken))) : null, node.readonlyToken ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.ReadonlyKeyword)), true) : this.leftPadded(java_1.Space.EMPTY, false), new JS.MappedType.KeysRemapping((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)), core_1.Markers.EMPTY, this.rightPadded(new JS.MappedType.MappedTypeParameter((0, core_1.randomId)(), this.prefix(node.typeParameter), core_1.Markers.EMPTY, this.visit(node.typeParameter.name), this.leftPadded(this.suffix(node.typeParameter.name), this.visit(node.typeParameter.constraint))), this.suffix(node.typeParameter)), node.nameType ? this.rightPadded(this.visit(node.nameType), this.suffix(node.nameType)) : null), hasSuffixToken(node.questionToken) ? this.leftPadded(this.prefix(node.questionToken), new J.Literal((0, core_1.randomId)(), this.prefix(node.questionToken), core_1.Markers.EMPTY, null, node.questionToken.getText(), null, this.mapPrimitiveType(node.questionToken))) : null, node.questionToken ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.QuestionToken)), true) : this.leftPadded(java_1.Space.EMPTY, false), new java_1.JContainer(this.prefix(this.findChildNode(node, ts.SyntaxKind.ColonToken)), [this.rightPadded(this.visit(node.type), this.suffix(node.type)),
|
|
650
|
+
this.findChildNode(node, ts.SyntaxKind.SemicolonToken) ?
|
|
651
|
+
this.rightPadded(this.newJEmpty(java_1.Space.EMPTY, core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())])), this.prefix(node.getLastToken()))
|
|
652
|
+
: this.rightPadded(this.newJEmpty(), this.prefix(node.getLastToken()))
|
|
653
|
+
], core_1.Markers.EMPTY), this.mapType(node));
|
|
605
654
|
}
|
|
606
655
|
visitLiteralType(node) {
|
|
607
|
-
return this.visit(node.literal);
|
|
656
|
+
return new JS.LiteralType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.literal), this.mapType(node));
|
|
608
657
|
}
|
|
609
658
|
visitNamedTupleMember(node) {
|
|
610
|
-
|
|
659
|
+
if (node.questionToken) {
|
|
660
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
661
|
+
}
|
|
662
|
+
if (node.dotDotDotToken) {
|
|
663
|
+
return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.visit(node.name), this.mapType(node)), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
664
|
+
}
|
|
665
|
+
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.visit(node.name), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
611
666
|
}
|
|
612
667
|
visitTemplateLiteralType(node) {
|
|
613
668
|
return new JS.TemplateExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.head), node.templateSpans.map(s => this.rightPadded(this.visit(s), this.suffix(s))), this.mapType(node));
|
|
@@ -616,7 +671,7 @@ class JavaScriptParserVisitor {
|
|
|
616
671
|
return new JS.TemplateExpression.TemplateSpan((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.type), this.visit(node.literal));
|
|
617
672
|
}
|
|
618
673
|
visitImportType(node) {
|
|
619
|
-
return this.
|
|
674
|
+
return new JS.ImportType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.isTypeOf ? this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.TypeOfKeyword))) : this.rightPadded(false, java_1.Space.EMPTY), new J.ParenthesizedTypeTree((0, core_1.randomId)(), this.suffix(this.findChildNode(node, ts.SyntaxKind.ImportKeyword)), core_1.Markers.EMPTY, [], new J.Parentheses((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.rightPadded(this.visit(node.argument), this.suffix(node.argument)))), node.qualifier ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.DotToken)), this.visit(node.qualifier)) : null, node.typeArguments ? this.mapTypeArguments(this.suffix(node.qualifier), node.typeArguments) : null, this.mapType(node));
|
|
620
675
|
}
|
|
621
676
|
visitObjectBindingPattern(node) {
|
|
622
677
|
return new JS.ObjectBindingDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], null, this.mapCommaSeparatedList(node.getChildren(this.sourceFile)), null);
|
|
@@ -673,8 +728,11 @@ class JavaScriptParserVisitor {
|
|
|
673
728
|
}
|
|
674
729
|
return new J.MethodInvocation((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, select, typeArguments, name, this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), this.mapMethodType(node));
|
|
675
730
|
}
|
|
731
|
+
visitSuperKeyword(node) {
|
|
732
|
+
return this.mapIdentifier(node, node.getText());
|
|
733
|
+
}
|
|
676
734
|
visitNewExpression(node) {
|
|
677
|
-
return new J.NewClass((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, java_1.Space.EMPTY, this.visit(node.expression), this.
|
|
735
|
+
return new J.NewClass((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, java_1.Space.EMPTY, node.typeArguments ? new J.ParameterizedType((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.visit(node.expression), this.mapTypeArguments(this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)), node.typeArguments), null) : this.visit(node.expression), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, this.mapMethodType(node));
|
|
678
736
|
}
|
|
679
737
|
visitTaggedTemplateExpression(node) {
|
|
680
738
|
return new JS.TaggedTemplateExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.tag), this.suffix(node.tag)), node.typeArguments ? this.mapTypeArguments(java_1.Space.EMPTY, node.typeArguments) : null, this.visit(node.template), this.mapType(node));
|
|
@@ -683,10 +741,10 @@ class JavaScriptParserVisitor {
|
|
|
683
741
|
return new J.TypeCast((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(node.getFirstToken()), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.type), this.prefix(node.getChildAt(2, this.sourceFile)))), this.convert(node.expression));
|
|
684
742
|
}
|
|
685
743
|
visitParenthesizedExpression(node) {
|
|
686
|
-
return new J.
|
|
744
|
+
return new J.Parentheses((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.expression), this.prefix(node.getLastToken())));
|
|
687
745
|
}
|
|
688
746
|
visitFunctionExpression(node) {
|
|
689
|
-
return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
747
|
+
return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), !!node.asteriskToken), this.leftPadded(node.asteriskToken ? this.prefix(node.asteriskToken) : java_1.Space.EMPTY, node.name ? this.visit(node.name) : new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], "", null, null)), this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
|
|
690
748
|
}
|
|
691
749
|
visitArrowFunction(node) {
|
|
692
750
|
const openParenToken = this.findChildNode(node, ts.SyntaxKind.OpenParenToken);
|
|
@@ -694,7 +752,7 @@ class JavaScriptParserVisitor {
|
|
|
694
752
|
return new JS.ArrowFunction((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), node.typeParameters ? this.mapTypeParametersAsObject(node) : null, new java_1.Lambda.Parameters((0, core_1.randomId)(), isParenthesized ? this.prefix(openParenToken) : java_1.Space.EMPTY, core_1.Markers.EMPTY, isParenthesized, node.parameters.length > 0 ?
|
|
695
753
|
node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p)))
|
|
696
754
|
.concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken))) : []) :
|
|
697
|
-
isParenthesized ? [this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)))] : []), this.mapTypeInfo(node), this.prefix(node.equalsGreaterThanToken), this.convert(node.body), this.mapType(node));
|
|
755
|
+
isParenthesized ? [this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)))] : []), this.mapTypeInfo(node), this.leftPadded(this.prefix(node.equalsGreaterThanToken), this.convert(node.body)), this.mapType(node));
|
|
698
756
|
}
|
|
699
757
|
visitDeleteExpression(node) {
|
|
700
758
|
return new JS.Delete((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.mapType(node));
|
|
@@ -764,6 +822,12 @@ class JavaScriptParserVisitor {
|
|
|
764
822
|
case ts.SyntaxKind.QuestionQuestionToken:
|
|
765
823
|
binaryOperator = JS.JsBinary.Type.QuestionQuestion;
|
|
766
824
|
break;
|
|
825
|
+
case ts.SyntaxKind.InKeyword:
|
|
826
|
+
binaryOperator = JS.JsBinary.Type.In;
|
|
827
|
+
break;
|
|
828
|
+
case ts.SyntaxKind.CommaToken:
|
|
829
|
+
binaryOperator = JS.JsBinary.Type.Comma;
|
|
830
|
+
break;
|
|
767
831
|
}
|
|
768
832
|
if (binaryOperator !== undefined) {
|
|
769
833
|
return new JS.JsBinary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.left), this.leftPadded(this.prefix(node.operatorToken), binaryOperator), this.convert(node.right), this.mapType(node));
|
|
@@ -773,7 +837,25 @@ class JavaScriptParserVisitor {
|
|
|
773
837
|
}
|
|
774
838
|
binaryOperator = this.mapBinaryOperator(node);
|
|
775
839
|
if (binaryOperator === undefined) {
|
|
776
|
-
|
|
840
|
+
let assignmentOperation;
|
|
841
|
+
switch (node.operatorToken.kind) {
|
|
842
|
+
case ts.SyntaxKind.QuestionQuestionEqualsToken:
|
|
843
|
+
assignmentOperation = JS.JsAssignmentOperation.Type.QuestionQuestion;
|
|
844
|
+
break;
|
|
845
|
+
case ts.SyntaxKind.AmpersandAmpersandEqualsToken:
|
|
846
|
+
assignmentOperation = JS.JsAssignmentOperation.Type.And;
|
|
847
|
+
break;
|
|
848
|
+
case ts.SyntaxKind.BarBarEqualsToken:
|
|
849
|
+
assignmentOperation = JS.JsAssignmentOperation.Type.Or;
|
|
850
|
+
break;
|
|
851
|
+
case ts.SyntaxKind.AsteriskAsteriskToken:
|
|
852
|
+
assignmentOperation = JS.JsAssignmentOperation.Type.Power;
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
if (assignmentOperation !== undefined) {
|
|
856
|
+
return new JS.JsAssignmentOperation((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.left), this.leftPadded(this.prefix(node.operatorToken), assignmentOperation), this.convert(node.right), this.mapType(node));
|
|
857
|
+
}
|
|
858
|
+
assignmentOperation = this.mapAssignmentOperation(node);
|
|
777
859
|
if (assignmentOperation === undefined) {
|
|
778
860
|
return this.visitUnknown(node);
|
|
779
861
|
}
|
|
@@ -858,7 +940,7 @@ class JavaScriptParserVisitor {
|
|
|
858
940
|
return new JS.TemplateExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.head), node.templateSpans.map(s => this.rightPadded(this.visit(s), this.suffix(s))), this.mapType(node));
|
|
859
941
|
}
|
|
860
942
|
visitYieldExpression(node) {
|
|
861
|
-
return new JS.Yield((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, false, node.expression ? this.visit(node.expression) : null, this.mapType(node));
|
|
943
|
+
return new JS.Yield((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.asteriskToken ? this.leftPadded(this.prefix(node.asteriskToken), true) : this.leftPadded(java_1.Space.EMPTY, false), node.expression ? this.visit(node.expression) : null, this.mapType(node));
|
|
862
944
|
}
|
|
863
945
|
visitSpreadElement(node) {
|
|
864
946
|
return new JS.Unary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.convert(node.expression), this.mapType(node));
|
|
@@ -885,13 +967,13 @@ class JavaScriptParserVisitor {
|
|
|
885
967
|
return new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.expression), JS.Unary.Type.Exclamation), this.visit(node.expression), this.mapType(node));
|
|
886
968
|
}
|
|
887
969
|
visitMetaProperty(node) {
|
|
888
|
-
return this.
|
|
970
|
+
return new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.keywordToken === ts.SyntaxKind.NewKeyword ? this.mapIdentifier(node, 'new') : this.mapIdentifier(node, 'import'), this.leftPadded(this.prefix(node.getChildAt(1, this.sourceFile)), this.convert(node.name)), this.mapType(node));
|
|
889
971
|
}
|
|
890
972
|
visitSyntheticExpression(node) {
|
|
891
973
|
return this.visitUnknown(node);
|
|
892
974
|
}
|
|
893
975
|
visitSatisfiesExpression(node) {
|
|
894
|
-
return this.
|
|
976
|
+
return new JS.SatisfiesExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression), this.leftPadded(this.suffix(node.expression), this.visit(node.type)), this.mapType(node));
|
|
895
977
|
}
|
|
896
978
|
visitTemplateSpan(node) {
|
|
897
979
|
return new JS.TemplateExpression.TemplateSpan((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.visit(node.literal));
|
|
@@ -918,9 +1000,10 @@ class JavaScriptParserVisitor {
|
|
|
918
1000
|
return new JS.ExpressionStatement((0, core_1.randomId)(), expression);
|
|
919
1001
|
}
|
|
920
1002
|
visitIfStatement(node) {
|
|
921
|
-
var _a;
|
|
1003
|
+
var _a, _b, _c;
|
|
922
1004
|
const semicolonAfterThen = ((_a = node.thenStatement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken;
|
|
923
|
-
|
|
1005
|
+
const semicolonAfterElse = ((_c = (_b = node.elseStatement) === null || _b === void 0 ? void 0 : _b.getLastToken()) === null || _c === void 0 ? void 0 : _c.kind) == ts.SyntaxKind.SemicolonToken;
|
|
1006
|
+
return new J.If((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.thenStatement), semicolonAfterThen ? this.prefix(node.thenStatement.getLastToken()) : java_1.Space.EMPTY, semicolonAfterThen ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY), node.elseStatement ? new J.If.Else((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.ElseKeyword)), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.elseStatement), semicolonAfterElse ? this.prefix(node.elseStatement.getLastToken()) : java_1.Space.EMPTY, semicolonAfterElse ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY)) : null);
|
|
924
1007
|
}
|
|
925
1008
|
visitDoStatement(node) {
|
|
926
1009
|
return new J.DoWhileLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.statement), this.suffix(node.statement)), this.leftPadded(java_1.Space.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression)))));
|
|
@@ -933,18 +1016,18 @@ class JavaScriptParserVisitor {
|
|
|
933
1016
|
var _a;
|
|
934
1017
|
return new J.ForLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ForLoop.Control((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, [node.initializer ?
|
|
935
1018
|
(ts.isVariableDeclarationList(node.initializer) ? this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY) :
|
|
936
|
-
this.rightPadded(this.
|
|
937
|
-
this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)))], node.condition ? this.rightPadded(this.
|
|
938
|
-
this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.SemicolonToken))), [node.incrementor ? this.rightPadded(this.
|
|
1019
|
+
this.rightPadded(new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.initializer)), this.suffix(node.initializer.getLastToken()))) :
|
|
1020
|
+
this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)))], node.condition ? this.rightPadded(ts.isStatement(node.condition) ? this.visit(node.condition) : new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.condition)), this.suffix(node.condition.getLastToken())) :
|
|
1021
|
+
this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.SemicolonToken))), [node.incrementor ? this.rightPadded(ts.isStatement(node.incrementor) ? this.visit(node.incrementor) : new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.incrementor)), this.suffix(node.incrementor.getLastToken())) :
|
|
939
1022
|
this.rightPadded(this.newJEmpty(this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken))), java_1.Space.EMPTY)]), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
|
|
940
1023
|
}
|
|
941
1024
|
visitForInStatement(node) {
|
|
942
1025
|
var _a;
|
|
943
|
-
return new JS.JSForInLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.
|
|
1026
|
+
return new JS.JSForInLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.suffix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
|
|
944
1027
|
}
|
|
945
1028
|
visitForOfStatement(node) {
|
|
946
1029
|
var _a;
|
|
947
|
-
return new JS.JSForOfLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.awaitModifier ? this.leftPadded(this.prefix(node.awaitModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.
|
|
1030
|
+
return new JS.JSForOfLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.awaitModifier ? this.leftPadded(this.prefix(node.awaitModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.suffix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
|
|
948
1031
|
}
|
|
949
1032
|
visitContinueStatement(node) {
|
|
950
1033
|
return new J.Continue((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.label ? this.visit(node.label) : null);
|
|
@@ -971,7 +1054,7 @@ class JavaScriptParserVisitor {
|
|
|
971
1054
|
return new J.Try((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, this.visit(node.tryBlock), node.catchClause ? [this.visit(node.catchClause)] : [], node.finallyBlock ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FinallyKeyword)), this.visit(node.finallyBlock)) : null);
|
|
972
1055
|
}
|
|
973
1056
|
visitDebuggerStatement(node) {
|
|
974
|
-
return this.
|
|
1057
|
+
return new _1.ExpressionStatement((0, core_1.randomId)(), this.mapIdentifier(node, 'debugger'));
|
|
975
1058
|
}
|
|
976
1059
|
visitVariableDeclaration(node) {
|
|
977
1060
|
const nameExpression = this.visit(node.name);
|
|
@@ -994,7 +1077,7 @@ class JavaScriptParserVisitor {
|
|
|
994
1077
|
}));
|
|
995
1078
|
}
|
|
996
1079
|
visitFunctionDeclaration(node) {
|
|
997
|
-
return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), node.name ? this.visit(node.name) : null, this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
|
|
1080
|
+
return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), !!node.asteriskToken), this.leftPadded(node.asteriskToken ? this.prefix(node.asteriskToken) : java_1.Space.EMPTY, node.name ? this.visit(node.name) : new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], "", null, null)), this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), node.body ? this.convert(node.body) : null, this.mapMethodType(node));
|
|
998
1081
|
}
|
|
999
1082
|
getParameterListNodes(node, openToken = ts.SyntaxKind.OpenParenToken) {
|
|
1000
1083
|
const children = node.getChildren(this.sourceFile);
|
|
@@ -1078,19 +1161,21 @@ class JavaScriptParserVisitor {
|
|
|
1078
1161
|
: this.convert(node.name), this.mapType(node));
|
|
1079
1162
|
}
|
|
1080
1163
|
visitExportAssignment(node) {
|
|
1081
|
-
return this.
|
|
1164
|
+
return new JS.ExportAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(node.isExportEquals ? this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsToken)) : java_1.Space.EMPTY, (!!node.isExportEquals)), this.visit(node.expression));
|
|
1082
1165
|
}
|
|
1083
1166
|
visitExportDeclaration(node) {
|
|
1084
|
-
return this.
|
|
1167
|
+
return new JS.ExportDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(node.isTypeOnly ? this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)) : java_1.Space.EMPTY, node.isTypeOnly), node.exportClause ? this.visit(node.exportClause) : this.mapIdentifier(this.findChildNode(node, ts.SyntaxKind.AsteriskToken), "*"), node.moduleSpecifier ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FromKeyword)), this.visit(node.moduleSpecifier)) : null);
|
|
1085
1168
|
}
|
|
1086
1169
|
visitNamedExports(node) {
|
|
1087
|
-
return this.
|
|
1170
|
+
return new JS.NamedExports((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapCommaSeparatedList(node.getChildren()), this.mapType(node));
|
|
1088
1171
|
}
|
|
1089
1172
|
visitNamespaceExport(node) {
|
|
1090
|
-
return this.
|
|
1173
|
+
return new JS.Alias((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.mapIdentifier(this.findChildNode(node, ts.SyntaxKind.AsteriskToken), "*"), this.prefix(this.findChildNode(node, ts.SyntaxKind.AsKeyword))), this.visit(node.name));
|
|
1091
1174
|
}
|
|
1092
1175
|
visitExportSpecifier(node) {
|
|
1093
|
-
return this.
|
|
1176
|
+
return new JS.ExportSpecifier((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(node.isTypeOnly ? this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)) : java_1.Space.EMPTY, node.isTypeOnly), node.propertyName
|
|
1177
|
+
? new JS.Alias((0, core_1.randomId)(), this.prefix(node.propertyName), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.propertyName), this.suffix(node.propertyName)), this.convert(node.name))
|
|
1178
|
+
: this.convert(node.name), this.mapType(node));
|
|
1094
1179
|
}
|
|
1095
1180
|
visitMissingDeclaration(node) {
|
|
1096
1181
|
return this.visitUnknown(node);
|
|
@@ -1391,22 +1476,10 @@ class JavaScriptParserVisitor {
|
|
|
1391
1476
|
: null;
|
|
1392
1477
|
}
|
|
1393
1478
|
mapTypeParametersAsObject(node) {
|
|
1394
|
-
|
|
1479
|
+
const typeParameters = node.typeParameters;
|
|
1480
|
+
if (!typeParameters)
|
|
1395
1481
|
return null;
|
|
1396
|
-
|
|
1397
|
-
if (ts.isConstructSignatureDeclaration(node)) {
|
|
1398
|
-
ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword));
|
|
1399
|
-
}
|
|
1400
|
-
else if (ts.isFunctionExpression(node)) {
|
|
1401
|
-
ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword));
|
|
1402
|
-
}
|
|
1403
|
-
else if (ts.isTypeAliasDeclaration(node)) {
|
|
1404
|
-
ts_prefix = this.suffix(node.name);
|
|
1405
|
-
}
|
|
1406
|
-
else {
|
|
1407
|
-
ts_prefix = node.questionToken ? this.suffix(node.questionToken) : node.name ? this.suffix(node.name) : java_1.Space.EMPTY;
|
|
1408
|
-
}
|
|
1409
|
-
return new J.TypeParameters((0, core_1.randomId)(), ts_prefix, core_1.Markers.EMPTY, [], node.typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))));
|
|
1482
|
+
return new J.TypeParameters((0, core_1.randomId)(), this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === typeParameters[0].pos) - 1)), core_1.Markers.EMPTY, [], typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))));
|
|
1410
1483
|
}
|
|
1411
1484
|
mapTypeParametersList(typeParamsNodeArray) {
|
|
1412
1485
|
return typeParamsNodeArray.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp)));
|