Search in sources :

Example 1 with ErrorReporter

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;
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) Comment(com.google.javascript.jscomp.parsing.parser.trees.Comment) ParserRunner(com.google.javascript.jscomp.parsing.ParserRunner) Config(com.google.javascript.jscomp.parsing.Config) ErrorReporter(com.google.javascript.rhino.ErrorReporter) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) InputId(com.google.javascript.rhino.InputId) SourceFile(com.google.javascript.jscomp.SourceFile)

Example 2 with ErrorReporter

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;
}
Also used : ErrorReporter(com.google.javascript.rhino.ErrorReporter) JSType(com.google.javascript.rhino.jstype.JSType)

Example 3 with ErrorReporter

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());
}
Also used : ErrorReporter(com.google.javascript.rhino.ErrorReporter) ProgramTree(com.google.javascript.jscomp.parsing.parser.trees.ProgramTree) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) SourceFile(com.google.javascript.jscomp.parsing.parser.SourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) Parser(com.google.javascript.jscomp.parsing.parser.Parser)

Example 4 with ErrorReporter

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;
}
Also used : ErrorReporter(com.google.javascript.rhino.ErrorReporter) ParserRunner(com.google.javascript.jscomp.parsing.ParserRunner)

Aggregations

ErrorReporter (com.google.javascript.rhino.ErrorReporter)4 ParserRunner (com.google.javascript.jscomp.parsing.ParserRunner)2 Compiler (com.google.javascript.jscomp.Compiler)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 Config (com.google.javascript.jscomp.parsing.Config)1 Parser (com.google.javascript.jscomp.parsing.parser.Parser)1 SourceFile (com.google.javascript.jscomp.parsing.parser.SourceFile)1 Comment (com.google.javascript.jscomp.parsing.parser.trees.Comment)1 ProgramTree (com.google.javascript.jscomp.parsing.parser.trees.ProgramTree)1 InputId (com.google.javascript.rhino.InputId)1 SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)1 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)1 JSType (com.google.javascript.rhino.jstype.JSType)1