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

The following examples show how to use com.google.javascript.rhino.Node#isLet() . 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: TypeAnnotationPass.java    From clutz with MIT License 6 votes vote down vote up
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  JSDocInfo bestJSDocInfo = NodeUtil.getBestJSDocInfo(n);
  if (bestJSDocInfo == null) {
    return;
  }

  // Add visibility for private and protected.
  if (Visibility.PRIVATE.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PRIVATE);
  } else if (Visibility.PROTECTED.equals(bestJSDocInfo.getVisibility())) {
    n.putProp(Node.ACCESS_MODIFIER, Visibility.PROTECTED);
  }

  // Change variable declarations to constants
  if (bestJSDocInfo.isConstant() && (n.isVar() || n.isLet())) {
    n.setToken(Token.CONST);
  }
}
 
Example 2
Source File: ImportBasedMapBuilder.java    From clutz with MIT License 6 votes vote down vote up
/** Matches destructing from a variable ie `const {foo, bar: baz} = quux;` */
protected static boolean isVariableDestructuringAssignment(Node statement) {
  if (!(statement.isConst() || statement.isVar() || statement.isLet())) {
    return false;
  }

  if (!statement.getFirstChild().isDestructuringLhs()) {
    return false;
  }

  Node destructuringAssignment = statement.getFirstChild();

  Node rightHandSide = destructuringAssignment.getSecondChild();

  return rightHandSide.isName();
}
 
Example 3
Source File: ImportBasedMapBuilder.java    From clutz with MIT License 6 votes vote down vote up
/**
 * Matches either `const {foo} = goog.require()` or `const {foo} = goog.module.get()` depending on
 * if statement is in a goog.module or a goog.scope.
 */
protected static boolean isImportDestructuringAssignment(Node statement) {
  if (!(statement.isConst() || statement.isVar() || statement.isLet())) {
    return false;
  }

  if (!statement.getFirstChild().isDestructuringLhs()) {
    return false;
  }

  Node destructuringAssignment = statement.getFirstChild();

  Node rightHandSide = destructuringAssignment.getSecondChild();

  return rightHandSide.isCall()
      && (rightHandSide.getFirstChild().matchesQualifiedName("goog.require")
          || rightHandSide.getFirstChild().matchesQualifiedName("goog.module.get"));
}
 
Example 4
Source File: ImportBasedMapBuilder.java    From clutz with MIT License 5 votes vote down vote up
/**
 * Matches either `const foo = goog.require()` or `const foo = goog.module.get()` or `const foo =
 * goog.forwardDeclare()` or `const foo = goog.requireType` depending on if statement is in a
 * goog.module or a goog.scope.
 */
protected static boolean isImportAssignment(Node statement) {
  if (!(statement.isConst() || statement.isVar() || statement.isLet())) {
    return false;
  }

  Node rightHandSide = statement.getFirstFirstChild();

  return rightHandSide != null
      && rightHandSide.isCall()
      && (rightHandSide.getFirstChild().matchesQualifiedName("goog.require")
          || rightHandSide.getFirstChild().matchesQualifiedName("goog.module.get")
          || rightHandSide.getFirstChild().matchesQualifiedName("goog.forwardDeclare")
          || rightHandSide.getFirstChild().matchesQualifiedName("goog.requireType"));
}
 
Example 5
Source File: ModuleConversionPass.java    From clutz with MIT License 4 votes vote down vote up
private boolean isDeclaration(Node n) {
  Node parent = n.getParent();
  return parent.isConst() || parent.isLet() || parent.isVar();
}