/** * @return Whether node is a reference to locally declared name. */ private boolean isLocalName(Node node) { if (node.isName()) { String name = node.getString(); return locals.contains(name); } return false; } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isName()) { visitName(t, n, parent); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isName()) { Var dep = allVarsInFn.get(n.getString()); if (dep == null) { def.unknownDependencies = true; } else { def.depends.add(dep); } } } });
@Override public boolean apply(Node n) { return n.isName() && n.getString().equals(name); } }
@Override public boolean apply(Node n) { if (n.isName()) { return n.getString().equals("eval"); } if (!assumeMinimumCapture && n.isFunction()) { return n != fnNode; } return false; } };
private void recordTopLevelClassOrFunctionName(Node classOrFunctionNode) { Node nameNode = classOrFunctionNode.getFirstChild(); if (nameNode.isName() && !Strings.isNullOrEmpty(nameNode.getString())) { String name = nameNode.getString(); currentScript.topLevelNames.add(name); } }
@Override public void visit(Node n) { if (n.isName()) { Node parent = n.getParent(); if (parent != null && parent.isVar()) { String name = n.getString(); vars.putIfAbsent(name, n); } } } }
private String evalString(Node ttlAst, NameResolver nameResolver) { if (ttlAst.isName()) { // Return the empty string if the name variable cannot be resolved if (!nameResolver.nameVars.containsKey(ttlAst.getString())) { reportWarning(ttlAst, UNKNOWN_STRVAR, ttlAst.getString()); return ""; } return nameResolver.nameVars.get(ttlAst.getString()); } return ttlAst.getString(); }
public static Node importNode(Node name, Node importSpecs, Node moduleIdentifier) { checkState(name.isName() || name.isEmpty(), name); checkState( importSpecs.isImportSpec() || importSpecs.isImportStar() || importSpecs.isEmpty(), importSpecs); checkState(moduleIdentifier.isString(), moduleIdentifier); return new Node(Token.IMPORT, name, importSpecs, moduleIdentifier); }
private static boolean isPropertyTestFunction(AbstractCompiler compiler, Node n) { if (compiler.getCodingConvention().isPropertyTestFunction(n)) { return true; } Node target = n.getFirstChild(); return target.isName() && PROPERTY_TEST_FUNCTIONS.contains(target.getString()); }
/** @see #findCalledFunctions(Node) */ private static void findCalledFunctions(Node node, Set<String> changed) { checkArgument(changed != null); // For each referenced function, add a new reference if (node.isName() && isCandidateUsage(node)) { changed.add(node.getString()); } for (Node c = node.getFirstChild(); c != null; c = c.getNext()) { findCalledFunctions(c, changed); } }
/** * Returns whether this is a bleeding function (an anonymous named function * that bleeds into the inner scope). */ static boolean isBleedingFunctionName(Node n) { if (!n.isName() || n.getString().isEmpty()) { return false; } Node parent = n.getParent(); return isFunctionExpression(parent) && n == parent.getFirstChild(); }
private void checkForPrimitiveObjectConstructor(NodeTraversal t, Node n) { if (n.isNew()) { Node constructorFunction = n.getFirstChild(); if (constructorFunction.isName()) { String constructorName = constructorFunction.getString(); if (PRIMITIVE_OBJECT_CONSTRUCTORS.contains(constructorName)) { t.report(n, NEW_PRIMITIVE_OBJECT, constructorName); } } } } }
@Override public void visit(Node node) { if ((node.isName() && (node.getString().equals(MODULE) || node.getString().equals("define"))) || (node.isGetProp() && node.matchesQualifiedName("window.define")) || (node.isString() && node.getString().equals("amd") && node.getParent().isIn())) { umdTests.add(node); } } });
public static Node declaration(Node lhs, Node value, Token type) { if (lhs.isName()) { checkState(!lhs.hasChildren()); } else { checkState(lhs.isArrayPattern() || lhs.isObjectPattern()); lhs = new Node(Token.DESTRUCTURING_LHS, lhs); } Preconditions.checkState(mayBeExpression(value), "%s can't be an expression", value); lhs.addChildToBack(value); return new Node(type, lhs); }
public static Node declaration(Node lhs, Token type) { checkState(lhs.isName() || lhs.isDestructuringPattern() || lhs.isDestructuringLhs(), lhs); if (lhs.isDestructuringPattern()) { lhs = new Node(Token.DESTRUCTURING_LHS, lhs); } return new Node(type, lhs); }
private static String getLastPartOfQualifiedName(Node n) { if (n.isName()) { return n.getString(); } else if (n.isGetProp()) { return n.getLastChild().getString(); } return null; }
/** * Heuristic method to check whether symbol was created by DeclaredGlobalExternsOnWindow.java * pass. */ private boolean isSymbolDuplicatedExternOnWindow(Symbol symbol) { Node node = symbol.getDeclarationNode(); // Check that node is of type "window.foo"; return !node.isIndexable() && node.isGetProp() && node.getFirstChild().isName() && node.getFirstChild().getString().equals("window"); }
static ExportDefinition newNamedExport(NodeTraversal t, String name, Node rhs) { ExportDefinition newExport = new ExportDefinition(); newExport.exportName = name; newExport.rhs = rhs; if (rhs != null && (rhs.isName() || rhs.isStringKey())) { newExport.nameDecl = t.getScope().getVar(rhs.getString()); } return newExport; }