/** True for `this.propertyName` */ private static boolean isThisDotProperty(Node n) { return n.isGetProp() && n.getFirstChild().isThis(); }
private void replaceThis(LexicalContext ctx, Node n) { checkArgument(n.isThis()); checkArgument(ctx != null && isInContextOfAsyncGenerator(ctx)); checkArgument(ctx.function != null, "Cannot prepend declarations to root scope"); checkNotNull(ctx.thisSuperArgsContext); n.replaceWith(IR.name(thisVarName).useSourceInfoFrom(n)); ctx.thisSuperArgsContext.usedThis = true; compiler.reportChangeToChangeScope(ctx.function); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis()) { compiler.report( JSError.make(n, UNSAFE_THIS, name.getFullName())); } } });
/** * Gets the root node of a qualified name. Must be either NAME, THIS or SUPER. */ static Node getRootOfQualifiedName(Node qName) { for (Node current = qName; true; current = current.getFirstChild()) { if (current.isName() || current.isThis() || current.isSuper()) { return current; } checkState(current.isGetProp(), "Not a getprop node: ", current); } }
/** * Finds the occurrence of "this" in the provided property tree and replaces * it with replacement */ private static void replaceThis(Node expectedGetprop, Node replacement) { Node leftChild = expectedGetprop.getFirstChild(); if (leftChild.isThis()) { expectedGetprop.replaceChild(leftChild, replacement); } else { replaceThis(leftChild, replacement); } }
/** * Finds the occurrence of "this" in the provided property tree and replaces * it with replacement */ private static void replaceThis(Node expectedGetprop, Node replacement) { Node leftChild = expectedGetprop.getFirstChild(); if (leftChild.isThis()) { expectedGetprop.replaceChild(leftChild, replacement); } else { replaceThis(leftChild, replacement); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis() && shouldReportThis(n)) { compiler.report(t.makeError(n, GLOBAL_THIS)); } if (n == assignLhsChild) { assignLhsChild = null; } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis()) { compiler.report( JSError.make(n, UNSAFE_THIS, name.getFullName())); } } });
/** * Gets the root node of a qualified name. Must be either NAME, THIS or SUPER. */ static Node getRootOfQualifiedName(Node qName) { for (Node current = qName; true; current = current.getFirstChild()) { if (current.isName() || current.isThis() || current.isSuper()) { return current; } Preconditions.checkState(current.isGetProp()); } }
private static boolean isGlobalThisObject(NodeTraversal t, Node n) { if (n.isThis()) { return t.inGlobalHoistScope(); } else if (n.isQualifiedName()) { int items = GLOBAL_THIS_NAMES.length; for (int i = 0; i < items; i++) { if (n.matchesQualifiedName(GLOBAL_THIS_NAMES[i])) { return true; } } } return false; }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis() && shouldReportThis(n)) { compiler.report(t.makeError(n, GLOBAL_THIS)); } if (n == assignLhsChild) { assignLhsChild = null; } }
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")); }
private boolean isRemovablePropertyDefinition(Node n) { Preconditions.checkState(n.isGetProp(), n); Node target = n.getFirstChild(); return target.isThis() || (this.removeUnusedConstructorProperties && isConstructor(target)) || (target.isGetProp() && target.getLastChild().getString().equals("prototype")); }
private boolean isCandidatePropertyDefinition(Node n) { Preconditions.checkState(n.isGetProp(), n); Node target = n.getFirstChild(); return target.isThis() || (isConstructor(target)) || (target.isGetProp() && target.getLastChild().getString().equals("prototype")); }
private FlowScope narrowScope(FlowScope scope, Node node, JSType narrowed) { if (node.isThis()) { // "this" references don't need to be modeled in the control flow graph. return scope; } if (node.isGetProp()) { return scope.inferQualifiedSlot( node, node.getQualifiedName(), getJSType(node), narrowed, false); } return redeclareSimpleVar(scope, node, narrowed); }
static boolean isAliasingGlobalThis(CodingConvention convention, Node n) { return n.isAssign() && n.getFirstChild().matchesQualifiedName(convention.getGlobalObject()) && n.getLastChild().isThis(); }
private boolean hasBindThisCall(Node functionNode) { Node parentNode = functionNode.getParent(); return parentNode.isGetProp() && functionNode.getNext().getString().equals("bind") && parentNode.getParent().isCall() && parentNode.getNext().isThis(); }
private static boolean isClassPropertyDeclaration(Node n, NTIScope s) { Node parent = n.getParent(); return n.isGetProp() && n.getFirstChild().isThis() && (parent.isAssign() && parent.getFirstChild().equals(n) || parent.isExprResult()) && (s.isConstructor() || s.isPrototypeMethod()); }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis()) { Node name = IR.name(THIS_VAR).srcref(n); parent.replaceChild(n, name); changedThis = true; } else if (n.isName() && n.getString().equals("arguments")) { Node name = IR.name(ARGUMENTS_VAR).srcref(n); parent.replaceChild(n, name); changedArguments = true; } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isThis()) { Node superThis = astFactory.createName(SUPER_THIS, n.getJSType()).useSourceInfoFrom(n); parent.replaceChild(n, superThis); } else if (n.isReturn() && !n.hasChildren()) { // An empty return needs to be changed to return $jscomp$super$this n.addChildToFront(astFactory.createName(SUPER_THIS, typeOfThis).useSourceInfoFrom(n)); } } };