@openrewrite/rewrite 0.26.0 → 0.28.0
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/remote/receiver.d.ts.map +1 -1
- package/dist/src/java/remote/receiver.js +0 -10
- package/dist/src/java/remote/receiver.js.map +1 -1
- package/dist/src/java/remote/sender.d.ts.map +1 -1
- package/dist/src/java/remote/sender.js +0 -7
- package/dist/src/java/remote/sender.js.map +1 -1
- package/dist/src/java/tree/tree.d.ts +0 -39
- package/dist/src/java/tree/tree.d.ts.map +1 -1
- package/dist/src/java/tree/tree.js +2 -48
- package/dist/src/java/tree/tree.js.map +1 -1
- package/dist/src/java/visitor.d.ts +1 -2
- package/dist/src/java/visitor.d.ts.map +1 -1
- package/dist/src/java/visitor.js +0 -15
- package/dist/src/java/visitor.js.map +1 -1
- package/dist/src/javascript/parser.d.ts +14 -9
- package/dist/src/javascript/parser.d.ts.map +1 -1
- package/dist/src/javascript/parser.js +90 -32
- package/dist/src/javascript/parser.js.map +1 -1
- package/dist/src/javascript/remote/receiver.d.ts.map +1 -1
- package/dist/src/javascript/remote/receiver.js +84 -17
- package/dist/src/javascript/remote/receiver.js.map +1 -1
- package/dist/src/javascript/remote/sender.d.ts.map +1 -1
- package/dist/src/javascript/remote/sender.js +62 -13
- package/dist/src/javascript/remote/sender.js.map +1 -1
- package/dist/src/javascript/tree/support_types.d.ts +19 -4
- package/dist/src/javascript/tree/support_types.d.ts.map +1 -1
- package/dist/src/javascript/tree/support_types.js +15 -0
- package/dist/src/javascript/tree/support_types.js.map +1 -1
- package/dist/src/javascript/tree/tree.d.ts +350 -26
- package/dist/src/javascript/tree/tree.d.ts.map +1 -1
- package/dist/src/javascript/tree/tree.js +448 -59
- package/dist/src/javascript/tree/tree.js.map +1 -1
- package/dist/src/javascript/visitor.d.ts +8 -1
- package/dist/src/javascript/visitor.d.ts.map +1 -1
- package/dist/src/javascript/visitor.js +67 -6
- package/dist/src/javascript/visitor.js.map +1 -1
- package/package.json +1 -1
|
@@ -221,8 +221,31 @@ class JavaScriptParserVisitor {
|
|
|
221
221
|
};
|
|
222
222
|
this.typeMapping = new typeMapping_1.JavaScriptTypeMapping(typeChecker);
|
|
223
223
|
}
|
|
224
|
+
detectBOMAndTextEncoding(content) {
|
|
225
|
+
const BOM_UTF8 = "\uFEFF";
|
|
226
|
+
const BOM_UTF16_LE = [0xFF, 0xFE];
|
|
227
|
+
const hasUtf8Bom = content.startsWith(BOM_UTF8);
|
|
228
|
+
const hasUtf16LeBom = content.charCodeAt(0) === BOM_UTF16_LE[0] && content.charCodeAt(1) === BOM_UTF16_LE[1];
|
|
229
|
+
if (hasUtf8Bom) {
|
|
230
|
+
return { hasBom: true, encoding: 'utf8' };
|
|
231
|
+
}
|
|
232
|
+
else if (hasUtf16LeBom) {
|
|
233
|
+
return { hasBom: true, encoding: 'utf16le' };
|
|
234
|
+
}
|
|
235
|
+
return { hasBom: false, encoding: null };
|
|
236
|
+
}
|
|
224
237
|
visitSourceFile(node) {
|
|
225
|
-
|
|
238
|
+
let bomAndTextEncoding = this.detectBOMAndTextEncoding(node.getFullText());
|
|
239
|
+
let prefix = this.prefix(node);
|
|
240
|
+
if (bomAndTextEncoding.hasBom) {
|
|
241
|
+
if (bomAndTextEncoding.encoding === 'utf8') {
|
|
242
|
+
prefix = prefix.withWhitespace(prefix.whitespace.slice(1));
|
|
243
|
+
}
|
|
244
|
+
else if (bomAndTextEncoding.encoding === 'utf16le') {
|
|
245
|
+
prefix = prefix.withWhitespace(prefix.whitespace.slice(2));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return new JS.CompilationUnit((0, core_1.randomId)(), prefix, core_1.Markers.EMPTY, this.sourceFile.fileName, null, bomAndTextEncoding.encoding, bomAndTextEncoding.hasBom, null, [], this.semicolonPaddedStatementList(node.statements), this.prefix(node.endOfFileToken));
|
|
226
249
|
}
|
|
227
250
|
semicolonPaddedStatementList(statements) {
|
|
228
251
|
return [...statements].map(n => {
|
|
@@ -248,7 +271,7 @@ class JavaScriptParserVisitor {
|
|
|
248
271
|
|| ts.isInterfaceDeclaration(node) || ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isParameter(node)
|
|
249
272
|
|| ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node) || ts.isArrowFunction(node)
|
|
250
273
|
|| ts.isIndexSignatureDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isExportDeclaration(node)
|
|
251
|
-
|| ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isConstructorTypeNode(node) || ts.isTypeParameterDeclaration(node)) {
|
|
274
|
+
|| ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isConstructorTypeNode(node) || ts.isTypeParameterDeclaration(node) || ts.isImportDeclaration(node) || ts.isImportEqualsDeclaration(node)) {
|
|
252
275
|
return node.modifiers ? (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter(ts.isModifier).map(this.mapModifier) : [];
|
|
253
276
|
}
|
|
254
277
|
else if (ts.isExportAssignment(node)) {
|
|
@@ -373,6 +396,9 @@ class JavaScriptParserVisitor {
|
|
|
373
396
|
visitAnyKeyword(node) {
|
|
374
397
|
return this.mapIdentifier(node, 'any');
|
|
375
398
|
}
|
|
399
|
+
visitIntrinsicKeyword(node) {
|
|
400
|
+
return this.mapIdentifier(node, 'intrinsic');
|
|
401
|
+
}
|
|
376
402
|
visitObjectKeyword(node) {
|
|
377
403
|
return this.mapIdentifier(node, 'object');
|
|
378
404
|
}
|
|
@@ -476,6 +502,9 @@ class JavaScriptParserVisitor {
|
|
|
476
502
|
else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
477
503
|
annotationType = this.convert(node.expression);
|
|
478
504
|
}
|
|
505
|
+
else if (ts.isParenthesizedExpression(node.expression)) {
|
|
506
|
+
annotationType = new JS.TypeTreeExpression((0, core_1.randomId)(), this.prefix(node.expression), core_1.Markers.EMPTY, this.convert(node.expression));
|
|
507
|
+
}
|
|
479
508
|
else {
|
|
480
509
|
return this.visitUnknown(node);
|
|
481
510
|
}
|
|
@@ -513,7 +542,12 @@ class JavaScriptParserVisitor {
|
|
|
513
542
|
if (ts.isComputedPropertyName(node.name)) {
|
|
514
543
|
return new JS.JSMethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), this.convert(node.name), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, null, null, this.mapMethodType(node));
|
|
515
544
|
}
|
|
516
|
-
|
|
545
|
+
const name = !node.name
|
|
546
|
+
? this.mapIdentifier(node, "")
|
|
547
|
+
: ts.isStringLiteral(node.name)
|
|
548
|
+
? this.mapIdentifier(node.name, node.name.getText())
|
|
549
|
+
: this.visit(node.name);
|
|
550
|
+
return new J.MethodDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], [], this.mapTypeParametersAsObject(node), this.mapTypeInfo(node), new J.MethodDeclaration.IdentifierWithAnnotations(name, []), this.mapCommaSeparatedList(this.getParameterListNodes(node)), null, null, null, this.mapMethodType(node));
|
|
517
551
|
}
|
|
518
552
|
visitMethodDeclaration(node) {
|
|
519
553
|
if (node.questionToken || node.asteriskToken) {
|
|
@@ -574,11 +608,16 @@ class JavaScriptParserVisitor {
|
|
|
574
608
|
return this.visit(node.typeName);
|
|
575
609
|
}
|
|
576
610
|
visitFunctionType(node) {
|
|
577
|
-
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.leftPadded(java_1.Space.EMPTY, false), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.
|
|
578
|
-
|
|
611
|
+
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, [], this.leftPadded(java_1.Space.EMPTY, false), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.length == 0 ?
|
|
612
|
+
[this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)))]
|
|
613
|
+
: node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p)))
|
|
614
|
+
.concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken))) : []), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
579
615
|
}
|
|
580
616
|
visitConstructorType(node) {
|
|
581
|
-
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.NewKeyword)), true), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.
|
|
617
|
+
return new JS.FunctionType((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.NewKeyword)), true), this.mapTypeParametersAsObject(node), new java_1.JContainer(this.prefix(node.getChildAt(node.getChildren().findIndex(n => n.pos === node.parameters.pos) - 1)), node.parameters.length == 0 ?
|
|
618
|
+
[this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)))]
|
|
619
|
+
: node.parameters.map(p => this.rightPadded(this.visit(p), this.suffix(p)))
|
|
620
|
+
.concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken))) : []), core_1.Markers.EMPTY), this.prefix(this.findChildNode(node, ts.SyntaxKind.EqualsGreaterThanToken)), this.convert(node.type), null);
|
|
582
621
|
}
|
|
583
622
|
visitTypeQuery(node) {
|
|
584
623
|
return new JS.TypeQuery((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.exprName), node.typeArguments ? this.mapTypeArguments(this.suffix(node.exprName), node.typeArguments) : null, this.mapType(node));
|
|
@@ -804,7 +843,7 @@ class JavaScriptParserVisitor {
|
|
|
804
843
|
if (unaryOperator === undefined) {
|
|
805
844
|
return this.visitUnknown(node);
|
|
806
845
|
}
|
|
807
|
-
return new J.Unary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(this.
|
|
846
|
+
return new J.Unary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.operand), unaryOperator), this.convert(node.operand), this.mapType(node));
|
|
808
847
|
}
|
|
809
848
|
visitBinaryExpression(node) {
|
|
810
849
|
if (node.operatorToken.kind == ts.SyntaxKind.EqualsToken) {
|
|
@@ -850,6 +889,9 @@ class JavaScriptParserVisitor {
|
|
|
850
889
|
case ts.SyntaxKind.AsteriskAsteriskToken:
|
|
851
890
|
assignmentOperation = JS.JsAssignmentOperation.Type.Power;
|
|
852
891
|
break;
|
|
892
|
+
case ts.SyntaxKind.AsteriskAsteriskEqualsToken:
|
|
893
|
+
assignmentOperation = JS.JsAssignmentOperation.Type.Exp;
|
|
894
|
+
break;
|
|
853
895
|
}
|
|
854
896
|
if (assignmentOperation !== undefined) {
|
|
855
897
|
return new JS.JsAssignmentOperation((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.convert(node.left), this.leftPadded(this.prefix(node.operatorToken), assignmentOperation), this.convert(node.right), this.mapType(node));
|
|
@@ -945,7 +987,7 @@ class JavaScriptParserVisitor {
|
|
|
945
987
|
return new JS.Unary((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(java_1.Space.EMPTY, JS.Unary.Type.Spread), this.convert(node.expression), this.mapType(node));
|
|
946
988
|
}
|
|
947
989
|
visitClassExpression(node) {
|
|
948
|
-
return new JS.StatementExpression((0, core_1.randomId)(), new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY,
|
|
990
|
+
return new JS.StatementExpression((0, core_1.randomId)(), new J.ClassDeclaration((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapDecorators(node), [], new J.ClassDeclaration.Kind((0, core_1.randomId)(), node.modifiers ? this.suffix(node.modifiers[node.modifiers.length - 1]) : this.prefix(node), core_1.Markers.EMPTY, [], J.ClassDeclaration.Kind.Type.Class), node.name ? this.convert(node.name) : this.mapIdentifier(node, ""), this.mapTypeParametersAsJContainer(node), null, this.mapExtends(node), this.mapImplements(node), null, new J.Block((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenBraceToken)), core_1.Markers.EMPTY, this.rightPadded(false, java_1.Space.EMPTY), node.members.map(ce => {
|
|
949
991
|
var _a, _b;
|
|
950
992
|
return new java_1.JRightPadded(this.convert(ce), ((_a = ce.getLastToken()) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.SemicolonToken ? this.prefix(ce.getLastToken()) : java_1.Space.EMPTY, ((_b = ce.getLastToken()) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY);
|
|
951
993
|
}), this.prefix(node.getLastToken())), this.mapType(node)));
|
|
@@ -987,7 +1029,8 @@ class JavaScriptParserVisitor {
|
|
|
987
1029
|
return this.newJEmpty(this.prefix(node));
|
|
988
1030
|
}
|
|
989
1031
|
visitVariableStatement(node) {
|
|
990
|
-
|
|
1032
|
+
const declaration = this.visitVariableDeclarationList(node.declarationList);
|
|
1033
|
+
return declaration.withModifiers(this.mapModifiers(node).concat(declaration.modifiers)).withPrefix(this.prefix(node));
|
|
991
1034
|
}
|
|
992
1035
|
visitExpressionStatement(node) {
|
|
993
1036
|
const expression = this.visit(node.expression);
|
|
@@ -1009,7 +1052,7 @@ class JavaScriptParserVisitor {
|
|
|
1009
1052
|
}
|
|
1010
1053
|
visitWhileStatement(node) {
|
|
1011
1054
|
var _a;
|
|
1012
|
-
return new J.WhileLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.
|
|
1055
|
+
return new J.WhileLoop((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getChildAt(node.statement.getChildCount() - 1)) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
|
|
1013
1056
|
}
|
|
1014
1057
|
visitForStatement(node) {
|
|
1015
1058
|
var _a;
|
|
@@ -1038,7 +1081,8 @@ class JavaScriptParserVisitor {
|
|
|
1038
1081
|
return new J.Return((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.expression ? this.convert(node.expression) : null);
|
|
1039
1082
|
}
|
|
1040
1083
|
visitWithStatement(node) {
|
|
1041
|
-
|
|
1084
|
+
var _a;
|
|
1085
|
+
return new JS.WithStatement((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.rightPadded(this.convert(node.statement), this.semicolonPrefix(node.statement), ((_a = node.statement.getChildAt(node.statement.getChildCount() - 1)) === null || _a === void 0 ? void 0 : _a.kind) == ts.SyntaxKind.SemicolonToken ? core_1.Markers.build([new java_1.Semicolon((0, core_1.randomId)())]) : core_1.Markers.EMPTY));
|
|
1042
1086
|
}
|
|
1043
1087
|
visitSwitchStatement(node) {
|
|
1044
1088
|
return new J.Switch((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.expression), this.suffix(node.expression))), this.visit(node.caseBlock));
|
|
@@ -1051,6 +1095,10 @@ class JavaScriptParserVisitor {
|
|
|
1051
1095
|
return new J.Throw((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.expression));
|
|
1052
1096
|
}
|
|
1053
1097
|
visitTryStatement(node) {
|
|
1098
|
+
var _a, _b, _c, _d;
|
|
1099
|
+
if (((_b = (_a = node.catchClause) === null || _a === void 0 ? void 0 : _a.variableDeclaration) === null || _b === void 0 ? void 0 : _b.name) && !ts.isIdentifier((_d = (_c = node.catchClause) === null || _c === void 0 ? void 0 : _c.variableDeclaration) === null || _d === void 0 ? void 0 : _d.name)) {
|
|
1100
|
+
return new JS.JSTry((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.tryBlock), this.visit(node.catchClause), node.finallyBlock ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FinallyKeyword)), this.visit(node.finallyBlock)) : null);
|
|
1101
|
+
}
|
|
1054
1102
|
return new J.Try((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, null, this.visit(node.tryBlock), node.catchClause ? [this.visit(node.catchClause)] : [], node.finallyBlock ? this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.FinallyKeyword)), this.visit(node.finallyBlock)) : null);
|
|
1055
1103
|
}
|
|
1056
1104
|
visitDebuggerStatement(node) {
|
|
@@ -1064,12 +1112,19 @@ class JavaScriptParserVisitor {
|
|
|
1064
1112
|
return new JS.JSVariableDeclarations.JSNamedVariable((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.exclamationToken ? new JS.Unary((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.leftPadded(this.suffix(node.name), JS.Unary.Type.Exclamation), nameExpression, this.mapType(node)) : nameExpression, [], node.initializer ? this.leftPadded(this.prefix(node.getChildAt(node.getChildCount(this.sourceFile) - 2)), this.visit(node.initializer)) : null, this.mapVariableType(node));
|
|
1065
1113
|
}
|
|
1066
1114
|
visitVariableDeclarationList(node) {
|
|
1067
|
-
|
|
1068
|
-
|
|
1115
|
+
let kind = node.getFirstToken();
|
|
1116
|
+
let modifier;
|
|
1117
|
+
if ((kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.AwaitKeyword) {
|
|
1118
|
+
modifier = new J.Modifier((0, core_1.randomId)(), this.prefix(kind), core_1.Markers.EMPTY, 'await', J.Modifier.Type.LanguageExtension, []);
|
|
1119
|
+
kind = node.getChildAt(1);
|
|
1120
|
+
}
|
|
1121
|
+
return new JS.ScopedVariableDeclarations((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, modifier ? [modifier] : [], this.leftPadded(kind ? this.prefix(kind) : this.prefix(node), (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.LetKeyword
|
|
1069
1122
|
? JS.ScopedVariableDeclarations.Scope.Let
|
|
1070
1123
|
: (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.ConstKeyword
|
|
1071
1124
|
? JS.ScopedVariableDeclarations.Scope.Const
|
|
1072
|
-
:
|
|
1125
|
+
: (kind === null || kind === void 0 ? void 0 : kind.kind) === ts.SyntaxKind.UsingKeyword
|
|
1126
|
+
? JS.ScopedVariableDeclarations.Scope.Using
|
|
1127
|
+
: JS.ScopedVariableDeclarations.Scope.Var), node.declarations.map((declaration) => {
|
|
1073
1128
|
const declarationExpression = this.visit(declaration);
|
|
1074
1129
|
return this.rightPadded(JS.isJavaScript(declarationExpression)
|
|
1075
1130
|
? new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(declaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(declaration), null, [this.rightPadded(declarationExpression, java_1.Space.EMPTY)])
|
|
@@ -1142,30 +1197,25 @@ class JavaScriptParserVisitor {
|
|
|
1142
1197
|
], this.leftPadded(this.prefix(this.findChildNode(node, ts.SyntaxKind.NamespaceKeyword)), JS.NamespaceDeclaration.KeywordType.Namespace), this.rightPadded(this.convert(node.name), this.suffix(node.name)), null);
|
|
1143
1198
|
}
|
|
1144
1199
|
visitImportEqualsDeclaration(node) {
|
|
1145
|
-
|
|
1200
|
+
const kind = this.findChildNode(node, ts.SyntaxKind.ImportKeyword);
|
|
1201
|
+
return new JS.ScopedVariableDeclarations((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), this.leftPadded(this.prefix(kind), JS.ScopedVariableDeclarations.Scope.Import), [
|
|
1202
|
+
this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], node.isTypeOnly ? [new J.Modifier((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)), core_1.Markers.EMPTY, "type", J.Modifier.Type.LanguageExtension, [])] : [], null, null, [], [this.rightPadded(new J.VariableDeclarations.NamedVariable((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.visit(node.name), [], this.leftPadded(this.suffix(node.name), this.visit(node.moduleReference)), this.mapVariableType(node)), java_1.Space.EMPTY)]), java_1.Space.EMPTY)
|
|
1203
|
+
]);
|
|
1146
1204
|
}
|
|
1147
1205
|
visitImportKeyword(node) {
|
|
1148
1206
|
return this.mapIdentifier(node, 'import');
|
|
1149
1207
|
}
|
|
1150
1208
|
visitImportDeclaration(node) {
|
|
1151
|
-
|
|
1152
|
-
const children = node.getChildren(this.sourceFile);
|
|
1153
|
-
const _default = !!((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.name);
|
|
1154
|
-
const onlyDefault = _default && node.importClause.namedBindings == undefined;
|
|
1155
|
-
return new JS.JsImport((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, _default ? this.rightPadded(this.visit((_b = node.importClause) === null || _b === void 0 ? void 0 : _b.name), this.suffix((_c = node.importClause) === null || _c === void 0 ? void 0 : _c.name)) : null, ((_d = node.importClause) === null || _d === void 0 ? void 0 : _d.isTypeOnly) ? this.leftPadded(this.prefix(this.findChildNode(node.importClause, ts.SyntaxKind.TypeKeyword)), node.importClause.isTypeOnly) : this.leftPadded(java_1.Space.EMPTY, false), node.importClause && !onlyDefault ? this.visit(node.importClause) : null, children[children.indexOf(node.moduleSpecifier) - 1].kind == ts.SyntaxKind.FromKeyword ? this.prefix(children[children.indexOf(node.moduleSpecifier) - 1]) : null, this.convert(node.moduleSpecifier), null);
|
|
1209
|
+
return new JS.JsImport((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapModifiers(node), node.importClause ? this.visit(node.importClause) : null, this.leftPadded(node.importClause ? this.prefix(this.findChildNode(node, ts.SyntaxKind.FromKeyword)) : java_1.Space.EMPTY, this.visit(node.moduleSpecifier)), node.attributes ? this.visit(node.attributes) : null);
|
|
1156
1210
|
}
|
|
1157
1211
|
visitImportClause(node) {
|
|
1158
|
-
|
|
1159
|
-
if (node.namedBindings && ts.isNamespaceImport(node.namedBindings)) {
|
|
1160
|
-
return new java_1.JContainer(this.prefix(node), [this.rightPadded(new JS.Alias((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.rightPadded(this.mapIdentifier(node.namedBindings, "*"), this.prefix(node.namedBindings.getChildAt(1, this.sourceFile))), this.convert(node.namedBindings.name)), java_1.Space.EMPTY)], core_1.Markers.EMPTY);
|
|
1161
|
-
}
|
|
1162
|
-
return this.mapCommaSeparatedList((_a = node.namedBindings) === null || _a === void 0 ? void 0 : _a.getChildren(this.sourceFile));
|
|
1212
|
+
return new JS.JsImportClause((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.isTypeOnly, node.name ? this.rightPadded(this.visit(node.name), this.suffix(node.name)) : null, node.namedBindings ? this.visit(node.namedBindings) : null);
|
|
1163
1213
|
}
|
|
1164
1214
|
visitNamespaceImport(node) {
|
|
1165
|
-
return this.
|
|
1215
|
+
return new JS.Alias((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.mapIdentifier(node, "*"), this.prefix(this.findChildNode(node, ts.SyntaxKind.AsKeyword))), this.visit(node.name));
|
|
1166
1216
|
}
|
|
1167
1217
|
visitNamedImports(node) {
|
|
1168
|
-
return this.
|
|
1218
|
+
return new JS.NamedImports((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.mapCommaSeparatedList(node.getChildren(this.sourceFile)), null);
|
|
1169
1219
|
}
|
|
1170
1220
|
visitImportSpecifier(node) {
|
|
1171
1221
|
return new JS.JsImportSpecifier((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.leftPadded(node.isTypeOnly ? this.prefix(this.findChildNode(node, ts.SyntaxKind.TypeKeyword)) : java_1.Space.EMPTY, node.isTypeOnly), node.propertyName
|
|
@@ -1241,15 +1291,21 @@ class JavaScriptParserVisitor {
|
|
|
1241
1291
|
return this.convert(node.types[0]);
|
|
1242
1292
|
}
|
|
1243
1293
|
visitCatchClause(node) {
|
|
1294
|
+
var _a, _b;
|
|
1295
|
+
if (((_a = node.variableDeclaration) === null || _a === void 0 ? void 0 : _a.name) && !ts.isIdentifier((_b = node.variableDeclaration) === null || _b === void 0 ? void 0 : _b.name)) {
|
|
1296
|
+
return new JS.JSTry.JSCatch((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(new JS.JSVariableDeclarations((0, core_1.randomId)(), this.prefix(node.variableDeclaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node.variableDeclaration), null, [this.rightPadded(this.visit(node.variableDeclaration), java_1.Space.EMPTY)]), this.suffix(node.variableDeclaration))), this.visit(node.block));
|
|
1297
|
+
}
|
|
1244
1298
|
return new J.Try.Catch((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, node.variableDeclaration ?
|
|
1245
1299
|
new J.ControlParentheses((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)), core_1.Markers.EMPTY, this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), this.prefix(node.variableDeclaration), core_1.Markers.EMPTY, [], [], this.mapTypeInfo(node.variableDeclaration), null, [], [this.rightPadded(this.visit(node.variableDeclaration), java_1.Space.EMPTY)]), this.suffix(node.variableDeclaration))) :
|
|
1246
1300
|
new J.ControlParentheses((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, this.rightPadded(new J.VariableDeclarations((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], [], null, null, [], []), java_1.Space.EMPTY)), this.visit(node.block));
|
|
1247
1301
|
}
|
|
1248
1302
|
visitImportAttributes(node) {
|
|
1249
|
-
|
|
1303
|
+
const openBraceIndex = node.getChildren().findIndex(n => n.kind === ts.SyntaxKind.OpenBraceToken);
|
|
1304
|
+
const elements = this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(openBraceIndex, openBraceIndex + 3));
|
|
1305
|
+
return new JS.ImportAttributes((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, ts.SyntaxKind.WithKeyword === node.token ? JS.ImportAttributes.Token.With : JS.ImportAttributes.Token.Assert, elements);
|
|
1250
1306
|
}
|
|
1251
1307
|
visitImportAttribute(node) {
|
|
1252
|
-
return this.
|
|
1308
|
+
return new JS.ImportAttribute((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.visit(node.name), this.leftPadded(this.suffix(node.name), this.visit(node.value)));
|
|
1253
1309
|
}
|
|
1254
1310
|
visitPropertyAssignment(node) {
|
|
1255
1311
|
return new JS.PropertyAssignment((0, core_1.randomId)(), this.prefix(node), core_1.Markers.EMPTY, this.rightPadded(this.visit(node.name), this.suffix(node.name)), JS.PropertyAssignment.AssigmentToken.Colon, this.visit(node.initializer));
|
|
@@ -1484,7 +1540,7 @@ class JavaScriptParserVisitor {
|
|
|
1484
1540
|
}
|
|
1485
1541
|
mapTypeParametersAsJContainer(node) {
|
|
1486
1542
|
return node.typeParameters
|
|
1487
|
-
? java_1.JContainer.build(this.
|
|
1543
|
+
? java_1.JContainer.build(this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)), this.mapTypeParametersList(node.typeParameters)
|
|
1488
1544
|
.concat(node.typeParameters.hasTrailingComma ? this.rightPadded(new J.TypeParameter((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], [], this.newJEmpty(), null), this.prefix(this.findChildNode(node, ts.SyntaxKind.GreaterThanToken))) : []), core_1.Markers.EMPTY)
|
|
1489
1545
|
: null;
|
|
1490
1546
|
}
|
|
@@ -1492,8 +1548,10 @@ class JavaScriptParserVisitor {
|
|
|
1492
1548
|
const typeParameters = node.typeParameters;
|
|
1493
1549
|
if (!typeParameters)
|
|
1494
1550
|
return null;
|
|
1495
|
-
return new J.TypeParameters((0, core_1.randomId)(), this.prefix(
|
|
1496
|
-
|
|
1551
|
+
return new J.TypeParameters((0, core_1.randomId)(), this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)), core_1.Markers.EMPTY, [], typeParameters.length == 0 ?
|
|
1552
|
+
[this.rightPadded(new J.TypeParameter((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], [], this.newJEmpty(), null), this.prefix(this.findChildNode(node, ts.SyntaxKind.GreaterThanToken)))]
|
|
1553
|
+
: typeParameters.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp)))
|
|
1554
|
+
.concat(typeParameters.hasTrailingComma ? this.rightPadded(new J.TypeParameter((0, core_1.randomId)(), java_1.Space.EMPTY, core_1.Markers.EMPTY, [], [], this.newJEmpty(), null), this.prefix(this.findChildNode(node, ts.SyntaxKind.GreaterThanToken))) : []));
|
|
1497
1555
|
}
|
|
1498
1556
|
mapTypeParametersList(typeParamsNodeArray) {
|
|
1499
1557
|
return typeParamsNodeArray.map(tp => this.rightPadded(this.visit(tp), this.suffix(tp)));
|