use of com.google.javascript.jscomp.parsing.parser.SourceFile in project closure-compiler by google.
the class ParserRunner method parse.
public static ParseResult parse(StaticSourceFile sourceFile, String sourceString, Config config, ErrorReporter errorReporter) {
// TODO(johnlenz): unify "SourceFile", "Es6ErrorReporter" and "Config"
String sourceName = sourceFile.getName();
try {
SourceFile file = new SourceFile(sourceName, sourceString);
boolean keepGoing = config.runMode() == Config.RunMode.KEEP_GOING;
Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, keepGoing);
com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = newParserConfig(config);
Parser p = new Parser(es6config, es6ErrorReporter, file);
ProgramTree tree = p.parseProgram();
Node root = null;
List<Comment> comments = ImmutableList.of();
FeatureSet features = p.getFeatures();
if (tree != null && (!es6ErrorReporter.hadError() || keepGoing)) {
IRFactory factory = IRFactory.transformTree(tree, sourceFile, config, errorReporter);
root = factory.getResultNode();
features = features.union(factory.getFeatures());
root.putProp(Node.FEATURE_SET, features);
if (config.jsDocParsingMode().shouldParseDescriptions()) {
comments = p.getComments();
}
}
return new ParseResult(root, comments, features, p.getSourceMapURL());
} catch (Throwable t) {
throw new RuntimeException("Exception parsing \"" + sourceName + "\"", t);
}
}
use of com.google.javascript.jscomp.parsing.parser.SourceFile in project closure-compiler by google.
the class ParserRunner method detectFeatures.
// TODO(sdh): this is less useful if we end up needing the node for library version detection
public static FeatureSet detectFeatures(String sourcePath, String sourceString) {
SourceFile file = new SourceFile(sourcePath, sourceString);
ErrorReporter reporter = IRFactory.NULL_REPORTER;
com.google.javascript.jscomp.parsing.parser.Parser.Config config = newParserConfig(IRFactory.NULL_CONFIG);
Parser p = new Parser(config, new Es6ErrorReporter(reporter, false), file);
ProgramTree tree = p.parseProgram();
StaticSourceFile simpleSourceFile = new SimpleSourceFile(sourcePath, false);
return IRFactory.detectFeatures(tree, simpleSourceFile, sourceString).union(p.getFeatures());
}
Aggregations