Skip to content

Commit

Permalink
Handle RunTime exception thrown in TSCRuntime init.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 30, 2023
1 parent b0b6362 commit 34ab61a
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/main/java/org/openrewrite/javascript/JavaScriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.javascript.internal.JavetNativeBridge;
import org.openrewrite.javascript.internal.TsTreePrinter;
import org.openrewrite.javascript.internal.TypeScriptParserVisitor;
import org.openrewrite.javascript.internal.tsc.TSCRuntime;
import org.openrewrite.javascript.tree.JS;
Expand All @@ -41,7 +40,6 @@
import java.util.*;
import java.util.stream.Stream;

@SuppressWarnings("ConstantValue")
public class JavaScriptParser implements Parser {

@Nullable
Expand Down Expand Up @@ -75,7 +73,7 @@ private JavaScriptParser(Collection<NamedStyles> styles) {
public Stream<SourceFile> parse(String... sources) {
List<Input> inputs = new ArrayList<>(sources.length);
for (int i = 0; i < sources.length; i++) {
Path path = Paths.get("f" + i + ".ts");
Path path = Paths.get("f" + i + ".js");
int j = i;
inputs.add(new Input(
path, null,
Expand Down Expand Up @@ -118,34 +116,36 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re
sourceTextsForTSC.put(relativePath, sourceText.sourceText);
});

//noinspection resource
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);
try {
//noinspection resource
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);
}

compilationUnits.add(cu);
}
);
);
} catch (Exception e) {
return acceptedInputs(sources).map(input -> ParseError.build(this, input, relativeTo, ctx, e));
}
return compilationUnits.stream();
}

Expand Down

0 comments on commit 34ab61a

Please sign in to comment.