static String getIdForGeneratorNode(boolean consistent, Node n) { checkState(n.isString() || n.isStringKey(), n); if (consistent) { return n.getString(); } else { return n.getSourceFileName() + ':' + n.getLineno() + ":" + n.getCharno(); } } }
private boolean shouldReport(Node n) { // Ignore type names that appear in @template clauses in the same source file. In rare cases, // this may cause a false negative (if the name is used in a non-template capacity in the same // file) or a false positive (if the name is used in a template capacity in a separate file), // but it makes this check possible in the absence of type information. If the style guide ever // mandates template types (and nothing else) to be all-caps, we can use that assumption to make // this check more precise. return !n.isString() || !templateTypeNames.contains(n.getString()); }
public static Node getprop(Node target, Node prop, Node ...moreProps) { checkState(mayBeExpression(target)); checkState(prop.isString()); Node result = new Node(Token.GETPROP, target, prop); for (Node moreProp : moreProps) { checkState(moreProp.isString()); result = new Node(Token.GETPROP, result, moreProp); } return result; }
private void processGetElem(Node n) { // If this is a quoted property access (e.g. x['myprop']), we need to // ensure that we never rename some other property in a way that // could conflict with this quoted name. Node child = n.getLastChild(); if (child.isString()) { quotedNames.add(child.getString()); } }
private String extractFirstArgumentName(Node callNode) { Node firstArg = callNode.getSecondChild(); if (firstArg != null && firstArg.isString()) { return firstArg.getString(); } return null; }
RecordTypePropertyDefinition(Node name) { super(IR.getprop(IR.objectlit(), name.cloneNode()), /** isExtern */ true); Preconditions.checkArgument(name.isString()); }
private String toConstValue(Node node) { if (toTypeString().equals("Number")) return Integer.toString(getClassReference().getEnumConstant()); if (node.isString()) return "'" + node.getString() + "'"; return "undefined /* TODO type not set */"; }
private void renameTypeNode(NodeTraversal t, Iterable<Node> typeNodes) { for (Node type : typeNodes) { if (type.isString()) { renameReference(t, type, true); } renameTypeNode(t, type.children()); } }
private boolean isValidStringParam(Node expr) { if (!expr.isName() && !expr.isString()) { warnInvalid("string", expr); return false; } if (expr.getString().isEmpty()) { warnInvalid("string parameter", expr); return false; } return true; }
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); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { Node sibling = n.getNext(); if (sibling != null && sibling.isString() && NodeUtil.isGet(parent) && isGlobalThisObject(t, n)) { exportedVariables.add(sibling.getString()); } }
@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); } } });
@Override protected ConformanceResult checkConformance(NodeTraversal t, Node n) { if (n.isCall()) { Node tag = n.getSecondChild(); if (tag != null && tag.isString() && bannedTags.contains(Ascii.toLowerCase(tag.getString()))) { return checkCreateElement(n); } } return ConformanceResult.CONFORMANCE; }
private Node deletionNodeForRestProperty(Node restTempVarNameNode, Node property) { boolean useSquareBrackets = !property.isString() || property.isQuotedString(); Node get = useSquareBrackets ? astFactory.createGetElem(restTempVarNameNode, property) : astFactory.createGetProp(restTempVarNameNode, property.getString()); return astFactory.createDelProp(get); }
private void visitDefineProperty(Node definePropertyCall) { Node propertyNameNode = definePropertyCall.getChildAtIndex(2); Node descriptor = definePropertyCall.getChildAtIndex(3); if (!propertyNameNode.isString() || !descriptor.isObjectLit()) { return; } String propertyName = propertyNameNode.getString(); visitDescriptor(propertyName, descriptor); }
private void visitImportOrExport(NodeTraversal t, Node importOrExport) { checkNotNull(currentModule); currentModule.moduleType(ModuleType.ES6_MODULE, t, importOrExport); if (importOrExport.isImport() // export from || (importOrExport.hasTwoChildren() && importOrExport.getLastChild().isString())) { currentModule .metadataBuilder .es6ImportSpecifiersBuilder() .add(importOrExport.getLastChild().getString()); } }
private void visitGoogModuleGet(NodeTraversal t, Node getCall, Node parent) { if (!getCall.hasTwoChildren() || !getCall.getLastChild().isString()) { t.report(getCall, INVALID_GET_NAMESPACE); return; } // Module has already been turned into a script at this point. if (t.inGlobalHoistScope()) { t.report(getCall, MODULE_USES_GOOG_MODULE_GET); return; } visitRequireOrGet(t, getCall, parent, /* isRequire= */ false); }
private void maybeProcessType(Node typeTarget, ParseTree typeTree) { if (typeTree != null) { recordJsDoc(typeTree.location, typeTarget.getJSDocInfo()); Node typeExpression = convertTypeTree(typeTree); if (typeExpression.isString()) { typeExpression = cloneProps( new TypeDeclarationNode(Token.STRING, typeExpression.getString())); } typeTarget.setDeclaredTypeExpression((TypeDeclarationNode) typeExpression); } }
@Override public boolean apply(Node node) { return node.isCall() || node.isNew() || node.isFunction() || node.isName() || NodeUtil.isGet(node) || NodeUtil.mayBeObjectLitKey(node) || (node.isString() && NodeUtil.isGet(node.getParent())) || node.isTaggedTemplateLit(); } }