From d6ce060920eccca13f6766c9887faef2a79d4b6e Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Wed, 15 Nov 2023 09:40:05 +0100 Subject: [PATCH] Use shared `TSCRuntime` in `JavaScriptParser` Constructing a new `TSCRuntime` (and thereby a new `V8Runtime`) is a very costly operation, which is especially bad for unit tests, where this happens for every test case. This commit changes that by using a shared `TSCRuntime` instance for all `JavaScriptParser` instances. Additionally, this commit gets rid of the `javaScript()` methods in `ParserTest`. Instead, all tests now directly use the corresponding `Assertions` methods. --- build.gradle.kts | 1 + .../openrewrite/javascript/Assertions.java | 69 ++++++++-- .../javascript/JavaScriptParser.java | 91 +++++++++++-- .../javascript/internal/TSCMapper.java | 121 ------------------ .../internal/tsc/TSCInstanceOfChecks.java | 5 +- .../javascript/internal/tsc/TSCNodeList.java | 21 +-- .../javascript/internal/tsc/TSCRuntime.java | 10 +- .../javascript/internal/tsc/TSCV8Utils.java | 2 +- .../javascript/tree/AnnotationTest.java | 5 +- .../javascript/tree/ArrayTest.java | 5 +- .../javascript/tree/ArrowFunctionTest.java | 5 +- .../tree/AssignmentOperationTest.java | 5 +- .../javascript/tree/AssignmentTest.java | 5 +- .../javascript/tree/AwaitTest.java | 5 +- .../javascript/tree/BinaryTest.java | 5 +- .../javascript/tree/BreakTest.java | 5 +- .../openrewrite/javascript/tree/CastTest.java | 5 +- .../javascript/tree/ClassDeclarationTest.java | 5 +- .../javascript/tree/CommentTest.java | 5 +- .../javascript/tree/ContinueTest.java | 5 +- .../javascript/tree/DeleteTest.java | 5 +- .../javascript/tree/DestructureTest.java | 5 +- .../javascript/tree/DoWhileTest.java | 5 +- .../openrewrite/javascript/tree/EnumTest.java | 5 +- .../javascript/tree/ExportTest.java | 5 +- .../javascript/tree/FieldAccessTest.java | 5 +- .../javascript/tree/ForLoopTest.java | 5 +- .../javascript/tree/IfStatementTest.java | 5 +- .../javascript/tree/ImportTest.java | 5 +- .../javascript/tree/IndexedAccessTest.java | 5 +- .../javascript/tree/LiteralTest.java | 5 +- .../tree/MethodDeclarationTest.java | 5 +- .../javascript/tree/MethodInvocationTest.java | 5 +- .../javascript/tree/NewClassTest.java | 5 +- .../javascript/tree/ObjectBindingTest.java | 5 +- .../javascript/tree/ObjectLiteralTest.java | 5 +- .../javascript/tree/ParserPerfTest.java | 4 +- .../javascript/tree/ParserTest.java | 77 +---------- .../javascript/tree/PrimitiveTest.java | 5 +- .../javascript/tree/ReturnTest.java | 5 +- .../javascript/tree/SemiColonTest.java | 5 +- .../javascript/tree/SwitchTest.java | 5 +- .../javascript/tree/ThrowTest.java | 5 +- .../javascript/tree/TrailingCommaTest.java | 5 +- .../javascript/tree/TryCatchTest.java | 5 +- .../javascript/tree/TupleTest.java | 5 +- .../javascript/tree/TypeOperatorTest.java | 5 +- .../javascript/tree/UnaryTest.java | 5 +- .../javascript/tree/UnionTest.java | 5 +- .../tree/VariableDeclarationTest.java | 5 +- .../javascript/tree/WhileLoopTest.java | 5 +- .../javascript/tree/YieldTest.java | 5 +- 52 files changed, 329 insertions(+), 282 deletions(-) delete mode 100644 src/main/java/org/openrewrite/javascript/internal/TSCMapper.java diff --git a/build.gradle.kts b/build.gradle.kts index c390d97e..f4db713f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,7 @@ dependencies { implementation(platform("org.openrewrite:rewrite-bom:$latest")) implementation("org.openrewrite:rewrite-java") + compileOnly("org.assertj:assertj-core:latest.release") testImplementation("org.assertj:assertj-core:latest.release") testImplementation("org.junit.jupiter:junit-jupiter-api:latest.release") testImplementation("org.junit.jupiter:junit-jupiter-params:latest.release") diff --git a/src/main/java/org/openrewrite/javascript/Assertions.java b/src/main/java/org/openrewrite/javascript/Assertions.java index c7396856..3f5b419f 100644 --- a/src/main/java/org/openrewrite/javascript/Assertions.java +++ b/src/main/java/org/openrewrite/javascript/Assertions.java @@ -17,37 +17,88 @@ import org.intellij.lang.annotations.Language; +import org.openrewrite.ExecutionContext; +import org.openrewrite.ParseExceptionResult; import org.openrewrite.internal.lang.Nullable; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.Space; import org.openrewrite.javascript.tree.JS; import org.openrewrite.test.SourceSpec; import org.openrewrite.test.SourceSpecs; import java.util.function.Consumer; +import static org.assertj.core.api.Assertions.assertThat; + public final class Assertions { + private Assertions() { } - public static SourceSpecs javaScript(@Language("js") @Nullable String before) { + public static SourceSpecs javaScript(@Language("typescript") @Nullable String before) { return javaScript(before, s -> { }); } - public static SourceSpecs javaScript(@Language("js") @Nullable String before, Consumer> spec) { - SourceSpec js = new SourceSpec<>(JS.CompilationUnit.class, null, JavaScriptParser.builder(), before, null); - spec.accept(js); - return js; + public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, Consumer> spec) { + return javaScript0(before, null, spec); } - public static SourceSpecs javaScript(@Language("js") @Nullable String before, @Language("js") String after) { + public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, @Language("typescript") String after) { return javaScript(before, after, s -> { }); } - public static SourceSpecs javaScript(@Language("js") @Nullable String before, @Language("js") String after, + public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, @Language("typescript") String after, Consumer> spec) { - SourceSpec js = new SourceSpec<>(JS.CompilationUnit.class, null, JavaScriptParser.builder(), before, s -> after); - spec.accept(js); + return javaScript0(before, after, spec); + } + + private static SourceSpec javaScript0(@Language("typescript") @Nullable String before, @Language("typescript") @Nullable String after, Consumer> spec) { + SourceSpec js = new SourceSpec<>( + JS.CompilationUnit.class, + null, + JavaScriptParser.builder(), + before, + SourceSpec.ValidateSource.noop, + Assertions::customizeExecutionContext + ); + if (after != null) { + js = js.after(s -> after); + } + acceptSpec(spec, js); return js; } + + static void customizeExecutionContext(ExecutionContext ctx) { + } + + private static void acceptSpec(Consumer> spec, SourceSpec javaScript) { + Consumer userSuppliedAfterRecipe = javaScript.getAfterRecipe(); + javaScript.afterRecipe(userSuppliedAfterRecipe::accept); + isFullyParsed().andThen(spec).accept(javaScript); + } + + public static Consumer> isFullyParsed() { + return spec -> spec.afterRecipe(cu -> { + new JavaScriptIsoVisitor() { + @Override + public Space visitSpace(Space space, Space.Location loc, Integer integer) { + assertThat(space.getWhitespace().trim()).isEmpty(); + return super.visitSpace(space, loc, integer); + } + }.visit(cu, 0); + + new JavaScriptVisitor() { + @Override + public @Nullable J preVisit(J tree, Integer integer) { + if (tree instanceof J.Unknown) { + ((J.Unknown) tree).getSource().getMarkers().findFirst(ParseExceptionResult.class) + .ifPresent(result -> assertThat(result.getMessage()).isEqualTo("")); + } + return super.preVisit(tree, integer); + } + }.visit(cu, 0); + }); + } } diff --git a/src/main/java/org/openrewrite/javascript/JavaScriptParser.java b/src/main/java/org/openrewrite/javascript/JavaScriptParser.java index b495e10d..956933ad 100644 --- a/src/main/java/org/openrewrite/javascript/JavaScriptParser.java +++ b/src/main/java/org/openrewrite/javascript/JavaScriptParser.java @@ -15,18 +15,25 @@ */ package org.openrewrite.javascript; +import lombok.Value; import org.openrewrite.ExecutionContext; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Parser; import org.openrewrite.SourceFile; -import org.openrewrite.internal.lang.NonNull; +import org.openrewrite.internal.EncodingDetectingInputStream; import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.javascript.internal.TSCMapper; +import org.openrewrite.java.internal.JavaTypeCache; +import org.openrewrite.javascript.internal.JavetNativeBridge; +import org.openrewrite.javascript.internal.TypeScriptParserVisitor; +import org.openrewrite.javascript.internal.tsc.TSCRuntime; import org.openrewrite.javascript.tree.JS; import org.openrewrite.style.NamedStyles; +import org.openrewrite.tree.ParseError; +import org.openrewrite.tree.ParsingEventListener; import org.openrewrite.tree.ParsingExecutionContextView; import java.io.ByteArrayInputStream; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; @@ -35,6 +42,28 @@ public class JavaScriptParser implements Parser { + private static final TSCRuntime RUNTIME; + + static { + JavetNativeBridge.init(); + RUNTIME = TSCRuntime.init(); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + RUNTIME.close(); + } + }); + } + + @Value + private static class SourceWrapper { + Parser.Input input; + Path sourcePath; + Charset charset; + boolean isCharsetBomMarked; + String sourceText; + } + private final Collection styles; private JavaScriptParser(Collection styles) { @@ -42,7 +71,7 @@ private JavaScriptParser(Collection styles) { } @Override - public Stream parse(@NonNull String... sources) { + public Stream parse(String... sources) { List inputs = new ArrayList<>(sources.length); for (int i = 0; i < sources.length; i++) { Path path = Paths.get("f" + i + ".js"); @@ -64,14 +93,56 @@ public Stream parse(@NonNull String... sources) { @Override public Stream parseInputs(Iterable sources, @Nullable Path relativeTo, ExecutionContext ctx) { ParsingExecutionContextView pctx = ParsingExecutionContextView.view(ctx); - List outputs; - try (TSCMapper mapper = new TSCMapper(relativeTo, styles, pctx) {}) { - for (Input source : sources) { - mapper.add(source); - } - outputs = mapper.build(); + Map sourcesByRelativePath = new LinkedHashMap<>(); + + for (Input input : sources) { + EncodingDetectingInputStream is = input.getSource(pctx); + String inputSourceText = is.readFully(); + Path relativePath = input.getRelativePath(relativeTo); + + SourceWrapper source = new SourceWrapper( + input, + relativePath, + is.getCharset(), + is.isCharsetBomMarked(), + inputSourceText + ); + sourcesByRelativePath.put(relativePath, source); } - return outputs.stream(); + + List compilationUnits = new ArrayList<>(sourcesByRelativePath.size()); + ParsingEventListener parsingListener = ParsingExecutionContextView.view(pctx).getParsingListener(); + Map sourceTextsForTSC = new LinkedHashMap<>(); + sourcesByRelativePath.forEach((relativePath, sourceText) -> { + sourceTextsForTSC.put(relativePath, sourceText.sourceText); + }); + + RUNTIME.parseSourceTexts( + sourceTextsForTSC, + (node, context) -> { + SourceWrapper source = sourcesByRelativePath.get(context.getRelativeSourcePath()); + parsingListener.startedParsing(source.getInput()); + TypeScriptParserVisitor fileMapper = new TypeScriptParserVisitor( + node, + context, + source.getSourcePath(), + new JavaTypeCache(), + source.getCharset().toString(), + source.isCharsetBomMarked(), + styles + ); + SourceFile cu; + try { + cu = fileMapper.visitSourceFile(); + parsingListener.parsed(source.getInput(), cu); + } catch (Throwable t) { + ((ExecutionContext) pctx).getOnError().accept(t); + cu = ParseError.build(JavaScriptParser.builder().build(), source.getInput(), relativeTo, pctx, t); + } + compilationUnits.add(cu); + } + ); + return compilationUnits.stream(); } private final static List EXTENSIONS = Collections.unmodifiableList(Arrays.asList( diff --git a/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java b/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java deleted file mode 100644 index ccd13e4e..00000000 --- a/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.javascript.internal; - -import lombok.Value; -import org.openrewrite.ExecutionContext; -import org.openrewrite.Parser; -import org.openrewrite.SourceFile; -import org.openrewrite.internal.EncodingDetectingInputStream; -import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.internal.JavaTypeCache; -import org.openrewrite.javascript.JavaScriptParser; -import org.openrewrite.javascript.internal.tsc.TSCRuntime; -import org.openrewrite.style.NamedStyles; -import org.openrewrite.tree.ParseError; -import org.openrewrite.tree.ParsingEventListener; -import org.openrewrite.tree.ParsingExecutionContextView; - -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.*; - -public abstract class TSCMapper implements AutoCloseable { - - @Value - private static class SourceWrapper { - Parser.Input input; - Path sourcePath; - Charset charset; - boolean isCharsetBomMarked; - String sourceText; - } - - private final TSCRuntime runtime; - - @Nullable - private final Path relativeTo; - - private final Collection styles; - - private final ExecutionContext ctx; - private final Map sourcesByRelativePath = new LinkedHashMap<>(); - - public TSCMapper(@Nullable Path relativeTo, Collection styles, ExecutionContext ctx) { - JavetNativeBridge.init(); - this.runtime = TSCRuntime.init(); - this.relativeTo = relativeTo; - this.styles = styles; - this.ctx = ctx; - } - - public void add(Parser.Input input) { - EncodingDetectingInputStream is = input.getSource(ctx); - String inputSourceText = is.readFully(); - Path relativePath = input.getRelativePath(relativeTo); - - SourceWrapper source = new SourceWrapper( - input, - relativePath, - is.getCharset(), - is.isCharsetBomMarked(), - inputSourceText - ); - sourcesByRelativePath.put(relativePath, source); - } - - public List build() { - List compilationUnits = new ArrayList<>(sourcesByRelativePath.size()); - ParsingEventListener parsingListener = ParsingExecutionContextView.view(ctx).getParsingListener(); - Map sourceTextsForTSC = new LinkedHashMap<>(); - this.sourcesByRelativePath.forEach((relativePath, sourceText) -> { - sourceTextsForTSC.put(relativePath, sourceText.sourceText); - }); - - this.runtime.parseSourceTexts( - sourceTextsForTSC, - (node, context) -> { - SourceWrapper source = this.sourcesByRelativePath.get(context.getRelativeSourcePath()); - parsingListener.startedParsing(source.getInput()); - TypeScriptParserVisitor fileMapper = new TypeScriptParserVisitor( - node, - context, - source.getSourcePath(), - new JavaTypeCache(), - source.getCharset().toString(), - source.isCharsetBomMarked(), - styles - ); - SourceFile cu; - try { - cu = fileMapper.visitSourceFile(); - parsingListener.parsed(source.getInput(), cu); - } catch (Throwable t) { - ctx.getOnError().accept(t); - cu = ParseError.build(JavaScriptParser.builder().build(), source.getInput(), relativeTo, ctx, t); - } - compilationUnits.add(cu); - } - ); - return compilationUnits; - } - - @Override - public void close() { - this.runtime.close(); - } - -} 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 80ee6176..855000e5 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCInstanceOfChecks.java @@ -21,13 +21,10 @@ import com.caoccao.javet.values.primitive.V8ValuePrimitive; import com.caoccao.javet.values.reference.V8ValueArray; import com.caoccao.javet.values.reference.V8ValueFunction; -import com.caoccao.javet.values.reference.V8ValueMap; import com.caoccao.javet.values.reference.V8ValueObject; import org.intellij.lang.annotations.Language; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Map; public class TSCInstanceOfChecks extends TSCV8ValueHolder { @@ -77,7 +74,7 @@ public static TSCInstanceOfChecks fromJS(V8ValueObject tsGlobalsV8) { } } - @Language("javascript") + @Language("typescript") String code = "" + "(arg) => {\n" + " for (let i = 0; i < ctors.length; i++) {\n" + diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNodeList.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNodeList.java index 02edf18a..b018c884 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNodeList.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNodeList.java @@ -19,12 +19,9 @@ import com.caoccao.javet.values.V8Value; import com.caoccao.javet.values.reference.V8ValueArray; import com.caoccao.javet.values.reference.V8ValueObject; -import org.openrewrite.internal.lang.NonNull; import java.util.*; -import static org.openrewrite.javascript.internal.tsc.TSCConversions.NODE; - public class TSCNodeList implements TSCV8Backed, List { public static TSCNodeList wrap(TSCProgramContext programContext, V8ValueObject maybeArrayV8) { @@ -71,13 +68,11 @@ public boolean contains(Object o) { return indexOf(o) >= 0; } - @NonNull @Override public Iterator iterator() { return listIterator(); } - @NonNull @Override public Object[] toArray() { int size = size(); @@ -88,9 +83,8 @@ public Object[] toArray() { return array; } - @NonNull @Override - public T2[] toArray(@NonNull T2[] array) { + public T2[] toArray(T2[] array) { int size = size(); if (array.length < size) { array = Arrays.copyOf(array, size); @@ -112,7 +106,7 @@ public boolean remove(Object o) { } @Override - public boolean containsAll(@NonNull Collection args) { + public boolean containsAll(Collection args) { for (Object arg : args) { if (!contains(arg)) { return false; @@ -122,22 +116,22 @@ public boolean containsAll(@NonNull Collection args) { } @Override - public boolean addAll(@NonNull Collection c) { + public boolean addAll(Collection c) { throw new UnsupportedOperationException("node list is not modifiable"); } @Override - public boolean addAll(int index, @NonNull Collection c) { + public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException("node list is not modifiable"); } @Override - public boolean removeAll(@NonNull Collection c) { + public boolean removeAll(Collection c) { throw new UnsupportedOperationException("node list is not modifiable"); } @Override - public boolean retainAll(@NonNull Collection c) { + public boolean retainAll(Collection c) { throw new UnsupportedOperationException("node list is not modifiable"); } @@ -200,13 +194,11 @@ public int lastIndexOf(Object o) { return -1; } - @NonNull @Override public ListIterator listIterator() { return listIterator(0); } - @NonNull @Override public ListIterator listIterator(int startIndex) { return new ListIterator() { @@ -261,7 +253,6 @@ public void add(TSCNode tscNode) { }; } - @NonNull @Override public List subList(int fromIndex, int toIndex) { ArrayList result = new ArrayList<>(toIndex - fromIndex); 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 63c6558b..96fcf2a6 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java @@ -79,14 +79,16 @@ public static TSCRuntime init(boolean forceWrappedV8Runtime) { public TSCRuntime setCompilerOptionOverride(String key, Object value) { try { - V8Value compilerOptions = this.parseOptionsV8.get("compilerOptions"); + this.close(); + TSCRuntime runtime = init(false); + V8Value compilerOptions = runtime.parseOptionsV8.get("compilerOptions"); if (compilerOptions.isNullOrUndefined()) { - compilerOptions = this.v8Runtime.createV8ValueObject(); - this.parseOptionsV8.set("compilerOptions", compilerOptions); + compilerOptions = runtime.v8Runtime.createV8ValueObject(); + runtime.parseOptionsV8.set("compilerOptions", compilerOptions); } ((V8ValueObject) compilerOptions).setWeak(); ((V8ValueObject) compilerOptions).set(key, value); - return this; + return runtime; } catch (JavetException e) { throw new RuntimeException(e); } 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 482dafe1..7b791f4e 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCV8Utils.java @@ -41,7 +41,7 @@ public static void assertValidIdentifier(String name) { public static V8ValueFunction makeFunction( V8Runtime runtime, - @Language("javascript") String innerCode, + @Language("typescript") String innerCode, IV8ValueObject variables ) { final List varNames; diff --git a/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java b/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java index 0c43f29b..ca3d1ebf 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AnnotationTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class AnnotationTest extends ParserTest { +class AnnotationTest implements RewriteTest { @Test void classDecorator() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java b/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java index 86c8fa7f..8617c519 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ArrayTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable"}) -class ArrayTest extends ParserTest { +class ArrayTest implements RewriteTest { @Test void array() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java b/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java index 6387363e..344f6e38 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ArrowFunctionTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"TypeScriptCheckImport", "JSUnusedLocalSymbols"}) -class ArrowFunctionTest extends ParserTest { +class ArrowFunctionTest implements RewriteTest { @Test void asMethodParameter() { diff --git a/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java b/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java index 7ea2a066..23034e3d 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AssignmentOperationTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"RedundantConditionalExpressionJS", "EqualityComparisonWithCoercionJS"}) -class AssignmentOperationTest extends ParserTest { +class AssignmentOperationTest implements RewriteTest { @Test void minusEqual() { diff --git a/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java b/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java index 83e89980..f36c074c 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AssignmentTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "TypeScriptCheckImport", "TypeScriptUnresolvedFunction"}) -class AssignmentTest extends ParserTest { +class AssignmentTest implements RewriteTest { @Test void assignment() { diff --git a/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java b/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java index 4ecddc3e..a5ab2872 100644 --- a/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/AwaitTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "TypeScriptCheckImport"}) -class AwaitTest extends ParserTest { +class AwaitTest implements RewriteTest { @Test void await() { diff --git a/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java b/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java index b484aaa3..bf18fd74 100644 --- a/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/BinaryTest.java @@ -18,8 +18,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.openrewrite.Issue; +import org.openrewrite.test.RewriteTest; -class BinaryTest extends ParserTest { +import static org.openrewrite.javascript.Assertions.javaScript; + +class BinaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { diff --git a/src/test/java/org/openrewrite/javascript/tree/BreakTest.java b/src/test/java/org/openrewrite/javascript/tree/BreakTest.java index edeac1ae..1579e7c2 100644 --- a/src/test/java/org/openrewrite/javascript/tree/BreakTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/BreakTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "LoopStatementThatDoesntLoopJS"}) -class BreakTest extends ParserTest { +class BreakTest implements RewriteTest { @Test void breakFromWhileLoop() { diff --git a/src/test/java/org/openrewrite/javascript/tree/CastTest.java b/src/test/java/org/openrewrite/javascript/tree/CastTest.java index 9f369981..47b8c8c3 100644 --- a/src/test/java/org/openrewrite/javascript/tree/CastTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/CastTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable"}) -class CastTest extends ParserTest { +class CastTest implements RewriteTest { @Test void castAs() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java index 8ff88283..3ed9a328 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ClassDeclarationTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable"}) -class ClassDeclarationTest extends ParserTest { +class ClassDeclarationTest implements RewriteTest { @Test void classDeclaration() { diff --git a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java index 9a453a5e..06b9378f 100644 --- a/src/test/java/org/openrewrite/javascript/tree/CommentTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/CommentTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class CommentTest extends ParserTest { +class CommentTest implements RewriteTest { @Test void singleLineComment() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java b/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java index f14b4919..48acc93b 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ContinueTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"UnnecessaryContinueJS", "JSUnusedLocalSymbols"}) -class ContinueTest extends ParserTest { +class ContinueTest implements RewriteTest { @Test void continueStatement() { diff --git a/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java b/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java index 9d6e495e..609bbbe1 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DeleteTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable"}) -class DeleteTest extends ParserTest { +class DeleteTest implements RewriteTest { @Test void delete() { diff --git a/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java b/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java index 48e8ecd6..05ce6792 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DestructureTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class DestructureTest extends ParserTest { +class DestructureTest implements RewriteTest { @ExpectedToFail @Test diff --git a/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java b/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java index 945d3284..3dca1a14 100644 --- a/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/DoWhileTest.java @@ -16,8 +16,11 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; -class DoWhileTest extends ParserTest { +import static org.openrewrite.javascript.Assertions.javaScript; + +class DoWhileTest implements RewriteTest { @Test void doWhileLoop() { diff --git a/src/test/java/org/openrewrite/javascript/tree/EnumTest.java b/src/test/java/org/openrewrite/javascript/tree/EnumTest.java index 0181256d..fe01c50b 100644 --- a/src/test/java/org/openrewrite/javascript/tree/EnumTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/EnumTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class EnumTest extends ParserTest { +class EnumTest implements RewriteTest { @Test void enumDeclaration() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ExportTest.java b/src/test/java/org/openrewrite/javascript/tree/ExportTest.java index 8f5f5084..b288ab79 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ExportTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ExportTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSFileReferences", "JSUnusedLocalSymbols", "TypeScriptCheckImport", "TypeScriptUnresolvedVariable"}) -class ExportTest extends ParserTest { +class ExportTest implements RewriteTest { @Test void exportDeclaration() { diff --git a/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java b/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java index b6f08759..fc587a1a 100644 --- a/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/FieldAccessTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnresolvedVariable", "JSUnusedLocalSymbols"}) -class FieldAccessTest extends ParserTest { +class FieldAccessTest implements RewriteTest { @Test void thisAccess() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java b/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java index 8233f27c..b0f7529c 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ForLoopTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("ALL") -class ForLoopTest extends ParserTest { +class ForLoopTest implements RewriteTest { @Test void forLoop() { diff --git a/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java b/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java index 91726755..5a09af31 100644 --- a/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/IfStatementTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "PointlessBooleanExpressionJS", "JSUnresolvedVariable"}) -class IfStatementTest extends ParserTest { +class IfStatementTest implements RewriteTest { @Test void ifStatement() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ImportTest.java b/src/test/java/org/openrewrite/javascript/tree/ImportTest.java index 2570bc17..0007180f 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ImportTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ImportTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"ES6UnusedImports", "TypeScriptCheckImport"}) -class ImportTest extends ParserTest { +class ImportTest implements RewriteTest { @Test void importStatement() { diff --git a/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java b/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java index 3bd6ebca..ac1cd816 100644 --- a/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/IndexedAccessTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class IndexedAccessTest extends ParserTest { +class IndexedAccessTest implements RewriteTest { @Test void indexedAccess() { diff --git a/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java b/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java index 82dfdb48..8d36fe0c 100644 --- a/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/LiteralTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "TypeScriptCheckImport", "TypeScriptUnresolvedFunction"}) -class LiteralTest extends ParserTest { +class LiteralTest implements RewriteTest { @Test void stringLiteral() { diff --git a/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java index 95e40709..0ac6d619 100644 --- a/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/MethodDeclarationTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable"}) -class MethodDeclarationTest extends ParserTest { +class MethodDeclarationTest implements RewriteTest { @Test void functionDeclaration() { diff --git a/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java b/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java index e9f6ed60..af9ce236 100644 --- a/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/MethodInvocationTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class MethodInvocationTest extends ParserTest { +class MethodInvocationTest implements RewriteTest { @Test void methodInvocation() { diff --git a/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java b/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java index de49ce66..e3a0bc69 100644 --- a/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/NewClassTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("ALL") -class NewClassTest extends ParserTest { +class NewClassTest implements RewriteTest { @Test void newClass() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java b/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java index 008104fb..bcd20f5e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ObjectBindingTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "LoopStatementThatDoesntLoopJS", "ES6UnusedImports", "TypeScriptCheckImport"}) -class ObjectBindingTest extends ParserTest { +class ObjectBindingTest implements RewriteTest { @Test void destructObject() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java index 96914b82..c1a68801 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ObjectLiteralTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "LoopStatementThatDoesntLoopJS", "TypeScriptCheckImport"}) -class ObjectLiteralTest extends ParserTest { +class ObjectLiteralTest implements RewriteTest { @Disabled // times out @Test diff --git a/src/test/java/org/openrewrite/javascript/tree/ParserPerfTest.java b/src/test/java/org/openrewrite/javascript/tree/ParserPerfTest.java index 3b08fdf0..640a56e8 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ParserPerfTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ParserPerfTest.java @@ -20,6 +20,8 @@ import org.openrewrite.internal.StringUtils; import org.openrewrite.test.RewriteTest; +import static org.openrewrite.javascript.Assertions.javaScript; + class ParserPerfTest implements RewriteTest { // from https://github.com/apache/camel/blob/main/components/camel-cometd/src/test/resources/webapp/dojo/org/cometd.js @@ -28,6 +30,6 @@ class ParserPerfTest implements RewriteTest { @Test void tryParseCometd() { - rewriteRun(ParserTest.javaScript(cometd)); + rewriteRun(javaScript(cometd)); } } diff --git a/src/test/java/org/openrewrite/javascript/tree/ParserTest.java b/src/test/java/org/openrewrite/javascript/tree/ParserTest.java index fb9d5d7b..f72e54da 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ParserTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ParserTest.java @@ -15,87 +15,14 @@ */ package org.openrewrite.javascript.tree; -import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; -import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.Space; -import org.openrewrite.javascript.JavaScriptIsoVisitor; -import org.openrewrite.javascript.JavaScriptParser; -import org.openrewrite.javascript.JavaScriptVisitor; +import org.openrewrite.Issue; import org.openrewrite.test.RewriteTest; -import org.openrewrite.test.SourceSpec; -import org.openrewrite.test.SourceSpecs; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.javascript.Assertions.javaScript; public class ParserTest implements RewriteTest { - public static SourceSpecs javaScript(@Language("typescript") @Nullable String before) { - return javaScript(before, s -> { - }); - } - - static void customizeExecutionContext(ExecutionContext ctx) { - } - - public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, - Consumer> spec) { - SourceSpec js = new SourceSpec<>( - JS.CompilationUnit.class, null, JavaScriptParser.builder(), before, - SourceSpec.ValidateSource.noop, - ParserTest::customizeExecutionContext); - acceptSpec(spec, js); - return js; - } - - public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, @Language("typescript") String after) { - return javaScript(before, after, s -> { - }); - } - - public static SourceSpecs javaScript(@Language("typescript") @Nullable String before, @Language("typescript") String after, - Consumer> spec) { - SourceSpec js = new SourceSpec<>( - JS.CompilationUnit.class, null, JavaScriptParser.builder(), before, - SourceSpec.ValidateSource.noop, - ParserTest::customizeExecutionContext).after(s -> after); - acceptSpec(spec, js); - return js; - } - - private static void acceptSpec(Consumer> spec, SourceSpec javaScript) { - Consumer userSuppliedAfterRecipe = javaScript.getAfterRecipe(); - javaScript.afterRecipe(userSuppliedAfterRecipe::accept); - isFullyParsed().andThen(spec).accept(javaScript); - } - - public static Consumer> isFullyParsed() { - return spec -> spec.afterRecipe(cu -> { - new JavaScriptIsoVisitor() { - @Override - public Space visitSpace(Space space, Space.Location loc, Integer integer) { - assertThat(space.getWhitespace().trim()).isEmpty(); - return super.visitSpace(space, loc, integer); - } - }.visit(cu, 0); - - new JavaScriptVisitor() { - @Override - public @Nullable J preVisit(J tree, Integer integer) { - if (tree instanceof J.Unknown) { - ((J.Unknown) tree).getSource().getMarkers().findFirst(ParseExceptionResult.class) - .ifPresent(result -> assertThat(result.getMessage()).isEqualTo("")); - } - return super.preVisit(tree, integer); - } - }.visit(cu, 0); - }); - } - @Issue("https://github.com/openrewrite/rewrite-javascript/issues/57") @Test void preservesOrder() { diff --git a/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java b/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java index 3724a4a1..b1d6c443 100644 --- a/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/PrimitiveTest.java @@ -17,8 +17,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.openrewrite.test.RewriteTest; -class PrimitiveTest extends ParserTest { +import static org.openrewrite.javascript.Assertions.javaScript; + +class PrimitiveTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { diff --git a/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java b/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java index b399bc06..61ffcb8e 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ReturnTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class ReturnTest extends ParserTest { +class ReturnTest implements RewriteTest { @Test void returnValue() { diff --git a/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java b/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java index 5dd8096d..4fbdd982 100644 --- a/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/SemiColonTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "TrailingWhitespacesInTextBlock", "JSUnnecessarySemicolon"}) -class SemiColonTest extends ParserTest { +class SemiColonTest implements RewriteTest { @Test void semiColon() { diff --git a/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java b/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java index bb865b5e..bc33b9c4 100644 --- a/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/SwitchTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class SwitchTest extends ParserTest { +class SwitchTest implements RewriteTest { @Test void singleCase() { diff --git a/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java b/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java index 68fa00eb..33a3cb91 100644 --- a/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/ThrowTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class ThrowTest extends ParserTest { +class ThrowTest implements RewriteTest { @Test void throwError() { diff --git a/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java b/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java index 9c1803e9..418740f6 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TrailingCommaTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSLastCommaInArrayLiteral", "JSUnresolvedVariable", "JSUnusedLocalSymbols", "TypeScriptUnresolvedVariable"}) -class TrailingCommaTest extends ParserTest { +class TrailingCommaTest implements RewriteTest { @Test void onMethodParameter() { diff --git a/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java b/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java index 0dda4127..d8a710a1 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TryCatchTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("ExceptionCaughtLocallyJS") -class TryCatchTest extends ParserTest { +class TryCatchTest implements RewriteTest { @Test void tryCatch() { diff --git a/src/test/java/org/openrewrite/javascript/tree/TupleTest.java b/src/test/java/org/openrewrite/javascript/tree/TupleTest.java index d9648b27..6adceada 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TupleTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TupleTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnresolvedVariable", "JSUnusedLocalSymbols"}) -class TupleTest extends ParserTest { +class TupleTest implements RewriteTest { @ExpectedToFail @Test diff --git a/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java b/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java index 0e1dc352..b74a30ff 100644 --- a/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/TypeOperatorTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class TypeOperatorTest extends ParserTest { +class TypeOperatorTest implements RewriteTest { @ExpectedToFail @Test diff --git a/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java b/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java index b42454bb..3f0fb297 100644 --- a/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/UnaryTest.java @@ -17,8 +17,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.openrewrite.test.RewriteTest; -class UnaryTest extends ParserTest { +import static org.openrewrite.javascript.Assertions.javaScript; + +class UnaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { diff --git a/src/test/java/org/openrewrite/javascript/tree/UnionTest.java b/src/test/java/org/openrewrite/javascript/tree/UnionTest.java index 598dd9f9..1abb9b7b 100644 --- a/src/test/java/org/openrewrite/javascript/tree/UnionTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/UnionTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("JSUnusedLocalSymbols") -class UnionTest extends ParserTest { +class UnionTest implements RewriteTest { @Test void union() { diff --git a/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java b/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java index a609e6db..1796216a 100644 --- a/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/VariableDeclarationTest.java @@ -17,9 +17,12 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "JSUnresolvedVariable", "TypeScriptCheckImport", "TypeScriptUnresolvedVariable"}) -class VariableDeclarationTest extends ParserTest { +class VariableDeclarationTest implements RewriteTest { @Test void let() { diff --git a/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java b/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java index 6ae246a3..2dcecbc3 100644 --- a/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/WhileLoopTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings("InfiniteLoopJS") -class WhileLoopTest extends ParserTest { +class WhileLoopTest implements RewriteTest { @Test void whileLoop() { diff --git a/src/test/java/org/openrewrite/javascript/tree/YieldTest.java b/src/test/java/org/openrewrite/javascript/tree/YieldTest.java index 2c6290d0..16626b49 100644 --- a/src/test/java/org/openrewrite/javascript/tree/YieldTest.java +++ b/src/test/java/org/openrewrite/javascript/tree/YieldTest.java @@ -16,9 +16,12 @@ package org.openrewrite.javascript.tree; import org.junit.jupiter.api.Test; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.javascript.Assertions.javaScript; @SuppressWarnings({"JSUnusedLocalSymbols", "TypeScriptUnresolvedVariable"}) -class YieldTest extends ParserTest { +class YieldTest implements RewriteTest { @Test void yield() {