@openrewrite/rewrite 8.100.0 → 8.100.2
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/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +6 -1
- package/dist/java/rpc.js.map +1 -1
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +3 -0
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/binding.d.ts.map +1 -1
- package/dist/javascript/binding.js +8 -1
- package/dist/javascript/binding.js.map +1 -1
- package/dist/javascript/comparator.js +2 -1
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format/format.d.ts.map +1 -1
- package/dist/javascript/format/format.js +3 -2
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +3 -3
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
- package/dist/javascript/node-resolution-result.d.ts +4 -1
- package/dist/javascript/node-resolution-result.d.ts.map +1 -1
- package/dist/javascript/node-resolution-result.js +47 -16
- package/dist/javascript/node-resolution-result.js.map +1 -1
- package/dist/javascript/package-json-parser.d.ts.map +1 -1
- package/dist/javascript/package-json-parser.js +4 -2
- package/dist/javascript/package-json-parser.js.map +1 -1
- package/dist/javascript/package-manager.d.ts +2 -0
- package/dist/javascript/package-manager.d.ts.map +1 -1
- package/dist/javascript/package-manager.js +11 -4
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +11 -17
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.d.ts +4 -0
- package/dist/javascript/print.d.ts.map +1 -1
- package/dist/javascript/print.js +82 -20
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/rpc.js +2 -0
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/scope.d.ts.map +1 -1
- package/dist/javascript/scope.js +4 -1
- package/dist/javascript/scope.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +9 -0
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +21 -0
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/debug.d.ts.map +1 -1
- package/dist/javascript/templating/debug.js +2 -0
- package/dist/javascript/templating/debug.js.map +1 -1
- package/dist/javascript/templating/precedence.d.ts.map +1 -1
- package/dist/javascript/templating/precedence.js +36 -39
- package/dist/javascript/templating/precedence.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +4 -4
- package/dist/javascript/tree-debug.d.ts.map +1 -1
- package/dist/javascript/tree-debug.js +6 -3
- package/dist/javascript/tree-debug.js.map +1 -1
- package/dist/javascript/tree.d.ts +4 -1
- package/dist/javascript/tree.d.ts.map +1 -1
- package/dist/javascript/tree.js +2 -0
- package/dist/javascript/tree.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts +1 -0
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +12 -1
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/json/edit.d.ts +150 -0
- package/dist/json/edit.d.ts.map +1 -0
- package/dist/json/edit.js +667 -0
- package/dist/json/edit.js.map +1 -0
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -0
- package/dist/json/index.js.map +1 -1
- package/dist/json/parser.d.ts.map +1 -1
- package/dist/json/parser.js +8 -1
- package/dist/json/parser.js.map +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/print.d.ts +16 -0
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +33 -0
- package/dist/print.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/request/get-languages.d.ts.map +1 -1
- package/dist/rpc/request/get-languages.js +1 -0
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/request/parse.d.ts.map +1 -1
- package/dist/rpc/request/parse.js +4 -0
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/server.d.ts +1 -0
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +1 -0
- package/dist/rpc/server.js.map +1 -1
- package/dist/xml/assertions.d.ts +4 -0
- package/dist/xml/assertions.d.ts.map +1 -0
- package/dist/xml/assertions.js +31 -0
- package/dist/xml/assertions.js.map +1 -0
- package/dist/xml/index.d.ts +8 -0
- package/dist/xml/index.d.ts.map +1 -0
- package/dist/xml/index.js +39 -0
- package/dist/xml/index.js.map +1 -0
- package/dist/xml/namespaces.d.ts +36 -0
- package/dist/xml/namespaces.d.ts.map +1 -0
- package/dist/xml/namespaces.js +98 -0
- package/dist/xml/namespaces.js.map +1 -0
- package/dist/xml/parser.d.ts +15 -0
- package/dist/xml/parser.d.ts.map +1 -0
- package/dist/xml/parser.js +677 -0
- package/dist/xml/parser.js.map +1 -0
- package/dist/xml/print.d.ts +2 -0
- package/dist/xml/print.d.ts.map +1 -0
- package/dist/xml/print.js +209 -0
- package/dist/xml/print.js.map +1 -0
- package/dist/xml/rpc.d.ts +2 -0
- package/dist/xml/rpc.d.ts.map +1 -0
- package/dist/xml/rpc.js +313 -0
- package/dist/xml/rpc.js.map +1 -0
- package/dist/xml/tree.d.ts +244 -0
- package/dist/xml/tree.d.ts.map +1 -0
- package/dist/xml/tree.js +265 -0
- package/dist/xml/tree.js.map +1 -0
- package/dist/xml/visitor.d.ts +35 -0
- package/dist/xml/visitor.d.ts.map +1 -0
- package/dist/xml/visitor.js +203 -0
- package/dist/xml/visitor.js.map +1 -0
- package/package.json +5 -1
- package/src/java/rpc.ts +6 -1
- package/src/javascript/add-import.ts +3 -0
- package/src/javascript/binding.ts +10 -1
- package/src/javascript/comparator.ts +2 -1
- package/src/javascript/format/format.ts +3 -2
- package/src/javascript/format/minimum-viable-spacing-visitor.ts +3 -3
- package/src/javascript/node-resolution-result.ts +49 -15
- package/src/javascript/package-json-parser.ts +4 -1
- package/src/javascript/package-manager.ts +11 -4
- package/src/javascript/parser.ts +12 -17
- package/src/javascript/print.ts +85 -23
- package/src/javascript/rpc.ts +2 -0
- package/src/javascript/scope.ts +4 -1
- package/src/javascript/templating/comparator.ts +23 -0
- package/src/javascript/templating/debug.ts +1 -0
- package/src/javascript/templating/precedence.ts +17 -20
- package/src/javascript/templating/types.ts +4 -4
- package/src/javascript/tree-debug.ts +7 -3
- package/src/javascript/tree.ts +4 -1
- package/src/javascript/type-mapping.ts +15 -1
- package/src/json/edit.ts +750 -0
- package/src/json/index.ts +1 -0
- package/src/json/parser.ts +9 -1
- package/src/parser.ts +1 -1
- package/src/print.ts +42 -0
- package/src/rpc/request/get-languages.ts +1 -0
- package/src/rpc/request/parse.ts +3 -0
- package/src/rpc/server.ts +1 -0
- package/src/xml/assertions.ts +28 -0
- package/src/xml/index.ts +23 -0
- package/src/xml/namespaces.ts +109 -0
- package/src/xml/parser.ts +692 -0
- package/src/xml/print.ts +225 -0
- package/src/xml/rpc.ts +370 -0
- package/src/xml/tree.ts +455 -0
- package/src/xml/visitor.ts +227 -0
package/src/javascript/print.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import {JS, JSX} from "./tree";
|
|
19
19
|
import {JavaScriptVisitor} from "./visitor";
|
|
20
|
-
import {PrintOutputCapture, TreePrinters} from "../print";
|
|
20
|
+
import {PrintMark, PrintOutputCapture, TreePrinters} from "../print";
|
|
21
21
|
import {Cursor, isTree, Tree} from "../tree";
|
|
22
22
|
import {Comment, emptySpace, J, Statement, TextComment, TrailingComma, TypedTree} from "../java";
|
|
23
23
|
import {findMarker, Marker, Markers} from "../markers";
|
|
@@ -49,7 +49,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
49
49
|
override async visitAwait(awaitExpr: JS.Await, p: PrintOutputCapture): Promise<J | undefined> {
|
|
50
50
|
await this.beforeSyntax(awaitExpr, p);
|
|
51
51
|
p.append("await");
|
|
52
|
-
await this.
|
|
52
|
+
await this.visitAfterKeyword(awaitExpr.expression, p);
|
|
53
53
|
await this.afterSyntax(awaitExpr, p);
|
|
54
54
|
return awaitExpr;
|
|
55
55
|
}
|
|
@@ -69,7 +69,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
69
69
|
override async visitDelete(del: JS.Delete, p: PrintOutputCapture): Promise<J | undefined> {
|
|
70
70
|
await this.beforeSyntax(del, p);
|
|
71
71
|
p.append("delete");
|
|
72
|
-
await this.
|
|
72
|
+
await this.visitAfterKeyword(del.expression, p);
|
|
73
73
|
await this.afterSyntax(del, p);
|
|
74
74
|
return del;
|
|
75
75
|
}
|
|
@@ -205,6 +205,8 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
205
205
|
|
|
206
206
|
if (jsImportClause.typeOnly) {
|
|
207
207
|
p.append("type");
|
|
208
|
+
} else if (jsImportClause.deferred) {
|
|
209
|
+
p.append("defer");
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
if (jsImportClause.name) {
|
|
@@ -260,7 +262,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
260
262
|
override async visitSatisfiesExpression(satisfiesExpression: JS.SatisfiesExpression, p: PrintOutputCapture): Promise<J | undefined> {
|
|
261
263
|
await this.beforeSyntax(satisfiesExpression, p);
|
|
262
264
|
await this.visit(satisfiesExpression.expression, p);
|
|
263
|
-
await this.
|
|
265
|
+
await this.visitLeftPaddedKeyword("satisfies", satisfiesExpression.satisfiesType, p);
|
|
264
266
|
await this.afterSyntax(satisfiesExpression, p);
|
|
265
267
|
return satisfiesExpression;
|
|
266
268
|
}
|
|
@@ -268,7 +270,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
268
270
|
override async visitVoid(aVoid: JS.Void, p: PrintOutputCapture): Promise<J | undefined> {
|
|
269
271
|
await this.beforeSyntax(aVoid, p);
|
|
270
272
|
p.append("void");
|
|
271
|
-
await this.
|
|
273
|
+
await this.visitAfterKeyword(aVoid.expression, p);
|
|
272
274
|
await this.afterSyntax(aVoid, p);
|
|
273
275
|
return aVoid;
|
|
274
276
|
}
|
|
@@ -282,10 +284,11 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
282
284
|
if (delegated) {
|
|
283
285
|
await this.visitSpace(delegated.prefix, p);
|
|
284
286
|
p.append("*");
|
|
287
|
+
aYield.value && await this.visit(aYield.value, p);
|
|
288
|
+
} else {
|
|
289
|
+
await this.visitAfterKeyword(aYield.value, p);
|
|
285
290
|
}
|
|
286
291
|
|
|
287
|
-
aYield.value && await this.visit(aYield.value, p);
|
|
288
|
-
|
|
289
292
|
await this.afterSyntax(aYield, p);
|
|
290
293
|
return aYield;
|
|
291
294
|
}
|
|
@@ -377,7 +380,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
377
380
|
override async visitThrow(thrown: J.Throw, p: PrintOutputCapture): Promise<J | undefined> {
|
|
378
381
|
await this.beforeSyntax(thrown, p);
|
|
379
382
|
p.append("throw");
|
|
380
|
-
await this.
|
|
383
|
+
await this.visitAfterKeyword(thrown.exception, p);
|
|
381
384
|
await this.afterSyntax(thrown, p);
|
|
382
385
|
return thrown;
|
|
383
386
|
}
|
|
@@ -395,7 +398,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
395
398
|
override async visitElse(else_: J.If.Else, p: PrintOutputCapture): Promise<J | undefined> {
|
|
396
399
|
await this.beforeSyntax(else_, p);
|
|
397
400
|
p.append("else");
|
|
401
|
+
const body = p.mark();
|
|
398
402
|
await this.visitStatementLocal(else_.body, p);
|
|
403
|
+
this.separateFromKeyword(body, p);
|
|
399
404
|
await this.afterSyntax(else_, p);
|
|
400
405
|
return else_;
|
|
401
406
|
}
|
|
@@ -403,7 +408,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
403
408
|
override async visitDoWhileLoop(doWhileLoop: J.DoWhileLoop, p: PrintOutputCapture): Promise<J | undefined> {
|
|
404
409
|
await this.beforeSyntax(doWhileLoop, p);
|
|
405
410
|
p.append("do");
|
|
411
|
+
const body = p.mark();
|
|
406
412
|
await this.visitStatementLocal(doWhileLoop.body, p);
|
|
413
|
+
this.separateFromKeyword(body, p);
|
|
407
414
|
await this.visitLeftPaddedLocal("while", doWhileLoop.whileCondition, p);
|
|
408
415
|
await this.afterSyntax(doWhileLoop, p);
|
|
409
416
|
return doWhileLoop;
|
|
@@ -420,8 +427,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
420
427
|
|
|
421
428
|
override async visitInstanceOf(instanceOf: J.InstanceOf, p: PrintOutputCapture): Promise<J | undefined> {
|
|
422
429
|
await this.beforeSyntax(instanceOf, p);
|
|
423
|
-
await this.
|
|
424
|
-
|
|
430
|
+
await this.visitRightPadded(instanceOf.expression, p);
|
|
431
|
+
this.appendKeyword("instanceof", p);
|
|
432
|
+
await this.visitAfterKeyword(instanceOf.class, p);
|
|
425
433
|
instanceOf.pattern && await this.visit(instanceOf.pattern, p);
|
|
426
434
|
await this.afterSyntax(instanceOf, p);
|
|
427
435
|
return instanceOf;
|
|
@@ -573,7 +581,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
573
581
|
override async visitReturn(return_: J.Return, p: PrintOutputCapture): Promise<J | undefined> {
|
|
574
582
|
await this.beforeSyntax(return_, p);
|
|
575
583
|
p.append("return");
|
|
576
|
-
|
|
584
|
+
await this.visitAfterKeyword(return_.expression, p);
|
|
577
585
|
await this.afterSyntax(return_, p);
|
|
578
586
|
return return_;
|
|
579
587
|
}
|
|
@@ -879,7 +887,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
879
887
|
override async visitConditionalType(conditionalType: JS.ConditionalType, p: PrintOutputCapture): Promise<J | undefined> {
|
|
880
888
|
await this.beforeSyntax(conditionalType, p);
|
|
881
889
|
await this.visit(conditionalType.checkType, p);
|
|
882
|
-
await this.
|
|
890
|
+
await this.visitLeftPaddedKeyword("extends", conditionalType.condition, p);
|
|
883
891
|
await this.afterSyntax(conditionalType, p);
|
|
884
892
|
return conditionalType;
|
|
885
893
|
}
|
|
@@ -982,7 +990,11 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
982
990
|
override async visitExportAssignment(es: JS.ExportAssignment, p: PrintOutputCapture): Promise<J | undefined> {
|
|
983
991
|
await this.beforeSyntax(es, p);
|
|
984
992
|
p.append("export");
|
|
985
|
-
|
|
993
|
+
if (es.exportEquals) {
|
|
994
|
+
await this.visitLeftPaddedLocal("=", es.expression, p);
|
|
995
|
+
} else {
|
|
996
|
+
await this.visitLeftPaddedKeyword("default", es.expression, p);
|
|
997
|
+
}
|
|
986
998
|
await this.afterSyntax(es, p);
|
|
987
999
|
return es;
|
|
988
1000
|
}
|
|
@@ -1190,7 +1202,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1190
1202
|
override async visitTypeOf(typeOf: JS.TypeOf, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1191
1203
|
await this.beforeSyntax(typeOf, p);
|
|
1192
1204
|
p.append("typeof");
|
|
1193
|
-
await this.
|
|
1205
|
+
await this.visitAfterKeyword(typeOf.expression, p);
|
|
1194
1206
|
await this.afterSyntax(typeOf, p);
|
|
1195
1207
|
return typeOf;
|
|
1196
1208
|
}
|
|
@@ -1217,7 +1229,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1217
1229
|
|
|
1218
1230
|
p.append(keyword);
|
|
1219
1231
|
|
|
1232
|
+
const operand = p.mark();
|
|
1220
1233
|
await this.visitLeftPadded(typeOperator.expression, p);
|
|
1234
|
+
this.separateFromKeyword(operand, p);
|
|
1221
1235
|
|
|
1222
1236
|
await this.afterSyntax(typeOperator, p);
|
|
1223
1237
|
return typeOperator;
|
|
@@ -1277,7 +1291,7 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1277
1291
|
|
|
1278
1292
|
if (newClass.class) {
|
|
1279
1293
|
p.append("new");
|
|
1280
|
-
await this.
|
|
1294
|
+
await this.visitAfterKeyword(newClass.class, p);
|
|
1281
1295
|
|
|
1282
1296
|
if (!newClass.arguments.markers.markers.find(m => m.kind === J.Markers.OmitParentheses)) {
|
|
1283
1297
|
await this.visitContainerLocal("(", newClass.arguments, ",", ")", p);
|
|
@@ -1302,11 +1316,16 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1302
1316
|
await this.beforeSyntax(case_, p);
|
|
1303
1317
|
|
|
1304
1318
|
const elem = case_.caseLabels.elements[0].element;
|
|
1305
|
-
|
|
1319
|
+
const keyword = elem.kind !== J.Kind.Identifier || (elem as J.Identifier).simpleName !== "default";
|
|
1320
|
+
if (keyword) {
|
|
1306
1321
|
p.append("case");
|
|
1307
1322
|
}
|
|
1308
1323
|
|
|
1324
|
+
const labels = p.mark();
|
|
1309
1325
|
await this.visitContainerLocal("", case_.caseLabels, ",", "", p);
|
|
1326
|
+
if (keyword) {
|
|
1327
|
+
this.separateFromKeyword(labels, p);
|
|
1328
|
+
}
|
|
1310
1329
|
|
|
1311
1330
|
await this.visitSpace(case_.statements.before, p);
|
|
1312
1331
|
p.append(case_.type === J.Case.Type.Statement ? ":" : "->");
|
|
@@ -1378,8 +1397,8 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1378
1397
|
override async visitAs(as_: JS.As, p: PrintOutputCapture): Promise<J | undefined> {
|
|
1379
1398
|
await this.beforeSyntax(as_, p);
|
|
1380
1399
|
await this.visitRightPadded(as_.left, p);
|
|
1381
|
-
|
|
1382
|
-
await this.
|
|
1400
|
+
this.appendKeyword("as", p);
|
|
1401
|
+
await this.visitAfterKeyword(as_.right, p);
|
|
1383
1402
|
await this.afterSyntax(as_, p);
|
|
1384
1403
|
|
|
1385
1404
|
return as_;
|
|
@@ -1624,12 +1643,19 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1624
1643
|
case JS.Binary.Type.Comma:
|
|
1625
1644
|
keyword = ",";
|
|
1626
1645
|
break;
|
|
1646
|
+
case JS.Binary.Type.Exponentiation:
|
|
1647
|
+
keyword = "**";
|
|
1648
|
+
break;
|
|
1627
1649
|
}
|
|
1628
1650
|
|
|
1629
1651
|
await this.visitSpace(binary.operator.before, p);
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1652
|
+
if (binary.operator.element === JS.Binary.Type.In) {
|
|
1653
|
+
this.appendKeyword(keyword, p);
|
|
1654
|
+
await this.visitAfterKeyword(binary.right, p);
|
|
1655
|
+
} else {
|
|
1656
|
+
p.append(keyword);
|
|
1657
|
+
await this.visit(binary.right, p);
|
|
1658
|
+
}
|
|
1633
1659
|
|
|
1634
1660
|
await this.afterSyntax(binary, p);
|
|
1635
1661
|
return binary;
|
|
@@ -1725,8 +1751,10 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1725
1751
|
await this.beforeSyntax(control, p);
|
|
1726
1752
|
p.append('(');
|
|
1727
1753
|
await this.visitRightPadded(control.variable, p);
|
|
1728
|
-
|
|
1754
|
+
this.appendKeyword("of", p);
|
|
1755
|
+
const iterable = p.mark();
|
|
1729
1756
|
await this.visitRightPadded(control.iterable, p);
|
|
1757
|
+
this.separateFromKeyword(iterable, p);
|
|
1730
1758
|
p.append(')');
|
|
1731
1759
|
await this.afterSyntax(control, p);
|
|
1732
1760
|
await this.visitRightPadded(loop.loop.body, p);
|
|
@@ -1743,8 +1771,10 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1743
1771
|
await this.beforeSyntax(control, p);
|
|
1744
1772
|
p.append('(');
|
|
1745
1773
|
await this.visitRightPadded(control.variable, p);
|
|
1746
|
-
|
|
1774
|
+
this.appendKeyword("in", p);
|
|
1775
|
+
const iterable = p.mark();
|
|
1747
1776
|
await this.visitRightPadded(control.iterable, p);
|
|
1777
|
+
this.separateFromKeyword(iterable, p);
|
|
1748
1778
|
p.append(')');
|
|
1749
1779
|
await this.afterSyntax(control, p);
|
|
1750
1780
|
await this.visitRightPadded(loop.body, p);
|
|
@@ -1931,6 +1961,32 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
1931
1961
|
}
|
|
1932
1962
|
}
|
|
1933
1963
|
|
|
1964
|
+
private appendKeyword(keyword: string, p: PrintOutputCapture) {
|
|
1965
|
+
if (isWordChar(p.lastChar)) {
|
|
1966
|
+
p.append(" ");
|
|
1967
|
+
}
|
|
1968
|
+
p.append(keyword);
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
private async visitAfterKeyword(tree: J | undefined, p: PrintOutputCapture) {
|
|
1972
|
+
const printed = p.mark();
|
|
1973
|
+
tree && await this.visit(tree, p);
|
|
1974
|
+
this.separateFromKeyword(printed, p);
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
private separateFromKeyword(printed: PrintMark, p: PrintOutputCapture) {
|
|
1978
|
+
if (isWordChar(printed.firstChar)) {
|
|
1979
|
+
p.insert(printed.offset, " ");
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
private async visitLeftPaddedKeyword(keyword: string, leftPadded: J.LeftPadded<J>, p: PrintOutputCapture) {
|
|
1984
|
+
await this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
|
|
1985
|
+
this.appendKeyword(keyword, p);
|
|
1986
|
+
await this.visitAfterKeyword(leftPadded.element, p);
|
|
1987
|
+
await this.afterSyntaxMarkers(leftPadded.markers, p);
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1934
1990
|
private async visitLeftPaddedLocal(prefix: string | undefined, leftPadded: J.LeftPadded<J> | J.LeftPadded<boolean> | J.LeftPadded<string> | undefined, p: PrintOutputCapture) {
|
|
1935
1991
|
if (leftPadded) {
|
|
1936
1992
|
await this.beforeSyntaxExt(leftPadded.before, leftPadded.markers, p);
|
|
@@ -2038,3 +2094,9 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
|
|
|
2038
2094
|
}
|
|
2039
2095
|
|
|
2040
2096
|
TreePrinters.register(JS.Kind.CompilationUnit, () => new JavaScriptPrinter());
|
|
2097
|
+
|
|
2098
|
+
const WORD_CHAR = /^[\p{ID_Continue}$\u200C\u200D\\]$/u;
|
|
2099
|
+
|
|
2100
|
+
function isWordChar(char: string): boolean {
|
|
2101
|
+
return WORD_CHAR.test(char);
|
|
2102
|
+
}
|
package/src/javascript/rpc.ts
CHANGED
|
@@ -386,6 +386,7 @@ class JavaScriptSender extends JavaScriptRpcVisitor<RpcSendQueue> {
|
|
|
386
386
|
|
|
387
387
|
override visitImportClause(jsImportClause: JS.ImportClause, q: RpcSendQueue): J | undefined {
|
|
388
388
|
q.getAndSend(jsImportClause, el => el.typeOnly);
|
|
389
|
+
q.getAndSend(jsImportClause, el => el.deferred);
|
|
389
390
|
q.getAndSend(jsImportClause, el => el.name, el => this.visitRightPadded(el, q));
|
|
390
391
|
q.getAndSend(jsImportClause, el => el.namedBindings, el => this.visit(el, q));
|
|
391
392
|
return jsImportClause;
|
|
@@ -950,6 +951,7 @@ class JavaScriptReceiver extends JavaScriptRpcVisitor<RpcReceiveQueue> {
|
|
|
950
951
|
override visitImportClause(jsImportClause: JS.ImportClause, q: RpcReceiveQueue): J | undefined {
|
|
951
952
|
const updates = {
|
|
952
953
|
typeOnly: q.receive(jsImportClause.typeOnly),
|
|
954
|
+
deferred: q.receive(jsImportClause.deferred),
|
|
953
955
|
name: q.receive(jsImportClause.name, el => this.visitRightPadded(el, q)),
|
|
954
956
|
namedBindings: q.receive(jsImportClause.namedBindings, el => this.visitDefined<Expression>(el, q))
|
|
955
957
|
};
|
package/src/javascript/scope.ts
CHANGED
|
@@ -411,8 +411,11 @@ function writes(node: Tree, key: string): boolean {
|
|
|
411
411
|
switch (node.kind) {
|
|
412
412
|
case J.Kind.Assignment:
|
|
413
413
|
case J.Kind.AssignmentOperation:
|
|
414
|
-
case JS.Kind.AssignmentOperation:
|
|
415
414
|
return key === 'variable';
|
|
415
|
+
case JS.Kind.AssignmentOperation:
|
|
416
|
+
// `a ** b` as parsed before it was a JS.Binary assigns nothing
|
|
417
|
+
return key === 'variable' &&
|
|
418
|
+
(node as JS.AssignmentOperation).operator.element !== JS.AssignmentOperation.Type.Power;
|
|
416
419
|
case J.Kind.Unary:
|
|
417
420
|
return key === 'expression' && incrementing.has((node as J.Unary).operator.element);
|
|
418
421
|
case J.Kind.ForEachLoopControl:
|
|
@@ -128,6 +128,29 @@ export class PatternMatchingComparator extends JavaScriptSemanticComparatorVisit
|
|
|
128
128
|
super(lenientTypeMatching);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Lenient matching lets the code have a type annotation that the pattern leaves out, but not the
|
|
133
|
+
* other way round: `const ${x}: number = ${v}` must not match `const a = 1`. The check is here,
|
|
134
|
+
* not in the parent class, because the parent also compares the two places a repeated capture
|
|
135
|
+
* binds. Neither of those is the pattern, so there both sides are treated alike.
|
|
136
|
+
*/
|
|
137
|
+
override async visitVariableDeclarations(pattern: J.VariableDeclarations, other: J): Promise<J | undefined> {
|
|
138
|
+
if (pattern.typeExpression && other.kind === J.Kind.VariableDeclarations &&
|
|
139
|
+
!(other as J.VariableDeclarations).typeExpression) {
|
|
140
|
+
return this.structuralMismatch<J>('typeExpression');
|
|
141
|
+
}
|
|
142
|
+
return super.visitVariableDeclarations(pattern, other);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The same for a return type: `function ${f}(): string {…}` must not match `function a() {…}`. */
|
|
146
|
+
override async visitMethodDeclaration(pattern: J.MethodDeclaration, other: J): Promise<J | undefined> {
|
|
147
|
+
if (pattern.returnTypeExpression && other.kind === J.Kind.MethodDeclaration &&
|
|
148
|
+
!(other as J.MethodDeclaration).returnTypeExpression) {
|
|
149
|
+
return this.typeMismatch('returnTypeExpression');
|
|
150
|
+
}
|
|
151
|
+
return super.visitMethodDeclaration(pattern, other);
|
|
152
|
+
}
|
|
153
|
+
|
|
131
154
|
/**
|
|
132
155
|
* Builds the constraint context with the cursor and current captures.
|
|
133
156
|
* @param cursor The cursor to include in the context
|
|
@@ -581,6 +581,7 @@ export class DebugPatternMatchingComparator extends PatternMatchingComparator {
|
|
|
581
581
|
if (value === undefined) return 'undefined';
|
|
582
582
|
if (typeof value === 'string') return `"${value}"`;
|
|
583
583
|
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
584
|
+
if (typeof value === 'bigint') return `${value}n`;
|
|
584
585
|
|
|
585
586
|
if (Type.isType(value)) {
|
|
586
587
|
return Type.isFullyQualified(value) ?
|
|
@@ -95,9 +95,7 @@ export function precedenceOf(expression: J): number {
|
|
|
95
95
|
case JS.Kind.SatisfiesExpression:
|
|
96
96
|
return Precedence.Relational;
|
|
97
97
|
case JS.Kind.AssignmentOperation:
|
|
98
|
-
|
|
99
|
-
return (expression as JS.AssignmentOperation).operator.element === JS.AssignmentOperation.Type.Power ?
|
|
100
|
-
Precedence.Exponentiation : Precedence.Assignment;
|
|
98
|
+
return isLegacyPower(expression as JS.AssignmentOperation) ? Precedence.Exponentiation : Precedence.Assignment;
|
|
101
99
|
case J.Kind.Ternary:
|
|
102
100
|
case J.Kind.Assignment:
|
|
103
101
|
case J.Kind.AssignmentOperation:
|
|
@@ -160,10 +158,12 @@ function slotConstraints(parent: J, childId: string): SlotConstraints | undefine
|
|
|
160
158
|
if (precedence === undefined) {
|
|
161
159
|
return undefined;
|
|
162
160
|
}
|
|
161
|
+
// Right-associative, and `-a ** b` is a syntax error
|
|
162
|
+
const exponentiation = binary.operator.element === JS.Binary.Type.Exponentiation;
|
|
163
163
|
if (binary.left?.id === childId) {
|
|
164
|
-
return {precedence};
|
|
164
|
+
return {precedence: exponentiation ? Precedence.Postfix : precedence};
|
|
165
165
|
}
|
|
166
|
-
return binary.right?.id === childId ? {precedence: precedence + 1} : undefined;
|
|
166
|
+
return binary.right?.id === childId ? {precedence: exponentiation ? precedence : precedence + 1} : undefined;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
case J.Kind.Unary: {
|
|
@@ -195,25 +195,15 @@ function slotConstraints(parent: J, childId: string): SlotConstraints | undefine
|
|
|
195
195
|
return assignment.assignment?.element?.id === childId ? {precedence: Precedence.Assignment} : undefined;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
case J.Kind.AssignmentOperation:
|
|
199
|
-
const assignment = parent as J.AssignmentOperation;
|
|
200
|
-
if (assignment.variable?.id === childId) {
|
|
201
|
-
return {precedence: Precedence.Call};
|
|
202
|
-
}
|
|
203
|
-
return assignment.assignment?.id === childId ? {precedence: Precedence.Assignment} : undefined;
|
|
204
|
-
}
|
|
205
|
-
|
|
198
|
+
case J.Kind.AssignmentOperation:
|
|
206
199
|
case JS.Kind.AssignmentOperation: {
|
|
207
|
-
const assignment = parent as
|
|
208
|
-
const power =
|
|
200
|
+
const assignment = parent as J.AssignmentOperation;
|
|
201
|
+
const power = parent.kind === JS.Kind.AssignmentOperation && isLegacyPower(parent as JS.AssignmentOperation);
|
|
209
202
|
if (assignment.variable?.id === childId) {
|
|
210
|
-
// `-a ** b` is a syntax error, and `**` is right-associative besides
|
|
211
203
|
return {precedence: power ? Precedence.Postfix : Precedence.Call};
|
|
212
204
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
return undefined;
|
|
205
|
+
return assignment.assignment?.id === childId ?
|
|
206
|
+
{precedence: power ? Precedence.Exponentiation : Precedence.Assignment} : undefined;
|
|
217
207
|
}
|
|
218
208
|
|
|
219
209
|
case J.Kind.FieldAccess: {
|
|
@@ -468,11 +458,18 @@ function jsBinaryPrecedence(operator: JS.Binary.Type): number | undefined {
|
|
|
468
458
|
return Precedence.LogicalOr;
|
|
469
459
|
case JS.Binary.Type.Comma:
|
|
470
460
|
return Precedence.Comma;
|
|
461
|
+
case JS.Binary.Type.Exponentiation:
|
|
462
|
+
return Precedence.Exponentiation;
|
|
471
463
|
default:
|
|
472
464
|
return undefined;
|
|
473
465
|
}
|
|
474
466
|
}
|
|
475
467
|
|
|
468
|
+
/** `a ** b` as parsed before it was a {@link JS.Binary}, which trees from an older parser still hold. */
|
|
469
|
+
function isLegacyPower(assignment: JS.AssignmentOperation): boolean {
|
|
470
|
+
return assignment.operator.element === JS.AssignmentOperation.Type.Power;
|
|
471
|
+
}
|
|
472
|
+
|
|
476
473
|
function isUpdateOperator(operator: J.Unary.Type): boolean {
|
|
477
474
|
return operator === J.Unary.Type.PreIncrement || operator === J.Unary.Type.PreDecrement ||
|
|
478
475
|
isPostfixOperator(operator);
|
|
@@ -356,10 +356,10 @@ export interface PatternOptions {
|
|
|
356
356
|
types?: string[];
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* When true,
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
* have
|
|
359
|
+
* When true, a pattern without a type annotation matches code with or without one, so
|
|
360
|
+
* `const ${x} = ${v}` matches `const a: number = 1`, while an annotation the pattern spells out
|
|
361
|
+
* must be matched by the code's. Type attribution missing on either side is not a mismatch.
|
|
362
|
+
* When false, the pattern and the code must both have each annotation, or both lack it.
|
|
363
363
|
*
|
|
364
364
|
* @default true (lenient matching enabled for backward compatibility)
|
|
365
365
|
*/
|
|
@@ -423,6 +423,10 @@ function escapeString(str: string): string {
|
|
|
423
423
|
/**
|
|
424
424
|
* Format a literal value for inline display.
|
|
425
425
|
*/
|
|
426
|
+
function formatScalar(value: unknown): string {
|
|
427
|
+
return typeof value === 'bigint' ? `${value}n` : JSON.stringify(value);
|
|
428
|
+
}
|
|
429
|
+
|
|
426
430
|
function formatLiteralValue(lit: J.Literal): string {
|
|
427
431
|
let value: string;
|
|
428
432
|
if (lit.valueSource !== undefined) {
|
|
@@ -749,7 +753,7 @@ export class LstDebugPrinter {
|
|
|
749
753
|
|
|
750
754
|
// Primitive or unknown type
|
|
751
755
|
if (typeof node !== 'object') {
|
|
752
|
-
this.outputLines.push(`${this.indent(depth)}${
|
|
756
|
+
this.outputLines.push(`${this.indent(depth)}${formatScalar(node)}`);
|
|
753
757
|
return;
|
|
754
758
|
}
|
|
755
759
|
|
|
@@ -851,7 +855,7 @@ export class LstDebugPrinter {
|
|
|
851
855
|
// Skip complex objects that aren't J nodes
|
|
852
856
|
this.outputLines.push(`${this.indent(depth)}${key}: <object>`);
|
|
853
857
|
} else {
|
|
854
|
-
this.outputLines.push(`${this.indent(depth)}${key}: ${
|
|
858
|
+
this.outputLines.push(`${this.indent(depth)}${key}: ${formatScalar(value)}`);
|
|
855
859
|
}
|
|
856
860
|
}
|
|
857
861
|
}
|
|
@@ -934,7 +938,7 @@ export class LstDebugPrinter {
|
|
|
934
938
|
if (typeof value === 'object' && value !== null) {
|
|
935
939
|
this.outputLines.push(`${this.indent(depth + 1)}${key}: <object>`);
|
|
936
940
|
} else {
|
|
937
|
-
this.outputLines.push(`${this.indent(depth + 1)}${key}: ${
|
|
941
|
+
this.outputLines.push(`${this.indent(depth + 1)}${key}: ${formatScalar(value)}`);
|
|
938
942
|
}
|
|
939
943
|
}
|
|
940
944
|
this.outputLines.push(`${this.indent(depth)}}`);
|
package/src/javascript/tree.ts
CHANGED
|
@@ -264,6 +264,7 @@ export namespace JS {
|
|
|
264
264
|
export interface ImportClause extends JS {
|
|
265
265
|
readonly kind: typeof Kind.ImportClause;
|
|
266
266
|
readonly typeOnly: boolean;
|
|
267
|
+
readonly deferred: boolean;
|
|
267
268
|
readonly name?: J.RightPadded<J.Identifier>;
|
|
268
269
|
readonly namedBindings?: Expression;
|
|
269
270
|
}
|
|
@@ -346,7 +347,8 @@ export namespace JS {
|
|
|
346
347
|
IdentityNotEquals = "IdentityNotEquals",
|
|
347
348
|
In = "In",
|
|
348
349
|
QuestionQuestion = "QuestionQuestion",
|
|
349
|
-
Comma = "Comma"
|
|
350
|
+
Comma = "Comma",
|
|
351
|
+
Exponentiation = "Exponentiation"
|
|
350
352
|
}
|
|
351
353
|
}
|
|
352
354
|
|
|
@@ -580,6 +582,7 @@ export namespace JS {
|
|
|
580
582
|
QuestionQuestion = "QuestionQuestion",
|
|
581
583
|
And = "And",
|
|
582
584
|
Or = "Or",
|
|
585
|
+
/** @deprecated `a ** b` is a {@link JS.Binary} of type {@link JS.Binary.Type.Exponentiation}. */
|
|
583
586
|
Power = "Power",
|
|
584
587
|
Exp = "Exp"
|
|
585
588
|
}
|
|
@@ -116,6 +116,11 @@ export class JavaScriptTypeMapping {
|
|
|
116
116
|
// Fall through to regular type checking if not a variable
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// The checker asserts when asked for the type of the `import.defer` in `import.defer(...)`
|
|
120
|
+
if (this.isImportDefer(node)) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
119
124
|
// TypeNode needs getTypeFromTypeNode (resolves the annotation itself).
|
|
120
125
|
// Everything else — expressions, declarations, specifiers, bindings, etc. —
|
|
121
126
|
// uses getTypeAtLocation which works for virtually all node kinds.
|
|
@@ -707,13 +712,18 @@ export class JavaScriptTypeMapping {
|
|
|
707
712
|
node = this.unparenthesized(node);
|
|
708
713
|
if (ts.isAwaitExpression(node)) {
|
|
709
714
|
const call = this.unparenthesized(node.expression);
|
|
710
|
-
return ts.isCallExpression(call) &&
|
|
715
|
+
return ts.isCallExpression(call) &&
|
|
716
|
+
(call.expression.kind === ts.SyntaxKind.ImportKeyword || this.isImportDefer(call.expression)) ?
|
|
711
717
|
this.moduleSpecifierArgument(call) : undefined;
|
|
712
718
|
}
|
|
713
719
|
return ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require' ?
|
|
714
720
|
this.moduleSpecifierArgument(node) : undefined;
|
|
715
721
|
}
|
|
716
722
|
|
|
723
|
+
private isImportDefer(node: ts.Node): boolean {
|
|
724
|
+
return ts.isMetaProperty(node) && node.keywordToken === ts.SyntaxKind.ImportKeyword && node.name.text === 'defer';
|
|
725
|
+
}
|
|
726
|
+
|
|
717
727
|
private unparenthesized(node: ts.Expression): ts.Expression {
|
|
718
728
|
while (ts.isParenthesizedExpression(node)) {
|
|
719
729
|
node = node.expression;
|
|
@@ -1048,6 +1058,10 @@ export class JavaScriptTypeMapping {
|
|
|
1048
1058
|
let declaringType: Type.FullyQualified;
|
|
1049
1059
|
let declaredFormalTypeNames: string[] = [];
|
|
1050
1060
|
|
|
1061
|
+
if (ts.isCallExpression(node) && this.isImportDefer(node.expression)) {
|
|
1062
|
+
return undefined;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1051
1065
|
// Handle different kinds of nodes that represent methods or method invocations
|
|
1052
1066
|
if (ts.isCallOrNewExpression(node)) {
|
|
1053
1067
|
// For method invocations (e.g., _.map(...))
|