Search in sources :

Example 6 with SimpleSourceFile

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

the class GlobalTypeInfoCollector method dummyRawTypeForMissingExterns.

private RawNominalType dummyRawTypeForMissingExterns(String name) {
    Node defSite = NodeUtil.emptyFunction();
    defSite.setStaticSourceFile(new SimpleSourceFile("", true));
    return RawNominalType.makeClass(getCommonTypes(), defSite, name, ImmutableList.of(), ObjectKind.UNRESTRICTED, false);
}
Also used : Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 7 with SimpleSourceFile

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

the class AstValidatorTest method testValidScript.

@Test
public void testValidScript() {
    // Since we're building the AST by hand, there won't be any types on it.
    typeInfoValidationMode = AstValidator.TypeInfoValidation.NONE;
    Node n = new Node(Token.SCRIPT);
    expectInvalid(n, Check.SCRIPT);
    n.setInputId(new InputId("something_input"));
    n.setStaticSourceFile(new SimpleSourceFile("something", SourceKind.STRONG));
    expectValid(n, Check.SCRIPT);
    expectInvalid(n, Check.STATEMENT);
    expectInvalid(n, Check.EXPRESSION);
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) Test(org.junit.Test)

Example 8 with SimpleSourceFile

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

the class AstValidatorTest method testValidFeatureInScript.

@Test
public void testValidFeatureInScript() {
    // Since we're building the AST by hand, there won't be any types on it.
    typeInfoValidationMode = AstValidator.TypeInfoValidation.NONE;
    setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
    Node n = new Node(Token.SCRIPT);
    n.setInputId(new InputId("something_input"));
    n.setStaticSourceFile(new SimpleSourceFile("something", SourceKind.STRONG));
    expectValid(n, Check.SCRIPT);
    n.addChildToFront(IR.let(IR.name("a"), IR.number(3)));
    n.srcrefTree(n);
    expectInvalid(n, Check.SCRIPT);
    n.putProp(Node.FEATURE_SET, FeatureSet.BARE_MINIMUM.with(Feature.LET_DECLARATIONS));
    expectValid(n, Check.SCRIPT);
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) Test(org.junit.Test)

Example 9 with SimpleSourceFile

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

the class ParsingUtilTest method parse.

private static Node parse(String source, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = ParserRunner.createConfig(LanguageMode.ES_NEXT, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, null, true, StrictMode.STRICT);
    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) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 10 with SimpleSourceFile

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

the class JsDocInfoParserTest method parseFull.

private Node parseFull(String code, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE).setRunMode(RunMode.KEEP_GOING).setSuppressionNames(extraSuppressions).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(StrictMode.SLOPPY).build();
    ParseResult result = ParserRunner.parse(new SimpleSourceFile("source", SourceKind.STRONG), code, config, testErrorReporter);
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return result.ast;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

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