private void addExportForEs6Method(Node memberFunction, String ownerName) { // We always export ES6 member methods as properties. checkArgument(memberFunction.isMemberFunctionDef(), memberFunction); checkArgument(!ownerName.isEmpty(), ownerName); String fullExport = ownerName + "." + memberFunction.getString(); addExportPropertyCall(ownerName, memberFunction, fullExport, memberFunction.getString()); }
/** * @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; } }
/** Removes the named labels from the context. */ public void popLabels(ArrayList<Node> labelNames) { for (Node labelName : labelNames) { checkState(labelName.isLabelName()); namedLabels.remove(labelName.getString()); } }
@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 recordSetterDef(Node setterDef) { checkState(setterDef.isSetterDef()); String name = setterDef.getString(); record(name, PropertyAccessKind.SETTER_ONLY); }
private boolean isCandidateNode(Node n) { switch(n.getToken()) { case GETPROP: return n.getFirstChild().isQualifiedName(); case NAME: return !n.getString().isEmpty(); default: return false; } }
Node createMemberFunctionDef(String name, Node function) { // A function used for a member function definition must have an empty name, // because the name string goes on the MEMBER_FUNCTION_DEF node. checkArgument(function.getFirstChild().getString().isEmpty(), function); Node result = IR.memberFunctionDef(name, function); if (isAddingTypes()) { // member function definition must share the type of the function that implements it result.setJSType(function.getJSType()); } return result; }
private void maybeRename(Node n) { String prop = n.getString(); if (!n.getBooleanProp(Node.QUOTED_PROP) && this.convention.isPrivate(prop) && !blacklist.contains(prop)) { n.setString(prop + fileid); compiler.reportChangeToEnclosingScope(n); } } }
@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()); } }
/** * @param n String node containing goog.module namespace. * @return A NAMESPACE node with the same name and source info as provided node. */ private static Node createNamespaceNode(Node n) { Node node = Node.newString(n.getString()).useSourceInfoFrom(n); node.putBooleanProp(Node.IS_MODULE_NAME, true); return node; }
private void validateString(Node n) { validateNodeType(Token.STRING, n); validateChildCount(n); try { // Validate that getString doesn't throw n.getString(); } catch (UnsupportedOperationException e) { violation("Invalid STRING node.", n); } }
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); } }
private boolean isCandidatePropertyDefinition(Node n) { checkState(n.isGetProp(), n); Node target = n.getFirstChild(); return target.isThis() || (isConstructor(target)) || (target.isGetProp() && target.getLastChild().getString().equals("prototype")); }
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; }
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 JSTypeExpression getSuperclassFor(Node superNode) { final String superName; if (superNode.isQualifiedName()) { superName = superNode.getQualifiedName(); } else { checkState(NodeUtil.isCallTo(superNode, "goog.module.get")); superName = superNode.getLastChild().getString(); } return new JSTypeExpression(new Node(Token.BANG, IR.string(superName)), VIRTUAL_FILE); }
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()); } }