diff --git a/src/main/java/org/openrewrite/javascript/JavaScriptParser.java b/src/main/java/org/openrewrite/javascript/JavaScriptParser.java index 10e50299..0e3dfa69 100644 --- a/src/main/java/org/openrewrite/javascript/JavaScriptParser.java +++ b/src/main/java/org/openrewrite/javascript/JavaScriptParser.java @@ -69,7 +69,6 @@ public Stream parseInputs(Iterable sources, @Nullable Path re for (Input source : sources) { mapper.add(source); } - outputs = mapper.build(); } return outputs.stream(); diff --git a/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java b/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java index 7ef88e09..e368e4b8 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java +++ b/src/main/java/org/openrewrite/javascript/internal/TSCMapper.java @@ -15,6 +15,7 @@ */ package org.openrewrite.javascript.internal; +import lombok.RequiredArgsConstructor; import lombok.Value; import org.openrewrite.ExecutionContext; import org.openrewrite.Parser; @@ -33,17 +34,9 @@ import java.nio.file.Path; import java.util.*; +@RequiredArgsConstructor 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 @@ -54,20 +47,12 @@ private static class SourceWrapper { 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) { - final EncodingDetectingInputStream is = input.getSource(ctx); - final String inputSourceText = is.readFully(); - final Path relativePath = input.getRelativePath(relativeTo); + EncodingDetectingInputStream is = input.getSource(ctx); + String inputSourceText = is.readFully(); + Path relativePath = input.getRelativePath(relativeTo); - final SourceWrapper source = new SourceWrapper( + SourceWrapper source = new SourceWrapper( input, relativePath, is.getCharset(), @@ -81,15 +66,16 @@ public List build() { List compilationUnits = new ArrayList<>(sourcesByRelativePath.size()); ParsingEventListener parsingListener = ParsingExecutionContextView.view(ctx).getParsingListener(); Map sourceTextsForTSC = new LinkedHashMap<>(); - this.sourcesByRelativePath.forEach((relativePath, sourceText) -> { + sourcesByRelativePath.forEach((relativePath, sourceText) -> { sourceTextsForTSC.put(relativePath, sourceText.sourceText); }); - this.runtime.parseSourceTexts( + runtime.parseSourceTexts( sourceTextsForTSC, (node, context) -> { - final SourceWrapper source = this.sourcesByRelativePath.get(context.getRelativeSourcePath()); - final TypeScriptParserVisitor fileMapper = new TypeScriptParserVisitor( + SourceWrapper source = sourcesByRelativePath.get(context.getRelativeSourcePath()); + parsingListener.startedParsing(source.getInput()); + TypeScriptParserVisitor fileMapper = new TypeScriptParserVisitor( node, context, source.getSourcePath(), @@ -109,6 +95,7 @@ public List build() { compilationUnits.add(cu); } ); + return compilationUnits; } @@ -117,4 +104,12 @@ public void close() { this.runtime.close(); } + @Value + private static class SourceWrapper { + Parser.Input input; + Path sourcePath; + Charset charset; + boolean isCharsetBomMarked; + String sourceText; + } } 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 c68cc206..d7de6ef9 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCRuntime.java @@ -75,7 +75,6 @@ public static TSCRuntime init(boolean forceWrappedV8Runtime) { JavetException e) { throw new RuntimeException(e); } - } public TSCRuntime setCompilerOptionOverride(String key, Object value) {