Search in sources :

Example 1 with SimpleSourceFile

use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.

the class ParserTest method doParse.

private ParserRunner.ParseResult doParse(String string, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    StaticSourceFile file = new SimpleSourceFile("input", SourceKind.STRONG);
    ParserRunner.ParseResult result = ParserRunner.parse(file, string, createConfig(), testErrorReporter);
    // check expected features if specified
    assertFS(result.features).contains(expectedFeatures);
    // verifying that all warnings were seen
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    assertSourceInfoPresent(result.ast);
    return result;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult)

Example 2 with SimpleSourceFile

use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.

the class ParserTest method parseError.

/**
 * Verify that the given code has the given parse errors.
 *
 * @return If in IDE mode, returns a partial tree.
 */
private Node parseError(String source, String... errors) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllErrors(errors);
    ParseResult result = ParserRunner.parse(new SimpleSourceFile("input", SourceKind.STRONG), source, createConfig(), testErrorReporter);
    Node script = result.ast;
    // check expected features if specified
    assertFS(result.features).contains(expectedFeatures);
    // verifying that all errors were seen
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 3 with SimpleSourceFile

use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.

the class AttachJsdocsTest method parse.

private Node parse(String source, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = ParserRunner.createConfig(mode, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, null, true, StrictMode.SLOPPY);
    Node script = ParserRunner.parse(new SimpleSourceFile("input", SourceKind.STRONG), source, config, testErrorReporter).ast;
    // verifying that all warnings were seen
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 4 with SimpleSourceFile

use of com.google.javascript.rhino.SimpleSourceFile in project closure-compiler by google.

the class JsDocInfoParserTest method parse.

private JSDocInfo parse(String comment, JsDocParsing parseDocumentation, boolean parseFileOverview, String... warnings) {
    TestErrorReporter errorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(parseDocumentation).setSuppressionNames(extraSuppressions).setClosurePrimitiveNames(extraPrimitives).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(Config.StrictMode.SLOPPY).build();
    StaticSourceFile file = new SimpleSourceFile("testcode", SourceKind.STRONG);
    Node templateNode = IR.script();
    templateNode.setStaticSourceFile(file);
    JsDocInfoParser jsdocParser = new JsDocInfoParser(stream(comment), comment, 0, templateNode, config, errorReporter);
    jsdocParser.parse();
    this.prevLicense = jsdocParser.getLicenseText();
    errorReporter.verifyHasEncounteredAllWarningsAndErrors();
    final JSDocInfo result;
    if (parseFileOverview) {
        result = jsdocParser.getFileOverviewJSDocInfo();
    } else {
        result = jsdocParser.retrieveAndResetParsedJSDocInfo();
    }
    if (result != null) {
        assertThat(result.getTypeNodes()).comparingElementsUsing(transforming(NodeUtil::getSourceName, "has source name that")).doesNotContain(null);
    }
    return result;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) JSDocInfo(com.google.javascript.rhino.JSDocInfo) NodeUtil(com.google.javascript.jscomp.NodeUtil)

Example 5 with SimpleSourceFile

use of com.google.javascript.rhino.SimpleSourceFile 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)

Aggregations

SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)10 Node (com.google.javascript.rhino.Node)7 TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)6 ParseResult (com.google.javascript.jscomp.parsing.ParserRunner.ParseResult)3 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)3 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)3 InputId (com.google.javascript.rhino.InputId)2 Test (org.junit.Test)2 NodeUtil (com.google.javascript.jscomp.NodeUtil)1 Parser (com.google.javascript.jscomp.parsing.parser.Parser)1 SourceFile (com.google.javascript.jscomp.parsing.parser.SourceFile)1 ProgramTree (com.google.javascript.jscomp.parsing.parser.trees.ProgramTree)1 ErrorReporter (com.google.javascript.rhino.ErrorReporter)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1