Search in sources :

Example 6 with InputId

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

the class TypeCheckNoTranspileTest method parseAndTypeCheckWithScope.

private TypeCheckResult parseAndTypeCheckWithScope(String externs, String js) {
    registry.clearNamedTypes();
    registry.clearTemplateTypeNames();
    compiler.init(ImmutableList.of(SourceFile.fromCode("[externs]", externs)), ImmutableList.of(SourceFile.fromCode("[testcode]", js)), compiler.getOptions());
    Node n = IR.root(compiler.getInput(new InputId("[testcode]")).getAstRoot(compiler));
    Node externsNode = IR.root(compiler.getInput(new InputId("[externs]")).getAstRoot(compiler));
    Node externAndJsRoot = IR.root(externsNode, n);
    compiler.jsRoot = n;
    compiler.externsRoot = externsNode;
    compiler.externAndJsRoot = externAndJsRoot;
    assertEquals("parsing error: " + Joiner.on(", ").join(compiler.getErrors()), 0, compiler.getErrorCount());
    TypedScope s = makeTypeCheck().processForTesting(externsNode, n);
    return new TypeCheckResult(n, s);
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId)

Example 7 with InputId

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

the class Compiler method initInputsByIdMap.

/**
 * Creates a map to make looking up an input by name fast. Also checks for
 * duplicate inputs.
 */
void initInputsByIdMap() {
    inputsById.clear();
    for (CompilerInput input : externs) {
        InputId id = input.getInputId();
        CompilerInput previous = putCompilerInput(id, input);
        if (previous != null) {
            report(JSError.make(DUPLICATE_EXTERN_INPUT, input.getName()));
        }
    }
    for (CompilerInput input : inputs) {
        InputId id = input.getInputId();
        CompilerInput previous = putCompilerInput(id, input);
        if (previous != null) {
            report(JSError.make(DUPLICATE_INPUT, input.getName()));
        }
    }
}
Also used : InputId(com.google.javascript.rhino.InputId)

Example 8 with InputId

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

the class Compiler method replaceIncrementalSourceAst.

/**
 * Replace a source input dynamically. Intended for incremental
 * re-compilation.
 *
 * If the new source input doesn't parse, then keep the old input
 * in the AST and return false.
 *
 * @return Whether the new AST was attached successfully.
 */
boolean replaceIncrementalSourceAst(JsAst ast) {
    CompilerInput oldInput = getInput(ast.getInputId());
    checkNotNull(oldInput, "No input to replace: %s", ast.getInputId().getIdName());
    Node newRoot = ast.getAstRoot(this);
    if (newRoot == null) {
        return false;
    }
    Node oldRoot = oldInput.getAstRoot(this);
    if (oldRoot != null) {
        oldRoot.replaceWith(newRoot);
    } else {
        getRoot().getLastChild().addChildToBack(newRoot);
    }
    CompilerInput newInput = new CompilerInput(ast);
    putCompilerInput(ast.getInputId(), newInput);
    JSModule module = oldInput.getModule();
    if (module != null) {
        module.addAfter(newInput, oldInput);
        module.remove(oldInput);
    }
    // Verify the input id is set properly.
    checkState(newInput.getInputId().equals(oldInput.getInputId()));
    InputId inputIdOnAst = newInput.getAstRoot(this).getInputId();
    checkState(newInput.getInputId().equals(inputIdOnAst));
    inputs.remove(oldInput);
    return true;
}
Also used : Node(com.google.javascript.rhino.Node) InputId(com.google.javascript.rhino.InputId)

Example 9 with InputId

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

the class GlobalVarReferenceMap method updateGlobalVarReferences.

/**
 * Updates the internal reference map based on the provided parameters. If
 * {@code scriptRoot} is not SCRIPT, it basically replaces the internal map
 * with the new one, otherwise it replaces all the information associated to
 * the given script.
 *
 * @param refMapPatch The reference map result of a
 *     {@link ReferenceCollectingCallback} pass which might be collected from
 *     the whole AST or just a sub-tree associated to a SCRIPT node.
 * @param root AST sub-tree root on which reference collection was done.
 */
void updateGlobalVarReferences(Map<Var, ReferenceCollection> refMapPatch, Node root) {
    if (refMap == null || !root.isScript()) {
        resetGlobalVarReferences(refMapPatch);
        return;
    }
    InputId inputId = root.getInputId();
    checkNotNull(inputId);
    // Note there are two assumptions here (i) the order of compiler inputs
    // has not changed and (ii) all references are in the order they appear
    // in AST (this is enforced in ReferenceCollectionCallback).
    removeScriptReferences(inputId);
    for (Entry<Var, ReferenceCollection> entry : refMapPatch.entrySet()) {
        Var var = entry.getKey();
        if (var.isGlobal()) {
            replaceReferences(var.getName(), inputId, entry.getValue());
        }
    }
}
Also used : InputId(com.google.javascript.rhino.InputId)

Example 10 with InputId

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

the class Compiler method removeSyntheticVarsInput.

private void removeSyntheticVarsInput() {
    String sourceName = Compiler.SYNTHETIC_EXTERNS;
    removeExternInput(new InputId(sourceName));
}
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