Skip to content

Commit

Permalink
Delete unused tracking of parse results in JsAst & Node.PARSE_RESULTS
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 695848027
  • Loading branch information
lauraharker authored and copybara-github committed Nov 12, 2024
1 parent 0f372dc commit 2c19f11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 78 deletions.
82 changes: 9 additions & 73 deletions src/com/google/javascript/jscomp/JsAst.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.javascript.jscomp.base.JSCompObjects.identical;

import com.google.common.collect.ImmutableList;
import com.google.javascript.jscomp.parsing.ParserRunner;
import com.google.javascript.jscomp.parsing.parser.FeatureSet;
import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.Node;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -93,74 +89,21 @@ public FeatureSet getFeatures(AbstractCompiler compiler) {
return features;
}

/** Representation of Rhino parser error. */
public static class RhinoError implements Serializable {
private static final long serialVersionUID = 1L;

public final String message;
public final String sourceName;
public final int line;
public final int lineOffset;

public RhinoError(String message, String sourceName, int line, int lineOffset) {
this.message = message;
this.sourceName = sourceName;
this.line = line;
this.lineOffset = lineOffset;
}
}

/** Simple class to share parse results between compilation jobs */
public static class ParseResult implements Serializable {
private static final long serialVersionUID = 1L;

public final ImmutableList<RhinoError> errors;
public final ImmutableList<RhinoError> warnings;

ParseResult(ImmutableList<RhinoError> errors, ImmutableList<RhinoError> warnings) {
this.errors = errors;
this.warnings = warnings;
}
}

private static class RecordingReporterProxy implements ErrorReporter {
final ArrayList<RhinoError> errors = new ArrayList<>();
final ArrayList<RhinoError> warnings = new ArrayList<>();
private final ErrorReporter delegateReporter;

RecordingReporterProxy(ErrorReporter delegateReporter) {
this.delegateReporter = delegateReporter;
}

@Override
public void warning(String message, String sourceName, int line, int lineOffset) {
warnings.add(new RhinoError(message, sourceName, line, lineOffset));
delegateReporter.warning(message, sourceName, line, lineOffset);
}

@Override
public void error(String message, String sourceName, int line, int lineOffset) {
errors.add(new RhinoError(message, sourceName, line, lineOffset));
delegateReporter.error(message, sourceName, line, lineOffset);
}
}

boolean isParsed() {
return root != null;
}

private void parse(AbstractCompiler compiler) {
RecordingReporterProxy reporter = new RecordingReporterProxy(
compiler.getDefaultErrorReporter());

try {
ParserRunner.ParseResult result = ParserRunner.parse(
sourceFile,
sourceFile.getCode(),
compiler.getParserConfig(sourceFile.isExtern()
? AbstractCompiler.ConfigContext.EXTERNS
: AbstractCompiler.ConfigContext.DEFAULT),
reporter);
ParserRunner.ParseResult result =
ParserRunner.parse(
sourceFile,
sourceFile.getCode(),
compiler.getParserConfig(
sourceFile.isExtern()
? AbstractCompiler.ConfigContext.EXTERNS
: AbstractCompiler.ConfigContext.DEFAULT),
compiler.getDefaultErrorReporter());
root = result.ast;
features = result.features;

Expand All @@ -184,13 +127,6 @@ private void parse(AbstractCompiler compiler) {
root = IR.script();
}

if (!reporter.errors.isEmpty() || !reporter.warnings.isEmpty()) {
ParseResult result = new ParseResult(
ImmutableList.copyOf(reporter.errors),
ImmutableList.copyOf(reporter.warnings));
root.putProp(Node.PARSE_RESULTS, result);
}

// Set the source name so that the compiler passes can track
// the source file and module.
root.setStaticSourceFile(sourceFile);
Expand Down
4 changes: 0 additions & 4 deletions src/com/google/javascript/rhino/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ enum Prop {
ACCESS_MODIFIER,
// Indicates the node should not be indexed by analysis tools.
NON_INDEXABLE,
// Parse results stored on SCRIPT nodes to allow replaying parse warnings/errors when cloning
// cached ASTs.
PARSE_RESULTS,
// Indicates that a SCRIPT node is a goog.module. Remains set after the goog.module is
// desugared.
GOOG_MODULE,
Expand Down Expand Up @@ -284,7 +281,6 @@ public final boolean getIsParenthesized() {
public static final Prop IMPLEMENTS = Prop.IMPLEMENTS;
public static final Prop CONSTRUCT_SIGNATURE = Prop.CONSTRUCT_SIGNATURE;
public static final Prop ACCESS_MODIFIER = Prop.ACCESS_MODIFIER;
public static final Prop PARSE_RESULTS = Prop.PARSE_RESULTS;
public static final Prop GOOG_MODULE = Prop.GOOG_MODULE;
public static final Prop FEATURE_SET = Prop.FEATURE_SET;
public static final Prop IS_TYPESCRIPT_ABSTRACT = Prop.IS_TYPESCRIPT_ABSTRACT;
Expand Down
1 change: 0 additions & 1 deletion src/com/google/javascript/rhino/PropTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ private static final void setProps() {
case IMPLEMENTS:
case CONSTRUCT_SIGNATURE:
case ACCESS_MODIFIER:
case PARSE_RESULTS:
case IS_TYPESCRIPT_ABSTRACT:
case TYPEDEF_TYPE:
// These cases cannot be translated to a NodeProperty
Expand Down

0 comments on commit 2c19f11

Please sign in to comment.