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 = new com.google.javascript.jscomp.parsing.parser.Parser.Config(mode( IRFactory.NULL_CONFIG.languageMode)); 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).require(p.getFeatures()); }
Node root = null; List<Comment> comments = ImmutableList.of(); FeatureSet features = p.getFeatures(); if (tree != null && (!es6ErrorReporter.hadError() || keepGoing)) { IRFactory factory =
public static ParseResult parse( StaticSourceFile sourceFile, String sourceString, Config config, ErrorReporter errorReporter) { // TODO(johnlenz): unify "SourceFile", "Es6ErrorReporter" and "Config" SourceFile file = new SourceFile(sourceFile.getName(), sourceString); Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, config.isIdeMode); com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = new com.google.javascript.jscomp.parsing.parser.Parser.Config(mode( config.languageMode)); 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() || config.isIdeMode)) { IRFactory factory = IRFactory.transformTree(tree, sourceFile, sourceString, config, errorReporter); root = factory.getResultNode(); features = features.require(factory.getFeatures()); root.setIsSyntheticBlock(true); root.putProp(Node.FEATURE_SET, features); if (config.isIdeMode) { comments = p.getComments(); } } return new ParseResult(root, comments, features); }