use of com.google.javascript.rhino.ErrorReporter in project closure-compiler by google.
the class JsfileParser method parse.
/**
* Internal implementation to produce the {@link FileInfo} object.
*/
private static FileInfo parse(String code, String filename, @Nullable Reporter reporter) {
ErrorReporter errorReporter = new DelegatingReporter(reporter);
Compiler compiler = new Compiler();
compiler.init(ImmutableList.<SourceFile>of(), ImmutableList.<SourceFile>of(), new CompilerOptions());
Config config = ParserRunner.createConfig(// TODO(sdh): ES8 STRICT, with a non-strict fallback - then give warnings.
Config.LanguageMode.ECMASCRIPT8, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, /* extraAnnotationNames */
ImmutableSet.<String>of(), /* parseInlineSourceMaps */
true, Config.StrictMode.SLOPPY);
SourceFile source = SourceFile.fromCode(filename, code);
FileInfo info = new FileInfo(errorReporter);
ParserRunner.ParseResult parsed = ParserRunner.parse(source, code, config, errorReporter);
parsed.ast.setInputId(new InputId(filename));
String version = parsed.features.version();
if (!version.equals("es3")) {
info.loadFlags.add(JsArray.of("lang", version));
}
for (Comment comment : parsed.comments) {
if (comment.type == Comment.Type.JSDOC) {
parseComment(comment, info);
}
}
NodeTraversal.traverseEs6(compiler, parsed.ast, new Traverser(info));
return info;
}
use of com.google.javascript.rhino.ErrorReporter in project closure-compiler by google.
the class Asserts method assertValidResolve.
/**
* @return The resolved type
*/
public static JSType assertValidResolve(JSType type, StaticTypedScope<JSType> scope) {
ErrorReporter reporter = TestErrorReporter.forNoExpectedReports();
JSType resolvedType = type.resolve(reporter, scope);
assertTypeEquals("JSType#resolve should not affect object equality", type, resolvedType);
return resolvedType;
}
use of com.google.javascript.rhino.ErrorReporter 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());
}
use of com.google.javascript.rhino.ErrorReporter in project JSCover by tntim96.
the class SourceProcessor method parse.
private ParserRunner.ParseResult parse(String source, StaticSourceFile sourceFile) {
ErrorReporter errorReporter = new ErrorReporter() {
@Override
public void warning(String message, String sourceName, int line, int lineOffset) {
logger.log(Level.WARNING, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[] { message, sourceName, line, lineOffset });
}
@Override
public void error(String message, String sourceName, int line, int lineOffset) {
logger.log(Level.SEVERE, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[] { message, sourceName, line, lineOffset });
}
};
ParserRunner.ParseResult parseResult = ParserRunner.parse(sourceFile, source, config, errorReporter);
return parseResult;
}
Aggregations