Java Code Examples for com.google.javascript.rhino.Node#isDelProp()

The following examples show how to use com.google.javascript.rhino.Node#isDelProp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StrictModeCheck.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.isFunction()) {
    checkFunctionUse(t, n);
  } else if (n.isName()) {
    if (!isDeclaration(n)) {
      checkNameUse(t, n);
    }
  } else if (n.isAssign()) {
    checkAssignment(t, n);
  } else if (n.isDelProp()) {
    checkDelete(t, n);
  } else if (n.isObjectLit()) {
    checkObjectLiteral(t, n);
  } else if (n.isLabel()) {
    checkLabel(t, n);
  }
}
 
Example 2
Source File: Cardumen_0015_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 3
Source File: Cardumen_0015_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if ((!(n.isName())) && (apply(c))) {
      return true;
    }
  }
  return false;
}
 
Example 4
Source File: Cardumen_0088_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if ((!(n.isString())) && (apply(c))) {
      return true;
    }
  }
  return false;
}
 
Example 5
Source File: Cardumen_0088_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 6
Source File: Closure_3_FlowSensitiveInlineVariables_s.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 7
Source File: Closure_3_FlowSensitiveInlineVariables_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 8
Source File: Closure_15_FlowSensitiveInlineVariables_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: FlowSensitiveInlineVariables.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean apply(Node n) {
  // When the node is null it means, we reached the implicit return
  // where the function returns (possibly without an return statement)
  if (n == null) {
    return false;
  }

  // TODO(user): We only care about calls to functions that
  // passes one of the dependent variable to a non-side-effect free
  // function.
  if (n.isCall() && NodeUtil.functionCallHasSideEffects(n)) {
    return true;
  }

  if (n.isNew() && NodeUtil.constructorCallHasSideEffects(n)) {
    return true;
  }

  if (n.isDelProp()) {
    return true;
  }

  for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
    if (!ControlFlowGraph.isEnteringNewCfgNode(c) && apply(c)) {
      return true;
    }
  }
  return false;
}
 
Example 10
Source File: InlineProperties.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  boolean invalidatingPropRef = false;
  String propName = null;
  if (n.isGetProp()) {
    propName = n.getLastChild().getString();
    if (t.getInput().isExtern()) {
      // Any extern reference invalidates
      invalidatingPropRef = true;
    } else if (parent.isAssign()) {
      invalidatingPropRef = !maybeCandidateDefinition(t, n, parent);
    } else if (NodeUtil.isLValue(n)) {
      // Other LValue references invalidate
      invalidatingPropRef = true;
    } else if (parent.isDelProp()) {
      // Deletes invalidate
      invalidatingPropRef = true;
    } else {
      // A property read doesn't invalidate
      invalidatingPropRef = false;
    }
  } else if (n.isStringKey()) {
    propName = n.getString();
    if (t.getInput().isExtern()) {
      // Any extern reference invalidates
      invalidatingPropRef = true;
    } else {
      // For now, any object literal key invalidates
      // TODO(johnlenz): support prototype properties like:
      //   foo.prototype = { a: 1, b: 2 };
      invalidatingPropRef = true;
    }
  }

  if (invalidatingPropRef) {
    Preconditions.checkNotNull(propName);
    invalidateProperty(propName);
  }
}
 
Example 11
Source File: CheckAccessControls.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines whether the given property with @const tag got reassigned
 * @param t The current traversal.
 * @param getprop The getprop node.
 */
private void checkConstantProperty(NodeTraversal t,
    Node getprop) {
  // Check whether the property is modified
  Node parent = getprop.getParent();
  boolean isDelete = parent.isDelProp();
  if (!(NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == getprop)
      && !parent.isInc() && !parent.isDec()
      && !isDelete) {
    return;
  }

  ObjectType objectType =
    ObjectType.cast(dereference(getprop.getFirstChild().getJSType()));
  String propertyName = getprop.getLastChild().getString();

  boolean isConstant = isPropertyDeclaredConstant(objectType, propertyName);

  // Check whether constant properties are reassigned
  if (isConstant) {
    if (isDelete) {
      compiler.report(
          t.makeError(getprop, CONST_PROPERTY_DELETED, propertyName));
      return;
    }

    ObjectType oType = objectType;
    while (oType != null) {
      if (oType.hasReferenceName()) {
        if (initializedConstantProperties.containsEntry(
                oType.getReferenceName(), propertyName)) {
          compiler.report(
              t.makeError(getprop, CONST_PROPERTY_REASSIGNED_VALUE,
                  propertyName));
          break;
        }
      }
      oType = oType.getImplicitPrototype();
    }

    Preconditions.checkState(objectType.hasReferenceName());
    initializedConstantProperties.put(objectType.getReferenceName(),
        propertyName);

    // Add the prototype when we're looking at an instance object
    if (objectType.isInstanceType()) {
      ObjectType prototype = objectType.getImplicitPrototype();
      if (prototype != null) {
        if (prototype.hasProperty(propertyName)
            && prototype.hasReferenceName()) {
          initializedConstantProperties.put(prototype.getReferenceName(),
              propertyName);
        }
      }
    }
  }
}