@openrewrite/rewrite 0.23.0 → 0.24.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.
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.JavaScriptParserVisitor = exports.JavaScriptParser = void 0;
27
30
  const ts = __importStar(require("typescript"));
@@ -31,6 +34,8 @@ const JS = __importStar(require("."));
31
34
  const core_1 = require("../core");
32
35
  const parserUtils_1 = require("./parserUtils");
33
36
  const typeMapping_1 = require("./typeMapping");
37
+ const node_path_1 = __importDefault(require("node:path"));
38
+ const _1 = require(".");
34
39
  class JavaScriptParser extends core_1.Parser {
35
40
  constructor() {
36
41
  super();
@@ -54,7 +59,7 @@ class JavaScriptParser extends core_1.Parser {
54
59
  const input = new core_1.ParserInput(filePath, null, false, () => Buffer.from(ts.sys.readFile(filePath)));
55
60
  try {
56
61
  const parsed = new JavaScriptParserVisitor(this, sourceFile, typeChecker).visit(sourceFile);
57
- result.push(parsed);
62
+ result.push(parsed.withSourcePath(relativeTo != null ? node_path_1.default.relative(relativeTo, input.path) : input.path));
58
63
  }
59
64
  catch (error) {
60
65
  result.push(core_1.ParseError.build(this, input, relativeTo, ctx, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error), null));
@@ -112,7 +117,7 @@ class JavaScriptParser extends core_1.Parser {
112
117
  if (sourceFile) {
113
118
  try {
114
119
  const parsed = new JavaScriptParserVisitor(this, sourceFile, typeChecker).visit(sourceFile);
115
- result.push(parsed);
120
+ result.push(parsed.withSourcePath(relativeTo != null ? node_path_1.default.relative(relativeTo, input.path) : input.path));
116
121
  }
117
122
  catch (error) {
118
123
  result.push(core_1.ParseError.build(this, input, relativeTo, ctx, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error), null));
@@ -231,12 +236,17 @@ class JavaScriptParserVisitor {
231
236
  var _a, _b, _c, _d;
232
237
  if (ts.isVariableStatement(node) || ts.isModuleDeclaration(node) || ts.isClassDeclaration(node) || ts.isEnumDeclaration(node)
233
238
  || ts.isInterfaceDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)
234
- || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node) || ts.isIndexSignatureDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
239
+ || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node)
240
+ || ts.isIndexSignatureDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isExportDeclaration(node)
241
+ || ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node)) {
235
242
  return node.modifiers ? (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(ts.isModifier).map(this.mapModifier) : [];
236
243
  }
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, [])];
244
+ else if (ts.isExportAssignment(node)) {
245
+ const defaultModifier = this.findChildNode(node, ts.SyntaxKind.DefaultKeyword);
246
+ return [
247
+ ...node.modifiers ? (_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.filter(ts.isModifier).map(this.mapModifier) : [],
248
+ ...defaultModifier && ts.isModifier(defaultModifier) ? [this.mapModifier(defaultModifier)] : []
249
+ ];
240
250
  }
241
251
  else if (ts.isVariableDeclarationList(node)) {
242
252
  let modifier;
@@ -367,6 +377,9 @@ class JavaScriptParserVisitor {
367
377
  visitNullKeyword(node) {
368
378
  return this.mapLiteral(node, null);
369
379
  }
380
+ visitNeverKeyword(node) {
381
+ return this.mapIdentifier(node, 'never');
382
+ }
370
383
  mapLiteral(node, value) {
371
384
  return new J.Literal((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, value, node.getText(), null, this.mapPrimitiveType(node));
372
385
  }
@@ -395,9 +408,6 @@ class JavaScriptParserVisitor {
395
408
  return this.mapLiteral(node, node.text);
396
409
  }
397
410
  visitIdentifier(node) {
398
- if (node.text === 'undefined') {
399
- return this.mapLiteral(node, undefined);
400
- }
401
411
  return this.mapIdentifier(node, node.text);
402
412
  }
403
413
  mapIdentifier(node, name, withType = true) {
@@ -425,16 +435,16 @@ class JavaScriptParserVisitor {
425
435
  }
426
436
  visitParameter(node) {
427
437
  if (node.questionToken) {
428
- 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))]);
438
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
429
439
  }
430
440
  if (node.dotDotDotToken) {
431
- 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)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.visit(node.name), this.mapType(node)), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
441
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.visit(node.name), this.mapType(node)), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
432
442
  }
433
443
  const nameExpression = this.visit(node.name);
434
444
  if (nameExpression instanceof J.Identifier) {
435
- 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))]);
445
+ return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
436
446
  }
437
- 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))]);
447
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
438
448
  }
439
449
  visitDecorator(node) {
440
450
  let annotationType;
@@ -464,13 +474,13 @@ class JavaScriptParserVisitor {
464
474
  }
465
475
  visitPropertyDeclaration(node) {
466
476
  if (node.questionToken) {
467
- 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)]);
477
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
468
478
  }
469
479
  const nameExpression = this.visit(node.name);
470
480
  if (nameExpression instanceof J.Identifier) {
471
- 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))]);
481
+ return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), this.suffix(node.name))]);
472
482
  }
473
- 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)]);
483
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.initializer) - 1)), this.visit(node.initializer)) : null, this.mapVariableType(node)), java_1.Space.EMPTY)]);
474
484
  }
475
485
  visitMethodSignature(node) {
476
486
  if (node.questionToken) {
@@ -485,10 +495,11 @@ class JavaScriptParserVisitor {
485
495
  if (node.questionToken) {
486
496
  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));
487
497
  }
488
- if (ts.isComputedPropertyName(node.name)) {
489
- 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.convert(node.name), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
498
+ const name = node.name ? this.visit(node.name) : this.mapIdentifier(node, "");
499
+ if (!(name instanceof J.Identifier)) {
500
+ return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), name, this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
490
501
  }
491
- 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));
502
+ return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), this.mapModifiers(node), this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(name, []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, node.body ? this.convert(node.body) : null, null, this.mapMethodType(node));
492
503
  }
493
504
  mapTypeInfo(node) {
494
505
  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;
@@ -518,7 +529,7 @@ class JavaScriptParserVisitor {
518
529
  return new JS.IndexSignatureDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.mapCommaSeparatedList(this.getParameterListNodes(node, ts.SyntaxKind.OpenBracketToken)), this.leftPadded(this.prefix(node.getChildAt(node.getChildren().indexOf(node.type) - 1)), this.convert(node.type)), this.mapType(node));
519
530
  }
520
531
  visitTypePredicate(node) {
521
- return this.visitUnknown(node);
532
+ return new JS.TypePredicate((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.assertsModifier ? this.leftPadded(this.prefix(node.assertsModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), this.visit(node.parameterName), node.type ? this.leftPadded(this.suffix(node.parameterName), this.convert(node.type)) : null, this.mapType(node));
522
533
  }
523
534
  visitTypeReference(node) {
524
535
  if (node.typeArguments) {
@@ -527,10 +538,10 @@ class JavaScriptParserVisitor {
527
538
  return this.visit(node.typeName);
528
539
  }
529
540
  visitFunctionType(node) {
530
- return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), new java_1.JContainer(this.prefix(node), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
541
+ return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
531
542
  }
532
543
  visitConstructorType(node) {
533
- return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword))), new java_1.JContainer(this.prefix(node), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
544
+ return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword))), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p))), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
534
545
  }
535
546
  visitTypeQuery(node) {
536
547
  return new JS.TypeQuery((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.exprName), this.mapType(node));
@@ -574,13 +585,13 @@ class JavaScriptParserVisitor {
574
585
  return new JS.ConditionalType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.checkType), new java_1.JContainer(this.prefix(this.findChildNode(node, ts.SyntaxKind.ExtendsKeyword)), [this.rightPadded(new J.Ternary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.convert(node.extendsType), this.leftPadded(this.suffix(node.extendsType), this.convert(node.trueType)), this.leftPadded(this.suffix(node.trueType), this.convert(node.falseType)), this.mapType(node)), java_1.Space.EMPTY)], core_1.Markers.EMPTY), this.mapType(node));
575
586
  }
576
587
  visitInferType(node) {
577
- return this.visitUnknown(node);
588
+ return new JS.InferType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, this.convert(node.typeParameter)), this.mapType(node));
578
589
  }
579
590
  visitParenthesizedType(node) {
580
- return this.visitUnknown(node);
591
+ return new J.ParenthesizedTypeTree((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], new J.Parentheses((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.type), this.prefix(node.getLastToken()))));
581
592
  }
582
593
  visitThisType(node) {
583
- return this.visitUnknown(node);
594
+ return this.mapIdentifier(node, 'this');
584
595
  }
585
596
  visitTypeOperator(node) {
586
597
  function mapTypeOperator(operator) {
@@ -594,16 +605,22 @@ class JavaScriptParserVisitor {
594
605
  return new JS.TypeOperator((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, mapTypeOperator(node.operator), this.leftPadded(this.prefix(node.type), this.visit(node.type)));
595
606
  }
596
607
  visitIndexedAccessType(node) {
597
- return this.visitUnknown(node);
608
+ return new JS.IndexedAccessType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.objectType), this.rightPadded(new JS.IndexedAccessType.IndexType((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBracketToken)), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.indexType), this.suffix(node.indexType)), this.mapType(node.indexType)), this.suffix(this.findChildNode(node, ts.SyntaxKind.CloseBracketToken))), this.mapType(node));
598
609
  }
599
610
  visitMappedType(node) {
600
611
  return this.visitUnknown(node);
601
612
  }
602
613
  visitLiteralType(node) {
603
- return this.visit(node.literal);
614
+ return new JS.LiteralType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.literal), this.mapType(node));
604
615
  }
605
616
  visitNamedTupleMember(node) {
606
- return this.visitUnknown(node);
617
+ if (node.questionToken) {
618
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.getOptionalUnary(node), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
619
+ }
620
+ if (node.dotDotDotToken) {
621
+ return new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [this.rightPadded(new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.visit(node.name), this.mapType(node)), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
622
+ }
623
+ return new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node), null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), this.prefix(node.name), core_1.Markers.EMPTY, this.visit(node.name), [], null, this.mapVariableType(node)), this.suffix(node.name))]);
607
624
  }
608
625
  visitTemplateLiteralType(node) {
609
626
  return new JS.TemplateExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.head), node.templateSpans.map(s => this.rightPadded(this.visit(s), this.suffix(s))), this.mapType(node));
@@ -612,7 +629,7 @@ class JavaScriptParserVisitor {
612
629
  return new JS.TemplateExpression.TemplateSpan((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.type), this.visit(node.literal));
613
630
  }
614
631
  visitImportType(node) {
615
- return this.visitUnknown(node);
632
+ return new JS.ImportType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.isTypeOf ? this.rightPadded(true, this.suffix(this.findChildNode(node, ts.SyntaxKind.TypeOfKeyword))) : this.rightPadded(false, java_1.Space.EMPTY), new J.ParenthesizedTypeTree((0, core_1.randomId)(), this.suffix(this.findChildNode(node, ts.SyntaxKind.ImportKeyword)), core_1.Markers.EMPTY, [], new J.Parentheses((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.rightPadded(this.visit(node.argument), this.suffix(node.argument)))), node.qualifier ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.DotToken)), this.visit(node.qualifier)) : null, node.typeArguments ? this.mapTypeArguments(this.suffix(node.qualifier), node.typeArguments) : null, this.mapType(node));
616
633
  }
617
634
  visitObjectBindingPattern(node) {
618
635
  return new JS.ObjectBindingDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], null, this.mapCommaSeparatedList(node.getChildren(this.sourceFile)), null);
@@ -669,6 +686,9 @@ class JavaScriptParserVisitor {
669
686
  }
670
687
  return new J.MethodInvocation((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, select, typeArguments, name, this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), this.mapMethodType(node));
671
688
  }
689
+ visitSuperKeyword(node) {
690
+ return this.mapIdentifier(node, node.getText());
691
+ }
672
692
  visitNewExpression(node) {
673
693
  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));
674
694
  }
@@ -682,7 +702,7 @@ class JavaScriptParserVisitor {
682
702
  return new J.ParenthesizedTypeTree((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], new J.Parentheses((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.convert(node.expression), this.prefix(node.getLastToken()))));
683
703
  }
684
704
  visitFunctionExpression(node) {
685
- return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], node.name ? this.visit(node.name) : null, this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
705
+ return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), !!node.asteriskToken), this.leftPadded(node.asteriskToken ? this.prefix(node.asteriskToken) : java_1.Space.EMPTY, node.name ? this.visit(node.name) : new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], "", null, null)), this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
686
706
  }
687
707
  visitArrowFunction(node) {
688
708
  const openParenToken = this.findChildNode(node, ts.SyntaxKind.OpenParenToken);
@@ -760,6 +780,12 @@ class JavaScriptParserVisitor {
760
780
  case ts.SyntaxKind.QuestionQuestionToken:
761
781
  binaryOperator = JS.JsBinary.Type.QuestionQuestion;
762
782
  break;
783
+ case ts.SyntaxKind.InKeyword:
784
+ binaryOperator = JS.JsBinary.Type.In;
785
+ break;
786
+ case ts.SyntaxKind.CommaToken:
787
+ binaryOperator = JS.JsBinary.Type.Comma;
788
+ break;
763
789
  }
764
790
  if (binaryOperator !== undefined) {
765
791
  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));
@@ -769,7 +795,22 @@ class JavaScriptParserVisitor {
769
795
  }
770
796
  binaryOperator = this.mapBinaryOperator(node);
771
797
  if (binaryOperator === undefined) {
772
- const assignmentOperation = this.mapAssignmentOperation(node);
798
+ let assignmentOperation;
799
+ switch (node.operatorToken.kind) {
800
+ case ts.SyntaxKind.QuestionQuestionEqualsToken:
801
+ assignmentOperation = JS.JsAssignmentOperation.Type.QuestionQuestion;
802
+ break;
803
+ case ts.SyntaxKind.AmpersandAmpersandEqualsToken:
804
+ assignmentOperation = JS.JsAssignmentOperation.Type.And;
805
+ break;
806
+ case ts.SyntaxKind.BarBarEqualsToken:
807
+ assignmentOperation = JS.JsAssignmentOperation.Type.Or;
808
+ break;
809
+ }
810
+ if (assignmentOperation !== undefined) {
811
+ return new JS.JsAssignmentOperation((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.left), this.leftPadded(this.prefix(node.operatorToken), assignmentOperation), this.convert(node.right), this.mapType(node));
812
+ }
813
+ assignmentOperation = this.mapAssignmentOperation(node);
773
814
  if (assignmentOperation === undefined) {
774
815
  return this.visitUnknown(node);
775
816
  }
@@ -881,13 +922,13 @@ class JavaScriptParserVisitor {
881
922
  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));
882
923
  }
883
924
  visitMetaProperty(node) {
884
- return this.visitUnknown(node);
925
+ return new J.FieldAccess((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.keywordToken === ts.SyntaxKind.NewKeyword ? this.mapIdentifier(node, 'new') : this.mapIdentifier(node, 'import'), this.leftPadded(this.prefix(node.getChildAt(1, this.sourceFile)), this.convert(node.name)), this.mapType(node));
885
926
  }
886
927
  visitSyntheticExpression(node) {
887
928
  return this.visitUnknown(node);
888
929
  }
889
930
  visitSatisfiesExpression(node) {
890
- return this.visitUnknown(node);
931
+ return new JS.SatisfiesExpression((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression), this.leftPadded(this.suffix(node.expression), this.visit(node.type)), this.mapType(node));
891
932
  }
892
933
  visitTemplateSpan(node) {
893
934
  return new JS.TemplateExpression.TemplateSpan((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.expression), this.visit(node.literal));
@@ -929,18 +970,18 @@ class JavaScriptParserVisitor {
929
970
  var _a;
930
971
  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 ?
931
972
  (ts.isVariableDeclarationList(node.initializer) ? this.rightPadded(this.visit(node.initializer), java_1.Space.EMPTY) :
932
- this.rightPadded(this.convert(node.initializer), this.suffix(node.initializer.getLastToken()))) :
933
- 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())) :
934
- 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())) :
973
+ this.rightPadded(new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.initializer)), this.suffix(node.initializer.getLastToken()))) :
974
+ this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)))], node.condition ? this.rightPadded(ts.isStatement(node.condition) ? this.visit(node.condition) : new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.condition)), this.suffix(node.condition.getLastToken())) :
975
+ this.rightPadded(this.newJEmpty(), this.suffix(this.findChildNode(node, ts.SyntaxKind.SemicolonToken))), [node.incrementor ? this.rightPadded(ts.isStatement(node.incrementor) ? this.visit(node.incrementor) : new _1.ExpressionStatement((0, core_1.randomId)(), this.visit(node.incrementor)), this.suffix(node.incrementor.getLastToken())) :
935
976
  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));
936
977
  }
937
978
  visitForInStatement(node) {
938
979
  var _a;
939
- return new JS.JSForInLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.prefix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
980
+ return new JS.JSForInLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.suffix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
940
981
  }
941
982
  visitForOfStatement(node) {
942
983
  var _a;
943
- return new JS.JSForOfLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.awaitModifier ? this.leftPadded(this.prefix(node.awaitModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.prefix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
984
+ return new JS.JSForOfLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.awaitModifier ? this.leftPadded(this.prefix(node.awaitModifier), true) : this.leftPadded(java_1.Space.EMPTY, false), new JS.JSForInOfLoopControl((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.initializer), this.suffix(node.initializer)), this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
944
985
  }
945
986
  visitContinueStatement(node) {
946
987
  return new J.Continue((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.label ? this.visit(node.label) : null);
@@ -990,7 +1031,7 @@ class JavaScriptParserVisitor {
990
1031
  }));
991
1032
  }
992
1033
  visitFunctionDeclaration(node) {
993
- return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), node.name ? this.visit(node.name) : null, this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
1034
+ return new JS.FunctionDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword)), !!node.asteriskToken), this.leftPadded(node.asteriskToken ? this.prefix(node.asteriskToken) : java_1.Space.EMPTY, node.name ? this.visit(node.name) : new J.Identifier((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], "", null, null)), this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), this.convert(node.body), this.mapMethodType(node));
994
1035
  }
995
1036
  getParameterListNodes(node, openToken = ts.SyntaxKind.OpenParenToken) {
996
1037
  const children = node.getChildren(this.sourceFile);
@@ -1074,19 +1115,21 @@ class JavaScriptParserVisitor {
1074
1115
  : this.convert(node.name), this.mapType(node));
1075
1116
  }
1076
1117
  visitExportAssignment(node) {
1077
- return this.visitUnknown(node);
1118
+ return new JS.ExportAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(node.isExportEquals ? this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsToken)) : java_1.Space.EMPTY, (!!node.isExportEquals)), this.visit(node.expression));
1078
1119
  }
1079
1120
  visitExportDeclaration(node) {
1080
- return this.visitUnknown(node);
1121
+ return new JS.ExportDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(node.isTypeOnly ? this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)) : java_1.Space.EMPTY, node.isTypeOnly), node.exportClause ? this.visit(node.exportClause) : this.mapIdentifier(this.findChildNode(node, ts.SyntaxKind.AsteriskToken), "*"), node.moduleSpecifier ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FromKeyword)), this.visit(node.moduleSpecifier)) : null);
1081
1122
  }
1082
1123
  visitNamedExports(node) {
1083
- return this.visitUnknown(node);
1124
+ return new JS.NamedExports((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapCommaSeparatedList(node.getChildren()), this.mapType(node));
1084
1125
  }
1085
1126
  visitNamespaceExport(node) {
1086
- return this.visitUnknown(node);
1127
+ return new JS.Alias((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.mapIdentifier(this.findChildNode(node, ts.SyntaxKind.AsteriskToken), "*"), this.prefix(this.findChildNode(node, ts.SyntaxKind.AsKeyword))), this.visit(node.name));
1087
1128
  }
1088
1129
  visitExportSpecifier(node) {
1089
- return this.visitUnknown(node);
1130
+ return new JS.ExportSpecifier((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(node.isTypeOnly ? this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)) : java_1.Space.EMPTY, node.isTypeOnly), node.propertyName
1131
+ ? 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))
1132
+ : this.convert(node.name), this.mapType(node));
1090
1133
  }
1091
1134
  visitMissingDeclaration(node) {
1092
1135
  return this.visitUnknown(node);
@@ -1387,22 +1430,10 @@ class JavaScriptParserVisitor {
1387
1430
  : null;
1388
1431
  }
1389
1432
  mapTypeParametersAsObject(node) {
1390
- if (!node.typeParameters)
1433
+ const typeParameters = node.typeParameters;
1434
+ if (!typeParameters)
1391
1435
  return null;
1392
- let ts_prefix;
1393
- if (ts.isConstructSignatureDeclaration(node)) {
1394
- ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.NewKeyword));
1395
- }
1396
- else if (ts.isFunctionExpression(node)) {
1397
- ts_prefix = this.suffix(this.findChildNode(node, ts.SyntaxKind.FunctionKeyword));
1398
- }
1399
- else if (ts.isTypeAliasDeclaration(node)) {
1400
- ts_prefix = this.suffix(node.name);
1401
- }
1402
- else {
1403
- ts_prefix = node.questionToken ? this.suffix(node.questionToken) : node.name ? this.suffix(node.name) : java_1.Space.EMPTY;
1404
- }
1405
- 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))));
1436
+ return new J.TypeParameters((0, core_1.randomId)(), this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === typeParameters[0].pos) - 1)), core_1.Markers.EMPTY, [], typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp))));
1406
1437
  }
1407
1438
  mapTypeParametersList(typeParamsNodeArray) {
1408
1439
  return typeParamsNodeArray.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp)));