@openrewrite/rewrite 8.66.0-20251029-104214 → 8.66.0-20251029-143725

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/version.txt CHANGED
@@ -1 +1 @@
1
- 8.66.0-20251029-103720
1
+ 8.66.0-20251029-143223
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.66.0-20251029-104214",
3
+ "version": "8.66.0-20251029-143725",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "homepage": "https://github.com/openrewrite/rewrite",
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import {JS} from "./tree";
17
17
  import {JavaScriptVisitor} from "./visitor";
18
- import {Comment, emptySpace, J, Statement} from "../java";
18
+ import {Comment, J, Statement} from "../java";
19
19
  import {Draft, produce} from "immer";
20
20
  import {Cursor, isScope, Tree} from "../tree";
21
21
  import {
@@ -85,13 +85,6 @@ export class NormalizeWhitespaceVisitor<P> extends JavaScriptVisitor<P> {
85
85
  }
86
86
  return super.postVisit(tree, p);
87
87
  }
88
-
89
- private concatenatePrefix(node: Draft<J>, right: J.Space) {
90
- // TODO look at https://github.com/openrewrite/rewrite/commit/990a366fab9e5656812d81d0eb15ecb6bfd2fde0#diff-ec2e977fe8f1e189735e71b817f8f1ebaf79c1490c0210652e8a559f7f7877de
91
- // and possibly incorporate it here - some special logic needed to merge comments better (?)
92
- node.prefix.comments = [...node.prefix.comments, ...right.comments];
93
- node.prefix.whitespace = node.prefix.whitespace + right.whitespace;
94
- }
95
88
  }
96
89
 
97
90
  export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
@@ -193,11 +186,6 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
193
186
 
194
187
  protected async visitClassDeclaration(classDecl: J.ClassDeclaration, p: P): Promise<J | undefined> {
195
188
  const ret = await super.visitClassDeclaration(classDecl, p) as J.ClassDeclaration;
196
- // TODO
197
- // if (c.leadingAnnotations.length > 1) {
198
- // c = {...c, leadingAnnotations: spaceBetweenAnnotations(c.leadingAnnotations)};
199
- // }
200
-
201
189
  // TODO typeParameters - IntelliJ doesn't seem to provide a setting for angleBrackets spacing for Typescript (while it does for Java),
202
190
  // thus we either introduce our own setting or just enforce the natural spacing with no setting
203
191
 
@@ -326,10 +314,6 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
326
314
  draft.parameters = await this.spaceBeforeContainer(draft.parameters, this.style.beforeParentheses.functionDeclarationParentheses);
327
315
 
328
316
  // TODO typeParameters handling - see visitClassDeclaration
329
- // TODO
330
- // if (m.leadingAnnotations.length > 1) {
331
- // m = m.withLeadingAnnotations(this.spaceBetweenAnnotations(m.leadingAnnotations));
332
- // }
333
317
  });
334
318
  }
335
319
 
@@ -349,11 +333,6 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
349
333
  draft.arguments.elements[0] = await this.spaceAfterRightPadded(await this.spaceBeforeRightPaddedElement(draft.arguments.elements[0], this.style.within.functionCallParentheses), false);
350
334
  }
351
335
  // TODO typeParameters handling - see visitClassDeclaration
352
-
353
- // TODO
354
- // m = m.getPadding().withArguments(spaceBefore(m.getPadding().getArguments(), style.getBeforeParentheses().getMethodCall()));
355
- // if (m.getArguments().isEmpty() || m.getArguments()[0] instanceof J.Empty) {
356
- // ...
357
336
  });
358
337
  }
359
338
 
@@ -445,6 +424,10 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
445
424
  }
446
425
  protected async visitVariable(variable: J.VariableDeclarations.NamedVariable, p: P): Promise<J | undefined> {
447
426
  const ret = await super.visitVariable(variable, p) as J.VariableDeclarations.NamedVariable;
427
+ if (variable.initializer?.element?.kind == JS.Kind.StatementExpression
428
+ && (variable.initializer.element as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration) {
429
+ return ret;
430
+ }
448
431
  return produceAsync(ret, async draft => {
449
432
  if (draft.initializer) {
450
433
  draft.initializer.before.whitespace = this.style.aroundOperators.assignment ? " " : "";
@@ -582,20 +565,6 @@ export class WrappingAndBracesVisitor<P> extends JavaScriptVisitor<P> {
582
565
  return super.postVisit(tree, p);
583
566
  }
584
567
 
585
- public async visitStatement(statement: Statement, p: P): Promise<Statement> {
586
- const j = await super.visitStatement(statement, p) as Statement;
587
- // TODO is it needed?
588
- // const parent = this.cursor.parentTree()?.value;
589
- // if (parent?.kind === J.Kind.Block && j.kind !== J.Kind.EnumValueSet) {
590
- // if (!j.prefix.whitespace.includes("\n")) {
591
- // return produce(j, draft => {
592
- // draft.prefix.whitespace = "\n" + draft.prefix.whitespace;
593
- // });
594
- // }
595
- // }
596
- return j;
597
- }
598
-
599
568
  protected async visitVariableDeclarations(multiVariable: J.VariableDeclarations, p: P): Promise<J.VariableDeclarations> {
600
569
  const v = await super.visitVariableDeclarations(multiVariable, p) as J.VariableDeclarations;
601
570
  const parent = this.cursor.parentTree()?.value;
@@ -968,7 +937,11 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
968
937
  });
969
938
  return super.visit(cu, p, cursor);
970
939
  }
971
- if (tree.kind === J.Kind.MethodDeclaration) {
940
+ if (tree.kind === JS.Kind.StatementExpression && (tree as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration) {
941
+ tree = produce(tree as JS.StatementExpression, draft => {
942
+ this.ensurePrefixHasNewLine(draft);
943
+ });
944
+ } else if (tree.kind === J.Kind.MethodDeclaration && this.cursor.value.kind != JS.Kind.StatementExpression) {
972
945
  tree = produce(tree as J.MethodDeclaration, draft => {
973
946
  this.ensurePrefixHasNewLine(draft);
974
947
  });
@@ -1060,8 +1033,6 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
1060
1033
  if (!draft.end.whitespace.includes("\n")) {
1061
1034
  draft.end.whitespace = draft.end.whitespace + "\n";
1062
1035
  }
1063
- // TODO check if it's relevant to TS/JS
1064
- // draft.end = this.keepMaximumLines(draft.end, this.style.keepMaximum.beforeEndOfBlock);
1065
1036
  });
1066
1037
  }
1067
1038
 
@@ -1070,17 +1041,6 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
1070
1041
  this.keepMaximumBlankLines(e, this.style.keepMaximum.inCode);
1071
1042
  return e;
1072
1043
  }
1073
- // TODO check if it's relevant to TS/JS
1074
- // protected async visitNewClass(newClass: J.NewClass, p: P): Promise<J.NewClass> {
1075
- // const j = await super.visitNewClass(newClass, p) as J.NewClass;
1076
- // if (!j.body) return j;
1077
- //
1078
- // return produce(j, draft => {
1079
- // if (draft.body!.statements.length > 0) {
1080
- // draft.body!.statements[0] = this.minimumLines(draft.body!.statements[0].whitespace, this.style.minimum.afterFunction ?? 0);
1081
- // }
1082
- // });
1083
- // }
1084
1044
 
1085
1045
  private keepMaximumBlankLines<T extends J>(node: Draft<T>, max: number) {
1086
1046
  const whitespace = node.prefix.whitespace;
@@ -1129,12 +1089,10 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
1129
1089
  }
1130
1090
 
1131
1091
  export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
1132
- private readonly newline: string;
1133
1092
  private readonly singleIndent: string;
1134
1093
 
1135
1094
  constructor(private readonly tabsAndIndentsStyle: TabsAndIndentsStyle, private stopAfter?: Tree) {
1136
1095
  super();
1137
- this.newline = "\n"; // TODO this should be configurable and come from some style too
1138
1096
 
1139
1097
  if (this.tabsAndIndentsStyle.useTabCharacter) {
1140
1098
  this.singleIndent = "\t";
@@ -1149,7 +1107,7 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
1149
1107
  let indentShouldIncrease =
1150
1108
  tree.kind === J.Kind.Block
1151
1109
  || this.cursor.parent?.parent?.parent?.value.kind == J.Kind.Case
1152
- || (tree.kind === J.Kind.MethodDeclaration && this.cursor.parent?.value.kind === JS.Kind.StatementExpression);
1110
+ || (tree.kind === JS.Kind.StatementExpression && (tree as JS.StatementExpression).statement.kind == J.Kind.MethodDeclaration);
1153
1111
 
1154
1112
  const previousIndent = this.currentIndent;
1155
1113
 
@@ -3131,12 +3131,15 @@ export class JavaScriptParserVisitor {
3131
3131
  }
3132
3132
 
3133
3133
  visitFunctionExpression(node: ts.FunctionExpression): JS.StatementExpression {
3134
+ const delegate = this.mapFunctionDeclaration(node);
3134
3135
  return {
3135
3136
  kind: JS.Kind.StatementExpression,
3136
3137
  id: randomId(),
3137
- prefix: emptySpace,
3138
+ prefix: delegate.prefix,
3138
3139
  markers: emptyMarkers,
3139
- statement: this.mapFunctionDeclaration(node)
3140
+ statement: produce(delegate, draft => {
3141
+ draft.prefix = emptySpace;
3142
+ })
3140
3143
  };
3141
3144
  }
3142
3145