return new ParseResult(root, comments, features, p.getSourceMapURL()); } catch (Throwable t) { throw new RuntimeException("Exception parsing \"" + sourceName + "\"", t);
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); }