@openrewrite/rewrite 8.53.0 → 8.53.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.
- package/dist/src/java/visitor.d.ts.map +1 -1
- package/dist/src/java/visitor.js +10 -0
- package/dist/src/java/visitor.js.map +1 -1
- package/dist/src/javascript/assertions.d.ts +2 -0
- package/dist/src/javascript/assertions.d.ts.map +1 -1
- package/dist/src/javascript/assertions.js +20 -0
- package/dist/src/javascript/assertions.js.map +1 -1
- package/dist/src/javascript/format.d.ts +62 -44
- package/dist/src/javascript/format.d.ts.map +1 -1
- package/dist/src/javascript/format.js +244 -12
- package/dist/src/javascript/format.js.map +1 -1
- package/dist/src/javascript/parser.d.ts +11 -15
- package/dist/src/javascript/parser.d.ts.map +1 -1
- package/dist/src/javascript/parser.js +136 -56
- package/dist/src/javascript/parser.js.map +1 -1
- package/dist/src/javascript/print.d.ts +7 -3
- package/dist/src/javascript/print.d.ts.map +1 -1
- package/dist/src/javascript/print.js +93 -35
- package/dist/src/javascript/print.js.map +1 -1
- package/dist/src/javascript/rpc.js +83 -0
- package/dist/src/javascript/rpc.js.map +1 -1
- package/dist/src/javascript/style.d.ts +19 -6
- package/dist/src/javascript/style.d.ts.map +1 -1
- package/dist/src/javascript/style.js +31 -4
- package/dist/src/javascript/style.js.map +1 -1
- package/dist/src/javascript/tree.d.ts +48 -4
- package/dist/src/javascript/tree.d.ts.map +1 -1
- package/dist/src/javascript/tree.js +1 -1
- package/dist/src/javascript/tree.js.map +1 -1
- package/dist/src/javascript/visitor.d.ts +6 -1
- package/dist/src/javascript/visitor.d.ts.map +1 -1
- package/dist/src/javascript/visitor.js +59 -0
- package/dist/src/javascript/visitor.js.map +1 -1
- package/dist/src/tree.d.ts +1 -0
- package/dist/src/tree.d.ts.map +1 -1
- package/dist/src/tree.js +4 -0
- package/dist/src/tree.js.map +1 -1
- package/package.json +1 -1
- package/src/java/visitor.ts +12 -0
- package/src/javascript/assertions.ts +20 -0
- package/src/javascript/format.ts +254 -71
- package/src/javascript/parser.ts +195 -76
- package/src/javascript/print.ts +90 -39
- package/src/javascript/rpc.ts +78 -1
- package/src/javascript/style.ts +47 -9
- package/src/javascript/tree.ts +75 -4
- package/src/javascript/visitor.ts +56 -1
- package/src/tree.ts +5 -0
package/src/javascript/print.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
import {JS} from "./tree";
|
|
18
|
+
import {JS, JSX} from "./tree";
|
|
19
19
|
import {JavaScriptVisitor} from "./visitor";
|
|
20
20
|
import {PrintOutputCapture, TreePrinters} from "../print";
|
|
21
21
|
import {Cursor, isTree, Tree} from "../tree";
|
|
@@ -88,6 +88,71 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
88
88
|
return inferType;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
override async visitJsxTag(element: JSX.Tag, p: PrintOutputCapture): Promise<J | undefined> {
|
|
92
|
+
await this.beforeSyntax(element, p);
|
|
93
|
+
await this.visitLeftPaddedLocal("<", element.openName, p);
|
|
94
|
+
await this.visitSpace(element.afterName, p);
|
|
95
|
+
await this.visitRightPaddedLocal(element.attributes, "", p);
|
|
96
|
+
|
|
97
|
+
if (element.selfClosing) {
|
|
98
|
+
await this.visitSpace(element.selfClosing, p);
|
|
99
|
+
p.append("/>");
|
|
100
|
+
} else {
|
|
101
|
+
p.append(">");
|
|
102
|
+
if (element.children) {
|
|
103
|
+
await this.visitRightPaddedLocal(element.children, "", p);
|
|
104
|
+
await this.visitLeftPaddedLocal("</", element.closingName, p);
|
|
105
|
+
await this.visitSpace(element.afterClosingName, p);
|
|
106
|
+
p.append(">");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await this.afterSyntax(element, p);
|
|
111
|
+
return element;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override async visitJsxAttribute(attribute: JSX.Attribute, p: PrintOutputCapture): Promise<J | undefined> {
|
|
115
|
+
await this.beforeSyntax(attribute, p);
|
|
116
|
+
await this.visit(attribute.key, p);
|
|
117
|
+
if (attribute.value) {
|
|
118
|
+
p.append("=");
|
|
119
|
+
await this.visit(attribute.value.element, p);
|
|
120
|
+
}
|
|
121
|
+
await this.afterSyntax(attribute, p);
|
|
122
|
+
return attribute;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
override async visitJsxSpreadAttribute(spread: JSX.SpreadAttribute, p: PrintOutputCapture): Promise<J | undefined> {
|
|
126
|
+
await this.beforeSyntax(spread, p);
|
|
127
|
+
p.append("{");
|
|
128
|
+
await this.visitSpace(spread.dots, p);
|
|
129
|
+
p.append("...");
|
|
130
|
+
await this.visitRightPaddedLocal([spread.expression], "}", p);
|
|
131
|
+
p.append("}");
|
|
132
|
+
await this.afterSyntax(spread, p);
|
|
133
|
+
return spread;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
override async visitJsxExpression(expr: JSX.EmbeddedExpression, p: PrintOutputCapture): Promise<J | undefined> {
|
|
137
|
+
await this.beforeSyntax(expr, p);
|
|
138
|
+
p.append("{");
|
|
139
|
+
if (expr.expression) {
|
|
140
|
+
await this.visitRightPaddedLocal([expr.expression], "}", p);
|
|
141
|
+
}
|
|
142
|
+
p.append("}");
|
|
143
|
+
await this.afterSyntax(expr, p);
|
|
144
|
+
return expr;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
override async visitJsxNamespacedName(ns: JSX.NamespacedName, p: PrintOutputCapture): Promise<J | undefined> {
|
|
148
|
+
await this.beforeSyntax(ns, p);
|
|
149
|
+
await this.visit(ns.namespace, p);
|
|
150
|
+
p.append(":");
|
|
151
|
+
await this.visitLeftPadded(ns.name, p);
|
|
152
|
+
await this.afterSyntax(ns, p);
|
|
153
|
+
return ns;
|
|
154
|
+
}
|
|
155
|
+
|
|
91
156
|
override async visitImportDeclaration(jsImport: JS.Import, p: PrintOutputCapture): Promise<J | undefined> {
|
|
92
157
|
await this.beforeSyntax(jsImport, p);
|
|
93
158
|
p.append("import");
|
|
@@ -196,7 +261,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
196
261
|
p.append("try");
|
|
197
262
|
await this.visit(aTry.body, p);
|
|
198
263
|
await this.visitNodes(aTry.catches, p);
|
|
199
|
-
aTry.finally && await this.
|
|
264
|
+
aTry.finally && await this.visitLeftPaddedLocal("finally", aTry.finally, p);
|
|
200
265
|
await this.afterSyntax(aTry, p);
|
|
201
266
|
return aTry;
|
|
202
267
|
}
|
|
@@ -215,7 +280,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
215
280
|
override async visitArrayDimension(arrayDimension: J.ArrayDimension, p: PrintOutputCapture): Promise<J | undefined> {
|
|
216
281
|
await this.beforeSyntax(arrayDimension, p);
|
|
217
282
|
p.append("[");
|
|
218
|
-
await this.
|
|
283
|
+
await this.visitRightPaddedLocalSingle(arrayDimension.index, "]", p);
|
|
219
284
|
await this.afterSyntax(arrayDimension, p);
|
|
220
285
|
return arrayDimension;
|
|
221
286
|
}
|
|
@@ -265,8 +330,8 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
265
330
|
override async visitTernary(ternary: J.Ternary, p: PrintOutputCapture): Promise<J | undefined> {
|
|
266
331
|
await this.beforeSyntax(ternary, p);
|
|
267
332
|
await this.visit(ternary.condition, p);
|
|
268
|
-
await this.
|
|
269
|
-
await this.
|
|
333
|
+
await this.visitLeftPaddedLocal("?", ternary.truePart, p);
|
|
334
|
+
await this.visitLeftPaddedLocal(":", ternary.falsePart, p);
|
|
270
335
|
await this.afterSyntax(ternary, p);
|
|
271
336
|
return ternary;
|
|
272
337
|
}
|
|
@@ -301,7 +366,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
301
366
|
await this.beforeSyntax(doWhileLoop, p);
|
|
302
367
|
p.append("do");
|
|
303
368
|
await this.visitStatementLocal(doWhileLoop.body, p);
|
|
304
|
-
await this.
|
|
369
|
+
await this.visitLeftPaddedLocal("while", doWhileLoop.whileCondition, p);
|
|
305
370
|
await this.afterSyntax(doWhileLoop, p);
|
|
306
371
|
return doWhileLoop;
|
|
307
372
|
}
|
|
@@ -317,7 +382,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
317
382
|
|
|
318
383
|
override async visitInstanceOf(instanceOf: J.InstanceOf, p: PrintOutputCapture): Promise<J | undefined> {
|
|
319
384
|
await this.beforeSyntax(instanceOf, p);
|
|
320
|
-
await this.
|
|
385
|
+
await this.visitRightPaddedLocalSingle(instanceOf.expression, "instanceof", p);
|
|
321
386
|
await this.visit(instanceOf.class, p);
|
|
322
387
|
instanceOf.pattern && await this.visit(instanceOf.pattern, p);
|
|
323
388
|
await this.afterSyntax(instanceOf, p);
|
|
@@ -423,7 +488,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
423
488
|
}
|
|
424
489
|
|
|
425
490
|
if (variable.element.initializer) {
|
|
426
|
-
await this.
|
|
491
|
+
await this.visitLeftPaddedLocal("=", variable.element.initializer, p);
|
|
427
492
|
}
|
|
428
493
|
|
|
429
494
|
await this.afterSyntax(variable.element, p);
|
|
@@ -443,7 +508,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
443
508
|
await this.beforeSyntax(variable, p);
|
|
444
509
|
await this.visit(variable.name, p);
|
|
445
510
|
|
|
446
|
-
variable.initializer && await this.
|
|
511
|
+
variable.initializer && await this.visitLeftPaddedLocal("=", variable.initializer, p);
|
|
447
512
|
|
|
448
513
|
await this.afterSyntax(variable, p);
|
|
449
514
|
return variable;
|
|
@@ -608,7 +673,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
608
673
|
await this.visit(classDecl.name, p);
|
|
609
674
|
classDecl.typeParameters && await this.visitJContainerLocal("<", classDecl.typeParameters, ",", ">", p);
|
|
610
675
|
classDecl.primaryConstructor && await this.visitJContainerLocal("(", classDecl.primaryConstructor, ",", ")", p);
|
|
611
|
-
classDecl.extends && await this.
|
|
676
|
+
classDecl.extends && await this.visitLeftPaddedLocal("extends", classDecl.extends, p);
|
|
612
677
|
classDecl.implements && await this.visitJContainerLocal(classDecl.classKind.type === J.ClassDeclaration.Kind.Type.Interface ? "extends" : "implements",
|
|
613
678
|
classDecl.implements, ",", null, p);
|
|
614
679
|
await this.visit(classDecl.body, p);
|
|
@@ -696,7 +761,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
696
761
|
if (method.name.toString().length === 0) {
|
|
697
762
|
method.select && await this.visitRightPadded(method.select, p);
|
|
698
763
|
} else {
|
|
699
|
-
method.select && await this.
|
|
764
|
+
method.select && await this.visitRightPaddedLocalSingle(method.select, "", p);
|
|
700
765
|
await this.visit(method.name, p);
|
|
701
766
|
}
|
|
702
767
|
|
|
@@ -1099,7 +1164,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1099
1164
|
protected async visitComputedPropertyName(computedPropertyName: JS.ComputedPropertyName, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1100
1165
|
await this.beforeSyntax(computedPropertyName, p);
|
|
1101
1166
|
p.append("[");
|
|
1102
|
-
await this.
|
|
1167
|
+
await this.visitRightPaddedLocalSingle(computedPropertyName.expression, "]", p);
|
|
1103
1168
|
await this.afterSyntax(computedPropertyName, p);
|
|
1104
1169
|
return computedPropertyName;
|
|
1105
1170
|
}
|
|
@@ -1173,7 +1238,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1173
1238
|
|
|
1174
1239
|
override async visitNewClass(newClass: J.NewClass, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1175
1240
|
await this.beforeSyntax(newClass, p);
|
|
1176
|
-
newClass.enclosing && await this.
|
|
1241
|
+
newClass.enclosing && await this.visitRightPaddedLocalSingle(newClass.enclosing, ".", p);
|
|
1177
1242
|
await this.visitSpace(newClass.new, p);
|
|
1178
1243
|
|
|
1179
1244
|
if (newClass.class) {
|
|
@@ -1220,7 +1285,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1220
1285
|
|
|
1221
1286
|
override async visitLabel(label: J.Label, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1222
1287
|
await this.beforeSyntax(label, p);
|
|
1223
|
-
await this.
|
|
1288
|
+
await this.visitRightPaddedLocalSingle(label.label, ":", p);
|
|
1224
1289
|
await this.visit(label.statement, p);
|
|
1225
1290
|
await this.afterSyntax(label, p);
|
|
1226
1291
|
return label;
|
|
@@ -1246,7 +1311,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1246
1311
|
await this.beforeSyntax(fieldAccess, p);
|
|
1247
1312
|
await this.visit(fieldAccess.target, p);
|
|
1248
1313
|
|
|
1249
|
-
await this.
|
|
1314
|
+
await this.visitLeftPaddedLocal(".", fieldAccess.name, p);
|
|
1250
1315
|
await this.afterSyntax(fieldAccess, p);
|
|
1251
1316
|
return fieldAccess;
|
|
1252
1317
|
}
|
|
@@ -1263,7 +1328,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1263
1328
|
override async visitParentheses<T extends J>(parens: J.Parentheses<T>, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1264
1329
|
await this.beforeSyntax(parens, p);
|
|
1265
1330
|
p.append('(');
|
|
1266
|
-
await this.
|
|
1331
|
+
await this.visitRightPaddedLocalSingle(parens.tree, ")", p);
|
|
1267
1332
|
await this.afterSyntax(parens, p);
|
|
1268
1333
|
return parens;
|
|
1269
1334
|
}
|
|
@@ -1279,7 +1344,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1279
1344
|
override async visitAssignment(assignment: J.Assignment, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1280
1345
|
await this.beforeSyntax(assignment, p);
|
|
1281
1346
|
await this.visit(assignment.variable, p);
|
|
1282
|
-
await this.
|
|
1347
|
+
await this.visitLeftPaddedLocal("=", assignment.assignment, p);
|
|
1283
1348
|
await this.afterSyntax(assignment, p);
|
|
1284
1349
|
return assignment;
|
|
1285
1350
|
}
|
|
@@ -1588,7 +1653,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1588
1653
|
p.append('(');
|
|
1589
1654
|
await this.visitJRightPaddedLocal(ctrl.init, ",", p);
|
|
1590
1655
|
p.append(';');
|
|
1591
|
-
ctrl.condition && await this.
|
|
1656
|
+
ctrl.condition && await this.visitRightPaddedLocalSingle(ctrl.condition, ";", p);
|
|
1592
1657
|
await this.visitJRightPaddedLocal(ctrl.update, ",", p);
|
|
1593
1658
|
p.append(')');
|
|
1594
1659
|
await this.visitStatementLocal(forLoop.body, p);
|
|
@@ -1735,7 +1800,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1735
1800
|
return right;
|
|
1736
1801
|
}
|
|
1737
1802
|
|
|
1738
|
-
private async
|
|
1803
|
+
private async visitRightPaddedLocalSingle(node: J.RightPadded<J> | undefined, suffix: string, p: PrintOutputCapture) {
|
|
1739
1804
|
if (node) {
|
|
1740
1805
|
await this.visit(node.element, p);
|
|
1741
1806
|
|
|
@@ -1761,23 +1826,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1761
1826
|
}
|
|
1762
1827
|
}
|
|
1763
1828
|
|
|
1764
|
-
private async
|
|
1765
|
-
if (leftPadded) {
|
|
1766
|
-
await this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
|
|
1767
|
-
|
|
1768
|
-
if (prefix) {
|
|
1769
|
-
p.append(prefix);
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
if (typeof leftPadded.element !== 'boolean') {
|
|
1773
|
-
await this.visit(leftPadded.element, p);
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
await this.afterSyntaxMarkers(leftPadded.markers, p);
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
private async visitLeftPaddedLocal(prefix: string | undefined, leftPadded: J.LeftPadded<J> | J.LeftPadded<boolean> | undefined, p: PrintOutputCapture) {
|
|
1829
|
+
private async visitLeftPaddedLocal(prefix: string | undefined, leftPadded: J.LeftPadded<J> | J.LeftPadded<boolean> | J.LeftPadded<string> | undefined, p: PrintOutputCapture) {
|
|
1781
1830
|
if (leftPadded) {
|
|
1782
1831
|
await this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
|
|
1783
1832
|
|
|
@@ -1785,7 +1834,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1785
1834
|
p.append(prefix);
|
|
1786
1835
|
}
|
|
1787
1836
|
|
|
1788
|
-
if (typeof leftPadded.element
|
|
1837
|
+
if (typeof leftPadded.element === 'string') {
|
|
1838
|
+
p.append(leftPadded.element);
|
|
1839
|
+
} else if (typeof leftPadded.element !== 'boolean') {
|
|
1789
1840
|
await this.visit(leftPadded.element, p);
|
|
1790
1841
|
}
|
|
1791
1842
|
|
|
@@ -1888,10 +1939,10 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1888
1939
|
|
|
1889
1940
|
if (this.getParentCursor(1)?.value.kind === J.Kind.TypeCast) {
|
|
1890
1941
|
p.append('<');
|
|
1891
|
-
await this.
|
|
1942
|
+
await this.visitRightPaddedLocalSingle(controlParens.tree, ">", p);
|
|
1892
1943
|
} else {
|
|
1893
1944
|
p.append('(');
|
|
1894
|
-
await this.
|
|
1945
|
+
await this.visitRightPaddedLocalSingle(controlParens.tree, ")", p);
|
|
1895
1946
|
}
|
|
1896
1947
|
|
|
1897
1948
|
await this.afterSyntax(controlParens, p);
|
package/src/javascript/rpc.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {JavaScriptVisitor} from "./visitor";
|
|
17
17
|
import {asRef, RpcCodec, RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
|
|
18
|
-
import {isJavaScript, JS} from "./tree";
|
|
18
|
+
import {isJavaScript, JS, JSX} from "./tree";
|
|
19
19
|
import {Expression, J, JavaType, Statement, TypedTree, TypeTree} from "../java";
|
|
20
20
|
import {createDraft, finishDraft} from "immer";
|
|
21
21
|
import {JavaReceiver, JavaSender} from "../java/rpc";
|
|
@@ -371,6 +371,42 @@ class JavaScriptSender extends JavaScriptVisitor<RpcSendQueue> {
|
|
|
371
371
|
return withStatement;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
override async visitJsxTag(tag: JSX.Tag, q: RpcSendQueue): Promise<J | undefined> {
|
|
375
|
+
await q.getAndSend(tag, el => el.openName, el => this.visitLeftPadded(el, q));
|
|
376
|
+
await q.getAndSend(tag, el => el.afterName, space => this.visitSpace(space, q));
|
|
377
|
+
await q.getAndSendList(tag, el => el.attributes, attr => attr.element.id, attr => this.visitRightPadded(attr, q));
|
|
378
|
+
|
|
379
|
+
await q.getAndSend(tag, el => el.selfClosing, space => this.visitSpace(space, q));
|
|
380
|
+
await q.getAndSendList(tag, el => el.children!, child => child.element.id, child => this.visitRightPadded(child, q));
|
|
381
|
+
await q.getAndSend(tag, el => el.closingName, el => this.visitLeftPadded(el, q));
|
|
382
|
+
await q.getAndSend(tag, el => el.afterClosingName, el => this.visitSpace(el, q));
|
|
383
|
+
|
|
384
|
+
return tag;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
override async visitJsxAttribute(attribute: JSX.Attribute, q: RpcSendQueue): Promise<J | undefined> {
|
|
388
|
+
await q.getAndSend(attribute, el => el.key, el => this.visit(el, q));
|
|
389
|
+
await q.getAndSend(attribute, el => el.value, el => this.visitLeftPadded(el, q));
|
|
390
|
+
return attribute;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
override async visitJsxSpreadAttribute(spreadAttribute: JSX.SpreadAttribute, q: RpcSendQueue): Promise<J | undefined> {
|
|
394
|
+
await q.getAndSend(spreadAttribute, el => el.dots, space => this.visitSpace(space, q));
|
|
395
|
+
await q.getAndSend(spreadAttribute, el => el.expression, el => this.visitRightPadded(el, q));
|
|
396
|
+
return spreadAttribute;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
override async visitJsxExpression(embeddedExpression: JSX.EmbeddedExpression, q: RpcSendQueue): Promise<J | undefined> {
|
|
400
|
+
await q.getAndSend(embeddedExpression, el => el.expression, el => this.visitRightPadded(el, q));
|
|
401
|
+
return embeddedExpression;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
override async visitJsxNamespacedName(namespacedName: JSX.NamespacedName, q: RpcSendQueue): Promise<J | undefined> {
|
|
405
|
+
await q.getAndSend(namespacedName, el => el.namespace, el => this.visit(el, q));
|
|
406
|
+
await q.getAndSend(namespacedName, el => el.name, el => this.visitLeftPadded(el, q));
|
|
407
|
+
return namespacedName;
|
|
408
|
+
}
|
|
409
|
+
|
|
374
410
|
override async visitIndexSignatureDeclaration(indexSignatureDeclaration: JS.IndexSignatureDeclaration, q: RpcSendQueue): Promise<J | undefined> {
|
|
375
411
|
await q.getAndSendList(indexSignatureDeclaration, el => el.modifiers, el => el.id, el => this.visit(el, q));
|
|
376
412
|
await q.getAndSend(indexSignatureDeclaration, el => el.parameters, el => this.visitContainer(el, q));
|
|
@@ -900,6 +936,47 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
|
|
|
900
936
|
return finishDraft(draft);
|
|
901
937
|
}
|
|
902
938
|
|
|
939
|
+
override async visitJsxTag(tag: JSX.Tag, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
940
|
+
const draft = createDraft(tag);
|
|
941
|
+
draft.openName = await q.receive(draft.openName, el => this.visitLeftPadded(el, q));
|
|
942
|
+
draft.afterName = await q.receive(draft.afterName, space => this.visitSpace(space, q));
|
|
943
|
+
draft.attributes = await q.receiveListDefined(draft.attributes, attr => this.visitRightPadded(attr, q));
|
|
944
|
+
|
|
945
|
+
draft.selfClosing = await q.receive(draft.selfClosing, space => this.visitSpace(space, q));
|
|
946
|
+
draft.children = await q.receiveListDefined(draft.children, child => this.visitRightPadded(child, q));
|
|
947
|
+
draft.closingName = await q.receive(draft.closingName, el => this.visitLeftPadded(el, q));
|
|
948
|
+
draft.afterClosingName = await q.receive(draft.afterClosingName, el => this.visitSpace(el, q));
|
|
949
|
+
|
|
950
|
+
return finishDraft(draft);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
override async visitJsxAttribute(attribute: JSX.Attribute, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
954
|
+
const draft = createDraft(attribute);
|
|
955
|
+
draft.key = await q.receive(draft.key, el => this.visitDefined<J.Identifier | JSX.NamespacedName>(el, q));
|
|
956
|
+
draft.value = await q.receive(draft.value, el => this.visitLeftPadded(el, q));
|
|
957
|
+
return finishDraft(draft);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
override async visitJsxSpreadAttribute(spreadAttribute: JSX.SpreadAttribute, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
961
|
+
const draft = createDraft(spreadAttribute);
|
|
962
|
+
draft.dots = await q.receive(draft.dots, space => this.visitSpace(space, q));
|
|
963
|
+
draft.expression = await q.receive(draft.expression, el => this.visitRightPadded(el, q));
|
|
964
|
+
return finishDraft(draft);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
override async visitJsxExpression(embeddedExpression: JSX.EmbeddedExpression, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
968
|
+
const draft = createDraft(embeddedExpression);
|
|
969
|
+
draft.expression = await q.receive(draft.expression, el => this.visitRightPadded(el, q));
|
|
970
|
+
return finishDraft(draft);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
override async visitJsxNamespacedName(namespacedName: JSX.NamespacedName, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
974
|
+
const draft = createDraft(namespacedName);
|
|
975
|
+
draft.namespace = await q.receive(draft.namespace, el => this.visitDefined<J.Identifier>(el, q));
|
|
976
|
+
draft.name = await q.receive(draft.name, el => this.visitLeftPadded(el, q));
|
|
977
|
+
return finishDraft(draft);
|
|
978
|
+
}
|
|
979
|
+
|
|
903
980
|
override async visitIndexSignatureDeclaration(indexSignatureDeclaration: JS.IndexSignatureDeclaration, q: RpcReceiveQueue): Promise<J | undefined> {
|
|
904
981
|
const draft = createDraft(indexSignatureDeclaration);
|
|
905
982
|
draft.modifiers = await q.receiveListDefined(draft.modifiers, el => this.visitDefined<J.Modifier>(el, q));
|
package/src/javascript/style.ts
CHANGED
|
@@ -25,8 +25,9 @@ export const JavaScriptStyles = {
|
|
|
25
25
|
|
|
26
26
|
export const StyleKind = {
|
|
27
27
|
SpacesStyle: "org.openrewrite.javascript.style.SpacesStyle",
|
|
28
|
-
WrappingAndBracesStyle: "org.openrewrite.
|
|
29
|
-
BlankLinesStyle: "org.openrewrite.javascript.style.BlankLinesStyle"
|
|
28
|
+
WrappingAndBracesStyle: "org.openrewrite.javascript.style.WrappingAndBracesStyle",
|
|
29
|
+
BlankLinesStyle: "org.openrewrite.javascript.style.BlankLinesStyle",
|
|
30
|
+
TabsAndIndentsStyle: "org.openrewrite.javascript.style.TabsAndIndentsStyle"
|
|
30
31
|
} as const;
|
|
31
32
|
|
|
32
33
|
export const SpacesStyleDetailKind = {
|
|
@@ -156,6 +157,13 @@ export interface WrappingAndBracesStyle extends Style {
|
|
|
156
157
|
readonly ifStatement: WrappingAndBracesStyle.IfStatement;
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
export namespace WrappingAndBracesStyle {
|
|
161
|
+
export interface IfStatement {
|
|
162
|
+
readonly kind: typeof WrappingAndBracesStyleDetailKind.WrappingAndBracesStyleIfStatement;
|
|
163
|
+
readonly elseOnNewLine: boolean;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
159
167
|
export interface BlankLinesStyle extends Style {
|
|
160
168
|
readonly kind: "org.openrewrite.javascript.style.BlankLinesStyle";
|
|
161
169
|
readonly keepMaximum: BlankLinesStyle.KeepMaximum;
|
|
@@ -178,11 +186,15 @@ export namespace BlankLinesStyle {
|
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
|
|
181
|
-
export
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
export interface TabsAndIndentsStyle extends Style {
|
|
190
|
+
readonly kind: typeof StyleKind.TabsAndIndentsStyle;
|
|
191
|
+
readonly useTabCharacter: boolean;
|
|
192
|
+
readonly tabSize: number;
|
|
193
|
+
readonly indentSize: number;
|
|
194
|
+
readonly continuationIndent: number;
|
|
195
|
+
readonly keepIndentsOnEmptyLines: boolean;
|
|
196
|
+
readonly indentChainedMethods: boolean;
|
|
197
|
+
readonly indentAllChainedCallsInAGroup: boolean;
|
|
186
198
|
}
|
|
187
199
|
|
|
188
200
|
export namespace IntelliJ {
|
|
@@ -194,7 +206,7 @@ export namespace IntelliJ {
|
|
|
194
206
|
displayName: "IntelliJ IDEA",
|
|
195
207
|
description: "Default IntelliJ IDEA code style.",
|
|
196
208
|
tags: [],
|
|
197
|
-
styles: [spaces(), wrappingAndBraces(), blankLines()],
|
|
209
|
+
styles: [spaces(), wrappingAndBraces(), blankLines(), tabsAndIndents()],
|
|
198
210
|
}
|
|
199
211
|
|
|
200
212
|
export function spaces(): SpacesStyle {
|
|
@@ -315,6 +327,19 @@ export namespace IntelliJ {
|
|
|
315
327
|
}
|
|
316
328
|
};
|
|
317
329
|
}
|
|
330
|
+
|
|
331
|
+
export function tabsAndIndents(): TabsAndIndentsStyle {
|
|
332
|
+
return {
|
|
333
|
+
kind: StyleKind.TabsAndIndentsStyle,
|
|
334
|
+
useTabCharacter: false,
|
|
335
|
+
tabSize: 4,
|
|
336
|
+
indentSize: 4,
|
|
337
|
+
continuationIndent: 4,
|
|
338
|
+
keepIndentsOnEmptyLines: false,
|
|
339
|
+
indentChainedMethods: true,
|
|
340
|
+
indentAllChainedCallsInAGroup: false
|
|
341
|
+
};
|
|
342
|
+
}
|
|
318
343
|
}
|
|
319
344
|
|
|
320
345
|
export namespace TypeScript {
|
|
@@ -325,7 +350,7 @@ export namespace IntelliJ {
|
|
|
325
350
|
displayName: "IntelliJ IDEA",
|
|
326
351
|
description: "Default IntelliJ IDEA code style.",
|
|
327
352
|
tags: [],
|
|
328
|
-
styles: [spaces(), wrappingAndBraces(), blankLines()],
|
|
353
|
+
styles: [spaces(), wrappingAndBraces(), blankLines(), tabsAndIndents()],
|
|
329
354
|
}
|
|
330
355
|
|
|
331
356
|
export function spaces(): SpacesStyle {
|
|
@@ -448,6 +473,19 @@ export namespace IntelliJ {
|
|
|
448
473
|
}
|
|
449
474
|
};
|
|
450
475
|
}
|
|
476
|
+
|
|
477
|
+
export function tabsAndIndents(): TabsAndIndentsStyle {
|
|
478
|
+
return {
|
|
479
|
+
kind: StyleKind.TabsAndIndentsStyle,
|
|
480
|
+
useTabCharacter: false,
|
|
481
|
+
tabSize: 4,
|
|
482
|
+
indentSize: 4,
|
|
483
|
+
continuationIndent: 4,
|
|
484
|
+
keepIndentsOnEmptyLines: false,
|
|
485
|
+
indentChainedMethods: true,
|
|
486
|
+
indentAllChainedCallsInAGroup: false
|
|
487
|
+
};
|
|
488
|
+
}
|
|
451
489
|
}
|
|
452
490
|
}
|
|
453
491
|
|
package/src/javascript/tree.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import {SourceFile, TreeKind} from "../";
|
|
20
|
-
import {Expression, J, JavaType, Statement, TypedTree, TypeTree, VariableDeclarator,} from "../java";
|
|
20
|
+
import {Expression, J, JavaType, NameTree, Statement, TypedTree, TypeTree, VariableDeclarator,} from "../java";
|
|
21
21
|
import getType = TypedTree.getType;
|
|
22
22
|
import FunctionType = JS.FunctionType;
|
|
23
23
|
|
|
@@ -30,9 +30,12 @@ export namespace JS {
|
|
|
30
30
|
Alias: "org.openrewrite.javascript.tree.JS$Alias",
|
|
31
31
|
ArrayBindingPattern: "org.openrewrite.javascript.tree.JS$ArrayBindingPattern",
|
|
32
32
|
ArrowFunction: "org.openrewrite.javascript.tree.JS$ArrowFunction",
|
|
33
|
+
AssignmentOperation: "org.openrewrite.javascript.tree.JS$AssignmentOperation",
|
|
33
34
|
Await: "org.openrewrite.javascript.tree.JS$Await",
|
|
35
|
+
Binary: "org.openrewrite.javascript.tree.JS$Binary",
|
|
34
36
|
BindingElement: "org.openrewrite.javascript.tree.JS$BindingElement",
|
|
35
37
|
CompilationUnit: "org.openrewrite.javascript.tree.JS$CompilationUnit",
|
|
38
|
+
ComputedPropertyMethodDeclaration: "org.openrewrite.javascript.tree.JS$ComputedPropertyMethodDeclaration",
|
|
36
39
|
ComputedPropertyName: "org.openrewrite.javascript.tree.JS$ComputedPropertyName",
|
|
37
40
|
ConditionalType: "org.openrewrite.javascript.tree.JS$ConditionalType",
|
|
38
41
|
Delete: "org.openrewrite.javascript.tree.JS$Delete",
|
|
@@ -55,9 +58,11 @@ export namespace JS {
|
|
|
55
58
|
Intersection: "org.openrewrite.javascript.tree.JS$Intersection",
|
|
56
59
|
ForInLoop: "org.openrewrite.javascript.tree.JS$ForInLoop",
|
|
57
60
|
ForOfLoop: "org.openrewrite.javascript.tree.JS$ForOfLoop",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
JsxEmbeddedExpression: "org.openrewrite.javascript.tree.JSX$EmbeddedExpression",
|
|
62
|
+
JsxSpreadAttribute: "org.openrewrite.javascript.tree.JSX$SpreadAttribute",
|
|
63
|
+
JsxNamespacedName: "org.openrewrite.javascript.tree.JSX$NamespacedName",
|
|
64
|
+
JsxTag: "org.openrewrite.javascript.tree.JSX$Tag",
|
|
65
|
+
JsxAttribute: "org.openrewrite.javascript.tree.JSX$Attribute",
|
|
61
66
|
Import: "org.openrewrite.javascript.tree.JS$Import",
|
|
62
67
|
ImportClause: "org.openrewrite.javascript.tree.JS$ImportClause",
|
|
63
68
|
ImportSpecifier: "org.openrewrite.javascript.tree.JS$ImportSpecifier",
|
|
@@ -822,6 +827,72 @@ export namespace JS {
|
|
|
822
827
|
}
|
|
823
828
|
}
|
|
824
829
|
|
|
830
|
+
export namespace JSX {
|
|
831
|
+
/**
|
|
832
|
+
* Represents a JSX tag. Note that `selfClosing` and `children` are mutually exclusive.
|
|
833
|
+
* @example <div>{child}</div>
|
|
834
|
+
*/
|
|
835
|
+
export type Tag =
|
|
836
|
+
(BaseTag & {
|
|
837
|
+
readonly selfClosing: J.Space;
|
|
838
|
+
readonly children?: undefined;
|
|
839
|
+
readonly closingName?: undefined;
|
|
840
|
+
readonly afterClosingName?: undefined;
|
|
841
|
+
}) |
|
|
842
|
+
(BaseTag & {
|
|
843
|
+
readonly selfClosing?: undefined;
|
|
844
|
+
readonly children: J.RightPadded<EmbeddedExpression | Tag | J.Identifier | J.Literal | J.Empty>[];
|
|
845
|
+
readonly closingName: J.LeftPadded<J.Identifier | J.FieldAccess | NamespacedName | J.Empty>;
|
|
846
|
+
readonly afterClosingName: J.Space;
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
interface BaseTag extends JS, Expression {
|
|
850
|
+
readonly kind: typeof JS.Kind.JsxTag;
|
|
851
|
+
readonly openName: J.LeftPadded<J.Identifier | J.FieldAccess | NamespacedName | J.Empty>;
|
|
852
|
+
readonly afterName: J.Space;
|
|
853
|
+
readonly attributes: J.RightPadded<Attribute | SpreadAttribute>[];
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Represents a single JSX attribute.
|
|
858
|
+
* @example prop="value"
|
|
859
|
+
*/
|
|
860
|
+
export interface Attribute extends JS {
|
|
861
|
+
readonly kind: typeof JS.Kind.JsxAttribute;
|
|
862
|
+
readonly key: J.Identifier | NamespacedName;
|
|
863
|
+
readonly value?: J.LeftPadded<Expression>;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Represents a spread attribute in JSX.
|
|
868
|
+
* @example {...props}
|
|
869
|
+
*/
|
|
870
|
+
export interface SpreadAttribute extends JS {
|
|
871
|
+
readonly kind: typeof JS.Kind.JsxSpreadAttribute;
|
|
872
|
+
readonly dots: J.Space
|
|
873
|
+
readonly expression: J.RightPadded<Expression>;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Represents a JSX expression container.
|
|
878
|
+
* @example {expression}
|
|
879
|
+
*/
|
|
880
|
+
export interface EmbeddedExpression extends JS, Expression {
|
|
881
|
+
readonly kind: typeof JS.Kind.JsxEmbeddedExpression;
|
|
882
|
+
readonly expression: J.RightPadded<Expression>;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Represents a namespaced JSX name.
|
|
887
|
+
* @example namespace:Name
|
|
888
|
+
*/
|
|
889
|
+
export interface NamespacedName extends JS, NameTree {
|
|
890
|
+
readonly kind: typeof JS.Kind.JsxNamespacedName;
|
|
891
|
+
readonly namespace: J.Identifier;
|
|
892
|
+
readonly name: J.LeftPadded<J.Identifier>;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
825
896
|
const KindValues = new Set(Object.values(JS.Kind));
|
|
826
897
|
|
|
827
898
|
export function isJavaScript(tree: any): tree is JS {
|