@openrewrite/rewrite 8.66.0-SNAPSHOT → 8.66.1

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.
Files changed (84) hide show
  1. package/dist/javascript/comparator.d.ts +91 -5
  2. package/dist/javascript/comparator.d.ts.map +1 -1
  3. package/dist/javascript/comparator.js +679 -3091
  4. package/dist/javascript/comparator.js.map +1 -1
  5. package/dist/javascript/format.d.ts.map +1 -1
  6. package/dist/javascript/format.js +4 -3
  7. package/dist/javascript/format.js.map +1 -1
  8. package/dist/javascript/index.d.ts +1 -1
  9. package/dist/javascript/index.d.ts.map +1 -1
  10. package/dist/javascript/index.js +1 -1
  11. package/dist/javascript/index.js.map +1 -1
  12. package/dist/javascript/parser.d.ts.map +1 -1
  13. package/dist/javascript/parser.js +22 -21
  14. package/dist/javascript/parser.js.map +1 -1
  15. package/dist/javascript/print.d.ts +2 -2
  16. package/dist/javascript/print.d.ts.map +1 -1
  17. package/dist/javascript/print.js +4 -4
  18. package/dist/javascript/print.js.map +1 -1
  19. package/dist/javascript/templating/capture.d.ts +226 -0
  20. package/dist/javascript/templating/capture.d.ts.map +1 -0
  21. package/dist/javascript/templating/capture.js +371 -0
  22. package/dist/javascript/templating/capture.js.map +1 -0
  23. package/dist/javascript/templating/comparator.d.ts +61 -0
  24. package/dist/javascript/templating/comparator.d.ts.map +1 -0
  25. package/dist/javascript/templating/comparator.js +393 -0
  26. package/dist/javascript/templating/comparator.js.map +1 -0
  27. package/dist/javascript/templating/engine.d.ts +75 -0
  28. package/dist/javascript/templating/engine.d.ts.map +1 -0
  29. package/dist/javascript/templating/engine.js +228 -0
  30. package/dist/javascript/templating/engine.js.map +1 -0
  31. package/dist/javascript/templating/index.d.ts +6 -0
  32. package/dist/javascript/templating/index.d.ts.map +1 -0
  33. package/dist/javascript/templating/index.js +42 -0
  34. package/dist/javascript/templating/index.js.map +1 -0
  35. package/dist/javascript/templating/pattern.d.ts +171 -0
  36. package/dist/javascript/templating/pattern.d.ts.map +1 -0
  37. package/dist/javascript/templating/pattern.js +681 -0
  38. package/dist/javascript/templating/pattern.js.map +1 -0
  39. package/dist/javascript/templating/placeholder-replacement.d.ts +58 -0
  40. package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -0
  41. package/dist/javascript/templating/placeholder-replacement.js +365 -0
  42. package/dist/javascript/templating/placeholder-replacement.js.map +1 -0
  43. package/dist/javascript/templating/rewrite.d.ts +39 -0
  44. package/dist/javascript/templating/rewrite.d.ts.map +1 -0
  45. package/dist/javascript/templating/rewrite.js +81 -0
  46. package/dist/javascript/templating/rewrite.js.map +1 -0
  47. package/dist/javascript/templating/template.d.ts +204 -0
  48. package/dist/javascript/templating/template.d.ts.map +1 -0
  49. package/dist/javascript/templating/template.js +293 -0
  50. package/dist/javascript/templating/template.js.map +1 -0
  51. package/dist/javascript/templating/types.d.ts +263 -0
  52. package/dist/javascript/templating/types.d.ts.map +1 -0
  53. package/dist/javascript/templating/types.js +3 -0
  54. package/dist/javascript/templating/types.js.map +1 -0
  55. package/dist/javascript/templating/utils.d.ts +118 -0
  56. package/dist/javascript/templating/utils.d.ts.map +1 -0
  57. package/dist/javascript/templating/utils.js +253 -0
  58. package/dist/javascript/templating/utils.js.map +1 -0
  59. package/dist/test/rewrite-test.d.ts.map +1 -1
  60. package/dist/test/rewrite-test.js +65 -9
  61. package/dist/test/rewrite-test.js.map +1 -1
  62. package/dist/version.txt +1 -1
  63. package/package.json +2 -2
  64. package/src/javascript/comparator.ts +721 -3607
  65. package/src/javascript/format.ts +3 -2
  66. package/src/javascript/index.ts +1 -1
  67. package/src/javascript/parser.ts +23 -22
  68. package/src/javascript/print.ts +6 -6
  69. package/src/javascript/templating/capture.ts +503 -0
  70. package/src/javascript/templating/comparator.ts +430 -0
  71. package/src/javascript/templating/engine.ts +252 -0
  72. package/src/javascript/templating/index.ts +60 -0
  73. package/src/javascript/templating/pattern.ts +727 -0
  74. package/src/javascript/templating/placeholder-replacement.ts +372 -0
  75. package/src/javascript/templating/rewrite.ts +95 -0
  76. package/src/javascript/templating/template.ts +326 -0
  77. package/src/javascript/templating/types.ts +300 -0
  78. package/src/javascript/templating/utils.ts +284 -0
  79. package/src/test/rewrite-test.ts +65 -1
  80. package/dist/javascript/templating.d.ts +0 -265
  81. package/dist/javascript/templating.d.ts.map +0 -1
  82. package/dist/javascript/templating.js +0 -1069
  83. package/dist/javascript/templating.js.map +0 -1
  84. package/src/javascript/templating.ts +0 -1277
@@ -826,7 +826,7 @@ export class MinimumViableSpacingVisitor<P> extends JavaScriptVisitor<P> {
826
826
  return produce(ret, draft => {
827
827
  if (draft.class) {
828
828
  if (draft.class.kind == JS.Kind.TypeTreeExpression) {
829
- this.ensureSpace((draft.class as Draft<JS.TypeTreeExpression>).expression.prefix);
829
+ this.ensureSpace((draft.class as Draft<JS.TypeTreeExpression>).prefix);
830
830
  }
831
831
  }
832
832
  });
@@ -941,7 +941,8 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
941
941
  tree = produce(tree as JS.StatementExpression, draft => {
942
942
  this.ensurePrefixHasNewLine(draft);
943
943
  });
944
- } else if (tree.kind === J.Kind.MethodDeclaration && this.cursor.value.kind != JS.Kind.StatementExpression) {
944
+ } else if (tree.kind === J.Kind.MethodDeclaration && this.cursor.value.kind != JS.Kind.StatementExpression
945
+ && (this.cursor.parent?.value.kind != JS.Kind.CompilationUnit || (this.cursor.parent?.value as JS.CompilationUnit).statements[0].element !== tree)) {
945
946
  tree = produce(tree as J.MethodDeclaration, draft => {
946
947
  this.ensurePrefixHasNewLine(draft);
947
948
  });
@@ -20,7 +20,7 @@ export * from "./parser";
20
20
  export * from "./style";
21
21
  export * from "./markers";
22
22
  export * from "./preconditions";
23
- export * from "./templating";
23
+ export * from "./templating/index";
24
24
  export * from "./method-matcher";
25
25
 
26
26
  export * from "./add-import";
@@ -612,13 +612,12 @@ export class JavaScriptParserVisitor {
612
612
  }
613
613
  for (let heritageClause of node.heritageClauses) {
614
614
  if (heritageClause.token == ts.SyntaxKind.ExtendsKeyword) {
615
- const expression = this.visit(heritageClause.types[0]);
616
615
  return this.leftPadded<TypeTree>(this.prefix(heritageClause.getFirstToken()!), {
617
616
  kind: JS.Kind.TypeTreeExpression,
618
617
  id: randomId(),
619
- prefix: emptySpace,
618
+ prefix: this.prefix(heritageClause.types[0]),
620
619
  markers: emptyMarkers,
621
- expression: expression
620
+ expression: this.visit(heritageClause.types[0])
622
621
  } satisfies JS.TypeTreeExpression as JS.TypeTreeExpression);
623
622
  }
624
623
  }
@@ -1493,7 +1492,7 @@ export class JavaScriptParserVisitor {
1493
1492
  element: {
1494
1493
  kind: J.Kind.Ternary,
1495
1494
  id: randomId(),
1496
- prefix: emptySpace,
1495
+ prefix: this.prefix(node.extendsType),
1497
1496
  markers: emptyMarkers,
1498
1497
  condition: this.convert(node.extendsType),
1499
1498
  truePart: this.leftPadded(this.suffix(node.extendsType), this.convert(node.trueType)),
@@ -1998,7 +1997,7 @@ export class JavaScriptParserVisitor {
1998
1997
  class: node.typeArguments ? {
1999
1998
  kind: J.Kind.ParameterizedType,
2000
1999
  id: randomId(),
2001
- prefix: emptySpace,
2000
+ prefix: this.prefix(node.expression),
2002
2001
  markers: emptyMarkers,
2003
2002
  class: {
2004
2003
  kind: JS.Kind.TypeTreeExpression,
@@ -2012,7 +2011,7 @@ export class JavaScriptParserVisitor {
2012
2011
  } satisfies J.ParameterizedType as J.ParameterizedType : {
2013
2012
  kind: JS.Kind.TypeTreeExpression,
2014
2013
  id: randomId(),
2015
- prefix: emptySpace,
2014
+ prefix: this.prefix(node.expression),
2016
2015
  markers: emptyMarkers,
2017
2016
  expression: this.visit(node.expression),
2018
2017
  } satisfies JS.TypeTreeExpression as JS.TypeTreeExpression,
@@ -2460,12 +2459,12 @@ export class JavaScriptParserVisitor {
2460
2459
  return {
2461
2460
  kind: JS.Kind.StatementExpression,
2462
2461
  id: randomId(),
2463
- prefix: emptySpace,
2462
+ prefix: this.prefix(node),
2464
2463
  markers: emptyMarkers,
2465
2464
  statement: {
2466
2465
  kind: J.Kind.Yield,
2467
2466
  id: randomId(),
2468
- prefix: this.prefix(node),
2467
+ prefix: emptySpace,
2469
2468
  markers: node.asteriskToken ?
2470
2469
  markers({
2471
2470
  kind: JS.Markers.DelegatedYield,
@@ -2492,12 +2491,12 @@ export class JavaScriptParserVisitor {
2492
2491
  return {
2493
2492
  kind: JS.Kind.StatementExpression,
2494
2493
  id: randomId(),
2495
- prefix: emptySpace,
2494
+ prefix: this.prefix(node),
2496
2495
  markers: emptyMarkers,
2497
2496
  statement: {
2498
2497
  kind: J.Kind.ClassDeclaration,
2499
2498
  id: randomId(),
2500
- prefix: this.prefix(node),
2499
+ prefix: emptySpace,
2501
2500
  markers: emptyMarkers,
2502
2501
  leadingAnnotations: this.mapDecorators(node),
2503
2502
  modifiers: [],
@@ -2637,25 +2636,27 @@ export class JavaScriptParserVisitor {
2637
2636
  }
2638
2637
 
2639
2638
  visitVariableStatement(node: ts.VariableStatement): JS.ScopedVariableDeclarations | J.VariableDeclarations {
2639
+ const prefix = this.prefix(node);
2640
2640
  return produce(this.visitVariableDeclarationList(node.declarationList), draft => {
2641
- if (node.modifiers) {
2642
- draft.modifiers = this.mapModifiers(node).concat(draft.modifiers);
2643
- }
2644
- draft.prefix = this.prefix(node);
2641
+ draft.prefix = prefix;
2642
+ draft.modifiers = this.mapModifiers(node).concat(draft.modifiers);
2645
2643
  });
2646
2644
  }
2647
2645
 
2648
2646
  visitExpressionStatement(node: ts.ExpressionStatement): Statement {
2649
- const expression = this.visit(node.expression) as Expression;
2647
+ const expression: Expression = this.visit(node.expression) as Expression;
2650
2648
  if (isStatement(expression)) {
2651
2649
  return expression as Statement;
2652
2650
  }
2651
+ const e: Expression = expression;
2653
2652
  return {
2654
2653
  kind: JS.Kind.ExpressionStatement,
2655
2654
  id: randomId(),
2656
- prefix: emptySpace,
2655
+ prefix: e.prefix,
2657
2656
  markers: emptyMarkers,
2658
- expression: expression
2657
+ expression: produce(e, draft => {
2658
+ draft.prefix = emptySpace
2659
+ })
2659
2660
  } satisfies JS.ExpressionStatement as JS.ExpressionStatement;
2660
2661
  }
2661
2662
 
@@ -2768,7 +2769,7 @@ export class JavaScriptParserVisitor {
2768
2769
  update: [node.incrementor ? this.rightPadded(ts.isStatement(node.incrementor) ? this.visit(node.incrementor) : {
2769
2770
  kind: JS.Kind.ExpressionStatement,
2770
2771
  id: randomId(),
2771
- prefix: emptySpace,
2772
+ prefix: this.prefix(node.incrementor),
2772
2773
  markers: emptyMarkers,
2773
2774
  expression: this.visit(node.incrementor)
2774
2775
  }, this.suffix(node.incrementor)) :
@@ -3064,7 +3065,7 @@ export class JavaScriptParserVisitor {
3064
3065
  modifiers.push({
3065
3066
  kind: J.Kind.Modifier,
3066
3067
  id: randomId(),
3067
- prefix: this.prefix(kind),
3068
+ prefix: modifiers.length === 0 ? this.prefix(kind) : this.prefix(kind),
3068
3069
  markers: emptyMarkers,
3069
3070
  annotations: [],
3070
3071
  keyword: kind.kind === ts.SyntaxKind.VarKeyword ? 'var' :
@@ -3263,7 +3264,7 @@ export class JavaScriptParserVisitor {
3263
3264
  {
3264
3265
  kind: J.Kind.EnumValueSet,
3265
3266
  id: randomId(),
3266
- prefix: emptySpace,
3267
+ prefix: node.members[0] ? this.prefix(node.members[0]) : emptySpace,
3267
3268
  markers: emptyMarkers,
3268
3269
  enums: node.members.map(em => this.rightPadded(this.visit(em), this.suffix(em))),
3269
3270
  terminatedWithSemicolon: node.members.hasTrailingComma
@@ -3323,7 +3324,7 @@ export class JavaScriptParserVisitor {
3323
3324
  return {
3324
3325
  kind: JS.Kind.NamespaceDeclaration,
3325
3326
  id: randomId(),
3326
- prefix: node.parent.kind === ts.SyntaxKind.ModuleBlock ? this.prefix(node) : emptySpace,
3327
+ prefix: this.prefix(node),
3327
3328
  markers: emptyMarkers,
3328
3329
  modifiers: this.mapModifiers(node),
3329
3330
  keywordType: this.leftPadded(
@@ -3457,7 +3458,7 @@ export class JavaScriptParserVisitor {
3457
3458
  const typeKeyword = node.getChildren().find(n => n.kind === ts.SyntaxKind.TypeKeyword);
3458
3459
  return this.prefix(typeKeyword!);
3459
3460
  } else {
3460
- return emptySpace;
3461
+ return this.prefix(node.name);
3461
3462
  }
3462
3463
  })(),
3463
3464
  markers: emptyMarkers,
@@ -75,16 +75,16 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
75
75
  }
76
76
 
77
77
  override async visitExpressionStatement(statement: JS.ExpressionStatement, p: PrintOutputCapture): Promise<J | undefined> {
78
- await this.visitSpace(statement.prefix, p);
79
- await this.visitMarkers(statement.markers, p);
78
+ await this.beforeSyntax(statement, p);
80
79
  await this.visit(statement.expression, p);
80
+ await this.afterSyntax(statement, p);
81
81
  return statement;
82
82
  }
83
83
 
84
84
  override async visitStatementExpression(statementExpression: JS.StatementExpression, p: PrintOutputCapture): Promise<J | undefined> {
85
- await this.visitSpace(statementExpression.prefix, p);
86
- await this.visitMarkers(statementExpression.markers, p);
85
+ await this.beforeSyntax(statementExpression, p);
87
86
  await this.visit(statementExpression.statement, p);
87
+ await this.afterSyntax(statementExpression, p);
88
88
  return statementExpression;
89
89
  }
90
90
 
@@ -1767,7 +1767,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
1767
1767
  return cursor;
1768
1768
  }
1769
1769
 
1770
- private async afterSyntax(j: J, p: PrintOutputCapture) {
1770
+ protected async afterSyntax(j: J, p: PrintOutputCapture) {
1771
1771
  await this.afterSyntaxMarkers(j.markers, p);
1772
1772
  }
1773
1773
 
@@ -1777,7 +1777,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
1777
1777
  }
1778
1778
  }
1779
1779
 
1780
- private async beforeSyntax(j: J, p: PrintOutputCapture) {
1780
+ protected async beforeSyntax(j: J, p: PrintOutputCapture) {
1781
1781
  await this.beforeSyntaxExt(j.prefix, j.markers, p);
1782
1782
  }
1783
1783