@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isFunction()) { JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(n); if (jsDoc != null && jsDoc.isNoSideEffects()) { String name = NodeUtil.getName(n); noSideEffectExterns.add(name); } } } }
private void visitSuperAccess(NodeTraversal t, Node n) { Node classNode = NodeUtil.getEnclosingClass(n); if (classNode == null) { t.report(n, INVALID_SUPER_ACCESS); return; } }
/** * Returns the qualified name node of the function whose scope we're in, * or null if it cannot be found. */ private static Node getEnclosingDeclNameNode(Node n) { Node fn = NodeUtil.getEnclosingFunction(n); return fn == null ? null : NodeUtil.getNameNode(fn); }
/** * Check if we can safely generate a field initializer. We don't do this if the assignment rhs is * not a literal or the enclosing function is not a constructor. */ private boolean canPromoteFieldInitializer(ClassMemberDeclaration declaration) { if (!NodeUtil.isLiteralValue(declaration.rhs, false)) { return false; } Node fnNode = NodeUtil.getEnclosingFunction(declaration.exprRoot); if (fnNode != null) { String fnName = getEnclosingFunctionName(fnNode); if (!"constructor".equals(fnName)) { return false; } } return true; }
Node lhs = n.getFirstChild(); if (lhs.isQualifiedName()) { Node root = NodeUtil.getRootOfQualifiedName(lhs); if (root.matchesQualifiedName("exports") && (lhs.isName() || !root.getNext().getString().equals("prototype")) && !NodeUtil.isLegacyGoogModuleFile(NodeUtil.getEnclosingScript(n))) { JSDocInfo jsDoc = n.getJSDocInfo(); if (jsDoc != null && jsDoc.isExport()) { if (!NodeUtil.isStatement(n)) { break; case Token.LET: case Token.CONST: if (t.inGlobalHoistScope() && NodeUtil.getEnclosingClass(n) == null && NodeUtil.getEnclosingType(n, Token.OBJECTLIT) == null) { JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(n); if (jsdoc != null && jsdoc.isExport()) { t.report(n, AT_EXPORT_IN_GOOG_MODULE);
Node parent = n.getParent(); if (currentModuleInfo == null) { if (NodeUtil.isCallTo(n, "goog.module")) { t.report(n, GOOG_MODULE_IN_NON_MODULE); } else if (NodeUtil.isGoogModuleDeclareLegacyNamespaceCall(n)) { t.report(n, DECLARE_LEGACY_NAMESPACE_IN_NON_MODULE); if (!NodeUtil.isStatement(n)) { break; case CONST: if (t.inModuleHoistScope() && (n.isClass() || NodeUtil.getEnclosingClass(n) == null) && NodeUtil.getEnclosingType(n, Token.OBJECTLIT) == null) { JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(n); if (jsdoc != null && jsdoc.isExport()) { t.report(n, AT_EXPORT_IN_GOOG_MODULE);
/** Whether a function is an interface constructor, or a method on an interface. */ private boolean isInterface(Node n) { if (!n.isFunction()) { return false; } JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(n); return jsDoc != null && jsDoc.isInterface(); }
private boolean isInNamespace() { Node stringKey = getLhs(); Node objLit = stringKey.getParent(); Node lvalue = NodeUtil.getBestLValue(objLit); if (lvalue == null) { return false; } JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(lvalue); return !isExportLhs(lvalue) && !JsdocUtil.hasAnnotatedType(jsdoc) && NodeUtil.isNamespaceDecl(lvalue); }
/** * @return true if the reference is a normal VAR or FUNCTION declaration. */ private boolean isValidDeclaration(Reference declaration) { return (NodeUtil.isNameDeclaration(declaration.getParent()) && !NodeUtil.isLoopStructure(declaration.getGrandparent())) || NodeUtil.isFunctionDeclaration(declaration.getParent()); }
boolean isConstructor() { Node declNode = declaration.node; Node rvalueNode = NodeUtil.getRValueOfLValue(declNode); JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(declNode); return rvalueNode != null && rvalueNode.isFunction() && jsdoc != null && jsdoc.isConstructor(); }
Node classNode = NodeUtil.getEnclosingClass(callNode); if (callName == null || classNode == null) { return; String className = NodeUtil.getName(classNode); } else { nodeComments.replaceWithComment( callNode.getFirstChild(), NodeUtil.newQName(compiler, "super." + methodName));
static boolean isEnumDecl(Node n) { if (NodeUtil.isNameDeclaration(n) || (n.isName() && NodeUtil.isNameDeclaration(n.getParent())) || (n.isGetProp() && n.getParent().isAssign() && n.getGrandparent().isExprResult()) || (n.isAssign() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasEnumParameterType(); } return false; }
Node grandparent = parent.getParent(); if (NodeUtil.isLValue(parent)) { Node clazz = NodeUtil.getEnclosingClass(node); Node superName = clazz.getSecondChild(); if (!superName.isQualifiedName()) { NodeUtil.newQName(compiler, newPropName, node, "super").useSourceInfoFromForTree(node));
static boolean isConstToBeInferred(Node nameNode) { JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(nameNode); boolean isConst = nameNode.getParent().isConst() || isExportLhs(nameNode) || (jsdoc != null && jsdoc.isConstant()); return isConst && !JsdocUtil.hasAnnotatedType(jsdoc) && !NodeUtil.isNamespaceDecl(nameNode); }
/** Inserts a call to $jscomp.initSymbol() before {@code n}. */ private void initSymbolBefore(Node n) { compiler.ensureLibraryInjected("es6/symbol", false); Node statement = NodeUtil.getEnclosingStatement(n); Node initSymbol = IR.exprResult(IR.call(NodeUtil.newQName(compiler, "$jscomp.initSymbol"))); statement.getParent().addChildBefore(initSymbol.useSourceInfoFromForTree(statement), statement); compiler.reportChangeToEnclosingScope(initSymbol); }
private static boolean isLiteralValue(Node node) { return NodeUtil.isLiteralValue(node, false /* exclude functions */); } }
private Node buildQualifiedName(Node internalName) { String externalName = this.exports.get(internalName.getString()); return NodeUtil.newQName(compiler, this.namespaceName + "." + externalName) .srcrefTree(internalName); } }
private void visitSuperCall(NodeTraversal t, Node n, Node parent) { Node classNode = NodeUtil.getEnclosingClass(n); if (classNode == null || classNode.getSecondChild().isEmpty()) { t.report(n, INVALID_SUPER_CALL); return; } Node fn = NodeUtil.getEnclosingFunction(parent); if (fn == null) { t.report(n, INVALID_SUPER_CALL); return; } Node memberDef = fn.getParent(); if (memberDef.isMemberFunctionDef()) { if (memberDef.matchesQualifiedName("constructor")) { // No error. } else { t.report(n, INVALID_SUPER_CALL_WITH_SUGGESTION, memberDef.getString()); } } else { t.report(n, INVALID_SUPER_CALL); } }
switch (n.getType()) { case Token.CAST: return getKnownValueType(n.getFirstChild()); case Token.ASSIGN: case Token.COMMA: return getKnownValueType(n.getLastChild()); case Token.AND: case Token.OR: return and( getKnownValueType(n.getFirstChild()), getKnownValueType(n.getLastChild())); case Token.HOOK: return and( getKnownValueType(n.getSecondChild()), getKnownValueType(n.getLastChild())); ValueType last = getKnownValueType(n.getLastChild()); if (last == ValueType.STRING) { return ValueType.STRING; ValueType first = getKnownValueType(n.getFirstChild()); if (first == ValueType.STRING) { return ValueType.STRING; if (!mayBeString(first) && !mayBeString(last)) { ValueType last = getKnownValueType(n.getLastChild()); if (last == ValueType.STRING) { return ValueType.STRING;
public NameDeclarationStatement(RemovableBuilder builder, Node declarationStatement) { super(builder); checkArgument(NodeUtil.isNameDeclaration(declarationStatement), declarationStatement); this.declarationStatement = declarationStatement; }