public J2clPropertyEs5(Node getKey, Node setKey) { super(getKey, setKey); checkArgument(getKey.isStringKey() && getKey.getString().equals("get"), getKey); checkArgument(setKey.isStringKey() && setKey.getString().equals("set"), setKey); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { // Remove all IS_SHORTHAND_PROPERTY annotations on all nodes so that the code printer // does not print it as shorthand. if (n.isStringKey()) { n.setShorthandProperty(false); } } }
public static Node propdef(Node string, Node value) { checkState(string.isStringKey()); checkState(!string.hasChildren()); checkState(mayBeExpression(value)); string.addChildToFront(value); return string; }
public static Node propdef(Node string, Node value) { Preconditions.checkState(string.isStringKey()); Preconditions.checkState(!string.hasChildren()); Preconditions.checkState(mayBeExpression(value)); string.addChildToFront(value); return string; }
private void visitQualifiedName(NodeTraversal t, Node n, Node parent) { checkState(n.isName() || n.isGetProp() || n.isStringKey(), n); String qualifiedName = n.isStringKey() ? n.getString() : n.getQualifiedName(); addWeakUsagesOfAllPrefixes(qualifiedName); if (mode != Mode.SINGLE_FILE) { // TODO(b/71638622): Fix violations and remove this check. return; } if (!n.isStringKey() && !NodeUtil.isLhsOfAssign(n) && !parent.isExprResult()) { addUsageOfOutermostClassName(n, t); } }
static boolean isGetterOrSetter(Node propNode) { if (isGetOrSetKey(propNode)) { return true; } if (!propNode.isStringKey() || !propNode.getFirstChild().isFunction()) { return false; } String keyName = propNode.getString(); return keyName.equals("get") || keyName.equals("set"); }
static PotentialDeclaration fromStringKey(Node stringKeyNode) { checkArgument(stringKeyNode.isStringKey()); checkArgument(stringKeyNode.getParent().isObjectLit()); String name = "this." + stringKeyNode.getString(); return new StringKeyDeclaration(name, stringKeyNode); }
public static boolean isLhsByDestructuring(Node n) { Node parent = n.getParent(); if (parent.isDestructuringPattern() || (parent.isStringKey() && parent.getParent().isObjectPattern())) { if (n.isStringKey() && n.hasChildren()) { return false; } return true; } return false; }
private void processDeclarationWithRhs(NodeTraversal t, Node lhs) { checkArgument( lhs.isQualifiedName() || lhs.isStringKey() || lhs.isDestructuringLhs(), lhs); checkState(NodeUtil.getRValueOfLValue(lhs) != null, lhs); if (!PotentialDeclaration.isConstToBeInferred(lhs)) { return; } processConstWithRhs(t, lhs); }
public static Node objectPattern(Node... keys) { Node objectPattern = new Node(Token.OBJECT_PATTERN); for (Node key : keys) { checkState(key.isStringKey() || key.isComputedProp() || key.isRest()); objectPattern.addChildToBack(key); } return objectPattern; }
/** Returns whether of not the given name is valid target for the result of goog.getMsg */ private boolean isValidMsgName(Node nameNode) { if (nameNode.isName() || nameNode.isStringKey()) { return nameNode.getString().startsWith("MSG_"); } else if (nameNode.isQualifiedName()) { return nameNode.getLastChild().getString().startsWith("MSG_"); } else { return false; } }
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(); } } }
ClassOrPrototypeNamedProperty buildClassOrPrototypeNamedProperty(Node propertyNode) { checkArgument( propertyNode.isMemberFunctionDef() || NodeUtil.isGetOrSetKey(propertyNode) || (propertyNode.isStringKey() && !propertyNode.isQuotedString()), propertyNode); this.propertyName = propertyNode.getString(); return new ClassOrPrototypeNamedProperty(this, propertyNode); }
private void reportErrorOnContext(Node parent){ if (parent.isStringKey()){ compiler.report(JSError.make(parent, GOOG_CLASS_STATICS_NOT_VALID)); } else { // Report error in the context that the objlit is an // argument of goog.defineClass call. checkState(parent.isCall()); compiler.report(JSError.make(parent, GOOG_CLASS_DESCRIPTOR_NOT_VALID)); } }
private void reportErrorOnContext(Node parent){ if (parent.isStringKey()){ compiler.report(JSError.make(parent, GOOG_CLASS_STATICS_NOT_VALID)); } else { // Report error in the context that the objlit is an // argument of goog.defineClass call. Preconditions.checkState(parent.isCall()); compiler.report(JSError.make(parent, GOOG_CLASS_DESCRIPTOR_NOT_VALID)); } }
private void recordTopLevelVarNames(Node varNode) { for (Node lhs : NodeUtil.getLhsNodesOfDeclaration(varNode)) { String name = lhs.getString(); currentScript.topLevelNames.add(name); // Rewrite `const {x, y} = ...` syntax to `const {x: x, y: y} = ...` for easier processing if (lhs.isStringKey()) { lhs.addChildToFront(IR.name(name).srcref(lhs)); } } }
/** Returns true if the node is a property of an object literal. */ public static boolean isObjLitProperty(Node node) { return node.isStringKey() || node.isGetterDef() || node.isSetterDef() || node.isMemberFunctionDef() || node.isComputedProp(); }
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 checkName(NodeTraversal t, Node node) { if (node.isComputedProp()) { t.report(node, COMPUTED_PROP_NAME_IN_ENUM); return; } if (node.isStringKey() && node.isShorthandProperty()) { t.report(node, SHORTHAND_ASSIGNMENT_IN_ENUM); } if (!compiler.getCodingConvention().isValidEnumKey(node.getString())) { t.report(node, ENUM_PROP_NOT_CONSTANT); } }
private void checkName(NodeTraversal t, Node node) { if (node.isComputedProp()) { t.report(node, COMPUTED_PROP_NAME_IN_ENUM); return; } if (node.isStringKey() && !node.hasChildren()) { t.report(node, SHORTHAND_ASSIGNMENT_IN_ENUM); } if (!compiler.getCodingConvention().isValidEnumKey(node.getString())) { t.report(node, ENUM_PROP_NOT_CONSTANT); } }