@Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback( compiler, new InliningBehavior()); callback.process(externs, root); }
@Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback(compiler, new ReferenceCheckingBehavior()); callback.process(externs, root); }
@Override public void hotSwapScript(Node scriptRoot, Node originalRoot) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback(compiler, new ReferenceCheckingBehavior()); callback.hotSwapScript(scriptRoot, originalRoot); }
static ImmutableSet<String> collectExternVariableNames(AbstractCompiler compiler, Node externs) { ReferenceCollectingCallback externsRefs = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler)); externsRefs.process(externs); ImmutableSet.Builder<String> externsNames = ImmutableSet.builder(); for (Var v : externsRefs.getAllSymbols()) { if (!v.isParam()) { externsNames.add(v.getName()); } } return externsNames.build(); }
@Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback( compiler, new InliningBehavior(), getFilterForMode()); callback.process(externs, root); }
/** * Adds a map from each use NAME in {@code root} to its corresponding * declaring name, *provided the declaration is also under root*. * * If the declaration is not under root, then the reference will * not be added to the map. */ public void mapUses(Node root) { referencesByNameNode = new HashMap<Node, Node>(); ReferenceCollectingCallback callback = new ReferenceCollectingCallback(compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR); NodeTraversal.traverseEs6(compiler, root, callback); for (Var variable : callback.getAllSymbols()) { ReferenceCollection referenceCollection = callback.getReferences(variable); for (Reference reference : referenceCollection.references) { Node referenceNameNode = reference.getNode(); // Note that this counts a declaration as a reference to itself referencesByNameNode.put(referenceNameNode, variable.getNameNode()); } } }
@Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback( compiler, new InliningBehavior(), new Es6SyntacticScopeCreator(compiler)); callback.process(externs, root); }
@Override public void process(Node externs, Node root) { NodeTraversal.traverse(compiler, root, this); // Don't inline the VAR declaration if this compilation involves old-style ctemplates. if (compiler.getOptions().syntheticBlockStartMarker == null) { (new ReferenceCollectingCallback(compiler, this, new Es6SyntacticScopeCreator(compiler))) .process(root); } }
/** * Adds a map from each use NAME in {@code root} to its corresponding * declaring name, *provided the declaration is also under root*. * * If the declaration is not under root, then the reference will * not be added to the map. */ public void mapUses(Node root) { referencesByNameNode = new HashMap<>(); ReferenceCollectingCallback callback = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler)); callback.process(root); for (Var variable : callback.getAllSymbols()) { ReferenceCollection referenceCollection = callback.getReferences(variable); for (Reference reference : referenceCollection.references) { Node referenceNameNode = reference.getNode(); // Note that this counts a declaration as a reference to itself referencesByNameNode.put(referenceNameNode, variable.getNameNode()); } } }
@Override public void process(Node externs, Node root) { if (shouldProcess(root)) { new ReferenceCollectingCallback( compiler, new ReferenceCheckingBehavior(), new Es6SyntacticScopeCreator(compiler)) .process(externs, root); } }
private void collectReferences(Node root) { ReferenceCollectingCallback collector = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Predicate<Var>() { @Override public boolean apply(Var var) { // Only collect global and non-exported names. return var.isGlobal() && !compiler.getCodingConvention().isExported(var.getName()); } }); NodeTraversal.traverseEs6(compiler, root, collector); for (Var v : collector.getAllSymbols()) { ReferenceCollection refCollection = collector.getReferences(v); NamedInfo info = getNamedInfo(v); for (Reference ref : refCollection) { processReference(collector, ref, info); } } }
@Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback( compiler, new InliningBehavior(), new Es6SyntacticScopeCreator(compiler), getFilterForMode()); callback.process(externs, root); }
/** * Determines the visibility class for each variable in root. */ @Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback(compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR); NodeTraversal.traverseEs6(compiler, root, callback); for (Var variable : callback.getAllSymbols()) { ReferenceCollection referenceCollection = callback.getReferences(variable); VariableVisibility visibility; if (variableIsParameter(variable)) { visibility = VariableVisibility.PARAMETER; } else if (variable.isLocal()) { if (referenceCollection.isEscaped()) { visibility = VariableVisibility.CAPTURED_LOCAL; } else { visibility = VariableVisibility.LOCAL; } } else if (variable.isGlobal()) { visibility = VariableVisibility.GLOBAL; } else { throw new IllegalStateException("Un-handled variable visibility for " + variable); } visibilityByDeclaringNameNode.put(variable.getNameNode(), visibility); } }
/** * Determines the visibility class for each variable in root. */ @Override public void process(Node externs, Node root) { ReferenceCollectingCallback callback = new ReferenceCollectingCallback(compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler)); callback.process(root); for (Var variable : callback.getAllSymbols()) { ReferenceCollection referenceCollection = callback.getReferences(variable); VariableVisibility visibility; if (variableIsParameter(variable)) { visibility = VariableVisibility.PARAMETER; } else if (variable.isLocal()) { if (referenceCollection.isEscaped()) { visibility = VariableVisibility.CAPTURED_LOCAL; } else { visibility = VariableVisibility.LOCAL; } } else if (variable.isGlobal()) { visibility = VariableVisibility.GLOBAL; } else { throw new IllegalStateException("Un-handled variable visibility for " + variable); } visibilityByDeclaringNameNode.put(variable.getNameNode(), visibility); } }
@Override public void process(Node externs, Node js) { ReferenceCollectingCallback collector = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR); NodeTraversal.traverseEs6(compiler, js, collector); for (Var v : collector.getAllSymbols()) { considerVar(v, collector.getReferences(v)); } Scope globalExternsScope = SyntacticScopeCreator.makeUntyped(compiler).createScope(externs, null); for (Var v : globalExternsScope.getAllSymbols()) { considerVar(v, null); } }
@Override public void hotSwapScript(Node scriptRoot, Node originalRoot) { if (!forTranspileOnly || (compiler.getOptions().getLanguageIn().toFeatureSet().contains(FeatureSet.ES6) && TranspilationPasses.isScriptEs6OrHigher(scriptRoot))) { new ReferenceCollectingCallback( compiler, new ReferenceCheckingBehavior(), new Es6SyntacticScopeCreator(compiler)) .hotSwapScript(scriptRoot, originalRoot); } }
@Override public void process(Node externs, Node js) { ReferenceCollectingCallback collector = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler)); collector.process(js); for (Var v : collector.getAllSymbols()) { considerVar(v, collector.getReferences(v)); } Scope globalExternsScope = new Es6SyntacticScopeCreator(compiler).createScope(externs, null); for (Var v : globalExternsScope.getAllSymbols()) { considerVar(v, null); } }
checkState(aliasVar != null, "Expected variable to be defined in scope", aliasVarName); ReferenceCollectingCallback collector = new ReferenceCollectingCallback( compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
new ReferenceCollectingCallback( this, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR); NodeTraversal.traverse(this, getRoot(), refCollector);
new ReferenceCollectingCallback( this, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,