From a157cf683dd9293776a2e0334d4a58b8c4b87907 Mon Sep 17 00:00:00 2001 From: Bryce Tompkins Date: Wed, 9 Apr 2025 09:52:44 -0400 Subject: [PATCH] refactor: Format Java code Use this link to re-run the recipe: http://localhost%3A3000/recipes/org.openrewrite.java.format.AutoFormat?organizationId=QUxM Co-authored-by: Moderne --- .../caoccao/javet/interop/JavetBridge.java | 3 +- .../javascript/AddLicenseHeader.java | 4 +- .../javascript/JavaScriptVisitor.java | 4 +- .../internal/JavetNativeBridge.java | 2 +- .../javascript/internal/JavetUtils.java | 3 +- .../javascript/internal/TsTreePrinter.java | 6 +- .../internal/TypeScriptParserVisitor.java | 9 +- .../internal/tsc/TSCConversion.java | 3 +- .../javascript/internal/tsc/TSCIndexInfo.java | 6 +- .../internal/tsc/TSCInstanceOfChecks.java | 2 +- .../internal/tsc/TSCProgramContext.java | 2 +- .../javascript/internal/tsc/TSCRuntime.java | 2 +- .../internal/tsc/TSCTypeAccessors.java | 2 +- .../javascript/internal/tsc/TSCV8Backed.java | 2 +- .../javascript/internal/tsc/TSCV8Utils.java | 2 +- .../cleanup/UseCaseFallThroughTest.java | 42 +- .../javascript/format/SpacesTest.java | 360 +++++++++--------- .../javascript/internal/V8InteropTests.java | 233 ++++++------ .../recipe/AddLicenseHeaderTest.java | 16 +- .../javascript/recipe/RecipeTest.java | 18 +- .../javascript/tree/AnnotationTest.java | 18 +- .../javascript/tree/ArrayTest.java | 40 +- .../javascript/tree/ArrowFunctionTest.java | 24 +- .../tree/AssignmentOperationTest.java | 36 +- .../javascript/tree/AssignmentTest.java | 18 +- .../javascript/tree/AwaitTest.java | 6 +- .../javascript/tree/BinaryTest.java | 86 ++--- .../javascript/tree/BreakTest.java | 12 +- .../openrewrite/javascript/tree/CastTest.java | 6 +- .../javascript/tree/ClassDeclarationTest.java | 36 +- .../javascript/tree/CommentTest.java | 42 +- .../javascript/tree/ContinueTest.java | 12 +- .../javascript/tree/DeleteTest.java | 6 +- .../javascript/tree/DestructureTest.java | 12 +- .../javascript/tree/DoWhileTest.java | 12 +- .../openrewrite/javascript/tree/EnumTest.java | 6 +- .../javascript/tree/ExportTest.java | 78 ++-- .../javascript/tree/FieldAccessTest.java | 18 +- .../javascript/tree/ForLoopTest.java | 30 +- .../javascript/tree/IfStatementTest.java | 18 +- .../javascript/tree/ImportTest.java | 30 +- .../javascript/tree/IndexedAccessTest.java | 6 +- .../javascript/tree/LiteralTest.java | 84 ++-- .../tree/MethodDeclarationTest.java | 42 +- .../javascript/tree/MethodInvocationTest.java | 24 +- .../javascript/tree/NewClassTest.java | 12 +- .../javascript/tree/ObjectBindingTest.java | 30 +- .../javascript/tree/ObjectLiteralTest.java | 18 +- .../javascript/tree/ParenthesesTest.java | 12 +- .../javascript/tree/ParserTest.java | 6 +- .../javascript/tree/PrimitiveTest.java | 14 +- .../javascript/tree/ReturnTest.java | 6 +- .../javascript/tree/SemiColonTest.java | 24 +- .../javascript/tree/SwitchTest.java | 30 +- .../javascript/tree/ThrowTest.java | 6 +- .../javascript/tree/TrailingCommaTest.java | 30 +- .../javascript/tree/TryCatchTest.java | 12 +- .../javascript/tree/TupleTest.java | 36 +- .../javascript/tree/TypeOperatorTest.java | 32 +- .../javascript/tree/UnaryTest.java | 38 +- .../javascript/tree/UnionTest.java | 6 +- .../tree/VariableDeclarationTest.java | 78 ++-- .../javascript/tree/WhileLoopTest.java | 6 +- .../javascript/tree/YieldTest.java | 12 +- 64 files changed, 920 insertions(+), 911 deletions(-) diff --git a/src/main/java/com/caoccao/javet/interop/JavetBridge.java b/src/main/java/com/caoccao/javet/interop/JavetBridge.java index c8ba44a3..2677e88d 100644 --- a/src/main/java/com/caoccao/javet/interop/JavetBridge.java +++ b/src/main/java/com/caoccao/javet/interop/JavetBridge.java @@ -27,7 +27,8 @@ import java.util.Map; public final class JavetBridge { - private JavetBridge() {} + private JavetBridge() { + } public static Map getReferenceMapSnapshot(V8Runtime runtime) { return new HashMap<>(runtime.referenceMap); diff --git a/src/main/java/org/openrewrite/javascript/AddLicenseHeader.java b/src/main/java/org/openrewrite/javascript/AddLicenseHeader.java index 8edd0861..f8b3b22b 100644 --- a/src/main/java/org/openrewrite/javascript/AddLicenseHeader.java +++ b/src/main/java/org/openrewrite/javascript/AddLicenseHeader.java @@ -32,8 +32,8 @@ public class AddLicenseHeader extends Recipe { * See {@link MethodMatcher} for details on the expression's syntax. */ @Option(displayName = "License text", - description = "The license header text without the block comment. May contain ${CURRENT_YEAR} property.", - example = "Copyright ${CURRENT_YEAR} the original author or authors...") + description = "The license header text without the block comment. May contain ${CURRENT_YEAR} property.", + example = "Copyright ${CURRENT_YEAR} the original author or authors...") String licenseText; @Override diff --git a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java index 6c41d40a..a260b4c5 100644 --- a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -242,6 +242,7 @@ public J visitJsImport(JS.JsImport jsImport, P p) { } return i; } + public J visitJsOperator(JS.JsOperator operator, P p) { JS.JsOperator o = operator; o = o.withPrefix(visitSpace(o.getPrefix(), JsSpace.Location.OPERATOR_PREFIX, p)); @@ -458,7 +459,8 @@ private JContainer visitTypeNames(@Nullable JContainer na if (nameTrees == null) { return null; } - @SuppressWarnings("unchecked") List> js = ListUtils.map(nameTrees.getPadding().getElements(), + @SuppressWarnings("unchecked") + List> js = ListUtils.map(nameTrees.getPadding().getElements(), t -> t.getElement() instanceof NameTree ? (JRightPadded) visitTypeName((JRightPadded) t, p) : t); return js == nameTrees.getPadding().getElements() ? nameTrees : JContainer.build(nameTrees.getBefore(), js, Markers.EMPTY); } diff --git a/src/main/java/org/openrewrite/javascript/internal/JavetNativeBridge.java b/src/main/java/org/openrewrite/javascript/internal/JavetNativeBridge.java index f61446bc..7af776d7 100644 --- a/src/main/java/org/openrewrite/javascript/internal/JavetNativeBridge.java +++ b/src/main/java/org/openrewrite/javascript/internal/JavetNativeBridge.java @@ -110,7 +110,7 @@ private static void actuallyInit() { try ( InputStream inputStream = JavetLibLoader.class.getResourceAsStream(nativeLibPath); FileOutputStream outputStream = new FileOutputStream(tempFile) - ) { + ) { if (inputStream == null) { throw new IllegalStateException("Could not find bundled resource for " + nativeLibPath); } diff --git a/src/main/java/org/openrewrite/javascript/internal/JavetUtils.java b/src/main/java/org/openrewrite/javascript/internal/JavetUtils.java index e07ffc96..3fc9c962 100644 --- a/src/main/java/org/openrewrite/javascript/internal/JavetUtils.java +++ b/src/main/java/org/openrewrite/javascript/internal/JavetUtils.java @@ -19,7 +19,8 @@ import org.openrewrite.internal.lang.Nullable; public class JavetUtils { - private JavetUtils() {} + private JavetUtils() { + } public static void close(@Nullable IV8Value valueV8) { if (valueV8 != null && !valueV8.isClosed()) { diff --git a/src/main/java/org/openrewrite/javascript/internal/TsTreePrinter.java b/src/main/java/org/openrewrite/javascript/internal/TsTreePrinter.java index 1e334703..42fefd34 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TsTreePrinter.java +++ b/src/main/java/org/openrewrite/javascript/internal/TsTreePrinter.java @@ -124,7 +124,7 @@ private void printTSCNode(TSCNode node, int depth, TSCSourceFileContext context, outputLines.add(line); List tscNodes = node.getAllChildNodes(); - for ( int i = 0; i < tscNodes.size(); i++) { + for (int i = 0; i < tscNodes.size(); i++) { TSCNode childNode = tscNodes.get(i); TSCNode nextChildNode = i < tscNodes.size() - 1 ? tscNodes.get(i + 1) : null; boolean hasGap = nextChildNode != null && nextChildNode.getStart() > childNode.getEnd(); @@ -161,7 +161,7 @@ private void printTSCNode(TSCNode node, int depth, TSCSourceFileContext context, } private static String toString(TSCNode node) { - return "[" + node.getStart() + "," + node.getEnd() + ")" + " | " + node.syntaxKind().name() + " | Text : \"" + + return "[" + node.getStart() + "," + node.getEnd() + ")" + " | " + node.syntaxKind().name() + " | Text : \"" + truncate(node.getText()).replace("\n", "\\n").replace("\r", "\\r") + "\""; } @@ -401,7 +401,7 @@ public static String printIndexedSourceCode(String sourceCode) { } if (!digits.isEmpty()) { - spacesSb.append(digits.poll()) ; + spacesSb.append(digits.poll()); } else { spacesSb.append(" "); } diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index 2a7db084..5d4cdb52 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -72,7 +72,8 @@ public JS.CompilationUnit visitSourceFile() { List> statements = new ArrayList<>(statementList.size()); Space prefix = whitespace(); for (TSCNode child : statementList) { - @Nullable J visited; + @Nullable + J visited; int saveCursor = getCursor(); try { visited = visitNode(child); @@ -1728,7 +1729,7 @@ private J.Literal visitNumericLiteral(TSCNode node) { private J visitObjectLiteralExpression(TSCNode node) { Space prefix = whitespace(); - return mapPropertyNodesToNewClass( node.getOptionalNodeListProperty("properties"), prefix); + return mapPropertyNodesToNewClass(node.getOptionalNodeListProperty("properties"), prefix); } private JS.ObjectBindingDeclarations mapObjectBindingDeclaration(TSCNode node) { @@ -2334,7 +2335,7 @@ private JS.JsOperator visitTsOperator(TSCNode node) { private J visitTypeLiteral(TSCNode node) { Space prefix = whitespace(); - return mapPropertyNodesToNewClass( node.getOptionalNodeListProperty("members"), prefix); + return mapPropertyNodesToNewClass(node.getOptionalNodeListProperty("members"), prefix); } private JS.TypeOperator visitTypeOperator(TSCNode node) { @@ -3606,4 +3607,4 @@ private void implementMe(TSCNode node, String propertyName) { throw new UnsupportedOperationException(node.syntaxKind() + "#" + propertyName + " not implemented"); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCConversion.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCConversion.java index 3ccdec9f..c6876f72 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCConversion.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCConversion.java @@ -36,7 +36,8 @@ public interface TSCConversion { } default T convertNonNull(TSCProgramContext context, V8Value value) { - @Nullable T converted = convertNullable(context, value); + @Nullable + T converted = convertNullable(context, value); if (converted == null) { throw new IllegalArgumentException("value converted to null, but was required to be non-null"); } diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCIndexInfo.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCIndexInfo.java index 370a8278..6dde9ab6 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCIndexInfo.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCIndexInfo.java @@ -21,8 +21,10 @@ @Value public class TSCIndexInfo { - @NonNull TSCType keyType; - @NonNull TSCType type; + @NonNull + TSCType keyType; + @NonNull + TSCType type; boolean isReadonly; TSCNode declaration; diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java index 855000e5..e469334d 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java @@ -66,7 +66,7 @@ public static TSCInstanceOfChecks fromJS(V8ValueObject tsGlobalsV8) { V8ValueObject allocators = tsGlobalsV8.get("objectAllocator"); V8ValueArray constructors = runtimeV8.createV8ValueArray(); V8ValueObject outerVars = runtimeV8.createV8ValueObject() - ) { + ) { for (ConstructorKind constructorKind : ConstructorKind.values()) { try (V8ValueFunction constructor = allocators.invoke(constructorKind.allocatorAccessorName)) { diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCProgramContext.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCProgramContext.java index b91d6bf1..5cf80da8 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCProgramContext.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCProgramContext.java @@ -81,7 +81,7 @@ public static TSCProgramContext fromJS(V8ValueObject contextV8) { V8ValueFunction createScanner = contextV8.get("createScanner"); V8ValueFunction getOpenRewriteId = contextV8.get("getOpenRewriteId"); V8ValueObject pathPrefixes = contextV8.get("pathPrefixes"); - ) { + ) { return new TSCProgramContext( program, tsGlobals, diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java index 5a35e5ca..3bf74dff 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java @@ -158,7 +158,7 @@ public void parseSourceTexts(Map sourceTexts, BiConsumer { if (maybeSourceFileV8.isNullOrUndefined()) { // TODO figure out how to handle this diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCTypeAccessors.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCTypeAccessors.java index 815b2b85..daee343a 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCTypeAccessors.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCTypeAccessors.java @@ -203,7 +203,7 @@ public String toString() { if (enclosing != null) { interfaceName = enclosing.getSimpleName(); } - return "Type[as " + interfaceName + "]#" + getTypeId() + "(" + typeToString() + ")"; + return "Type[as " + interfaceName + "]#" + getTypeId() + "(" + typeToString() + ")"; } } diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Backed.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Backed.java index 9b9d2e2e..0ae73529 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Backed.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Backed.java @@ -394,7 +394,7 @@ default List getOwnPropertyNames() { } default List getAllPropertyNames() { - try(IV8ValueArray propertyNames = this.getBackingV8Object().getPropertyNames()) { + try (IV8ValueArray propertyNames = this.getBackingV8Object().getPropertyNames()) { List result = new ArrayList<>(propertyNames.getLength()); for (int i = 0; i < propertyNames.getLength(); i++) { result.add(propertyNames.getString(i)); diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java index 7b791f4e..3c8f4597 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java @@ -60,7 +60,7 @@ public static V8ValueFunction makeFunction( try ( V8ValueFunction outerFn = runtime.createV8ValueFunction(outerCode); V8Value innerFnObject = outerFn.call(null, variables) - ) { + ) { if (!(innerFnObject instanceof V8ValueFunction)) { throw new IllegalStateException("expected a function; found: " + innerFnObject.getClass().getSimpleName()); } diff --git a/src/test/java/org/openrewrite/javascript/cleanup/UseCaseFallThroughTest.java b/src/test/java/org/openrewrite/javascript/cleanup/UseCaseFallThroughTest.java index 03c49faf..2510c744 100644 --- a/src/test/java/org/openrewrite/javascript/cleanup/UseCaseFallThroughTest.java +++ b/src/test/java/org/openrewrite/javascript/cleanup/UseCaseFallThroughTest.java @@ -35,8 +35,8 @@ public void defaults(RecipeSpec spec) { @Test void noChange() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo(x) { switch (x) { case "a": @@ -52,15 +52,15 @@ function foo(x) { } } """ - ) + ) ); } @Test void booleanLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ function method(x: number) { switch (true) { case foo(), bar(): @@ -75,15 +75,15 @@ function foo(): boolean { function bar(): boolean { } """ - ) + ) ); } @Test void logicalAndWithOr() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo(x) { switch (x) { case "a" && "b" || "c": @@ -94,7 +94,7 @@ function foo(x) { } } """ - ) + ) ); } @@ -102,8 +102,8 @@ function foo(x) { @Test void logicalOrs() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo(x) { switch (x) { case "a" || "b" || "c": @@ -114,7 +114,7 @@ function foo(x) { } } """, - """ + """ function foo(x) { switch (x) { case "a": @@ -127,15 +127,15 @@ function foo(x) { } } """ - ) + ) ); } @Test void logicalComma() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo(x) { switch (x) { case "a" , "b" , "c": @@ -146,7 +146,7 @@ function foo(x) { } } """, - """ + """ function foo(x) { switch (x) { case "a": @@ -159,15 +159,15 @@ function foo(x) { } } """ - ) + ) ); } @Test void withBraces() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo(x) { switch (x) { case "a" , "b" , "c": { @@ -179,7 +179,7 @@ function foo(x) { } } """, - """ + """ function foo(x) { switch (x) { case "a": @@ -193,7 +193,7 @@ function foo(x) { } } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/format/SpacesTest.java b/src/test/java/org/openrewrite/javascript/format/SpacesTest.java index 9dafd989..9af7752d 100644 --- a/src/test/java/org/openrewrite/javascript/format/SpacesTest.java +++ b/src/test/java/org/openrewrite/javascript/format/SpacesTest.java @@ -47,9 +47,9 @@ private static Consumer spaces(UnaryOperator with) { @Test void beforeParensFunctionDeclarationTrue() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true))), + javaScript( + """ function method1() { } function method2() { @@ -57,7 +57,7 @@ function method2() { function method3() { } """, - """ + """ function method1 () { } function method2 () { @@ -65,16 +65,16 @@ function method2 () { function method3 () { } """ - ) + ) ); } @Test void beforeParensFunctionDeclarationFalse() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), + javaScript( + """ function method1 () { } function method2 () { @@ -82,7 +82,7 @@ function method2 () { function method3 () { } """, - """ + """ function method1() { } function method2() { @@ -90,201 +90,201 @@ function method2() { function method3() { } """ - ) + ) ); } @Test void beforeParensFunctionDeclarationTrueWithComment() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true))), + javaScript( + """ function method1 /*comment*/() { } """, - """ + """ function method1 /*comment*/ () { } """ - ) + ) ); } @Test void beforeParensFunctionDeclarationFalseWithComment() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), + javaScript( + """ function method1 /*comment*/ () { } """, - """ + """ function method1 /*comment*/() { } """ - ) + ) ); } @Test void beforeParensFunctionDeclarationFalseWithLineBreakIgnored() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(false))), + javaScript( + """ function method1 () { } """ - ) + ) ); } @Test void beforeParensFunctionCallTrue() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionCallParentheses(true))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionCallParentheses(true))), + javaScript( + """ class Test {} function foo() { foo(); const test = new Test(); } """, - """ + """ class Test {} function foo() { foo (); const test = new Test (); } """ - ) + ) ); } @Test void beforeParensFunctionCallFalse() { rewriteRun( - spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionCallParentheses(false))), - javaScript( - """ + spaces(style -> style.withBeforeParentheses(style.getBeforeParentheses().withFunctionCallParentheses(false))), + javaScript( + """ class Test {} function foo() { foo (); const test = new Test (); } """, - """ + """ class Test {} function foo() { foo(); const test = new Test(); } """ - ) + ) ); } @Test void beforeLeftBraceFunctionLeftBraceTrue() { rewriteRun( - spaces(style -> style.withBeforeLeftBrace(style.getBeforeLeftBrace().withFunctionLeftBrace(true))), - javaScript( - """ + spaces(style -> style.withBeforeLeftBrace(style.getBeforeLeftBrace().withFunctionLeftBrace(true))), + javaScript( + """ function foo(){ } """, - """ + """ function foo() { } """ - ) + ) ); } @Test void beforeLeftBraceFunctionLeftBraceFalse() { rewriteRun( - spaces(style -> style.withBeforeLeftBrace(style.getBeforeLeftBrace().withFunctionLeftBrace(false))), - javaScript( - """ + spaces(style -> style.withBeforeLeftBrace(style.getBeforeLeftBrace().withFunctionLeftBrace(false))), + javaScript( + """ function foo() { } """, - """ + """ function foo(){ } """ - ) + ) ); } @Test void withinFunctionDeclarationParenthesesTrue() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), + javaScript( + """ function foo(x: number) { } function bar( y: number ) { } """, - """ + """ function foo( x: number ) { } function bar( y: number ) { } """ - ) + ) ); } @Test void withinFunctionDeclarationParenthesesFalse() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(false))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(false))), + javaScript( + """ function foo( x: number ) { } """, - """ + """ function foo(x: number) { } """ - ) + ) ); } @Test void compositeFunctionDeclarationParentheses() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true)) - .withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true)) - ), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true)) + .withBeforeParentheses(style.getBeforeParentheses().withFunctionDeclarationParentheses(true)) + ), + javaScript( + """ function /*c1*/ foo /*c2*/ ( /*c3*/ x: number, y: number /*c4*/ ) { } """, - """ + """ function /*c1*/ foo /*c2*/ ( /*c3*/ x: number, y: number /*c4*/ ) { } """ - ) + ) ); } @Test void withinFunctionDeclarationParenthesesTrueWithComment() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), + javaScript( + """ function foo( /*c1*/ x: number ) { } function bar( y: number /*c2*/ ) { @@ -292,7 +292,7 @@ function bar( y: number /*c2*/ ) { function baz( /*c3*/ z: number /*c4*/ ) { } """, - """ + """ function foo( /*c1*/ x: number ) { } function bar( y: number /*c2*/ ) { @@ -300,237 +300,237 @@ function bar( y: number /*c2*/ ) { function baz( /*c3*/ z: number /*c4*/ ) { } """ - ) + ) ); } @Test void withinFunctionDeclarationParenthesesTrueWithLineBreakIgnored() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionDeclarationParentheses(true))), + javaScript( + """ function foo( x: number ) { } """ - ) + ) ); } @Test void withinFunctionCallParenthesesTrue() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionCallParentheses(true))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionCallParentheses(true))), + javaScript( + """ function bar(x: number) { } function foo() { bar(1); } """, - """ + """ function bar(x: number) { } function foo() { bar( 1 ); } """ - ) + ) ); } @Test void withinFunctionCallParenthesesFalse() { rewriteRun( - spaces(style -> style.withWithin(style.getWithin().withFunctionCallParentheses(false))), - javaScript( - """ + spaces(style -> style.withWithin(style.getWithin().withFunctionCallParentheses(false))), + javaScript( + """ function bar(x: number) { } function foo() { bar( 1 ); } """, - """ + """ function bar(x: number) { } function foo() { bar(1); } """ - ) + ) ); } @Test void otherBeforeCommaTrueFunctionDeclArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), + javaScript( + """ function bar(x: number, y: number) { } """, - """ + """ function bar(x: number , y: number) { } """ - ) + ) ); } @Test void otherBeforeCommaFalseFunctionDeclArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), + javaScript( + """ function bar(x: number , y: number) { } """, - """ + """ function bar(x: number, y: number) { } """ - ) + ) ); } @Test void otherAfterCommaTrueFunctionDeclArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(true))), + javaScript( + """ function bar(x: number,y: number) { } """, - """ + """ function bar(x: number, y: number) { } """ - ) + ) ); } @Test void otherAfterCommaFalseFunctionDeclArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(false))), + javaScript( + """ function bar(x: number, y: number) { } """, - """ + """ function bar(x: number,y: number) { } """ - ) + ) ); } @Test void otherBeforeCommaTrueFunctionInvocationParams() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), + javaScript( + """ function foo() { bar(1, 2); } function bar(x: number, y: number) { } """, - """ + """ function foo() { bar(1 , 2); } function bar(x: number , y: number) { } """ - ) + ) ); } @Test void otherBeforeCommaFalseFunctionInvocationParams() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), + javaScript( + """ function foo() { bar(1 , 2); } function bar(x: number , y: number) { } """, - """ + """ function foo() { bar(1, 2); } function bar(x: number, y: number) { } """ - ) + ) ); } @Test void otherAfterCommaTrueFunctionInvocationParams() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(true))), + javaScript( + """ function foo() { bar(1,2); } function bar(x: number,y: number) { } """, - """ + """ function foo() { bar(1, 2); } function bar(x: number, y: number) { } """ - ) + ) ); } @Test void otherAfterCommaFalseFunctionInvocationParams() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(false))), + javaScript( + """ function foo() { bar(1, 2); } function bar(x: number, y: number) { } """, - """ + """ function foo() { bar(1,2); } function bar(x: number,y: number) { } """ - ) + ) ); } @Test void otherBeforeCommaTrueNewClassArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(true))), + javaScript( + """ function foo() { new A("hello", 1); } @@ -543,7 +543,7 @@ class A { } } """, - """ + """ function foo() { new A("hello" , 1); } @@ -556,16 +556,16 @@ class A { } } """ - ) + ) ); } @Test void otherBeforeCommaFalseNewClassArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeComma(false))), + javaScript( + """ function foo() { new A("hello" , 1); } @@ -578,7 +578,7 @@ class A { } } """, - """ + """ function foo() { new A("hello", 1); } @@ -591,16 +591,16 @@ class A { } } """ - ) + ) ); } @Test void otherAfterCommaTrueNewClassArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(true))), + javaScript( + """ function foo() { new A("hello",1); } @@ -613,7 +613,7 @@ class A { } } """, - """ + """ function foo() { new A("hello", 1); } @@ -626,16 +626,16 @@ class A { } } """ - ) + ) ); } @Test void otherAfterCommaFalseNewClassArgs() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterComma(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterComma(false))), + javaScript( + """ function foo() { new A("hello", 1); } @@ -648,7 +648,7 @@ class A { } } """, - """ + """ function foo() { new A("hello",1); } @@ -661,151 +661,151 @@ class A { } } """ - ) + ) ); } @Test void otherBeforeTypeReferenceColonTrue() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeTypeReferenceColon(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeTypeReferenceColon(true))), + javaScript( + """ function foo(): boolean { return true } """, - """ + """ function foo() : boolean { return true } """ - ) + ) ); } @Test void otherBeforeTypeReferenceColonFalse() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforeTypeReferenceColon(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforeTypeReferenceColon(false))), + javaScript( + """ function foo() : boolean { return true } """, - """ + """ function foo(): boolean { return true } """ - ) + ) ); } @Test void otherAfterTypeReferenceColonTrue() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterTypeReferenceColon(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterTypeReferenceColon(true))), + javaScript( + """ function foo():boolean { return true } """, - """ + """ function foo(): boolean { return true } """ - ) + ) ); } @Test void otherAfterTypeReferenceColonFalse() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterTypeReferenceColon(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterTypeReferenceColon(false))), + javaScript( + """ function foo(): boolean { return true } """, - """ + """ function foo():boolean { return true } """ - ) + ) ); } @Test void otherBeforePropertyNameValueColonTrue() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforePropertyNameValueSeparator(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforePropertyNameValueSeparator(true))), + javaScript( + """ function foo(x: boolean) { } """, - """ + """ function foo(x : boolean) { } """ - ) + ) ); } @Test void otherBeforePropertyNameValueColonFalse() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withBeforePropertyNameValueSeparator(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withBeforePropertyNameValueSeparator(false))), + javaScript( + """ function foo(x : boolean) { } """, - """ + """ function foo(x: boolean) { } """ - ) + ) ); } @Test void otherAfterPropertyNameValueColonTrue() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterPropertyNameValueSeparator(true))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterPropertyNameValueSeparator(true))), + javaScript( + """ function foo(x:boolean) { } """, - """ + """ function foo(x: boolean) { } """ - ) + ) ); } @Test void otherAfterPropertyNameValueColonFalse() { rewriteRun( - spaces(style -> style.withOther(style.getOther().withAfterPropertyNameValueSeparator(false))), - javaScript( - """ + spaces(style -> style.withOther(style.getOther().withAfterPropertyNameValueSeparator(false))), + javaScript( + """ function foo(x: boolean) { } """, - """ + """ function foo(x:boolean) { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/internal/V8InteropTests.java b/src/test/java/org/openrewrite/javascript/internal/V8InteropTests.java index 921ad653..90ca6db3 100644 --- a/src/test/java/org/openrewrite/javascript/internal/V8InteropTests.java +++ b/src/test/java/org/openrewrite/javascript/internal/V8InteropTests.java @@ -210,20 +210,20 @@ public void testNodeConstructorKind() { TSCInstanceOfChecks instanceOfChecks = ctx.getProgramContext().getInstanceOfChecks(); assertEquals( - TSCInstanceOfChecks.ConstructorKind.SourceFile, - instanceOfChecks.identifyConstructorKind(root.getBackingV8Object()) + TSCInstanceOfChecks.ConstructorKind.SourceFile, + instanceOfChecks.identifyConstructorKind(root.getBackingV8Object()) ); TSCNode ident = root.firstNodeWithText("x"); assertEquals( - TSCInstanceOfChecks.ConstructorKind.Identifier, - instanceOfChecks.identifyConstructorKind(ident.getBackingV8Object()) + TSCInstanceOfChecks.ConstructorKind.Identifier, + instanceOfChecks.identifyConstructorKind(ident.getBackingV8Object()) ); TSCNode stmt = root.firstNodeWithText("const x = 3;"); assertEquals( - TSCInstanceOfChecks.ConstructorKind.Node, - instanceOfChecks.identifyConstructorKind(stmt.getBackingV8Object()) + TSCInstanceOfChecks.ConstructorKind.Node, + instanceOfChecks.identifyConstructorKind(stmt.getBackingV8Object()) ); }); } @@ -231,95 +231,95 @@ public void testNodeConstructorKind() { @Test public void testTypeNodeType() { parseSingleSource( - """ + """ class Foo {} function test(x: Foo) { } """, - (root, ctx) -> { - TSCNode Foo = root.firstNodeWithText("class Foo {}"); - TSCType FooType = Foo.getTypeForNode(); + (root, ctx) -> { + TSCNode Foo = root.firstNodeWithText("class Foo {}"); + TSCType FooType = Foo.getTypeForNode(); - TSCNode x = root.firstNodeWithText("x: Foo"); - TSCNode.TypeNode xTypeNode = x.getTypeNodeProperty("type"); - TSCType xType = xTypeNode.getTypeFromTypeNode(); + TSCNode x = root.firstNodeWithText("x: Foo"); + TSCNode.TypeNode xTypeNode = x.getTypeNodeProperty("type"); + TSCType xType = xTypeNode.getTypeFromTypeNode(); - assertSame(FooType, xType); - } + assertSame(FooType, xType); + } ); } @Test public void testGenericTypeBound() { parseSingleSource( - """ + """ class A {} """, - (root, ctx) -> { - TSCNode classDef = root.firstNodeContaining("class A"); - TSCType classType = classDef.getTypeForNode(); - assertNotNull(classType); + (root, ctx) -> { + TSCNode classDef = root.firstNodeContaining("class A"); + TSCType classType = classDef.getTypeForNode(); + assertNotNull(classType); - TSCType.InterfaceType asInterfaceType = classType.assertInterfaceType(); - List typeParams = asInterfaceType.getTypeParameters(); - assertNotNull(typeParams); - assertEquals(1, typeParams.size()); + TSCType.InterfaceType asInterfaceType = classType.assertInterfaceType(); + List typeParams = asInterfaceType.getTypeParameters(); + assertNotNull(typeParams); + assertEquals(1, typeParams.size()); - TSCType typeParam = typeParams.get(0); - assertNotNull(typeParam); + TSCType typeParam = typeParams.get(0); + assertNotNull(typeParam); - TSCType typeParamConstraint = typeParam.getConstraint(); - assertNotNull(typeParamConstraint); + TSCType typeParamConstraint = typeParam.getConstraint(); + assertNotNull(typeParamConstraint); - TSCType globalStringType = ctx.getProgramContext().getTypeChecker().getStringType(); - assertSame(globalStringType, typeParamConstraint); - } + TSCType globalStringType = ctx.getProgramContext().getTypeChecker().getStringType(); + assertSame(globalStringType, typeParamConstraint); + } ); } @Test public void testGenericTypeBoundWithLocalReference() { parseSingleSource( - """ + """ class A> {} interface B { foo(): [U1, U2, U3]; } """, - (root, ctx) -> { - TSCType classA = root.firstNodeContaining("class A").getTypeForNode(); - assertNotNull(classA); - - TSCType interfaceB = root.firstNodeContaining("interface B").getTypeForNode(); - assertNotNull(interfaceB); - - TSCType.InterfaceType asInterfaceType = classA.assertInterfaceType(); - List typeParams = asInterfaceType.getTypeParameters(); - assertNotNull(typeParams); - assertEquals(2, typeParams.size()); - - TSCType typeParam1 = typeParams.get(0); - TSCType typeParam2 = typeParams.get(1); - assertNotNull(typeParam1); - assertNotNull(typeParam2); - - TSCType typeParam1Constraint = typeParam1.getConstraint(); - TSCType typeParam2Constraint = typeParam2.getConstraint(); - assertNull(typeParam1Constraint); - assertNotNull(typeParam2Constraint); - - TSCType globalStringType = ctx.getProgramContext().getTypeChecker().getStringType(); - TSCType globalNumberType = ctx.getProgramContext().getTypeChecker().getNumberType(); - - // The constraint type args are those passed to `B` in `T2 extends B` - List constraintTypeArgs = typeParam2Constraint.assertTypeReference().getTypeArguments(); - assertEquals(3, constraintTypeArgs.size()); - // Used type variables, i.e. `string, T1, number` - assertSame(globalStringType, constraintTypeArgs.get(0)); - assertSame(typeParam1, constraintTypeArgs.get(1)); - assertSame(globalNumberType, constraintTypeArgs.get(2)); - } + (root, ctx) -> { + TSCType classA = root.firstNodeContaining("class A").getTypeForNode(); + assertNotNull(classA); + + TSCType interfaceB = root.firstNodeContaining("interface B").getTypeForNode(); + assertNotNull(interfaceB); + + TSCType.InterfaceType asInterfaceType = classA.assertInterfaceType(); + List typeParams = asInterfaceType.getTypeParameters(); + assertNotNull(typeParams); + assertEquals(2, typeParams.size()); + + TSCType typeParam1 = typeParams.get(0); + TSCType typeParam2 = typeParams.get(1); + assertNotNull(typeParam1); + assertNotNull(typeParam2); + + TSCType typeParam1Constraint = typeParam1.getConstraint(); + TSCType typeParam2Constraint = typeParam2.getConstraint(); + assertNull(typeParam1Constraint); + assertNotNull(typeParam2Constraint); + + TSCType globalStringType = ctx.getProgramContext().getTypeChecker().getStringType(); + TSCType globalNumberType = ctx.getProgramContext().getTypeChecker().getNumberType(); + + // The constraint type args are those passed to `B` in `T2 extends B` + List constraintTypeArgs = typeParam2Constraint.assertTypeReference().getTypeArguments(); + assertEquals(3, constraintTypeArgs.size()); + // Used type variables, i.e. `string, T1, number` + assertSame(globalStringType, constraintTypeArgs.get(0)); + assertSame(typeParam1, constraintTypeArgs.get(1)); + assertSame(globalNumberType, constraintTypeArgs.get(2)); + } ); } @@ -327,74 +327,74 @@ interface B { public void testLibSupport() { // Explicitly turn libs off --> `string` type should be empty parseSingleSource( - "const x: string = '';", - runtime -> runtime.setCompilerOptionOverride("noLib", true), - (root, ctx) -> { - TSCNode x = root.firstNodeContaining("x"); - TSCType xType = x.getTypeForNode(); - assertNotNull(xType); - assertEquals(0, xType.getTypeProperties().size()); - } + "const x: string = '';", + runtime -> runtime.setCompilerOptionOverride("noLib", true), + (root, ctx) -> { + TSCNode x = root.firstNodeContaining("x"); + TSCType xType = x.getTypeForNode(); + assertNotNull(xType); + assertEquals(0, xType.getTypeProperties().size()); + } ); // Explicitly turn libs on --> `string` type should have properties parseSingleSource( - "const x: string = '';", - runtime -> runtime.setCompilerOptionOverride("lib", Collections.singletonList("ES2020")), - (root, ctx) -> { - TSCNode x = root.firstNodeContaining("x"); - TSCType xType = x.getTypeForNode(); - assertNotNull(xType); - assertNotEquals(0, xType.getTypeProperties().size()); - } + "const x: string = '';", + runtime -> runtime.setCompilerOptionOverride("lib", Collections.singletonList("ES2020")), + (root, ctx) -> { + TSCNode x = root.firstNodeContaining("x"); + TSCType xType = x.getTypeForNode(); + assertNotNull(xType); + assertNotEquals(0, xType.getTypeProperties().size()); + } ); // Default lib --> `string` type should also have properties parseSingleSource( - "const x: string = '';", - (root, ctx) -> { - TSCNode x = root.firstNodeContaining("x"); - TSCType xType = x.getTypeForNode(); - assertNotNull(xType); - assertNotEquals(0, xType.getTypeProperties().size()); - } + "const x: string = '';", + (root, ctx) -> { + TSCNode x = root.firstNodeContaining("x"); + TSCType xType = x.getTypeForNode(); + assertNotNull(xType); + assertNotEquals(0, xType.getTypeProperties().size()); + } ); } @Test public void testBridgeSourceInfo() { parseSingleSource( - """ + """ class Foo {} function test(x: String) {} """, - "example.ts", - (root, ctx) -> { - TSCNode Foo = root.firstNodeWithText("Foo"); - assertEquals( - new TSCProgramContext.CompilerBridgeSourceInfo( - TSCProgramContext.CompilerBridgeSourceKind.ApplicationCode, - Paths.get("example.ts") - ), - Foo.getSourceFile().getCompilerBridgeSourceInfo() - ); - - TSCNode string = root.firstNodeWithText("String"); - TSCType stringType = string.getTypeForNode(); - assertNotNull(stringType); - List declarations = stringType.getSymbolForType().getDeclarations(); - assertNotNull(declarations); - assertFalse(declarations.isEmpty()); - for (TSCNode declaration : declarations) { - TSCProgramContext.CompilerBridgeSourceInfo declSourceInfo = declaration.getSourceFile().getCompilerBridgeSourceInfo(); - assertEquals( - TSCProgramContext.CompilerBridgeSourceKind.SystemLibrary, - declSourceInfo.getSourceKind() - ); - assertTrue(declSourceInfo.getRelativePath().toString().startsWith("lib.")); - } - } + "example.ts", + (root, ctx) -> { + TSCNode Foo = root.firstNodeWithText("Foo"); + assertEquals( + new TSCProgramContext.CompilerBridgeSourceInfo( + TSCProgramContext.CompilerBridgeSourceKind.ApplicationCode, + Paths.get("example.ts") + ), + Foo.getSourceFile().getCompilerBridgeSourceInfo() + ); + + TSCNode string = root.firstNodeWithText("String"); + TSCType stringType = string.getTypeForNode(); + assertNotNull(stringType); + List declarations = stringType.getSymbolForType().getDeclarations(); + assertNotNull(declarations); + assertFalse(declarations.isEmpty()); + for (TSCNode declaration : declarations) { + TSCProgramContext.CompilerBridgeSourceInfo declSourceInfo = declaration.getSourceFile().getCompilerBridgeSourceInfo(); + assertEquals( + TSCProgramContext.CompilerBridgeSourceKind.SystemLibrary, + declSourceInfo.getSourceKind() + ); + assertTrue(declSourceInfo.getRelativePath().toString().startsWith("lib.")); + } + } ); } @@ -432,6 +432,7 @@ function test() { @Test public void testEmptyFile() { - parseSingleSource("", (root, ctx) -> {}); + parseSingleSource("", (root, ctx) -> { + }); } } diff --git a/src/test/java/org/openrewrite/javascript/recipe/AddLicenseHeaderTest.java b/src/test/java/org/openrewrite/javascript/recipe/AddLicenseHeaderTest.java index fcebf9f7..d0038e88 100644 --- a/src/test/java/org/openrewrite/javascript/recipe/AddLicenseHeaderTest.java +++ b/src/test/java/org/openrewrite/javascript/recipe/AddLicenseHeaderTest.java @@ -30,7 +30,7 @@ class AddLicenseHeaderTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec.recipe(new AddLicenseHeader( - """ + """ Copyright ${CURRENT_YEAR} the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,12 +43,12 @@ public void defaults(RecipeSpec spec) { @Test void addLicenseHeader() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { } """, - """ + """ /* * Copyright %s the original author or authors. *

@@ -59,7 +59,7 @@ class Foo { class Foo { } """.formatted(getInstance().get(YEAR)) - ) + ) ); } @@ -67,15 +67,15 @@ class Foo { @Test void dontChangeExistingHeader() { rewriteRun( - javaScript( - """ + javaScript( + """ /* * My license header */ class Test { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/recipe/RecipeTest.java b/src/test/java/org/openrewrite/javascript/recipe/RecipeTest.java index c954f8dc..898df31e 100644 --- a/src/test/java/org/openrewrite/javascript/recipe/RecipeTest.java +++ b/src/test/java/org/openrewrite/javascript/recipe/RecipeTest.java @@ -30,28 +30,28 @@ class RecipeTest implements RewriteTest { @Test void simplifyBooleanExpression() { rewriteRun( - spec -> spec.recipe(new SimplifyBooleanExpression()), - javaScript( - """ + spec -> spec.recipe(new SimplifyBooleanExpression()), + javaScript( + """ const b = !false """, - """ + """ const b = true """ - ) + ) ); } @Test void shortenFullyQualifiedNames() { rewriteRun( - spec -> spec.recipe(new ShortenFullyQualifiedTypeReferences()), - javaScript( - """ + spec -> spec.recipe(new ShortenFullyQualifiedTypeReferences()), + javaScript( + """ const a = { b: false } const c = a.b """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java b/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java index ca3d1ebf..6882a248 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java @@ -26,8 +26,8 @@ class AnnotationTest implements RewriteTest { @Test void classDecorator() { rewriteRun( - javaScript( - """ + javaScript( + """ function enumerable ( value : boolean ) { return function ( target : any , propertyKey : string, @@ -42,15 +42,15 @@ class Foo { } } """ - ) + ) ); } @Test void methodDecorator() { rewriteRun( - javaScript( - """ + javaScript( + """ function enumerable ( value : boolean ) { return function ( target : any , propertyKey : string, @@ -65,15 +65,15 @@ class Foo { } } """ - ) + ) ); } @Test void propertyDecorator() { rewriteRun( - javaScript( - """ + javaScript( + """ function enumerable ( value : boolean ) { return function ( target : any , propertyKey : string , @@ -86,7 +86,7 @@ class Foo { foo : String = "hello" ; } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java b/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java index 0404105c..c905d902 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java @@ -27,30 +27,30 @@ class ArrayTest implements RewriteTest { @Test void array() { rewriteRun( - javaScript( - """ + javaScript( + """ let arr : string [ ] = [ 'a' , 'b' , 'c' ] """ - ) + ) ); } @Test void multiDimensional() { rewriteRun( - javaScript( - """ + javaScript( + """ var multi : number [ ] [ ] = [ [ 1 , 2 , 3 ] , [ 23 , 24 , 25 ] ] """ - ) + ) ); } @Test void multiline() { rewriteRun( - javaScript( - """ + javaScript( + """ var multi : number [ ] [ ] = [ [ @@ -65,43 +65,43 @@ void multiline() { ] ] """ - ) + ) ); } @Test void arrayAccess() { rewriteRun( - javaScript( - """ + javaScript( + """ const arr = [ 1 , 2 ] const a = arr [ 0 ] """ - ) + ) ); } @Test void threeDimensional() { rewriteRun( - javaScript( - // This test is a proof that the dimensions are converted correctly from a TS Node to a J.ArrayType. - """ + javaScript( + // This test is a proof that the dimensions are converted correctly from a TS Node to a J.ArrayType. + """ const arr: number [ ] [ ] [ ] = [ ] """ - ) + ) ); } @Test void noElementType() { rewriteRun( - javaScript( - // This test is a proof that the dimensions are converted correctly from a TS Node to a J.ArrayType. - """ + javaScript( + // This test is a proof that the dimensions are converted correctly from a TS Node to a J.ArrayType. + """ const arr: [ ] [ ] [ ] = [ ] """ - ) + ) ); } diff --git a/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java b/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java index 344f6e38..32cb581c 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java @@ -26,52 +26,52 @@ class ArrowFunctionTest implements RewriteTest { @Test void asMethodParameter() { rewriteRun( - javaScript( - """ + javaScript( + """ import foo from './index.js'; const bar = foo.map(protocol => { return protocol + ':'; }); """ - ) + ) ); } @Test void asVariableInitializer() { rewriteRun( - javaScript( - """ + javaScript( + """ let sum = ( a , b ) => { return a + b ; }; """ - ) + ) ); } @Test void varArg() { rewriteRun( - javaScript( - """ + javaScript( + """ let sum = ( a , ... b ) => { return a ; } ; """ - ) + ) ); } @Test void modifier() { rewriteRun( - javaScript( - """ + javaScript( + """ const c = async ( ) => { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java b/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java index 23034e3d..05806919 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java @@ -26,72 +26,72 @@ class AssignmentOperationTest implements RewriteTest { @Test void minusEqual() { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 0 n -= 5 """ - ) + ) ); } @Test void plusEqual() { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 0 n += 5 """ - ) + ) ); } @Test void timesEqual() { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 0 n *= 5 """ - ) + ) ); } @Test void divideEqual() { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 0 n /= 5 """ - ) + ) ); } @Test void moduloEqual() { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 0 n = n %= 5 """ - ) + ) ); } @Test void ternary() { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 let r = ( n == 0 ) ? true : false """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java b/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java index f36c074c..9db6593e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java @@ -26,40 +26,40 @@ class AssignmentTest implements RewriteTest { @Test void assignment() { rewriteRun( - javaScript( - """ + javaScript( + """ let b = 1 b = 2 """ - ) + ) ); } @Test void methodDeclarationAssignment() { rewriteRun( - javaScript( - """ + javaScript( + """ let a = null a = function all(promises) { return Promise.all(promises); }; """ - ) + ) ); } @Test void metaProperty() { rewriteRun( - javaScript( - """ + javaScript( + """ import path from 'path'; import {fileURLToPath} from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java b/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java index a5ab2872..dea0fc10 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java @@ -26,14 +26,14 @@ class AwaitTest implements RewriteTest { @Test void await() { rewriteRun( - javaScript( - """ + javaScript( + """ import foo from '../../../index.js'; async function name ( ) { const data = await foo . get( 'https:..' ) ; } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java b/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java index d6f59da2..d0ecbb27 100644 --- a/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java @@ -27,118 +27,118 @@ class BinaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "+", - "-", - "*", - "/", - "%", + "+", + "-", + "*", + "/", + "%", }) void arithmeticOps(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 %s 1 """.formatted(arg) - ) + ) ); } @ParameterizedTest @ValueSource(strings = { - "<", - "<=", - ">", - "==", - "!=", + "<", + "<=", + ">", + "==", + "!=", }) void comparisonOps(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 %s 1 """.formatted(arg) - ) + ) ); } @Issue("https://github.com/openrewrite/rewrite-javascript/issues/65") @ParameterizedTest @ValueSource(strings = { - "&&", - "||", - ",", + "&&", + "||", + ",", }) void logicalOps(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ function foo( left : boolean , right : boolean ) { if ( left %s right ) { } } """.formatted(arg) - ) + ) ); } @ParameterizedTest @ValueSource(strings = { - "&", - "|", - "^", - "<<", + "&", + "|", + "^", + "<<", }) void bitwiseOps(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 %s 1 """.formatted(arg) - ) + ) ); } @ParameterizedTest @ValueSource(strings = { - ">=", - ">>", - ">>>", + ">=", + ">>", + ">>>", }) void greaterThanOps(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 %s 1 """.formatted(arg) - ) + ) ); } @ParameterizedTest @ValueSource(strings = { - "===", - "!==", + "===", + "!==", }) void identityEquals(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ if ( 1 %s 2 ) { } """.formatted(arg) - ) + ) ); } @Test void in() { rewriteRun( - javaScript( - """ + javaScript( + """ let foo = { bar : 'v1' , buz : 'v2' } var x = 'bar' in foo """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/BreakTest.java b/src/test/java/org/openrewrite/javascript/tree/BreakTest.java index 1579e7c2..2b74755e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/BreakTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/BreakTest.java @@ -26,21 +26,21 @@ class BreakTest implements RewriteTest { @Test void breakFromWhileLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ function method ( ) { while ( true ) break } """ - ) + ) ); } @Test void labeled() { rewriteRun( - javaScript( - """ + javaScript( + """ function test ( ) { outer : for ( var i = 0 ; i < 3 ; i++ ) { for ( var j = 0 ; j < 3 ; j++ ) { @@ -51,7 +51,7 @@ function test ( ) { } } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/CastTest.java b/src/test/java/org/openrewrite/javascript/tree/CastTest.java index 47b8c8c3..60248d06 100644 --- a/src/test/java/org/openrewrite/javascript/tree/CastTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/CastTest.java @@ -26,12 +26,12 @@ class CastTest implements RewriteTest { @Test void castAs() { rewriteRun( - javaScript( - """ + javaScript( + """ let x : unknown = 'hello' let b = ( x as string ) . length """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java index 3ed9a328..1565b16d 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java @@ -26,35 +26,35 @@ class ClassDeclarationTest implements RewriteTest { @Test void classDeclaration() { rewriteRun( - javaScript( - "class Foo { }" - ) + javaScript( + "class Foo { }" + ) ); } @Test void abstractClass() { rewriteRun( - javaScript( - "abstract class Foo { }" - ) + javaScript( + "abstract class Foo { }" + ) ); } @Test void interfaceDeclaration() { rewriteRun( - javaScript( - "interface Foo { }" - ) + javaScript( + "interface Foo { }" + ) ); } @Test void withConstructor() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { private name : string ; constructor ( theName : string ) { @@ -62,15 +62,15 @@ class Foo { } } """ - ) + ) ); } @Test void parameterizedType() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo < T , S extends PT < S > & C > { } interface C { @@ -78,22 +78,22 @@ interface C { interface PT < T > { } """ - ) + ) ); } @Test void endOfFile() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java index 06b9378f..7d42f872 100644 --- a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java @@ -26,48 +26,48 @@ class CommentTest implements RewriteTest { @Test void singleLineComment() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { // C1 } """ - ) + ) ); } @Test void multilineNestedInsideSingleLine() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { // /* } """ - ) + ) ); } @Test void multilineComment() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { /* C1 */ } """ - ) + ) ); } @Test void preserveWhitespaceBetweenComments() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { /* C1 @@ -80,15 +80,15 @@ class Test { */ } """ - ) + ) ); } @Test void javaScriptDoc() { rewriteRun( - javaScript( - """ + javaScript( + """ var s ; /** @@ -98,34 +98,34 @@ void javaScriptDoc() { function f ( p1 , p2 ) { } """ - ) + ) ); } @Test void leadingComment() { rewriteRun( - javaScript( - """ + javaScript( + """ /* * */ class Foo {} """ - ) + ) ); } @Test void stringTemplateSingleSpanWithHead() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string) { console . log ( `group: ${ /* C1 */ group /* C2 */ }` ) } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java b/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java index 48acc93b..f5eab4f5 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java @@ -26,22 +26,22 @@ class ContinueTest implements RewriteTest { @Test void continueStatement() { rewriteRun( - javaScript( - """ + javaScript( + """ for ( let i = 0 ; i < 10 ; i++ ) { if ( i % 2 ) continue ; } """ - ) + ) ); } @Test void labeled() { rewriteRun( - javaScript( - """ + javaScript( + """ function test ( ) { outer : for ( var i = 0 ; i < 3 ; i++ ) { for ( var j = 0 ; j < 3 ; j++ ) { @@ -52,7 +52,7 @@ function test ( ) { } } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java b/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java index 609bbbe1..fbadcc52 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java @@ -26,11 +26,11 @@ class DeleteTest implements RewriteTest { @Test void delete() { rewriteRun( - javaScript( - """ + javaScript( + """ delete console.log(1) """ - ) + ) ); } diff --git a/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java b/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java index 05ce6792..bc5bc0e4 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java @@ -28,12 +28,12 @@ class DestructureTest implements RewriteTest { @Test void destruct() { rewriteRun( - javaScript( - """ + javaScript( + """ let input = [ 1 , 2 ] ; let [ first , second ] = input ; """ - ) + ) ); } @@ -41,11 +41,11 @@ void destruct() { @Test void varArg() { rewriteRun( - javaScript( - """ + javaScript( + """ let [ first , ... rest ] = [ 1 , 2 , 3 ] """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java b/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java index 3dca1a14..9f2b07d7 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java @@ -25,24 +25,24 @@ class DoWhileTest implements RewriteTest { @Test void doWhileLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ var i = 0 do { i++ } while ( i < 10 ) """ - ) + ) ); } @Test void noBlock() { rewriteRun( - javaScript( - """ + javaScript( + """ var i = 0 do i++ ; while ( i < 10 ) """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/EnumTest.java b/src/test/java/org/openrewrite/javascript/tree/EnumTest.java index fe01c50b..5916b097 100644 --- a/src/test/java/org/openrewrite/javascript/tree/EnumTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/EnumTest.java @@ -26,13 +26,13 @@ class EnumTest implements RewriteTest { @Test void enumDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ enum Foo { Bar , Buz } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ExportTest.java b/src/test/java/org/openrewrite/javascript/tree/ExportTest.java index b288ab79..c36f9ba8 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ExportTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ExportTest.java @@ -27,8 +27,8 @@ class ExportTest implements RewriteTest { @Test void exportDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ class ZipCodeValidator { isAcceptable ( s : string ) { return s . length === 5 ; @@ -36,68 +36,68 @@ class ZipCodeValidator { } export { ZipCodeValidator } ; """ - ) + ) ); } @Test void fromClass() { rewriteRun( - javaScript( - """ + javaScript( + """ export * from "./f0.ts" ; """ - ) + ) ); } @Test void exportAssignment() { rewriteRun( - javaScript( - """ + javaScript( + """ export default null; """ - ) + ) ); } @Test void multiExport() { rewriteRun( - javaScript( - """ + javaScript( + """ export { first , second , third } """ - ) + ) ); } @Test void alias() { rewriteRun( - javaScript( - """ + javaScript( + """ export { name as default } """ - ) + ) ); } @Test void exportProperty() { rewriteRun( - javaScript( - """ + javaScript( + """ export const numberRegexp = /^[0-9]+$/ ; """ - ) + ) ); } @@ -105,89 +105,89 @@ void exportProperty() { @Test void exportInterface() { rewriteRun( - javaScript( - """ + javaScript( + """ export interface Foo { ( value : any , defaultEncoder : ( value : any ) => any ) : any ; } """ - ) + ) ); } @Test void exportInterfaceParameterizedAssignment() { rewriteRun( - javaScript( - """ + javaScript( + """ export interface Foo < D = any > { url ? : string ; method ? : Method | string ; baseURL ? : string ; } """ - ) + ) ); } @Test void exportInterfaceAndExtends() { rewriteRun( - javaScript( - """ + javaScript( + """ export interface Foo extends Bar { encode ? : Baz ; serialize ? : Buz ; } """ - ) + ) ); } @Test void readOnlyProperty() { rewriteRun( - javaScript( - """ + javaScript( + """ export interface Foo { readonly encode ? : string ; } """ - ) + ) ); } @Test void exportFunction() { rewriteRun( - javaScript( - """ + javaScript( + """ export default function methodName() { } """ - ) + ) ); } @Test void functionWithTypeParameter() { rewriteRun( - javaScript( - """ + javaScript( + """ export function spread < T , R > ( t : T , r : R ) { } """ - ) + ) ); } @Test void exportType() { rewriteRun( - javaScript( - """ + javaScript( + """ export type Value = string | string[] | number | boolean | null; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java b/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java index fc587a1a..ccd8e1c1 100644 --- a/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java @@ -26,8 +26,8 @@ class FieldAccessTest implements RewriteTest { @Test void thisAccess() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { private id : String = "" ; setId ( id : String ) { @@ -35,15 +35,15 @@ class Test { } } """ - ) + ) ); } @Test void superAccess() { rewriteRun( - javaScript( - """ + javaScript( + """ class Super { id : string = "" ; constructor ( theId : string ) { @@ -61,15 +61,15 @@ class Test extends Super { } } """ - ) + ) ); } @Test void nullSafeDereference() { rewriteRun( - javaScript( - """ + javaScript( + """ class Test { property : number = 42 } @@ -77,7 +77,7 @@ class Test { const t = new Test ( ) const p = t ?. property """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java b/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java index b0f7529c..8e33a1fd 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java @@ -27,50 +27,50 @@ class ForLoopTest implements RewriteTest { @Test void forLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ for ( let i = 0 ; i < 3 ; i++ ) { } """ - ) + ) ); } @Test void multiDeclarationForLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ for ( let i = 0 , j = 1 , k = 2 ; i < 10 ; i++ , j *= 2 , k += 2 ) { } """ - ) + ) ); } @Test void forOfLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ let arr = [ 10 , 20 , 30 , 40 ] ; for ( var val of arr ) { } """ - ) + ) ); } @Test void forInLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ let arr = [ 10 , 20 , 30 , 40 ] ; for ( var val in arr ) { } """ - ) + ) ); } @@ -78,12 +78,12 @@ void forInLoop() { @Test void destruct() { rewriteRun( - javaScript( - """ + javaScript( + """ for ( const { a , b } of [ { a : 1 , b : 2 } , { a : 3 , b : 4 } ] ) { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java b/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java index 5a09af31..d0df380c 100644 --- a/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java @@ -26,20 +26,20 @@ class IfStatementTest implements RewriteTest { @Test void ifStatement() { rewriteRun( - javaScript( - """ + javaScript( + """ if ( true ) { } """ - ) + ) ); } @Test void ifElse() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo( a : number ) { if ( a <= 0 ) { } else if ( a > 0 && a <= 10 ) { @@ -47,15 +47,15 @@ function foo( a : number ) { } } """ - ) + ) ); } @Test void singleLineIfElseStatements() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( a : number ) { if ( a <= 0 ) console . log ( "a <= 0" ) @@ -65,7 +65,7 @@ else if ( a > 0 && a <= 10 ) console . log ( "other" ) } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ImportTest.java b/src/test/java/org/openrewrite/javascript/tree/ImportTest.java index 0007180f..c01efaf8 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ImportTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ImportTest.java @@ -26,55 +26,55 @@ class ImportTest implements RewriteTest { @Test void importStatement() { rewriteRun( - javaScript( - """ + javaScript( + """ import num from "./file" """ - ) + ) ); } @Test void importAssignment() { rewriteRun( - javaScript( - """ + javaScript( + """ import axios = require ( 'foo' ) ; """ - ) + ) ); } @Test void importObjectLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ import { First , Second , Third } from 'target'; """ - ) + ) ); } @Test void mixedTypes() { rewriteRun( - javaScript( - """ + javaScript( + """ import nameA , { First , Second } from 'targetA'; """ - ) + ) ); } @Test void multiAlias() { rewriteRun( - javaScript( - """ + javaScript( + """ import { FormData as FormDataPolyfill , Blob as BlobPolyfill , File as FilePolyfill } from 'formdata-node' """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java b/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java index ac1cd816..c9aaaec1 100644 --- a/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java @@ -26,12 +26,12 @@ class IndexedAccessTest implements RewriteTest { @Test void indexedAccess() { rewriteRun( - javaScript( - """ + javaScript( + """ let args : IArguments const a0 = args[0] """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java b/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java index 8d36fe0c..44af0115 100644 --- a/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java @@ -26,159 +26,159 @@ class LiteralTest implements RewriteTest { @Test void stringLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ let hello = 'World' ; """ - ) + ) ); } @Test void numericLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ let n = 0 ; """ - ) + ) ); } @Test void intentionallyBadUnicodeCharacter() { rewriteRun( - javaScript( - """ + javaScript( + """ let s1 = "\\\\u{U1}" let s2 = "\\\\u1234" let s3 = "\\\\u{00AUF}" """ - ) + ) ); } @Test void unmatchedSurrogatePair() { rewriteRun( - javaScript( - """ + javaScript( + """ let c1 = '\uD800' let c2 = '\uDfFf' """ - ) + ) ); } @Test void unmatchedSurrogatePairInString() { rewriteRun( - javaScript( - """ + javaScript( + """ let s1 : String = "\uD800" let s2 : String = "\uDfFf" """ - ) + ) ); } @Test void templateSingleSpan() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string ) { console . log ( `${group}` ) } """ - ) + ) ); } @Test void whitespaceBetween() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string ) { console . log ( `${ group }` ) } """ - ) + ) ); } @Test void templateSingleSpanWithHead() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string ) { console . log ( `group: ${ group }` ) } """ - ) + ) ); } @Test void templateSingleSpanWithTail() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string ) { console . log ( `group: ${ group } after` ) } """ - ) + ) ); } @Test void templateWithMiddleSpan() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( group : string , version : string ) { console . log ( `group: ${ group } version: ${ version } after` ) } """ - ) + ) ); } @Test void templateWithTag() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( ) { const c = "" console . log ( colorize ( ) `[${c}]: ✓ OK` ) ; } """ - ) + ) ); } @Test void templateWithNoSpans() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( ) { console . log ( `template` ) } """ - ) + ) ); } @Test void template() { rewriteRun( - javaScript( - """ + javaScript( + """ import utils from "../utils.js" ; const CRLF = '\\r\\n' ; class Foo { @@ -191,18 +191,18 @@ class Foo { } } """ - ) + ) ); } @Test void multipleSpansWithRawTextBetween() { rewriteRun( - javaScript( - """ + javaScript( + """ const fn1 = ( a : number , b : number , c : number ) => `${a}-${b}-${c}` ; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java index 0ac6d619..788333b1 100644 --- a/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java @@ -27,22 +27,22 @@ class MethodDeclarationTest implements RewriteTest { @Test void functionDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( ) { } """ - ) + ) ); } @Test void functionParameters() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( x : number , y : number ) { } """ - ) + ) ); } @@ -50,19 +50,19 @@ function foo ( x : number , y : number ) { } @Test void typeLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( x : { suit : string , card : number } [ ] ) { } """ - ) + ) ); } @Test void decorator() { rewriteRun( - javaScript( - """ + javaScript( + """ function enumerable ( value : boolean ) { return function ( target : any , propertyKey : string , @@ -71,42 +71,42 @@ function enumerable ( value : boolean ) { }; } """ - ) + ) ); } @Test void methodDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { foo ( ) { } } """ - ) + ) ); } @Test void arrowDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ let sum = ( a : number , b : number ) : number => { return a + b ; } """ - ) + ) ); } @Test void typeArguments() { rewriteRun( - javaScript( - """ + javaScript( + """ class User { } @@ -114,7 +114,7 @@ class User { return arg ; } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java b/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java index af9ce236..fe362eac 100644 --- a/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java @@ -27,25 +27,25 @@ class MethodInvocationTest implements RewriteTest { @Test void methodInvocation() { rewriteRun( - javaScript( - """ + javaScript( + """ console . log ( "hello world" ) """ - ) + ) ); } @Test void statementParameter() { rewriteRun( - javaScript( - """ + javaScript( + """ export default function ( req ) { req . on ( 'data' , function ( ) { } ) ; } """ - ) + ) ); } @@ -53,8 +53,8 @@ export default function ( req ) { @Test void typeArguments() { rewriteRun( - javaScript( - """ + javaScript( + """ class User { } @@ -64,15 +64,15 @@ class User { const bar = foo(); """ - ) + ) ); } @Test void parenthesizedSelect() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { constructor( x : any ) { } } @@ -81,7 +81,7 @@ class Foo { const headers = new Foo( { x : 1 } ) ; } ) ( ) ; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java b/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java index e3a0bc69..a2edf406 100644 --- a/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java @@ -26,20 +26,20 @@ class NewClassTest implements RewriteTest { @Test void newClass() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { } const foo = new Foo ( ) ; """ - ) + ) ); } @Test void withParams() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { private name : string ; constructor ( theName : string ) { @@ -48,7 +48,7 @@ class Foo { } const foo = new Foo ( "foooooo" ) ; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java b/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java index bcd20f5e..2527713b 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java @@ -26,55 +26,55 @@ class ObjectBindingTest implements RewriteTest { @Test void destructObject() { rewriteRun( - javaScript( - """ + javaScript( + """ const c = { fName : 'Foo' , lName : 'Bar' } const { fName, lName } = c """ - ) + ) ); } @Test void binding() { rewriteRun( - javaScript( - """ + javaScript( + """ const { o1 , o2 , o3 } = "" ; """ - ) + ) ); } @Test void varArg() { rewriteRun( - javaScript( - """ + javaScript( + """ const { o1 , o2 , ... o3 } = "" ; """ - ) + ) ); } @Test void propertyNames() { rewriteRun( - javaScript( - """ + javaScript( + """ import followRedirects from 'follow-redirects'; const { http : httpFollow , https : httpsFollow } = followRedirects ; """ - ) + ) ); } @Test void bindingInitializers() { rewriteRun( - javaScript( - """ + javaScript( + """ const formDataToStream = ( form , headersHandler , options ) => { const { tag = 'form-data-boundary' , @@ -83,7 +83,7 @@ void bindingInitializers() { } = options || { } ; } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java index c1a68801..73760f09 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java @@ -28,34 +28,34 @@ class ObjectLiteralTest implements RewriteTest { @Test void empty() { rewriteRun( - javaScript( - """ + javaScript( + """ const value = { } ; """ - ) + ) ); } @Test void objectLiteralWithType() { rewriteRun( - javaScript( - """ + javaScript( + """ const value = { x : 1 } ; """ - ) + ) ); } @Test void innerObjectLiteral() { rewriteRun( - javaScript( - """ + javaScript( + """ import foo from '/foo.js' ; foo . create ( { headers : { foo : 'bar' } } ) ; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ParenthesesTest.java b/src/test/java/org/openrewrite/javascript/tree/ParenthesesTest.java index 06ba64a8..4b804d7b 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ParenthesesTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ParenthesesTest.java @@ -25,8 +25,8 @@ class ParenthesesTest implements RewriteTest { @Test void nestedParens() { rewriteRun( - javaScript( - """ + javaScript( + """ var condition = true; if ( ( ( condition ) ) ) { @@ -37,7 +37,7 @@ function exampleFunction() { return ('42'); } """ - ) + ) ); } @@ -45,11 +45,11 @@ function exampleFunction() { @Test void parensOnType() { rewriteRun( - javaScript( - """ + javaScript( + """ type Point = { x: ( (number) ) , y: number }; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ParserTest.java b/src/test/java/org/openrewrite/javascript/tree/ParserTest.java index 944935f6..9e417543 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ParserTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ParserTest.java @@ -27,9 +27,9 @@ class ParserTest implements RewriteTest { @Test void preservesOrder() { rewriteRun( - javaScript("class A {}", s -> s.path("A.js")), - javaScript("class B {}", s -> s.path("B.js")), - javaScript("class C {}", s -> s.path("C.js")) + javaScript("class A {}", s -> s.path("A.js")), + javaScript("class B {}", s -> s.path("B.js")), + javaScript("class C {}", s -> s.path("C.js")) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java b/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java index b1d6c443..7e4646df 100644 --- a/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java @@ -25,18 +25,18 @@ class PrimitiveTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "true", - "false", - "0", - "'c'", + "true", + "false", + "0", + "'c'", }) void primitives(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ var a = %s """.formatted(arg) - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java b/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java index 61ffcb8e..1a4fa8f2 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java @@ -26,13 +26,13 @@ class ReturnTest implements RewriteTest { @Test void returnValue() { rewriteRun( - javaScript( - """ + javaScript( + """ function method ( ) { return "42" } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java b/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java index 4fbdd982..a49e0885 100644 --- a/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java @@ -26,41 +26,41 @@ class SemiColonTest implements RewriteTest { @Test void semiColon() { rewriteRun( - javaScript( - """ + javaScript( + """ let hello = "World" ; """ - ) + ) ); } @Test void noSemiColon() { rewriteRun( - javaScript( - """ + javaScript( + """ let hello = "World" """ - ) + ) ); } @Test void multiSemiColon() { rewriteRun( - javaScript( - """ + javaScript( + """ let hello = "World" ; ; """ - ) + ) ); } @Test void singleLineIfElseStatements() { rewriteRun( - javaScript( - """ + javaScript( + """ function foo ( a : number ) { if ( a <= 0 ) console . log ( "a <= 0" ) ; @@ -70,7 +70,7 @@ else if ( a > 0 && a <= 10 ) console . log ( "other" ) ; } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java b/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java index bc33b9c4..34fb87f8 100644 --- a/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java @@ -26,48 +26,48 @@ class SwitchTest implements RewriteTest { @Test void singleCase() { rewriteRun( - javaScript( - """ + javaScript( + """ const n = 0 ; switch ( n ) { case 0 : } """ - ) + ) ); } @Test void defaultCase() { rewriteRun( - javaScript( - """ + javaScript( + """ const n = 0 ; switch ( n ) { default : console . log ( "default!" ) ; } """ - ) + ) ); } @Test void noCases() { rewriteRun( - javaScript( - """ + javaScript( + """ const n = 0 ; switch ( n ) { } """ - ) + ) ); } @Test void multipleCasesWithNoBody() { rewriteRun( - javaScript( - """ + javaScript( + """ const n = 0 ; switch ( n ) { case 0: @@ -76,15 +76,15 @@ void multipleCasesWithNoBody() { break ; } """ - ) + ) ); } @Test void multipleCases() { rewriteRun( - javaScript( - """ + javaScript( + """ const n = 0 ; switch ( n ) { case 0: { @@ -95,7 +95,7 @@ void multipleCases() { } } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java b/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java index 33a3cb91..edd2d3c4 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java @@ -26,13 +26,13 @@ class ThrowTest implements RewriteTest { @Test void throwError() { rewriteRun( - javaScript( - """ + javaScript( + """ function method ( ) { throw new Error ( "42" ) } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java b/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java index 93f69777..49d3d26e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java @@ -26,61 +26,61 @@ class TrailingCommaTest implements RewriteTest { @Test void onMethodParameter() { rewriteRun( - javaScript( - """ + javaScript( + """ console . log ( "hello world" , ) """ - ) + ) ); } @Test void onTuple() { rewriteRun( - javaScript( - """ + javaScript( + """ let tuple : [ number , boolean , ] = [ 1, true , ] """ - ) + ) ); } @Test void onEnum() { rewriteRun( - javaScript( - """ + javaScript( + """ enum Foo { Bar , Buz , } """ - ) + ) ); } @Test void multiExport() { rewriteRun( - javaScript( - """ + javaScript( + """ export { first , second , third , } """ - ) + ) ); } @Test void objectBindingDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ const { o1 , o2 , o3 , } = "" ; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java b/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java index d8a710a1..0b9dfc21 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java @@ -26,29 +26,29 @@ class TryCatchTest implements RewriteTest { @Test void tryCatch() { rewriteRun( - javaScript( - """ + javaScript( + """ try { throw new Error ( 'err' ) ; } catch ( e ) { } """ - ) + ) ); } @Test void tryCatchFinally() { rewriteRun( - javaScript( - """ + javaScript( + """ try { throw new Error ( 'err' ) ; } catch ( e ) { } finally { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/TupleTest.java b/src/test/java/org/openrewrite/javascript/tree/TupleTest.java index e29713e4..c68d7327 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TupleTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TupleTest.java @@ -27,22 +27,22 @@ class TupleTest implements RewriteTest { @Test void emptyTuple() { rewriteRun( - javaScript( - """ + javaScript( + """ let tuple : [ ] """ - ) + ) ); } @Test void tuple() { rewriteRun( - javaScript( - """ + javaScript( + """ let tuple : [ number , boolean ] = [ 1 , true ] """ - ) + ) ); } @@ -50,24 +50,24 @@ void tuple() { @Test void namedTupleMember() { rewriteRun( - javaScript( - """ + javaScript( + """ type NewLocation = [lat: number, long: number] """ - ) + ) ); } @Test void spreadOperators() { rewriteRun( - javaScript( - """ + javaScript( + """ function concat(arr1, arr2) { return [...arr1, ...arr2] } """ - ) + ) ); } @@ -75,25 +75,25 @@ function concat(arr1, arr2) { @Test void arrayBindingPattern() { rewriteRun( - javaScript( - """ + javaScript( + """ function tail(arg) { const [_, ...result] = arg; return result; } """ - ) + ) ); } @Test void trailingCommas() { rewriteRun( - javaScript( - """ + javaScript( + """ let input : [ number , boolean , ] = [ 1 , true , ] """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java b/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java index 5856f7a5..c1fe91e3 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java @@ -29,36 +29,36 @@ class TypeOperatorTest implements RewriteTest { @Test void delete() { rewriteRun( - javaScript( - """ + javaScript( + """ let foo = { bar : 'v1' , buz : 'v2' } delete foo . buz """ - ) + ) ); } @Test void typeof() { rewriteRun( - javaScript( - """ + javaScript( + """ let s = "hello" let t = typeof s """ - ) + ) ); } @Test void instanceofOp() { rewriteRun( - javaScript( - """ + javaScript( + """ let arr = [ 1, 2 ] let t = arr instanceof Array """ - ) + ) ); } @@ -66,8 +66,8 @@ void instanceofOp() { @Test void extendsKeyword() { rewriteRun( - javaScript( - """ + javaScript( + """ type PartialPerson = { name?: string; age?: number }; function merge(obj1: T, obj2: U): T & U { @@ -76,7 +76,7 @@ void extendsKeyword() { const merged = merge({ name: 'John' }, { age: 30 }); """ - ) + ) ); } @@ -84,24 +84,24 @@ void extendsKeyword() { @Test void typeLiteralDelimiterSemicolon() { rewriteRun( - javaScript(""" + javaScript(""" type Person = { name: string ; // Semicolon as delimiter age: number }; """ - ) + ) ); } @Test void typeLiteralDelimiterComma() { rewriteRun( - javaScript(""" + javaScript(""" type Person = { name: string , // Comma as delimiter age: number }; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java b/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java index 1a37798d..056a3c2f 100644 --- a/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java @@ -28,48 +28,48 @@ class UnaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "++ n", - "-- n", - "n ++", - "n --", + "++ n", + "-- n", + "n ++", + "n --", }) void incrementAndDecrement(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ var n = 1 %s """.formatted(arg) - ) + ) ); } @ParameterizedTest @ValueSource(strings = { - "! n", - "- n", - "+ n", + "! n", + "- n", + "+ n", }) void unaryMinusAndPlus(String arg) { rewriteRun( - javaScript( - """ + javaScript( + """ const n1 = 1 const n2 = %s """.formatted(arg) - ) + ) ); } @Test void keyofKeyword() { rewriteRun( - javaScript( - """ + javaScript( + """ type Person = { name: string , age: number }; type KeysOfPerson = keyof Person; """ - ) + ) ); } @@ -77,13 +77,13 @@ void keyofKeyword() { @Test void spreadOperator() { rewriteRun( - javaScript( - """ + javaScript( + """ function spread(arr) { return [...arr] } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/UnionTest.java b/src/test/java/org/openrewrite/javascript/tree/UnionTest.java index 1abb9b7b..0ca16627 100644 --- a/src/test/java/org/openrewrite/javascript/tree/UnionTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/UnionTest.java @@ -26,11 +26,11 @@ class UnionTest implements RewriteTest { @Test void union() { rewriteRun( - javaScript( - """ + javaScript( + """ let unionField: typeof Boolean | typeof Number """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java index e7b93a7c..614ae69e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java @@ -28,44 +28,44 @@ class VariableDeclarationTest implements RewriteTest { @Test void let() { rewriteRun( - javaScript( - """ + javaScript( + """ let hello = "World" ; """ - ) + ) ); } @Test void multiTypeLet() { rewriteRun( - javaScript( - """ + javaScript( + """ let stringWord : string | null ; """ - ) + ) ); } @Test void constant() { rewriteRun( - javaScript( - """ + javaScript( + """ const hello = "World" ; """ - ) + ) ); } @Test void var() { rewriteRun( - javaScript( - """ + javaScript( + """ var hello = "World" ; """ - ) + ) ); } @@ -73,22 +73,22 @@ void var() { @Test void multiTypeVariableDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ let x : number , y : string ; """ - ) + ) ); } @Test void declareModifier() { rewriteRun( - javaScript( - """ + javaScript( + """ declare const name ; """ - ) + ) ); } @@ -96,67 +96,67 @@ void declareModifier() { @Test void readOnlyModifier() { rewriteRun( - javaScript( - """ + javaScript( + """ interface SomeType { readonly prop: string; } """ - ) + ) ); } @Test void generic() { rewriteRun( - javaScript( - """ + javaScript( + """ var v : Array < string > = [ 'foo' , 'bar', 'buz' ] ; """ - ) + ) ); } @Test void methodInvocationInitializer() { rewriteRun( - javaScript( - """ + javaScript( + """ import parseProtocol from './parseProtocol.js'; const protocol = parseProtocol(""); """ - ) + ) ); } @Test void typeDeclaration() { rewriteRun( - javaScript( - """ + javaScript( + """ type Value = string | string[] | number | boolean | null; """ - ) + ) ); } @Test void typeDeclarationWithParameters() { rewriteRun( - javaScript( - """ + javaScript( + """ import Foo from 'foo' ; type Other < T = unknown , D = any > = Foo < T , D > ; """ - ) + ) ); } @Test void optionalProperty() { rewriteRun( - javaScript( - """ + javaScript( + """ import foo from 'foo' ; const config : foo . Bar = { params : { @@ -164,20 +164,20 @@ void optionalProperty() { } } """ - ) + ) ); } @Test void methodDeclarationInitializer() { rewriteRun( - javaScript( - """ + javaScript( + """ let a = function all(promises) { return Promise.all(promises); }; """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java b/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java index 2dcecbc3..c0e1cb85 100644 --- a/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java @@ -26,11 +26,11 @@ class WhileLoopTest implements RewriteTest { @Test void whileLoop() { rewriteRun( - javaScript( - """ + javaScript( + """ while ( true ) { } """ - ) + ) ); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/YieldTest.java b/src/test/java/org/openrewrite/javascript/tree/YieldTest.java index 16626b49..00c579f3 100644 --- a/src/test/java/org/openrewrite/javascript/tree/YieldTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/YieldTest.java @@ -26,30 +26,30 @@ class YieldTest implements RewriteTest { @Test void yield() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { async * encode ( ) { yield this . headers; } } """ - ) + ) ); } @Test void asteriskPrefix() { rewriteRun( - javaScript( - """ + javaScript( + """ class Foo { async * encode() { yield * this . headers ; } } """ - ) + ) ); } }