Search in sources :

Example 1 with InputId

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

the class TypeCheckTest method testNameNode.

/**
 * Type checks a NAME node and retrieve its type.
 */
private JSType testNameNode(String name) {
    Node node = Node.newString(Token.NAME, name);
    Node parent = new Node(Token.SCRIPT, node);
    parent.setInputId(new InputId("code"));
    Node externs = new Node(Token.SCRIPT);
    externs.setInputId(new InputId("externs"));
    IR.root(externs, parent);
    makeTypeCheck().processForTesting(null, parent);
    return node.getJSType();
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId)

Example 2 with InputId

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

the class TypedScopeCreatorTest method createEmptyRoot.

private static Node createEmptyRoot() {
    Node root = new Node(Token.ROOT, new Node(Token.SCRIPT));
    root.getFirstChild().setInputId(new InputId("input"));
    return root;
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId)

Example 3 with InputId

use of com.google.javascript.rhino.InputId 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 4 with InputId

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

the class CompilerTest method testNormalInputs.

public void testNormalInputs() {
    CompilerOptions options = new CompilerOptions();
    Compiler compiler = new Compiler();
    List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("in1", ""), SourceFile.fromCode("in2", ""));
    compiler.compile(EMPTY_EXTERNS, inputs, options);
    assertTrue(compiler.getInput(new InputId("externs")).isExtern());
    assertFalse(compiler.getInput(new InputId("in1")).isExtern());
    assertFalse(compiler.getInput(new InputId("in2")).isExtern());
}
Also used : InputId(com.google.javascript.rhino.InputId)

Example 5 with InputId

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

the class SimpleReplaceScriptTest method testInferWithModules.

public void testInferWithModules() {
    CompilerOptions options = getOptions();
    Compiler compiler = new Compiler();
    List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("in", ""));
    Result result = compiler.compile(EXTVAR_EXTERNS, inputs, options);
    assertTrue(result.success);
    CompilerInput oldInput = compiler.getInput(new InputId("in"));
    JSModule myModule = oldInput.getModule();
    assertThat(myModule.getInputs()).hasSize(1);
    SourceFile newSource = SourceFile.fromCode("in", "var x;");
    JsAst ast = new JsAst(newSource);
    compiler.replaceScript(ast);
    assertThat(myModule.getInputs()).hasSize(1);
    assertThat(myModule.getInputs()).doesNotContain(oldInput);
    assertThat(myModule.getInputs()).containsExactly(compiler.getInput(new InputId("in")));
}
Also used : InputId(com.google.javascript.rhino.InputId)

Aggregations

InputId (com.google.javascript.rhino.InputId)15 Node (com.google.javascript.rhino.Node)9 Compiler (com.google.javascript.jscomp.Compiler)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 GraphNode (com.google.javascript.jscomp.graph.GraphNode)1 Config (com.google.javascript.jscomp.parsing.Config)1 ParserRunner (com.google.javascript.jscomp.parsing.ParserRunner)1 Comment (com.google.javascript.jscomp.parsing.parser.trees.Comment)1 ErrorReporter (com.google.javascript.rhino.ErrorReporter)1 SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)1 ArrayList (java.util.ArrayList)1