@openrewrite/rewrite 8.92.16 → 8.92.17

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 (79) hide show
  1. package/dist/javascript/comparator.d.ts.map +1 -1
  2. package/dist/javascript/comparator.js +4 -0
  3. package/dist/javascript/comparator.js.map +1 -1
  4. package/dist/javascript/format/tabs-and-indents-visitor.d.ts.map +1 -1
  5. package/dist/javascript/format/tabs-and-indents-visitor.js +31 -4
  6. package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
  7. package/dist/javascript/markers.d.ts +12 -0
  8. package/dist/javascript/markers.d.ts.map +1 -1
  9. package/dist/javascript/markers.js +17 -2
  10. package/dist/javascript/markers.js.map +1 -1
  11. package/dist/javascript/node-resolution-result.js +3 -2
  12. package/dist/javascript/node-resolution-result.js.map +1 -1
  13. package/dist/javascript/parser.d.ts +9 -0
  14. package/dist/javascript/parser.d.ts.map +1 -1
  15. package/dist/javascript/parser.js +185 -88
  16. package/dist/javascript/parser.js.map +1 -1
  17. package/dist/javascript/print.d.ts +10 -1
  18. package/dist/javascript/print.d.ts.map +1 -1
  19. package/dist/javascript/print.js +120 -77
  20. package/dist/javascript/print.js.map +1 -1
  21. package/dist/javascript/templating/engine.d.ts.map +1 -1
  22. package/dist/javascript/templating/engine.js +8 -3
  23. package/dist/javascript/templating/engine.js.map +1 -1
  24. package/dist/javascript/type-mapping.d.ts +1 -0
  25. package/dist/javascript/type-mapping.d.ts.map +1 -1
  26. package/dist/javascript/type-mapping.js +18 -3
  27. package/dist/javascript/type-mapping.js.map +1 -1
  28. package/dist/print.d.ts +6 -1
  29. package/dist/print.d.ts.map +1 -1
  30. package/dist/print.js +21 -7
  31. package/dist/print.js.map +1 -1
  32. package/dist/rewrite-javascript-version.txt +1 -1
  33. package/dist/rpc/java-rpc-client.d.ts +2 -0
  34. package/dist/rpc/java-rpc-client.d.ts.map +1 -1
  35. package/dist/rpc/java-rpc-client.js +1 -0
  36. package/dist/rpc/java-rpc-client.js.map +1 -1
  37. package/dist/rpc/queue.d.ts +8 -0
  38. package/dist/rpc/queue.d.ts.map +1 -1
  39. package/dist/rpc/queue.js +45 -3
  40. package/dist/rpc/queue.js.map +1 -1
  41. package/dist/rpc/request/get-object.d.ts +4 -0
  42. package/dist/rpc/request/get-object.d.ts.map +1 -1
  43. package/dist/rpc/request/get-object.js +23 -1
  44. package/dist/rpc/request/get-object.js.map +1 -1
  45. package/dist/rpc/request/parse.d.ts.map +1 -1
  46. package/dist/rpc/request/parse.js +3 -1
  47. package/dist/rpc/request/parse.js.map +1 -1
  48. package/dist/rpc/request/print.d.ts +8 -2
  49. package/dist/rpc/request/print.d.ts.map +1 -1
  50. package/dist/rpc/request/print.js +12 -9
  51. package/dist/rpc/request/print.js.map +1 -1
  52. package/dist/rpc/rewrite-rpc.d.ts +3 -2
  53. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  54. package/dist/rpc/rewrite-rpc.js +9 -3
  55. package/dist/rpc/rewrite-rpc.js.map +1 -1
  56. package/dist/rpc/server.d.ts.map +1 -1
  57. package/dist/rpc/server.js +19 -5
  58. package/dist/rpc/server.js.map +1 -1
  59. package/dist/test/java-rpc.d.ts.map +1 -1
  60. package/dist/test/java-rpc.js +3 -0
  61. package/dist/test/java-rpc.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/javascript/comparator.ts +10 -0
  64. package/src/javascript/format/tabs-and-indents-visitor.ts +30 -3
  65. package/src/javascript/markers.ts +34 -4
  66. package/src/javascript/node-resolution-result.ts +3 -2
  67. package/src/javascript/parser.ts +200 -91
  68. package/src/javascript/print.ts +123 -76
  69. package/src/javascript/templating/engine.ts +7 -2
  70. package/src/javascript/type-mapping.ts +19 -3
  71. package/src/print.ts +23 -8
  72. package/src/rpc/java-rpc-client.ts +3 -0
  73. package/src/rpc/queue.ts +37 -3
  74. package/src/rpc/request/get-object.ts +24 -0
  75. package/src/rpc/request/parse.ts +4 -1
  76. package/src/rpc/request/print.ts +12 -8
  77. package/src/rpc/rewrite-rpc.ts +16 -5
  78. package/src/rpc/server.ts +18 -6
  79. package/src/test/java-rpc.ts +3 -0
@@ -179,15 +179,42 @@ export class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
179
179
  // TemplateExpressionSpan: reset indent context - template literal content determines its own indentation
180
180
  // The expression inside ${...} should be indented based on where it appears in the template, not outer code
181
181
  if (tree.kind === JS.Kind.TemplateExpressionSpan) {
182
- // Extract base indent from the expression's prefix whitespace (after the last newline)
182
+ // Whitespace after ${ belongs to the span, not its child expression.
183
183
  const span = tree as JS.TemplateExpression.Span;
184
- const prefix = span.expression?.prefix?.whitespace ?? "";
184
+ const prefix = lastWhitespace(span.prefix);
185
185
  const lastNewline = prefix.lastIndexOf("\n");
186
186
  if (lastNewline >= 0) {
187
- return prefix.length - lastNewline - 1;
187
+ return this.indentWidth(prefix.substring(lastNewline + 1));
188
+ }
189
+ const template = this.cursor.parentTree()?.value as JS.TemplateExpression | undefined;
190
+ if (template?.kind === JS.Kind.TemplateExpression) {
191
+ const index = template.spans.findIndex(s => s.element.id === span.id);
192
+ const preceding = index > 0 ? template.spans[index - 1].element.tail : template.head;
193
+ const text = preceding.valueSource ?? "";
194
+ const newline = text.lastIndexOf("\n");
195
+ if (newline >= 0) {
196
+ // A span on a literal's own line is anchored to that line's indentation.
197
+ const indent = text.substring(newline + 1).match(/^[ \t]*/)?.[0] ?? "";
198
+ return this.indentWidth(indent);
199
+ }
200
+ }
201
+ // An inline interpolation continues the surrounding code line, not column zero.
202
+ for (let c = this.cursor.parent; c; c = c.parent) {
203
+ const parent = c.value as J;
204
+ if (parent?.prefix && spaceContainsNewline(parent.prefix)) {
205
+ return (c.messages.get("indentContext") as IndentContext | undefined)?.[0] ?? parentMyIndent;
206
+ }
188
207
  }
189
208
  return 0;
190
209
  }
210
+ // The tail prefix is the whitespace before }, not another continuation of the expression.
211
+ const parentTree = this.cursor.parentTree()?.value;
212
+ if (parentTree?.kind === JS.Kind.TemplateExpressionSpan &&
213
+ (parentTree as JS.TemplateExpression.Span).tail === tree) {
214
+ const prefix = lastWhitespace(tree.prefix);
215
+ const newline = prefix.lastIndexOf("\n");
216
+ return newline < 0 ? parentMyIndent : this.indentWidth(prefix.substring(newline + 1));
217
+ }
191
218
  if (tree.kind === J.Kind.IfElse || parentIndentKind === 'align') {
192
219
  return parentMyIndent;
193
220
  }
@@ -24,9 +24,10 @@ import {
24
24
  StyleKind,
25
25
  TabsAndIndentsStyle,
26
26
  WrappingAndBracesStyle,
27
- WrappingAndBracesStyleDetailKind
27
+ WrappingAndBracesStyleDetailKind,
28
+ prettierStyle
28
29
  } from "./style";
29
- import {Autodetect} from "./autodetect";
30
+ import {Autodetect, autodetect} from "./autodetect";
30
31
  import {updateIfChanged} from "../util";
31
32
 
32
33
  declare module "./tree" {
@@ -37,6 +38,7 @@ declare module "./tree" {
37
38
  readonly NonNullAssertion: "org.openrewrite.javascript.marker.NonNullAssertion";
38
39
  readonly DelegatedYield: "org.openrewrite.javascript.marker.DelegatedYield";
39
40
  readonly FunctionDeclaration: "org.openrewrite.javascript.marker.FunctionDeclaration";
41
+ readonly Computed: "org.openrewrite.javascript.marker.Computed";
40
42
  };
41
43
  }
42
44
  }
@@ -48,6 +50,7 @@ declare module "./tree" {
48
50
  Optional: "org.openrewrite.javascript.marker.Optional",
49
51
  NonNullAssertion: "org.openrewrite.javascript.marker.NonNullAssertion",
50
52
  FunctionDeclaration: "org.openrewrite.javascript.marker.FunctionDeclaration",
53
+ Computed: "org.openrewrite.javascript.marker.Computed",
51
54
  } as const;
52
55
 
53
56
  /**
@@ -80,6 +83,18 @@ export interface FunctionDeclaration extends Marker {
80
83
  readonly prefix: J.Space;
81
84
  }
82
85
 
86
+ /**
87
+ * A name written in brackets where the model has room for an identifier only, as the
88
+ * member of `enum A { ['b'] }` is. The identifier holds the bracketed literal.
89
+ */
90
+ export interface Computed extends Marker {
91
+ readonly kind: typeof JS.Markers.Computed;
92
+ /**
93
+ * The space before the closing bracket.
94
+ */
95
+ readonly suffix: J.Space;
96
+ }
97
+
83
98
  /**
84
99
  * Registers an RPC codec for any marker that has a `prefix: J.Space` field.
85
100
  */
@@ -107,11 +122,26 @@ registerPrefixedMarkerCodec<Generator>(JS.Markers.Generator);
107
122
  registerPrefixedMarkerCodec<NonNullAssertion>(JS.Markers.NonNullAssertion);
108
123
  registerPrefixedMarkerCodec<FunctionDeclaration>(JS.Markers.FunctionDeclaration);
109
124
 
125
+ RpcCodecs.registerCodec(JS.Markers.Computed, {
126
+ async rpcReceive(before: Computed, q: RpcReceiveQueue): Promise<Computed> {
127
+ return updateIfChanged(before, {
128
+ id: await q.receive(before.id),
129
+ suffix: await q.receive(before.suffix),
130
+ });
131
+ },
132
+
133
+ async rpcSend(after: Computed, q: RpcSendQueue): Promise<void> {
134
+ await q.getAndSend(after, a => a.id);
135
+ await q.getAndSend(after, a => a.suffix);
136
+ }
137
+ });
138
+
110
139
  // Register codec for PrettierStyle (a NamedStyles that contains Prettier configuration)
111
140
  // Only serialize the variable fields; constant fields are defined in the interface
112
141
  RpcCodecs.registerCodec(StyleKind.PrettierStyle, {
113
142
  async rpcReceive(before: PrettierStyle, q: RpcReceiveQueue): Promise<PrettierStyle> {
114
- return updateIfChanged(before, {
143
+ // the fields that never vary are not sent, so a marker first met here does not have them yet
144
+ return updateIfChanged(before.name ? before : {...prettierStyle(before.id, {}), ...before}, {
115
145
  id: await q.receive(before.id),
116
146
  config: await q.receive(before.config),
117
147
  prettierVersion: await q.receive(before.prettierVersion),
@@ -131,7 +161,7 @@ RpcCodecs.registerCodec(StyleKind.PrettierStyle, {
131
161
  // Only serialize the variable fields (id, styles); constant fields are defined in the interface
132
162
  RpcCodecs.registerCodec(StyleKind.Autodetect, {
133
163
  async rpcReceive(before: Autodetect, q: RpcReceiveQueue): Promise<Autodetect> {
134
- return updateIfChanged(before, {
164
+ return updateIfChanged(before.name ? before : {...autodetect(before.id, []), ...before}, {
135
165
  id: await q.receive(before.id),
136
166
  styles: (await q.receiveList(before.styles))!,
137
167
  });
@@ -659,7 +659,7 @@ export function createNodeResolutionResultMarker(
659
659
  resolvedDependencies,
660
660
  packageManager,
661
661
  engines: normalizeEngines(packageJsonContent.engines),
662
- npmrcConfigs,
662
+ npmrcConfigs: npmrcConfigs?.length ? npmrcConfigs : undefined,
663
663
  } as NodeResolutionResult;
664
664
  }
665
665
 
@@ -1022,7 +1022,8 @@ RpcCodecs.registerCodec(NodeResolutionResultKind, {
1022
1022
  resolvedDependencies: (await q.receiveList(before.resolvedDependencies)) || [],
1023
1023
  packageManager: await q.receive(before.packageManager),
1024
1024
  engines: await q.receive(before.engines),
1025
- npmrcConfigs: (await q.receiveList(before.npmrcConfigs)) || undefined,
1025
+ // an empty list is how having none is sent
1026
+ npmrcConfigs: await q.receiveList(before.npmrcConfigs).then(configs => configs?.length ? configs : undefined),
1026
1027
  });
1027
1028
  },
1028
1029