@openrewrite/rewrite 0.21.0 → 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,10 +228,16 @@ class JavaScriptParserVisitor {
228
228
  ]), node.getFullText()));
229
229
  }
230
230
  mapModifiers(node) {
231
- var _a, _b, _c;
232
- if (ts.isVariableStatement(node) || ts.isModuleDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isFunctionDeclaration(node) || ts.isParameter(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node)) {
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)) {
233
235
  return node.modifiers ? (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(ts.isModifier).map(this.mapModifier) : [];
234
236
  }
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, [])];
240
+ }
235
241
  else if (ts.isVariableDeclarationList(node)) {
236
242
  let modifier;
237
243
  if ((node.flags & ts.NodeFlags.Let) !== 0) {
@@ -246,10 +252,10 @@ class JavaScriptParserVisitor {
246
252
  return modifier ? [new J.Modifier((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, "let", J.Modifier.Type.LanguageExtension, [])] : [];
247
253
  }
248
254
  else if (ts.isGetAccessorDeclaration(node)) {
249
- return (node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.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, []));
250
256
  }
251
257
  else if (ts.isSetAccessorDeclaration(node)) {
252
- 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(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, []));
253
259
  }
254
260
  throw new Error(`Cannot get modifiers from ${node}`);
255
261
  }
@@ -279,7 +285,7 @@ class JavaScriptParserVisitor {
279
285
  return nodes.map(n => this.leftPadded(before(n), this.convert(n), markers === null || markers === void 0 ? void 0 : markers(n)));
280
286
  }
281
287
  visitClassDeclaration(node) {
282
- 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) => {
283
289
  var _a, _b;
284
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);
285
291
  }), this.prefix(node.getLastToken())), this.mapType(node));
@@ -402,14 +408,7 @@ class JavaScriptParserVisitor {
402
408
  return this.mapIdentifier(node, node.text);
403
409
  }
404
410
  visitQualifiedName(node) {
405
- 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));
406
- const parent = node.parent;
407
- if (parent.typeArguments) {
408
- 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));
409
- }
410
- else {
411
- return fieldAccess;
412
- }
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));
413
412
  }
414
413
  visitComputedPropertyName(node) {
415
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));
@@ -422,9 +421,13 @@ class JavaScriptParserVisitor {
422
421
  }
423
422
  visitParameter(node) {
424
423
  if (node.questionToken) {
425
- 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))]);
426
429
  }
427
- 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))]);
428
431
  }
429
432
  visitDecorator(node) {
430
433
  let annotationType;
@@ -456,7 +459,11 @@ class JavaScriptParserVisitor {
456
459
  if (node.questionToken) {
457
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)]);
458
461
  }
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), [], 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)]);
460
467
  }
461
468
  visitMethodSignature(node) {
462
469
  if (node.questionToken) {
@@ -466,9 +473,7 @@ class JavaScriptParserVisitor {
466
473
  }
467
474
  visitMethodDeclaration(node) {
468
475
  if (node.questionToken) {
469
- return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), node.typeParameters
470
- ? 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))))
471
- : 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));
472
477
  }
473
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));
474
479
  }
@@ -504,10 +509,7 @@ class JavaScriptParserVisitor {
504
509
  }
505
510
  visitTypeReference(node) {
506
511
  if (node.typeArguments) {
507
- if (ts.isQualifiedName(node.typeName)) {
508
- return this.visit(node.typeName);
509
- }
510
- 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));
511
513
  }
512
514
  return this.visit(node.typeName);
513
515
  }
@@ -578,13 +580,13 @@ class JavaScriptParserVisitor {
578
580
  return this.visitUnknown(node);
579
581
  }
580
582
  visitObjectBindingPattern(node) {
581
- 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);
582
584
  }
583
585
  visitArrayBindingPattern(node) {
584
586
  return this.visitUnknown(node);
585
587
  }
586
588
  visitBindingElement(node) {
587
- 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));
588
590
  }
589
591
  visitArrayLiteralExpression(node) {
590
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));
@@ -603,21 +605,31 @@ class JavaScriptParserVisitor {
603
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));
604
606
  }
605
607
  visitElementAccessExpression(node) {
606
- 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));
607
611
  }
608
612
  visitCallExpression(node) {
609
613
  const prefix = this.prefix(node);
610
614
  let select;
611
615
  let name;
612
616
  if (ts.isPropertyAccessExpression(node.expression)) {
613
- select = this.rightPadded(this.convert(node.expression.expression), this.prefix(node.expression.getChildAt(1, this.sourceFile)));
614
- 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;
615
621
  }
616
622
  else {
617
623
  select = null;
618
- 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));
619
632
  }
620
- 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));
621
633
  }
622
634
  visitNewExpression(node) {
623
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));
@@ -632,12 +644,13 @@ class JavaScriptParserVisitor {
632
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())));
633
645
  }
634
646
  visitFunctionExpression(node) {
635
- 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));
636
648
  }
637
649
  visitArrowFunction(node) {
638
- 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 ?
639
- node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) :
640
- [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));
641
654
  }
642
655
  visitDeleteExpression(node) {
643
656
  return new JS.Delete((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.mapType(node));
@@ -716,7 +729,11 @@ class JavaScriptParserVisitor {
716
729
  }
717
730
  binaryOperator = this.mapBinaryOperator(node);
718
731
  if (binaryOperator === undefined) {
719
- 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));
720
737
  }
721
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));
722
739
  }
@@ -763,6 +780,33 @@ class JavaScriptParserVisitor {
763
780
  }
764
781
  return undefined;
765
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
+ }
766
810
  visitConditionalExpression(node) {
767
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));
768
812
  }
@@ -776,14 +820,19 @@ class JavaScriptParserVisitor {
776
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));
777
821
  }
778
822
  visitClassExpression(node) {
779
- 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)));
780
827
  }
781
828
  visitOmittedExpression(node) {
782
829
  return this.visitUnknown(node);
783
830
  }
784
831
  visitExpressionWithTypeArguments(node) {
785
832
  if (node.typeArguments) {
786
- 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
+ }
787
836
  }
788
837
  return this.visit(node.expression);
789
838
  }
@@ -806,7 +855,7 @@ class JavaScriptParserVisitor {
806
855
  return this.visitUnknown(node);
807
856
  }
808
857
  visitSemicolonClassElement(node) {
809
- return this.visitUnknown(node);
858
+ return this.newJEmpty(this.semicolonPrefix(node));
810
859
  }
811
860
  visitBlock(node) {
812
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()));
@@ -832,31 +881,33 @@ class JavaScriptParserVisitor {
832
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);
833
882
  }
834
883
  visitDoStatement(node) {
835
- 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)))));
836
885
  }
837
886
  visitWhileStatement(node) {
838
- 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));
839
889
  }
840
890
  visitForStatement(node) {
841
891
  var _a;
842
- 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 ?
843
893
  (ts.isVariableDeclarationList(node.initializer) ? this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY) :
844
894
  this.rightPadded(this.convert(node.initializer), this.suffix(node.initializer.getLastToken()))) :
845
- this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY)], node.condition ? this.rightPadded(this.convert(node.condition), this.suffix(node.condition.getLastToken())) :
846
- this.rightPadded(this.newJEmpty(), java_1.Space.EMPTY), [node.incrementor ? this.rightPadded(this.convert(node.incrementor), this.suffix(node.incrementor.getLastToken())) :
847
- 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));
848
898
  }
849
899
  visitForInStatement(node) {
850
900
  return this.visitUnknown(node);
851
901
  }
852
902
  visitForOfStatement(node) {
853
- 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));
854
905
  }
855
906
  visitContinueStatement(node) {
856
- 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);
857
908
  }
858
909
  visitBreakStatement(node) {
859
- 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);
860
911
  }
861
912
  visitReturnStatement(node) {
862
913
  return new J.Return((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.expression ? this.convert(node.expression) : null);
@@ -865,25 +916,26 @@ class JavaScriptParserVisitor {
865
916
  return this.visitUnknown(node);
866
917
  }
867
918
  visitSwitchStatement(node) {
868
- 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));
869
920
  }
870
921
  visitLabeledStatement(node) {
871
- 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));
872
923
  }
873
924
  visitThrowStatement(node) {
874
925
  return new J.Throw((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression));
875
926
  }
876
927
  visitTryStatement(node) {
877
- var _a;
878
- return new J.Try((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, this.visit(node.tryBlock), node.catchClause ?
879
- [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))
880
- : 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);
881
929
  }
882
930
  visitDebuggerStatement(node) {
883
931
  return this.visitUnknown(node);
884
932
  }
885
933
  visitVariableDeclaration(node) {
886
- 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));
887
939
  }
888
940
  visitVariableDeclarationList(node) {
889
941
  const kind = node.getFirstToken(this.sourceFile);
@@ -892,11 +944,14 @@ class JavaScriptParserVisitor {
892
944
  : (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.ConstKeyword
893
945
  ? JS.ScopedVariableDeclarations.Scope.Const
894
946
  : JS.ScopedVariableDeclarations.Scope.Var), node.declarations.map((declaration) => {
895
- 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));
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));
896
951
  }));
897
952
  }
898
953
  visitFunctionDeclaration(node) {
899
- 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));
900
955
  }
901
956
  getParameterListNodes(node) {
902
957
  const children = node.getChildren(this.sourceFile);
@@ -908,7 +963,7 @@ class JavaScriptParserVisitor {
908
963
  return [];
909
964
  }
910
965
  visitInterfaceDeclaration(node) {
911
- 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 => {
912
967
  var _a, _b, _c, _d;
913
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);
914
969
  }), this.prefix(node.getLastToken())), this.mapType(node));
@@ -917,23 +972,7 @@ class JavaScriptParserVisitor {
917
972
  return this.visitUnknown(node);
918
973
  }
919
974
  visitEnumDeclaration(node) {
920
- 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));
921
- }
922
- convertEnumBlock(enumDeclaration) {
923
- if (enumDeclaration.members.length == 0) {
924
- return [];
925
- }
926
- const node = enumDeclaration.getChildren()[enumDeclaration.getChildCount() - 2];
927
- const children = node.getChildren();
928
- const childCount = children.length;
929
- const enumMembers = [];
930
- for (let i = 0; i < childCount; i++) {
931
- if (children[i].kind === ts.SyntaxKind.EnumMember) {
932
- 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);
933
- enumMembers.push(rp);
934
- }
935
- }
936
- 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));
937
976
  }
938
977
  visitModuleDeclaration(node) {
939
978
  const body = this.visit(node.body);
@@ -951,7 +990,7 @@ class JavaScriptParserVisitor {
951
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()));
952
991
  }
953
992
  visitCaseBlock(node) {
954
- 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()));
955
994
  }
956
995
  visitNamespaceExportDeclaration(node) {
957
996
  return this.visitUnknown(node);
@@ -963,11 +1002,11 @@ class JavaScriptParserVisitor {
963
1002
  return this.mapIdentifier(node, 'import');
964
1003
  }
965
1004
  visitImportDeclaration(node) {
966
- var _a, _b, _c;
1005
+ var _a, _b, _c, _d;
967
1006
  const children = node.getChildren(this.sourceFile);
968
1007
  const _default = !!((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.name);
969
1008
  const onlyDefault = _default && node.importClause.namedBindings == undefined;
970
- 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);
971
1010
  }
972
1011
  visitImportClause(node) {
973
1012
  var _a;
@@ -983,7 +1022,9 @@ class JavaScriptParserVisitor {
983
1022
  return this.visitUnknown(node);
984
1023
  }
985
1024
  visitImportSpecifier(node) {
986
- 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));
987
1028
  }
988
1029
  visitExportAssignment(node) {
989
1030
  return this.visitUnknown(node);
@@ -1043,16 +1084,18 @@ class JavaScriptParserVisitor {
1043
1084
  return this.visitUnknown(node);
1044
1085
  }
1045
1086
  visitCaseClause(node) {
1046
- 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);
1047
1088
  }
1048
1089
  visitDefaultClause(node) {
1049
- 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);
1050
1091
  }
1051
1092
  visitHeritageClause(node) {
1052
1093
  return this.convert(node.types[0]);
1053
1094
  }
1054
1095
  visitCatchClause(node) {
1055
- 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));
1056
1099
  }
1057
1100
  visitImportAttributes(node) {
1058
1101
  return this.visitUnknown(node);
@@ -1064,10 +1107,10 @@ class JavaScriptParserVisitor {
1064
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));
1065
1108
  }
1066
1109
  visitShorthandPropertyAssignment(node) {
1067
- 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);
1068
1111
  }
1069
1112
  visitSpreadAssignment(node) {
1070
- 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);
1071
1114
  }
1072
1115
  visitEnumMember(node) {
1073
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);
@@ -1303,6 +1346,9 @@ class JavaScriptParserVisitor {
1303
1346
  if (ts.isConstructSignatureDeclaration(node)) {
1304
1347
  ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword));
1305
1348
  }
1349
+ else if (ts.isFunctionExpression(node)) {
1350
+ ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword));
1351
+ }
1306
1352
  else {
1307
1353
  ts_prefix = node.questionToken ? this.suffix(node.questionToken) : node.name ? this.suffix(node.name) : java_1.Space.EMPTY;
1308
1354
  }
@@ -1326,8 +1372,8 @@ class JavaScriptParserVisitor {
1326
1372
  return new java_1.Semicolon((0, core_1.randomId)());
1327
1373
  return null;
1328
1374
  }
1329
- newJEmpty(prefix = java_1.Space.EMPTY) {
1330
- 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);
1331
1377
  }
1332
1378
  getOptionalUnary(node) {
1333
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));