private void validateMaximumChildCount(Node n, int i) { boolean valid = false; if (i == 1) { valid = !n.hasMoreThanOneChild(); } else if (i == -1) { valid = true; // Varying number of children. } else { valid = n.getChildCount() <= i; } if (!valid) { violation("Expected no more than " + i + " children, but was " + n.getChildCount(), n); } }
private void validateMaximumChildCount(Node n, int i) { boolean valid = false; if (i == 1) { valid = !n.hasMoreThanOneChild(); } else if (i == -1) { valid = true; // Varying number of children. } else { valid = n.getChildCount() <= i; } if (!valid) { violation( "Expected no more than " + i + " children, but was " + n.getChildCount(), n); } }
private void simplifySymbol(AbstractCompiler compiler) { checkArgument(NodeUtil.isCallTo(getRhs(), "Symbol")); Node callNode = getRhs(); while (callNode.hasMoreThanOneChild()) { NodeUtil.deleteNode(callNode.getLastChild(), compiler); } }
/** Defines a variable declared with `var`, `let`, or `const`. */ void defineVars(Node n) { checkState(sourceName != null); checkState(NodeUtil.isNameDeclaration(n)); JSDocInfo info = n.getJSDocInfo(); // `var` declarations are hoisted, but `let` and `const` are not. TypedScope scope = n.isVar() ? currentHoistScope : currentScope; if (n.hasMoreThanOneChild() && info != null) { report(JSError.make(n, MULTIPLE_VAR_DEF)); } for (Node child : n.children()) { defineVarChild(info, child, scope); } }
private void validateMinimumChildCount(Node n, int i) { boolean valid = false; if (i == 1) { valid = n.hasChildren(); } else if (i == 2) { valid = n.hasMoreThanOneChild(); } else { valid = n.getChildCount() >= i; } if (!valid) { violation("Expected at least " + i + " children, but was " + n.getChildCount(), n); } }
private void validateMinimumChildCount(Node n, int i) { boolean valid = false; if (i == 1) { valid = n.hasChildren(); } else if (i == 2) { valid = n.hasMoreThanOneChild(); } else { valid = n.getChildCount() >= i; } if (!valid) { violation( "Expected at least " + i + " children, but was " + n.getChildCount(), n); } }
private void maybeSplitMultiVar(Node rhsNode) { Node statementNode = rhsNode.getGrandparent(); if (!statementNode.isVar() || !statementNode.hasMoreThanOneChild()) { return; } Node nameNode = rhsNode.getParent(); nameNode.detach(); rhsNode.detach(); statementNode.getParent().addChildBefore(IR.var(nameNode, rhsNode), statementNode); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if ((n.isString() || n.isTemplateLitString()) && !parent.isGetProp() && !parent.isRegExp()) { String s = n.isString() ? n.getString() : n.getCookedString(); for (blacklist.reset(s); blacklist.find();) { if (parent.isTemplateLit()) { if (parent.hasMoreThanOneChild()) { // Ignore template string with substitutions continue; } else { n = parent; } } if (insideGetCssNameCall(n)) { continue; } if (insideGetUniqueIdCall(n)) { continue; } if (insideAssignmentToIdConstant(n)) { continue; } compiler.report(t.makeError(n, level, MISSING_GETCSSNAME, blacklist.group())); } } }
private void maybeSplitMultiVar(Node rhsNode) { Node statementNode = rhsNode.getParent().getParent(); if (!statementNode.isVar() || !statementNode.hasMoreThanOneChild()) { return; } Node nameNode = rhsNode.getParent(); nameNode.detachFromParent(); rhsNode.detachFromParent(); statementNode.getParent().addChildBefore(IR.var(nameNode, rhsNode), statementNode); }
private static void handleDeclarationList(Node declarationList, Node parent) { // Normalize: "const i = 0, j = 0;" becomes "/** @const */ var i = 0; /** @const */ var j = 0;" while (declarationList.hasMoreThanOneChild()) { Node name = declarationList.getLastChild(); Node newDeclaration = IR.var(name.detachFromParent()).useSourceInfoFrom(declarationList); maybeAddConstJSDoc(declarationList, parent, name, newDeclaration); parent.addChildAfter(newDeclaration, declarationList); } maybeAddConstJSDoc(declarationList, parent, declarationList.getFirstChild(), declarationList); declarationList.setType(Token.VAR); }
private void handleDeclarationList(Node declarationList, Node parent) { // Normalize: "const i = 0, j = 0;" becomes "/** @const */ var i = 0; /** @const */ var j = 0;" while (declarationList.hasMoreThanOneChild()) { Node name = declarationList.getLastChild(); Node newDeclaration = IR.var(name.detach()).useSourceInfoFrom(declarationList); maybeAddConstJSDoc(declarationList, parent, name, newDeclaration); parent.addChildAfter(newDeclaration, declarationList); compiler.reportChangeToEnclosingScope(parent); } maybeAddConstJSDoc(declarationList, parent, declarationList.getFirstChild(), declarationList); declarationList.setToken(Token.VAR); }
private Map<TemplateType, JSType> inferTemplateTypesFromParameters( FunctionType fnType, Node call) { if (fnType.getTemplateTypeMap().getTemplateKeys().isEmpty()) { return Collections.emptyMap(); } Map<TemplateType, JSType> resolvedTypes = Maps.newIdentityHashMap(); Set<JSType> seenTypes = Sets.newIdentityHashSet(); Node callTarget = call.getFirstChild(); if (NodeUtil.isGet(callTarget)) { Node obj = callTarget.getFirstChild(); maybeResolveTemplatedType( fnType.getTypeOfThis(), getJSType(obj), resolvedTypes, seenTypes); } if (call.hasMoreThanOneChild()) { maybeResolveTemplateTypeFromNodes( fnType.getParameters(), call.getSecondChild().siblings(), resolvedTypes, seenTypes); } return resolvedTypes; }
/** * Defines a VAR initialization. */ void defineVar(Node n) { assertDefinitionNode(n, Token.VAR); JSDocInfo info = n.getJSDocInfo(); if (n.hasMoreThanOneChild()) { if (info != null) { // multiple children report(JSError.make(n, MULTIPLE_VAR_DEF)); } for (Node name : n.children()) { defineName(name, n, name.getJSDocInfo()); } } else { Node name = n.getFirstChild(); defineName(name, n, (info != null) ? info : name.getJSDocInfo()); } }
if (n.hasMoreThanOneChild() && compiler .getCodingConvention()
public void splitDeclaration(NodeTraversal t, Node n, Node parent) { // Cannot split cases like "for (let a = 3, [b] = arr; ..." or "a: let x = 3, [y] = arr;" yet // that are not in a statement block. if (n.hasMoreThanOneChild() && !NodeUtil.isStatementBlock(parent)) { t.report( n, Es6ToEs3Util.CANNOT_CONVERT_YET, "declaration with multiple destructuring children not in statement block"); return; } while (n.getFirstChild() != n.getLastChild()) { Node child = n.getLastChild().detach(); Node newVar = IR.declaration(child, n.getToken()).srcref(n); parent.addChildAfter(newVar, n); t.reportCodeChange(); } } }
private void visitExport(NodeTraversal t, Node n, Node parent) { if (currNamespace != null) { replaceWithNodes(t, n, n.children()); } else if (n.hasMoreThanOneChild()) { Node insertPoint = n; for (Node c = n.getSecondChild(); c != null; c = c.getNext()) { Node toAdd; if (!c.isExprResult()) { toAdd = n.cloneNode(); toAdd.addChildToFront(c.detach()); } else { toAdd = c.detach(); } parent.addChildAfter(toAdd, insertPoint); insertPoint = toAdd; } t.reportCodeChange(); } }
private void visitExport(Node n, Node parent) { if (currNamespace != null) { replaceWithNodes(n, n.children()); } else if (n.hasMoreThanOneChild()) { Node insertPoint = n; for (Node c = n.getSecondChild(); c != null; c = c.getNext()) { Node toAdd; if (!c.isExprResult()) { toAdd = n.cloneNode(); toAdd.addChildToFront(c.detachFromParent()); } else { toAdd = c.detachFromParent(); } parent.addChildAfter(toAdd, insertPoint); insertPoint = toAdd; } compiler.reportCodeChange(); } }
resolvedTypes, seenTypes); } else if (call.hasMoreThanOneChild()) { maybeResolveTemplateTypeFromNodes( fnType.getParameters(),
declParent.addChildBefore(newStatement, decl); } else { checkState(decl.hasMoreThanOneChild()); Node newDecl = new Node(decl.getToken()).srcref(decl); for (Node after = declChild.getNext(), next; after != null; after = next) {
if (parent.hasMoreThanOneChild()) { parent.removeChild(node); } else {