@openrewrite/rewrite 0.20.8 → 0.22.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.
@@ -228,27 +228,15 @@ class JavaScriptParserVisitor {
228
228
  ]), node.getFullText()));
229
229
  }
230
230
  mapModifiers(node) {
231
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
232
- if (ts.isVariableStatement(node)) {
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, [])];
231
+ var _a, _b, _c, _d;
232
+ if (ts.isVariableStatement(node) || ts.isModuleDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node)
233
+ || ts.isInterfaceDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)
234
+ || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node)) {
235
+ return node.modifiers ? (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(ts.isModifier).map(this.mapModifier) : [];
234
236
  }
235
- else if (ts.isModuleDeclaration(node)) {
236
- return node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.filter(ts.isModifier).map(this.mapModifier) : [];
237
- }
238
- else if (ts.isClassDeclaration(node)) {
239
- return node.modifiers ? (_c = node.modifiers) === null || _c === void 0 ? void 0 : _c.filter(ts.isModifier).map(this.mapModifier) : [];
240
- }
241
- else if (ts.isEnumDeclaration(node) || ts.isInterfaceDeclaration(node)) {
242
- return node.modifiers ? (_d = node.modifiers) === null || _d === void 0 ? void 0 : _d.filter(ts.isModifier).map(this.mapModifier) : [];
243
- }
244
- else if (ts.isPropertyDeclaration(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.isPropertySignature(node)) {
248
- return node.modifiers ? (_f = node.modifiers) === null || _f === void 0 ? void 0 : _f.filter(ts.isModifier).map(this.mapModifier) : [];
249
- }
250
- else if (ts.isFunctionDeclaration(node) || ts.isParameter(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node)) {
251
- return node.modifiers ? (_g = node.modifiers) === null || _g === void 0 ? void 0 : _g.filter(ts.isModifier).map(this.mapModifier) : [];
237
+ else if (ts.isFunctionDeclaration(node)) {
238
+ return [...node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.filter(ts.isModifier).map(this.mapModifier) : [],
239
+ new J.Modifier((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), core_1.Markers.EMPTY, null, J.Modifier.Type.LanguageExtension, [])];
252
240
  }
253
241
  else if (ts.isVariableDeclarationList(node)) {
254
242
  let modifier;
@@ -264,10 +252,10 @@ class JavaScriptParserVisitor {
264
252
  return modifier ? [new J.Modifier((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, "let", J.Modifier.Type.LanguageExtension, [])] : [];
265
253
  }
266
254
  else if (ts.isGetAccessorDeclaration(node)) {
267
- return (node.modifiers ? (_h = node.modifiers) === null || _h === void 0 ? void 0 : _h.filter(ts.isModifier).map(this.mapModifier) : []).concat(new J.Modifier((0, core_1.randomId)(), this.prefix(node.getChildren().find(c => c.getText() === 'get')), core_1.Markers.EMPTY, 'get', J.Modifier.Type.LanguageExtension, []));
255
+ return (node.modifiers ? (_c = node.modifiers) === null || _c === void 0 ? void 0 : _c.filter(ts.isModifier).map(this.mapModifier) : []).concat(new J.Modifier((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.GetKeyword)), core_1.Markers.EMPTY, 'get', J.Modifier.Type.LanguageExtension, []));
268
256
  }
269
257
  else if (ts.isSetAccessorDeclaration(node)) {
270
- return (node.modifiers ? (_j = node.modifiers) === null || _j === void 0 ? void 0 : _j.filter(ts.isModifier).map(this.mapModifier) : []).concat(new J.Modifier((0, core_1.randomId)(), this.prefix(node.getChildren().find(c => c.getText() === 'set')), core_1.Markers.EMPTY, 'set', J.Modifier.Type.LanguageExtension, []));
258
+ return (node.modifiers ? (_d = node.modifiers) === null || _d === void 0 ? void 0 : _d.filter(ts.isModifier).map(this.mapModifier) : []).concat(new J.Modifier((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.SetKeyword)), core_1.Markers.EMPTY, 'set', J.Modifier.Type.LanguageExtension, []));
271
259
  }
272
260
  throw new Error(`Cannot get modifiers from ${node}`);
273
261
  }
@@ -297,7 +285,7 @@ class JavaScriptParserVisitor {
297
285
  return nodes.map(n => this.leftPadded(before(n), this.convert(n), markers === null || markers === void 0 ? void 0 : markers(n)));
298
286
  }
299
287
  visitClassDeclaration(node) {
300
- 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.mapTypeParametersAsJContainer(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) => {
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.mapTypeParametersAsJContainer(node), null, this.mapExtends(node), this.mapImplements(node), null, new J.Block((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, new java_1.JRightPadded(false, java_1.Space.EMPTY, core_1.Markers.EMPTY), node.members.map((ce) => {
301
289
  var _a, _b;
302
290
  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);
303
291
  }), this.prefix(node.getLastToken())), this.mapType(node));
@@ -420,14 +408,7 @@ class JavaScriptParserVisitor {
420
408
  return this.mapIdentifier(node, node.text);
421
409
  }
422
410
  visitQualifiedName(node) {
423
- 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));
424
- const parent = node.parent;
425
- if (parent.typeArguments) {
426
- return new J.ParameterizedType((0, core_1.randomId)(), this.prefix(parent), core_1.Markers.EMPTY, fieldAccess, this.mapTypeArguments(this.suffix(parent.typeName), parent.typeArguments), this.mapType(parent));
427
- }
428
- else {
429
- return fieldAccess;
430
- }
411
+ return new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.left), this.leftPadded(this.suffix(node.left), this.convert(node.right)), this.mapType(node));
431
412
  }
432
413
  visitComputedPropertyName(node) {
433
414
  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));
@@ -440,9 +421,13 @@ class JavaScriptParserVisitor {
440
421
  }
441
422
  visitParameter(node) {
442
423
  if (node.questionToken) {
443
- 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), [], 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))]);
424
+ 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), [], 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))]);
425
+ }
426
+ const nameExpression = this.visit(node.name);
427
+ if (nameExpression instanceof J.Identifier) {
428
+ 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, [], 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))]);
444
429
  }
445
- 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))]);
430
+ 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, [], 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))]);
446
431
  }
447
432
  visitDecorator(node) {
448
433
  let annotationType;
@@ -474,7 +459,11 @@ class JavaScriptParserVisitor {
474
459
  if (node.questionToken) {
475
460
  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), [], 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)]);
476
461
  }
477
- 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)]);
462
+ const nameExpression = this.visit(node.name);
463
+ if (nameExpression instanceof J.Identifier) {
464
+ 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, [], 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))]);
465
+ }
466
+ 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.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)]);
478
467
  }
479
468
  visitMethodSignature(node) {
480
469
  if (node.questionToken) {
@@ -484,9 +473,7 @@ class JavaScriptParserVisitor {
484
473
  }
485
474
  visitMethodDeclaration(node) {
486
475
  if (node.questionToken) {
487
- return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), node.typeParameters
488
- ? 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))))
489
- : null, this.mapTypeInfo(node), this.getOptionalUnary(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
476
+ 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), this.getOptionalUnary(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
490
477
  }
491
478
  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(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));
492
479
  }
@@ -494,7 +481,7 @@ class JavaScriptParserVisitor {
494
481
  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;
495
482
  }
496
483
  visitClassStaticBlockDeclaration(node) {
497
- return new J.Block((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new java_1.JRightPadded(true, this.prefix(node.body.getChildren().find(v => v.kind === ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY), node.body.statements.map(ce => {
484
+ return new J.Block((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new java_1.JRightPadded(true, this.prefix(this.findChildNode(node.body, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY), node.body.statements.map(ce => {
498
485
  var _a, _b;
499
486
  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);
500
487
  }), this.prefix(node.getLastToken()));
@@ -512,7 +499,7 @@ class JavaScriptParserVisitor {
512
499
  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(new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], "", null, null), []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, null, null, this.mapMethodType(node));
513
500
  }
514
501
  visitConstructSignature(node) {
515
- return this.visitUnknown(node);
502
+ 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(new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], 'new', null, null), []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, null, null, this.mapMethodType(node));
516
503
  }
517
504
  visitIndexSignature(node) {
518
505
  return this.visitUnknown(node);
@@ -522,10 +509,7 @@ class JavaScriptParserVisitor {
522
509
  }
523
510
  visitTypeReference(node) {
524
511
  if (node.typeArguments) {
525
- if (ts.isQualifiedName(node.typeName)) {
526
- return this.visit(node.typeName);
527
- }
528
- return this.visitUnknown(node);
512
+ return new J.ParameterizedType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.typeName), this.mapTypeArguments(this.suffix(node.typeName), node.typeArguments), this.mapType(node));
529
513
  }
530
514
  return this.visit(node.typeName);
531
515
  }
@@ -596,13 +580,13 @@ class JavaScriptParserVisitor {
596
580
  return this.visitUnknown(node);
597
581
  }
598
582
  visitObjectBindingPattern(node) {
599
- return this.visitUnknown(node);
583
+ return new JS.ObjectBindingDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], null, this.mapCommaSeparatedList(node.getChildren(this.sourceFile)), null);
600
584
  }
601
585
  visitArrayBindingPattern(node) {
602
586
  return this.visitUnknown(node);
603
587
  }
604
588
  visitBindingElement(node) {
605
- return this.visitUnknown(node);
589
+ return new JS.ObjectBindingDeclarations.Binding((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.propertyName ? this.rightPadded(this.convert(node.propertyName), this.suffix(node.propertyName)) : null, node.dotDotDotToken ? new JS.Unary((0, core_1.randomId)(), this.prefix(node.dotDotDotToken), core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.convert(node.name), null) : this.convert(node.name), [], null, node.initializer ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsToken)), this.convert(node.initializer)) : null, this.mapVariableType(node));
606
590
  }
607
591
  visitArrayLiteralExpression(node) {
608
592
  return new J.NewArray((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, [], this.mapCommaSeparatedList(node.getChildren(this.sourceFile)), this.mapType(node));
@@ -617,24 +601,35 @@ class JavaScriptParserVisitor {
617
601
  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]));
618
602
  }
619
603
  visitPropertyAccessExpression(node) {
620
- return new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.leftPadded(this.prefix(node.getChildAt(1, this.sourceFile)), this.convert(node.name)), this.mapType(node));
604
+ return new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.questionDotToken ?
605
+ new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.expression), JS.Unary.Type.QuestionDot), this.visit(node.expression), this.mapType(node)) : this.convert(node.expression), this.leftPadded(this.prefix(node.getChildAt(1, this.sourceFile)), this.convert(node.name)), this.mapType(node));
621
606
  }
622
607
  visitElementAccessExpression(node) {
623
- return this.visitUnknown(node);
608
+ return new J.ArrayAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.questionDotToken ?
609
+ new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.expression), JS.Unary.Type.QuestionDotWithDot), this.visit(node.expression), this.mapType(node)) :
610
+ this.convert(node.expression), new J.ArrayDimension((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.argumentExpression), this.suffix(node.argumentExpression))), this.mapType(node));
624
611
  }
625
612
  visitCallExpression(node) {
626
613
  const prefix = this.prefix(node);
627
614
  let select;
628
615
  let name;
629
616
  if (ts.isPropertyAccessExpression(node.expression)) {
630
- select = this.rightPadded(this.convert(node.expression.expression), this.prefix(node.expression.getChildAt(1, this.sourceFile)));
631
- name = this.convert(node.expression.name);
617
+ select = this.rightPadded(node.expression.questionDotToken ?
618
+ new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.expression.expression), JS.Unary.Type.QuestionDot), this.visit(node.expression.expression), this.mapType(node)) :
619
+ this.convert(node.expression.expression), this.prefix(node.expression.getChildAt(1, this.sourceFile)));
620
+ name = node.expression.name;
632
621
  }
633
622
  else {
634
623
  select = null;
635
- name = this.convert(node.expression);
624
+ name = node.expression;
625
+ }
626
+ if (node.questionDotToken) {
627
+ const unary = new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(name), JS.Unary.Type.QuestionDotWithDot), this.visit(name), this.mapType(node));
628
+ return new JS.JSMethodInvocation((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, select, node.typeArguments ? this.mapTypeArguments(this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)), node.typeArguments) : null, unary, this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), this.mapMethodType(node));
629
+ }
630
+ else {
631
+ return new J.MethodInvocation((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, select, node.typeArguments ? this.mapTypeArguments(this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)), node.typeArguments) : null, this.convert(name), this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), this.mapMethodType(node));
636
632
  }
637
- return new J.MethodInvocation((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, select, null, name, this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), this.mapMethodType(node));
638
633
  }
639
634
  visitNewExpression(node) {
640
635
  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.mapCommaSeparatedList(node.arguments ? node.getChildren(this.sourceFile).slice(2) : []), null, this.mapMethodType(node));
@@ -649,12 +644,13 @@ class JavaScriptParserVisitor {
649
644
  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())));
650
645
  }
651
646
  visitFunctionExpression(node) {
652
- return this.visitUnknown(node);
647
+ return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], null, this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
653
648
  }
654
649
  visitArrowFunction(node) {
655
- 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 ?
656
- node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) :
657
- [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);
650
+ 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)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, true, node.parameters.length > 0 ?
651
+ node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p)))
652
+ .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken))) : []) :
653
+ [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));
658
654
  }
659
655
  visitDeleteExpression(node) {
660
656
  return new JS.Delete((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.mapType(node));
@@ -721,6 +717,9 @@ class JavaScriptParserVisitor {
721
717
  case ts.SyntaxKind.ExclamationEqualsEqualsToken:
722
718
  binaryOperator = JS.JsBinary.Type.IdentityNotEquals;
723
719
  break;
720
+ case ts.SyntaxKind.QuestionQuestionToken:
721
+ binaryOperator = JS.JsBinary.Type.QuestionQuestion;
722
+ break;
724
723
  }
725
724
  if (binaryOperator !== undefined) {
726
725
  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));
@@ -730,7 +729,11 @@ class JavaScriptParserVisitor {
730
729
  }
731
730
  binaryOperator = this.mapBinaryOperator(node);
732
731
  if (binaryOperator === undefined) {
733
- return this.visitUnknown(node);
732
+ const assignmentOperation = this.mapAssignmentOperation(node);
733
+ if (assignmentOperation === undefined) {
734
+ return this.visitUnknown(node);
735
+ }
736
+ return new J.AssignmentOperation((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));
734
737
  }
735
738
  return new J.Binary((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));
736
739
  }
@@ -777,6 +780,33 @@ class JavaScriptParserVisitor {
777
780
  }
778
781
  return undefined;
779
782
  }
783
+ mapAssignmentOperation(node) {
784
+ switch (node.operatorToken.kind) {
785
+ case ts.SyntaxKind.PlusEqualsToken:
786
+ return J.AssignmentOperation.Type.Addition;
787
+ case ts.SyntaxKind.MinusEqualsToken:
788
+ return J.AssignmentOperation.Type.Subtraction;
789
+ case ts.SyntaxKind.AsteriskEqualsToken:
790
+ return J.AssignmentOperation.Type.Multiplication;
791
+ case ts.SyntaxKind.SlashEqualsToken:
792
+ return J.AssignmentOperation.Type.Division;
793
+ case ts.SyntaxKind.PercentEqualsToken:
794
+ return J.AssignmentOperation.Type.Modulo;
795
+ case ts.SyntaxKind.LessThanLessThanEqualsToken:
796
+ return J.AssignmentOperation.Type.LeftShift;
797
+ case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
798
+ return J.AssignmentOperation.Type.RightShift;
799
+ case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
800
+ return J.AssignmentOperation.Type.UnsignedRightShift;
801
+ case ts.SyntaxKind.AmpersandEqualsToken:
802
+ return J.AssignmentOperation.Type.BitAnd;
803
+ case ts.SyntaxKind.BarEqualsToken:
804
+ return J.AssignmentOperation.Type.BitOr;
805
+ case ts.SyntaxKind.CaretEqualsToken:
806
+ return J.AssignmentOperation.Type.BitXor;
807
+ }
808
+ return undefined;
809
+ }
780
810
  visitConditionalExpression(node) {
781
811
  return new J.Ternary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.condition), this.leftPadded(this.suffix(node.condition), this.convert(node.whenTrue)), this.leftPadded(this.suffix(node.whenTrue), this.convert(node.whenFalse)), this.mapType(node));
782
812
  }
@@ -790,14 +820,19 @@ class JavaScriptParserVisitor {
790
820
  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));
791
821
  }
792
822
  visitClassExpression(node) {
793
- return this.visitUnknown(node);
823
+ return new JS.StatementExpression((0, core_1.randomId)(), new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], 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.mapTypeParametersAsJContainer(node), null, this.mapExtends(node), this.mapImplements(node), null, new J.Block((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), node.members.map(ce => {
824
+ var _a, _b;
825
+ 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);
826
+ }), this.prefix(node.getLastToken())), this.mapType(node)));
794
827
  }
795
828
  visitOmittedExpression(node) {
796
829
  return this.visitUnknown(node);
797
830
  }
798
831
  visitExpressionWithTypeArguments(node) {
799
832
  if (node.typeArguments) {
800
- return this.visitUnknown(node);
833
+ if (node.typeArguments) {
834
+ return new J.ParameterizedType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression), this.mapTypeArguments(this.suffix(node.expression), node.typeArguments), this.mapType(node));
835
+ }
801
836
  }
802
837
  return this.visit(node.expression);
803
838
  }
@@ -805,7 +840,7 @@ class JavaScriptParserVisitor {
805
840
  return new JS.JsBinary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.leftPadded(this.prefix(node.getChildAt(1, this.sourceFile)), JS.JsBinary.Type.As), this.convert(node.type), this.mapType(node));
806
841
  }
807
842
  visitNonNullExpression(node) {
808
- return this.visitUnknown(node);
843
+ 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));
809
844
  }
810
845
  visitMetaProperty(node) {
811
846
  return this.visitUnknown(node);
@@ -820,7 +855,7 @@ class JavaScriptParserVisitor {
820
855
  return this.visitUnknown(node);
821
856
  }
822
857
  visitSemicolonClassElement(node) {
823
- return this.visitUnknown(node);
858
+ return this.newJEmpty(this.semicolonPrefix(node));
824
859
  }
825
860
  visitBlock(node) {
826
861
  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()));
@@ -829,7 +864,7 @@ class JavaScriptParserVisitor {
829
864
  return this.newJEmpty(this.prefix(node));
830
865
  }
831
866
  visitVariableStatement(node) {
832
- return this.visitVariableDeclarationList(node.declarationList);
867
+ return this.visitVariableDeclarationList(node.declarationList).withModifiers(this.mapModifiers(node)).withPrefix(this.prefix(node));
833
868
  }
834
869
  visitExpressionStatement(node) {
835
870
  const expression = this.visit(node.expression);
@@ -846,31 +881,33 @@ class JavaScriptParserVisitor {
846
881
  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), semicolonAfterThen ? this.prefix(node.elseStatement.getLastToken()) : java_1.Space.EMPTY, semicolonAfterThen ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY)) : null);
847
882
  }
848
883
  visitDoStatement(node) {
849
- return this.visitUnknown(node);
884
+ 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)))));
850
885
  }
851
886
  visitWhileStatement(node) {
852
- return this.visitUnknown(node);
887
+ var _a;
888
+ return new J.WhileLoop((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.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));
853
889
  }
854
890
  visitForStatement(node) {
855
891
  var _a;
856
- 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 ?
892
+ 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 ?
857
893
  (ts.isVariableDeclarationList(node.initializer) ? this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY) :
858
894
  this.rightPadded(this.convert(node.initializer), this.suffix(node.initializer.getLastToken()))) :
859
- this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY)], node.condition ? this.rightPadded(this.convert(node.condition), this.suffix(node.condition.getLastToken())) :
860
- this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY), [node.incrementor ? this.rightPadded(this.convert(node.incrementor), this.suffix(node.incrementor.getLastToken())) :
861
- 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));
895
+ this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)))], node.condition ? this.rightPadded(this.convert(node.condition), this.suffix(node.condition.getLastToken())) :
896
+ this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.SemicolonToken))), [node.incrementor ? this.rightPadded(this.convert(node.incrementor), this.suffix(node.incrementor.getLastToken())) :
897
+ 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));
862
898
  }
863
899
  visitForInStatement(node) {
864
900
  return this.visitUnknown(node);
865
901
  }
866
902
  visitForOfStatement(node) {
867
- return this.visitUnknown(node);
903
+ var _a;
904
+ return new J.ForEachLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ForEachLoop.Control((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY), 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));
868
905
  }
869
906
  visitContinueStatement(node) {
870
- return this.visitUnknown(node);
907
+ return new J.Continue((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.label ? this.visit(node.label) : null);
871
908
  }
872
909
  visitBreakStatement(node) {
873
- return this.visitUnknown(node);
910
+ return new J.Break((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.label ? this.visit(node.label) : null);
874
911
  }
875
912
  visitReturnStatement(node) {
876
913
  return new J.Return((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.expression ? this.convert(node.expression) : null);
@@ -879,35 +916,42 @@ class JavaScriptParserVisitor {
879
916
  return this.visitUnknown(node);
880
917
  }
881
918
  visitSwitchStatement(node) {
882
- return this.visitUnknown(node);
919
+ return new J.Switch((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.visit(node.caseBlock));
883
920
  }
884
921
  visitLabeledStatement(node) {
885
- return this.visitUnknown(node);
922
+ return new J.Label((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.label), this.suffix(node.label)), this.visit(node.statement));
886
923
  }
887
924
  visitThrowStatement(node) {
888
925
  return new J.Throw((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression));
889
926
  }
890
927
  visitTryStatement(node) {
891
- var _a;
892
- return new J.Try((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, this.visit(node.tryBlock), node.catchClause ?
893
- [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))
894
- : null);
928
+ 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);
895
929
  }
896
930
  visitDebuggerStatement(node) {
897
931
  return this.visitUnknown(node);
898
932
  }
899
933
  visitVariableDeclaration(node) {
900
- 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));
934
+ const nameExpression = this.visit(node.name);
935
+ if (nameExpression instanceof J.Identifier) {
936
+ return new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildCount(this.sourceFile) - 2)), this.visit(node.initializer)) : null, this.mapVariableType(node));
937
+ }
938
+ return new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildCount(this.sourceFile) - 2)), this.visit(node.initializer)) : null, this.mapVariableType(node));
901
939
  }
902
940
  visitVariableDeclarationList(node) {
903
941
  const kind = node.getFirstToken(this.sourceFile);
904
- 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 :
905
- (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.ConstKeyword ? JS.ScopedVariableDeclarations.Scope.Const : JS.ScopedVariableDeclarations.Scope.Var, node.declarations.map(declaration => {
906
- 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));
942
+ return new JS.ScopedVariableDeclarations((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], this.leftPadded(this.prefix(node), (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.LetKeyword
943
+ ? JS.ScopedVariableDeclarations.Scope.Let
944
+ : (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.ConstKeyword
945
+ ? JS.ScopedVariableDeclarations.Scope.Const
946
+ : JS.ScopedVariableDeclarations.Scope.Var), node.declarations.map((declaration) => {
947
+ const declarationExpression = this.visit(declaration);
948
+ return this.rightPadded(JS.isJavaScript(declarationExpression)
949
+ ? new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(declaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(declaration), null, [this.rightPadded(declarationExpression, java_1.Space.EMPTY)])
950
+ : new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(declaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(declaration), null, [], [this.rightPadded(declarationExpression, java_1.Space.EMPTY)]), this.suffix(declaration));
907
951
  }));
908
952
  }
909
953
  visitFunctionDeclaration(node) {
910
- return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), [new J.Modifier((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), core_1.Markers.EMPTY, node.getChildAt(1, this.sourceFile).kind == ts.SyntaxKind.AsteriskToken ? "function*" : "function", J.Modifier.Type.LanguageExtension, []), ...this.mapModifiers(node)], 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, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
954
+ return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.visit(node.name), this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
911
955
  }
912
956
  getParameterListNodes(node) {
913
957
  const children = node.getChildren(this.sourceFile);
@@ -919,7 +963,7 @@ class JavaScriptParserVisitor {
919
963
  return [];
920
964
  }
921
965
  visitInterfaceDeclaration(node) {
922
- 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.mapTypeParametersAsJContainer(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 => {
966
+ 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.mapTypeParametersAsJContainer(node), null, null, this.mapInterfaceExtends(node), null, new J.Block((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), node.members.map(te => {
923
967
  var _a, _b, _c, _d;
924
968
  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);
925
969
  }), this.prefix(node.getLastToken())), this.mapType(node));
@@ -928,39 +972,25 @@ class JavaScriptParserVisitor {
928
972
  return this.visitUnknown(node);
929
973
  }
930
974
  visitEnumDeclaration(node) {
931
- 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));
932
- }
933
- convertEnumBlock(enumDeclaration) {
934
- if (enumDeclaration.members.length == 0) {
935
- return [];
936
- }
937
- const node = enumDeclaration.getChildren()[enumDeclaration.getChildCount() - 2];
938
- const children = node.getChildren();
939
- const childCount = children.length;
940
- const enumMembers = [];
941
- for (let i = 0; i < childCount; i++) {
942
- if (children[i].kind === ts.SyntaxKind.EnumMember) {
943
- 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);
944
- enumMembers.push(rp);
945
- }
946
- }
947
- return enumMembers;
975
+ 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(this.findChildNode(node, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), [this.rightPadded(new J.EnumValueSet((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, node.members.map(em => this.rightPadded(this.visit(em), this.suffix(em))), node.members.hasTrailingComma), java_1.Space.EMPTY)], this.prefix(node.getLastToken())), this.mapType(node));
948
976
  }
949
977
  visitModuleDeclaration(node) {
950
978
  const body = this.visit(node.body);
951
- const namespaceKeyword = this.findChildNode(node, ts.SyntaxKind.NamespaceKeyword);
979
+ let namespaceKeyword = this.findChildNode(node, ts.SyntaxKind.NamespaceKeyword);
980
+ const keywordType = namespaceKeyword ? JS.NamespaceDeclaration.KeywordType.Namespace : JS.NamespaceDeclaration.KeywordType.Module;
981
+ namespaceKeyword !== null && namespaceKeyword !== void 0 ? namespaceKeyword : (namespaceKeyword = this.findChildNode(node, ts.SyntaxKind.ModuleKeyword));
952
982
  if (body instanceof JS.NamespaceDeclaration) {
953
- return new JS.NamespaceDeclaration((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.mapModifiers(node), namespaceKeyword ? this.prefix(namespaceKeyword) : java_1.Space.EMPTY, this.rightPadded(new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.name), new J.JLeftPadded(this.suffix(node.name), body.name, core_1.Markers.EMPTY), null), java_1.Space.EMPTY), body.body);
983
+ return new JS.NamespaceDeclaration((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(namespaceKeyword ? this.prefix(namespaceKeyword) : java_1.Space.EMPTY, keywordType), this.rightPadded(new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.name), new J.JLeftPadded(this.suffix(node.name), body.name, core_1.Markers.EMPTY), null), java_1.Space.EMPTY), body.body);
954
984
  }
955
985
  else {
956
- return new JS.NamespaceDeclaration((0, core_1.randomId)(), node.parent.kind === ts.SyntaxKind.ModuleBlock ? this.prefix(node) : java_1.Space.EMPTY, core_1.Markers.EMPTY, this.mapModifiers(node), namespaceKeyword ? this.prefix(namespaceKeyword) : java_1.Space.EMPTY, this.rightPadded(this.convert(node.name), this.prefix(node)), body);
986
+ return new JS.NamespaceDeclaration((0, core_1.randomId)(), node.parent.kind === ts.SyntaxKind.ModuleBlock ? this.prefix(node) : java_1.Space.EMPTY, core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(namespaceKeyword ? this.prefix(namespaceKeyword) : java_1.Space.EMPTY, keywordType), this.rightPadded(this.convert(node.name), this.prefix(node)), body);
957
987
  }
958
988
  }
959
989
  visitModuleBlock(node) {
960
990
  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()));
961
991
  }
962
992
  visitCaseBlock(node) {
963
- return this.visitUnknown(node);
993
+ return new J.Block((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), node.clauses.map(clause => this.rightPadded(this.visit(clause), this.suffix(clause))), this.prefix(node.getLastToken()));
964
994
  }
965
995
  visitNamespaceExportDeclaration(node) {
966
996
  return this.visitUnknown(node);
@@ -972,11 +1002,11 @@ class JavaScriptParserVisitor {
972
1002
  return this.mapIdentifier(node, 'import');
973
1003
  }
974
1004
  visitImportDeclaration(node) {
975
- var _a, _b, _c;
1005
+ var _a, _b, _c, _d;
976
1006
  const children = node.getChildren(this.sourceFile);
977
1007
  const _default = !!((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.name);
978
1008
  const onlyDefault = _default && node.importClause.namedBindings == undefined;
979
- return new JS.JsImport((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, _default ? this.rightPadded(this.visit((_b = node.importClause) === null || _b === void 0 ? void 0 : _b.name), this.suffix((_c = node.importClause) === null || _c === void 0 ? void 0 : _c.name)) : null, node.importClause && !onlyDefault ? this.visit(node.importClause) : null, children[children.indexOf(node.moduleSpecifier) - 1].kind == ts.SyntaxKind.FromKeyword ? this.prefix(children[children.indexOf(node.moduleSpecifier) - 1]) : null, this.convert(node.moduleSpecifier), null);
1009
+ return new JS.JsImport((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, _default ? this.rightPadded(this.visit((_b = node.importClause) === null || _b === void 0 ? void 0 : _b.name), this.suffix((_c = node.importClause) === null || _c === void 0 ? void 0 : _c.name)) : null, ((_d = node.importClause) === null || _d === void 0 ? void 0 : _d.isTypeOnly) ? this.leftPadded(this.prefix(this.findChildNode(node.importClause, ts.SyntaxKind.TypeKeyword)), node.importClause.isTypeOnly) : this.leftPadded(java_1.Space.EMPTY, false), node.importClause && !onlyDefault ? this.visit(node.importClause) : null, children[children.indexOf(node.moduleSpecifier) - 1].kind == ts.SyntaxKind.FromKeyword ? this.prefix(children[children.indexOf(node.moduleSpecifier) - 1]) : null, this.convert(node.moduleSpecifier), null);
980
1010
  }
981
1011
  visitImportClause(node) {
982
1012
  var _a;
@@ -992,7 +1022,9 @@ class JavaScriptParserVisitor {
992
1022
  return this.visitUnknown(node);
993
1023
  }
994
1024
  visitImportSpecifier(node) {
995
- return this.mapIdentifier(node, node.name.text, false);
1025
+ return new JS.JsImportSpecifier((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
1026
+ ? 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))
1027
+ : this.convert(node.name), this.mapType(node));
996
1028
  }
997
1029
  visitExportAssignment(node) {
998
1030
  return this.visitUnknown(node);
@@ -1052,16 +1084,18 @@ class JavaScriptParserVisitor {
1052
1084
  return this.visitUnknown(node);
1053
1085
  }
1054
1086
  visitCaseClause(node) {
1055
- return this.visitUnknown(node);
1087
+ return new J.Case((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, J.Case.Type.Statement, new java_1.JContainer(this.prefix(node.expression), [this.rightPadded(this.visit(node.expression), this.suffix(node.expression))], core_1.Markers.EMPTY), new java_1.JContainer(this.prefix(node), this.semicolonPaddedStatementList(node.statements), core_1.Markers.EMPTY), null);
1056
1088
  }
1057
1089
  visitDefaultClause(node) {
1058
- return this.visitUnknown(node);
1090
+ return new J.Case((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, J.Case.Type.Statement, new java_1.JContainer(this.prefix(node), [this.rightPadded(this.mapIdentifier(node, 'default'), this.suffix(this.findChildNode(node, ts.SyntaxKind.DefaultKeyword)))], core_1.Markers.EMPTY), new java_1.JContainer(this.prefix(node), this.semicolonPaddedStatementList(node.statements), core_1.Markers.EMPTY), null);
1059
1091
  }
1060
1092
  visitHeritageClause(node) {
1061
1093
  return this.convert(node.types[0]);
1062
1094
  }
1063
1095
  visitCatchClause(node) {
1064
- return this.visitUnknown(node);
1096
+ return new J.Try.Catch((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.variableDeclaration ?
1097
+ new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node.variableDeclaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node.variableDeclaration), null, [], [this.rightPadded(this.visit(node.variableDeclaration), java_1.Space.EMPTY)]), this.suffix(node.variableDeclaration))) :
1098
+ new J.ControlParentheses((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], [], null, null, [], []), java_1.Space.EMPTY)), this.visit(node.block));
1065
1099
  }
1066
1100
  visitImportAttributes(node) {
1067
1101
  return this.visitUnknown(node);
@@ -1073,10 +1107,10 @@ class JavaScriptParserVisitor {
1073
1107
  return new JS.PropertyAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.name), this.suffix(node.name)), this.visit(node.initializer));
1074
1108
  }
1075
1109
  visitShorthandPropertyAssignment(node) {
1076
- return this.visitUnknown(node);
1110
+ return new JS.PropertyAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.name), this.suffix(node.name)), null);
1077
1111
  }
1078
1112
  visitSpreadAssignment(node) {
1079
- return this.visitUnknown(node);
1113
+ return new JS.PropertyAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(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.expression), this.mapType(node.expression)), this.suffix(node.expression)), null);
1080
1114
  }
1081
1115
  visitEnumMember(node) {
1082
1116
  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);
@@ -1306,9 +1340,19 @@ class JavaScriptParserVisitor {
1306
1340
  : null;
1307
1341
  }
1308
1342
  mapTypeParametersAsObject(node) {
1309
- return node.typeParameters
1310
- ? new J.TypeParameters((0, core_1.randomId)(), node.questionToken ? this.suffix(node.questionToken) : node.name ? this.suffix(node.name) : java_1.Space.EMPTY, core_1.Markers.EMPTY, [], node.typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))))
1311
- : null;
1343
+ if (!node.typeParameters)
1344
+ return null;
1345
+ let ts_prefix;
1346
+ if (ts.isConstructSignatureDeclaration(node)) {
1347
+ ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword));
1348
+ }
1349
+ else if (ts.isFunctionExpression(node)) {
1350
+ ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword));
1351
+ }
1352
+ else {
1353
+ ts_prefix = node.questionToken ? this.suffix(node.questionToken) : node.name ? this.suffix(node.name) : java_1.Space.EMPTY;
1354
+ }
1355
+ 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))));
1312
1356
  }
1313
1357
  mapTypeParametersList(typeParamsNodeArray) {
1314
1358
  return typeParamsNodeArray.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp)));
@@ -1328,8 +1372,8 @@ class JavaScriptParserVisitor {
1328
1372
  return new java_1.Semicolon((0, core_1.randomId)());
1329
1373
  return null;
1330
1374
  }
1331
- newJEmpty(prefix = java_1.Space.EMPTY) {
1332
- return new J.Empty((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY);
1375
+ newJEmpty(prefix = java_1.Space.EMPTY, markers) {
1376
+ return new J.Empty((0, core_1.randomId)(), prefix, markers !== null && markers !== void 0 ? markers : core_1.Markers.EMPTY);
1333
1377
  }
1334
1378
  getOptionalUnary(node) {
1335
1379
  return new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.name), JS.Unary.Type.Optional), this.visit(node.name), this.mapType(node));