@openrewrite/rewrite 0.18.9 → 0.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/java/remote/index.d.ts +1 -1
- package/dist/src/java/remote/index.d.ts.map +1 -1
- package/dist/src/java/remote/index.js +1 -1
- package/dist/src/java/remote/index.js.map +1 -1
- package/dist/src/java/remote/receiver.js +3 -3
- package/dist/src/java/remote/receiver.js.map +1 -1
- package/dist/src/java/remote/register.d.ts +1 -1
- package/dist/src/java/remote/register.d.ts.map +1 -1
- package/dist/src/java/remote/register.js +117 -112
- package/dist/src/java/remote/register.js.map +1 -1
- package/dist/src/java/remote/remote_extensions.d.ts.map +1 -1
- package/dist/src/java/remote/remote_extensions.js +41 -3
- package/dist/src/java/remote/remote_extensions.js.map +1 -1
- package/dist/src/java/remote/sender.js +2 -2
- package/dist/src/java/remote/sender.js.map +1 -1
- package/dist/src/javascript/parser.d.ts +22 -14
- package/dist/src/javascript/parser.d.ts.map +1 -1
- package/dist/src/javascript/parser.js +126 -33
- package/dist/src/javascript/parser.js.map +1 -1
- package/dist/src/javascript/remote/index.d.ts +1 -1
- package/dist/src/javascript/remote/index.d.ts.map +1 -1
- package/dist/src/javascript/remote/index.js +1 -1
- package/dist/src/javascript/remote/index.js.map +1 -1
- package/dist/src/javascript/remote/receiver.d.ts.map +1 -1
- package/dist/src/javascript/remote/receiver.js +10 -0
- package/dist/src/javascript/remote/receiver.js.map +1 -1
- package/dist/src/javascript/remote/register.d.ts +1 -1
- package/dist/src/javascript/remote/register.d.ts.map +1 -1
- package/dist/src/javascript/remote/register.js +7 -5
- package/dist/src/javascript/remote/register.js.map +1 -1
- package/dist/src/javascript/remote/sender.d.ts.map +1 -1
- package/dist/src/javascript/remote/sender.js +7 -0
- package/dist/src/javascript/remote/sender.js.map +1 -1
- package/dist/src/javascript/tree/support_types.d.ts +2 -1
- package/dist/src/javascript/tree/support_types.d.ts.map +1 -1
- package/dist/src/javascript/tree/support_types.js +1 -0
- package/dist/src/javascript/tree/support_types.js.map +1 -1
- package/dist/src/javascript/tree/tree.d.ts +41 -0
- package/dist/src/javascript/tree/tree.d.ts.map +1 -1
- package/dist/src/javascript/tree/tree.js +48 -2
- package/dist/src/javascript/tree/tree.js.map +1 -1
- package/dist/src/javascript/visitor.d.ts +2 -1
- package/dist/src/javascript/visitor.d.ts.map +1 -1
- package/dist/src/javascript/visitor.js +11 -0
- package/dist/src/javascript/visitor.js.map +1 -1
- package/dist/src/yaml/remote/index.d.ts +1 -1
- package/dist/src/yaml/remote/index.d.ts.map +1 -1
- package/dist/src/yaml/remote/index.js +1 -1
- package/dist/src/yaml/remote/index.js.map +1 -1
- package/dist/src/yaml/remote/register.d.ts +1 -1
- package/dist/src/yaml/remote/register.d.ts.map +1 -1
- package/dist/src/yaml/remote/register.js +7 -5
- package/dist/src/yaml/remote/register.js.map +1 -1
- package/package.json +5 -5
|
@@ -228,18 +228,24 @@ class JavaScriptParserVisitor {
|
|
|
228
228
|
]), node.getFullText()));
|
|
229
229
|
}
|
|
230
230
|
mapModifiers(node) {
|
|
231
|
-
var _a, _b, _c;
|
|
231
|
+
var _a, _b, _c, _d, _e, _f;
|
|
232
232
|
if (ts.isVariableStatement(node)) {
|
|
233
233
|
return [new J.Modifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, (_a = node.declarationList.getFirstToken()) === null || _a === void 0 ? void 0 : _a.getText(), J.Modifier.Type.LanguageExtension, [])];
|
|
234
234
|
}
|
|
235
235
|
else if (ts.isClassDeclaration(node)) {
|
|
236
236
|
return node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
237
237
|
}
|
|
238
|
+
else if (ts.isEnumDeclaration(node) || ts.isInterfaceDeclaration(node)) {
|
|
239
|
+
return node.modifiers ? (_c = node.modifiers) === null || _c === void 0 ? void 0 : _c.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
240
|
+
}
|
|
238
241
|
else if (ts.isPropertyDeclaration(node)) {
|
|
239
|
-
return [];
|
|
242
|
+
return node.modifiers ? (_d = node.modifiers) === null || _d === void 0 ? void 0 : _d.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
240
243
|
}
|
|
241
|
-
else if (ts.
|
|
242
|
-
return node.modifiers ? (
|
|
244
|
+
else if (ts.isPropertySignature(node)) {
|
|
245
|
+
return node.modifiers ? (_e = node.modifiers) === null || _e === void 0 ? void 0 : _e.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
246
|
+
}
|
|
247
|
+
else if (ts.isFunctionDeclaration(node) || ts.isParameter(node) || ts.isMethodDeclaration(node)) {
|
|
248
|
+
return node.modifiers ? (_f = node.modifiers) === null || _f === void 0 ? void 0 : _f.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
243
249
|
}
|
|
244
250
|
else if (ts.isVariableDeclarationList(node)) {
|
|
245
251
|
let modifier;
|
|
@@ -285,7 +291,10 @@ class JavaScriptParserVisitor {
|
|
|
285
291
|
if (node.typeParameters) {
|
|
286
292
|
return this.visitUnknown(node);
|
|
287
293
|
}
|
|
288
|
-
return new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), new J.ClassDeclaration.Kind((0, core_1.randomId)(), node.modifiers ? this.suffix(node.modifiers[node.modifiers.length - 1]) : this.prefix(node), core_1.Markers.EMPTY, [], J.ClassDeclaration.Kind.Type.Class), node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), this.mapTypeParameters(node), null, this.mapExtends(node), this.mapImplements(node), null, this.
|
|
294
|
+
return new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), new J.ClassDeclaration.Kind((0, core_1.randomId)(), node.modifiers ? this.suffix(node.modifiers[node.modifiers.length - 1]) : this.prefix(node), core_1.Markers.EMPTY, [], J.ClassDeclaration.Kind.Type.Class), node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), this.mapTypeParameters(node), null, this.mapExtends(node), this.mapImplements(node), null, new J.Block((0, core_1.randomId)(), this.prefix(node.getChildren().find(v => v.kind === ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, new java_1.JRightPadded(false, java_1.Space.EMPTY, core_1.Markers.EMPTY), node.members.map((ce) => {
|
|
295
|
+
var _a, _b;
|
|
296
|
+
return new java_1.JRightPadded(this.convert(ce), ((_a = ce.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.SemicolonToken ? this.prefix(ce.getLastToken()) : java_1.Space.EMPTY, ((_b = ce.getLastToken()) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY);
|
|
297
|
+
}), this.prefix(node.getLastToken())), this.mapType(node));
|
|
289
298
|
}
|
|
290
299
|
mapExtends(node) {
|
|
291
300
|
if (node.heritageClauses == undefined || node.heritageClauses.length == 0) {
|
|
@@ -298,6 +307,21 @@ class JavaScriptParserVisitor {
|
|
|
298
307
|
}
|
|
299
308
|
return null;
|
|
300
309
|
}
|
|
310
|
+
mapInterfaceExtends(node) {
|
|
311
|
+
if (node.heritageClauses == undefined || node.heritageClauses.length == 0) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
for (let heritageClause of node.heritageClauses) {
|
|
315
|
+
if ((heritageClause.token == ts.SyntaxKind.ExtendsKeyword)) {
|
|
316
|
+
const _extends = [];
|
|
317
|
+
for (let type of heritageClause.types) {
|
|
318
|
+
_extends.push(this.rightPadded(this.visit(type), this.suffix(type)));
|
|
319
|
+
}
|
|
320
|
+
return _extends.length > 0 ? new java_1.JContainer(this.prefix(heritageClause.getFirstToken()), _extends, core_1.Markers.EMPTY) : null;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
301
325
|
mapImplements(node) {
|
|
302
326
|
if (node.heritageClauses == undefined || node.heritageClauses.length == 0) {
|
|
303
327
|
return null;
|
|
@@ -331,6 +355,15 @@ class JavaScriptParserVisitor {
|
|
|
331
355
|
visitUndefinedKeyword(node) {
|
|
332
356
|
return this.mapIdentifier(node, 'undefined');
|
|
333
357
|
}
|
|
358
|
+
visitAnyKeyword(node) {
|
|
359
|
+
return this.mapIdentifier(node, 'any');
|
|
360
|
+
}
|
|
361
|
+
visitUnknownKeyword(node) {
|
|
362
|
+
return this.mapIdentifier(node, 'unknown');
|
|
363
|
+
}
|
|
364
|
+
visitVoidKeyword(node) {
|
|
365
|
+
return this.mapIdentifier(node, 'void');
|
|
366
|
+
}
|
|
334
367
|
visitFalseKeyword(node) {
|
|
335
368
|
return this.mapLiteral(node, false);
|
|
336
369
|
}
|
|
@@ -381,16 +414,26 @@ class JavaScriptParserVisitor {
|
|
|
381
414
|
return this.mapIdentifier(node, node.text);
|
|
382
415
|
}
|
|
383
416
|
visitQualifiedName(node) {
|
|
384
|
-
|
|
417
|
+
const fieldAccess = new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.left), new java_1.JLeftPadded(this.suffix(node.left), this.convert(node.right), core_1.Markers.EMPTY), this.mapType(node));
|
|
418
|
+
const parent = node.parent;
|
|
419
|
+
if (parent.typeArguments) {
|
|
420
|
+
return new J.ParameterizedType((0, core_1.randomId)(), this.prefix(parent), core_1.Markers.EMPTY, fieldAccess, this.mapTypeArguments(parent.typeArguments), this.mapType(parent));
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return fieldAccess;
|
|
424
|
+
}
|
|
385
425
|
}
|
|
386
426
|
visitComputedPropertyName(node) {
|
|
387
427
|
return new J.NewArray((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, [], new java_1.JContainer(java_1.Space.EMPTY, [this.rightPadded(this.convert(node.expression), this.suffix(node.expression))], core_1.Markers.EMPTY), this.mapType(node));
|
|
388
428
|
}
|
|
389
429
|
visitTypeParameter(node) {
|
|
390
|
-
|
|
430
|
+
if (node.constraint || (node.modifiers && node.modifiers.length) || node.default) {
|
|
431
|
+
return this.visitUnknown(node);
|
|
432
|
+
}
|
|
433
|
+
return new J.TypeParameter((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.visit(node.name), null);
|
|
391
434
|
}
|
|
392
435
|
visitParameter(node) {
|
|
393
|
-
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node),
|
|
436
|
+
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, this.visit(node.name), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildCount(this.sourceFile) - 2)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
|
|
394
437
|
}
|
|
395
438
|
visitDecorator(node) {
|
|
396
439
|
let annotationType;
|
|
@@ -413,16 +456,23 @@ class JavaScriptParserVisitor {
|
|
|
413
456
|
return new J.Annotation((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, annotationType, _arguments);
|
|
414
457
|
}
|
|
415
458
|
visitPropertySignature(node) {
|
|
416
|
-
return this.
|
|
459
|
+
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, this.visit(node.name), [], null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
|
|
417
460
|
}
|
|
418
461
|
visitPropertyDeclaration(node) {
|
|
419
|
-
return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node),
|
|
462
|
+
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, this.visit(node.name), [], 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)]);
|
|
420
463
|
}
|
|
421
464
|
visitMethodSignature(node) {
|
|
422
|
-
return this.
|
|
465
|
+
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], node.typeParameters
|
|
466
|
+
? new J.TypeParameters((0, core_1.randomId)(), this.suffix(node.name), core_1.Markers.EMPTY, [], node.typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))))
|
|
467
|
+
: null, 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));
|
|
423
468
|
}
|
|
424
469
|
visitMethodDeclaration(node) {
|
|
425
|
-
return this.
|
|
470
|
+
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), node.typeParameters
|
|
471
|
+
? new J.TypeParameters((0, core_1.randomId)(), this.suffix(node.name), core_1.Markers.EMPTY, [], node.typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))))
|
|
472
|
+
: null, this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(node.name ? this.visit(node.name) : this.mapIdentifier(node, ""), []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
|
|
473
|
+
}
|
|
474
|
+
mapTypeInfo(node) {
|
|
475
|
+
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;
|
|
426
476
|
}
|
|
427
477
|
visitClassStaticBlockDeclaration(node) {
|
|
428
478
|
return this.visitUnknown(node);
|
|
@@ -437,7 +487,9 @@ class JavaScriptParserVisitor {
|
|
|
437
487
|
return this.visitUnknown(node);
|
|
438
488
|
}
|
|
439
489
|
visitCallSignature(node) {
|
|
440
|
-
return this.
|
|
490
|
+
return new JS.ArrowFunction((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], new java_1.Lambda.Parameters((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, true, node.parameters.length > 0 ?
|
|
491
|
+
node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) :
|
|
492
|
+
[this.rightPadded(this.newJEmpty(), this.prefix(node.getChildren().find(n => n.kind === ts.SyntaxKind.CloseParenToken)))]), this.mapTypeInfo(node), java_1.Space.EMPTY, this.newJEmpty(), null);
|
|
441
493
|
}
|
|
442
494
|
visitConstructSignature(node) {
|
|
443
495
|
return this.visitUnknown(node);
|
|
@@ -450,12 +502,15 @@ class JavaScriptParserVisitor {
|
|
|
450
502
|
}
|
|
451
503
|
visitTypeReference(node) {
|
|
452
504
|
if (node.typeArguments) {
|
|
505
|
+
if (ts.isQualifiedName(node.typeName)) {
|
|
506
|
+
return this.visit(node.typeName);
|
|
507
|
+
}
|
|
453
508
|
return this.visitUnknown(node);
|
|
454
509
|
}
|
|
455
510
|
return this.visit(node.typeName);
|
|
456
511
|
}
|
|
457
512
|
visitFunctionType(node) {
|
|
458
|
-
return this.
|
|
513
|
+
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.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(node.getChildren().find(v => v.kind === ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
459
514
|
}
|
|
460
515
|
visitConstructorType(node) {
|
|
461
516
|
}
|
|
@@ -576,7 +631,9 @@ class JavaScriptParserVisitor {
|
|
|
576
631
|
return this.visitUnknown(node);
|
|
577
632
|
}
|
|
578
633
|
visitArrowFunction(node) {
|
|
579
|
-
return this.
|
|
634
|
+
return new JS.ArrowFunction((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], new java_1.Lambda.Parameters((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, true, node.parameters.length > 0 ?
|
|
635
|
+
node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) :
|
|
636
|
+
[this.rightPadded(this.newJEmpty(), this.prefix(node.getChildren().find(n => n.kind === ts.SyntaxKind.CloseParenToken)))]), this.mapTypeInfo(node), this.prefix(node.equalsGreaterThanToken), node.body ? this.convert(node.body) : this.newJEmpty(), null);
|
|
580
637
|
}
|
|
581
638
|
visitDeleteExpression(node) {
|
|
582
639
|
return new JS.Delete((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.mapType(node));
|
|
@@ -748,7 +805,7 @@ class JavaScriptParserVisitor {
|
|
|
748
805
|
return new J.Block((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), this.semicolonPaddedStatementList(node.statements), this.prefix(node.getLastToken()));
|
|
749
806
|
}
|
|
750
807
|
visitEmptyStatement(node) {
|
|
751
|
-
return
|
|
808
|
+
return this.newJEmpty(this.prefix(node));
|
|
752
809
|
}
|
|
753
810
|
visitVariableStatement(node) {
|
|
754
811
|
return this.visitVariableDeclarationList(node.declarationList);
|
|
@@ -778,9 +835,9 @@ class JavaScriptParserVisitor {
|
|
|
778
835
|
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(node.getChildAt(1)), core_1.Markers.EMPTY, [node.initializer ?
|
|
779
836
|
(ts.isVariableDeclarationList(node.initializer) ? this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY) :
|
|
780
837
|
this.rightPadded(this.convert(node.initializer), this.suffix(node.initializer.getLastToken()))) :
|
|
781
|
-
this.rightPadded(
|
|
782
|
-
this.rightPadded(
|
|
783
|
-
this.rightPadded(
|
|
838
|
+
this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY)], node.condition ? this.rightPadded(this.convert(node.condition), this.suffix(node.condition.getLastToken())) :
|
|
839
|
+
this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY), [node.incrementor ? this.rightPadded(this.convert(node.incrementor), this.suffix(node.incrementor.getLastToken())) :
|
|
840
|
+
this.rightPadded(this.newJEmpty(), 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));
|
|
784
841
|
}
|
|
785
842
|
visitForInStatement(node) {
|
|
786
843
|
return this.visitUnknown(node);
|
|
@@ -807,22 +864,25 @@ class JavaScriptParserVisitor {
|
|
|
807
864
|
return this.visitUnknown(node);
|
|
808
865
|
}
|
|
809
866
|
visitThrowStatement(node) {
|
|
810
|
-
return this.
|
|
867
|
+
return new J.Throw((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression));
|
|
811
868
|
}
|
|
812
869
|
visitTryStatement(node) {
|
|
813
|
-
|
|
870
|
+
var _a;
|
|
871
|
+
return new J.Try((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, this.visit(node.tryBlock), node.catchClause ?
|
|
872
|
+
[new J.Try.Catch((0, core_1.randomId)(), this.prefix(node.catchClause.getFirstToken()), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.suffix(node.catchClause.getFirstToken()), core_1.Markers.EMPTY, this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node.catchClause.variableDeclaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node.catchClause.variableDeclaration), null, [], [this.rightPadded(this.visit(node.catchClause.variableDeclaration), java_1.Space.EMPTY)]), this.suffix(node.catchClause.variableDeclaration))), this.visit((_a = node.catchClause) === null || _a === void 0 ? void 0 : _a.block))] : [], node.finallyBlock ? this.leftPadded(this.prefix(node.getChildren().find(n => n.kind === ts.SyntaxKind.FinallyKeyword)), this.visit(node.finallyBlock))
|
|
873
|
+
: null);
|
|
814
874
|
}
|
|
815
875
|
visitDebuggerStatement(node) {
|
|
816
876
|
return this.visitUnknown(node);
|
|
817
877
|
}
|
|
818
878
|
visitVariableDeclaration(node) {
|
|
819
|
-
return new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.name)
|
|
879
|
+
return new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.name), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildCount(this.sourceFile) - 2)), this.visit(node.initializer)) : null, this.mapVariableType(node));
|
|
820
880
|
}
|
|
821
881
|
visitVariableDeclarationList(node) {
|
|
822
882
|
const kind = node.getFirstToken(this.sourceFile);
|
|
823
883
|
return new JS.ScopedVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.LetKeyword ? JS.ScopedVariableDeclarations.Scope.Let :
|
|
824
884
|
(kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.ConstKeyword ? JS.ScopedVariableDeclarations.Scope.Const : JS.ScopedVariableDeclarations.Scope.Var, node.declarations.map(declaration => {
|
|
825
|
-
return this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(declaration), core_1.Markers.EMPTY, [], [],
|
|
885
|
+
return this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(declaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(declaration), null, [], [this.rightPadded(this.visit(declaration), java_1.Space.EMPTY)]), this.suffix(declaration));
|
|
826
886
|
}));
|
|
827
887
|
}
|
|
828
888
|
visitFunctionDeclaration(node) {
|
|
@@ -841,13 +901,35 @@ class JavaScriptParserVisitor {
|
|
|
841
901
|
return [];
|
|
842
902
|
}
|
|
843
903
|
visitInterfaceDeclaration(node) {
|
|
844
|
-
|
|
904
|
+
if (node.typeParameters) {
|
|
905
|
+
return this.visitUnknown(node);
|
|
906
|
+
}
|
|
907
|
+
return new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), new J.ClassDeclaration.Kind((0, core_1.randomId)(), node.modifiers ? this.suffix(node.modifiers[node.modifiers.length - 1]) : this.prefix(node), core_1.Markers.EMPTY, [], J.ClassDeclaration.Kind.Type.Interface), node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), this.mapTypeParameters(node), null, null, this.mapInterfaceExtends(node), null, new J.Block((0, core_1.randomId)(), this.prefix(node.getChildren().find(v => v.kind === ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, new java_1.JRightPadded(false, java_1.Space.EMPTY, core_1.Markers.EMPTY), node.members.map(te => {
|
|
908
|
+
var _a, _b, _c, _d;
|
|
909
|
+
return new java_1.JRightPadded(this.convert(te), (((_a = te.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.SemicolonToken) || (((_b = te.getLastToken()) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.CommaToken) ? this.prefix(te.getLastToken()) : java_1.Space.EMPTY, (((_c = te.getLastToken()) === null || _c === void 0 ? void 0 : _c.kind) === ts.SyntaxKind.SemicolonToken) || (((_d = te.getLastToken()) === null || _d === void 0 ? void 0 : _d.kind) === ts.SyntaxKind.CommaToken) ? core_1.Markers.build([this.convertToken(te.getLastToken())]) : core_1.Markers.EMPTY);
|
|
910
|
+
}), this.prefix(node.getLastToken())), this.mapType(node));
|
|
845
911
|
}
|
|
846
912
|
visitTypeAliasDeclaration(node) {
|
|
847
913
|
return this.visitUnknown(node);
|
|
848
914
|
}
|
|
849
915
|
visitEnumDeclaration(node) {
|
|
850
|
-
return this.
|
|
916
|
+
return new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.mapModifiers(node), new J.ClassDeclaration.Kind((0, core_1.randomId)(), node.modifiers ? this.suffix(node.modifiers[node.modifiers.length - 1]) : this.prefix(node), core_1.Markers.EMPTY, [], J.ClassDeclaration.Kind.Type.Enum), node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), null, null, null, null, null, new J.Block((0, core_1.randomId)(), this.prefix(node.getChildren().find(v => v.kind === ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, new java_1.JRightPadded(false, java_1.Space.EMPTY, core_1.Markers.EMPTY), this.convertEnumBlock(node), this.prefix(node.getLastToken())), this.mapType(node));
|
|
917
|
+
}
|
|
918
|
+
convertEnumBlock(enumDeclaration) {
|
|
919
|
+
if (enumDeclaration.members.length == 0) {
|
|
920
|
+
return [];
|
|
921
|
+
}
|
|
922
|
+
const node = enumDeclaration.getChildren()[enumDeclaration.getChildCount() - 2];
|
|
923
|
+
const children = node.getChildren();
|
|
924
|
+
const childCount = children.length;
|
|
925
|
+
const enumMembers = [];
|
|
926
|
+
for (let i = 0; i < childCount; i++) {
|
|
927
|
+
if (children[i].kind === ts.SyntaxKind.EnumMember) {
|
|
928
|
+
const rp = new java_1.JRightPadded(this.convert(children[i]), i + 1 < childCount ? this.prefix(children[i + 1]) : java_1.Space.EMPTY, i + 1 < childCount ? core_1.Markers.build([new java_1.TrailingComma((0, core_1.randomId)(), java_1.Space.EMPTY)]) : core_1.Markers.EMPTY);
|
|
929
|
+
enumMembers.push(rp);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return enumMembers;
|
|
851
933
|
}
|
|
852
934
|
visitModuleDeclaration(node) {
|
|
853
935
|
return this.visitUnknown(node);
|
|
@@ -975,7 +1057,7 @@ class JavaScriptParserVisitor {
|
|
|
975
1057
|
return this.visitUnknown(node);
|
|
976
1058
|
}
|
|
977
1059
|
visitEnumMember(node) {
|
|
978
|
-
return this.
|
|
1060
|
+
return new J.EnumValue((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), node.initializer ? new J.NewClass((0, core_1.randomId)(), this.suffix(node.name), core_1.Markers.EMPTY, null, java_1.Space.EMPTY, null, new java_1.JContainer(java_1.Space.EMPTY, [this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY)], core_1.Markers.EMPTY), null, this.mapMethodType(node)) : null);
|
|
979
1061
|
}
|
|
980
1062
|
visitBundle(node) {
|
|
981
1063
|
return this.visitUnknown(node);
|
|
@@ -1159,6 +1241,13 @@ class JavaScriptParserVisitor {
|
|
|
1159
1241
|
mapCommaSeparatedList(nodes) {
|
|
1160
1242
|
return this.mapToContainer(nodes, this.trailingComma(nodes));
|
|
1161
1243
|
}
|
|
1244
|
+
mapTypeArguments(nodes) {
|
|
1245
|
+
if (nodes.length === 0) {
|
|
1246
|
+
return java_1.JContainer.empty();
|
|
1247
|
+
}
|
|
1248
|
+
const args = nodes.map(node => this.rightPadded(this.visit(node), this.suffix(node), core_1.Markers.EMPTY));
|
|
1249
|
+
return new java_1.JContainer(this.prefix(nodes[0]), args, core_1.Markers.EMPTY);
|
|
1250
|
+
}
|
|
1162
1251
|
mapToContainer(nodes, markers) {
|
|
1163
1252
|
if (nodes.length === 0) {
|
|
1164
1253
|
return java_1.JContainer.empty();
|
|
@@ -1172,7 +1261,7 @@ class JavaScriptParserVisitor {
|
|
|
1172
1261
|
let childCount = elementList.length;
|
|
1173
1262
|
const args = [];
|
|
1174
1263
|
if (childCount === 0) {
|
|
1175
|
-
args.push(this.rightPadded(
|
|
1264
|
+
args.push(this.rightPadded(this.newJEmpty(), lastAfter, core_1.Markers.EMPTY));
|
|
1176
1265
|
}
|
|
1177
1266
|
else {
|
|
1178
1267
|
for (let i = 0; i < childCount - 1; i += 2) {
|
|
@@ -1192,12 +1281,6 @@ class JavaScriptParserVisitor {
|
|
|
1192
1281
|
mapTypeParameters(node) {
|
|
1193
1282
|
return null;
|
|
1194
1283
|
}
|
|
1195
|
-
convertBlock(nodes) {
|
|
1196
|
-
const prefix = this.prefix(nodes[0]);
|
|
1197
|
-
let statementList = nodes[1];
|
|
1198
|
-
const statements = this.rightPaddedSeparatedList([...statementList.getChildren(this.sourceFile)], ts.SyntaxKind.SemicolonToken, (nodes, i) => { var _a; return ((_a = nodes[i].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; });
|
|
1199
|
-
return new J.Block((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), statements, this.prefix(nodes[nodes.length - 1]));
|
|
1200
|
-
}
|
|
1201
1284
|
findChildNode(node, kind) {
|
|
1202
1285
|
for (let i = 0; i < node.getChildCount(this.sourceFile); i++) {
|
|
1203
1286
|
if (node.getChildAt(i, this.sourceFile).kind == kind) {
|
|
@@ -1206,6 +1289,16 @@ class JavaScriptParserVisitor {
|
|
|
1206
1289
|
}
|
|
1207
1290
|
return undefined;
|
|
1208
1291
|
}
|
|
1292
|
+
convertToken(token) {
|
|
1293
|
+
if ((token === null || token === void 0 ? void 0 : token.kind) === ts.SyntaxKind.CommaToken)
|
|
1294
|
+
return new java_1.TrailingComma((0, core_1.randomId)(), java_1.Space.EMPTY);
|
|
1295
|
+
if ((token === null || token === void 0 ? void 0 : token.kind) === ts.SyntaxKind.SemicolonToken)
|
|
1296
|
+
return new java_1.Semicolon((0, core_1.randomId)());
|
|
1297
|
+
return null;
|
|
1298
|
+
}
|
|
1299
|
+
newJEmpty(prefix = java_1.Space.EMPTY) {
|
|
1300
|
+
return new J.Empty((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY);
|
|
1301
|
+
}
|
|
1209
1302
|
}
|
|
1210
1303
|
exports.JavaScriptParserVisitor = JavaScriptParserVisitor;
|
|
1211
1304
|
function prefixFromNode(node, sourceFile) {
|