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

The following examples show how to use com.google.javascript.rhino.Node#isDefaultValue() . 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: TypeConversionPass.java    From clutz with MIT License 6 votes vote down vote up
private void stripFunctionDefaultParamsAndBody(Node member) {
  Node functionNode = member.getFirstChild();
  Node functionName = functionNode.getFirstChild();
  Node functionParams = functionNode.getSecondChild();
  // Remove defaults from parameters
  Node functionParamsNoDefaults = new Node(Token.PARAM_LIST);
  for (Node param : functionParams.children()) {
    Node paramNoDefault = param.isDefaultValue() ? param.getFirstChild() : param;
    functionParamsNoDefaults.addChildToBack(paramNoDefault.detach());
  }
  // Strip body from function definitions.
  Node newFunction =
      new Node(
          Token.FUNCTION,
          functionName.detach(),
          functionParamsNoDefaults,
          new Node(Token.EMPTY));
  newFunction.useSourceInfoFrom(functionNode);
  nodeComments.replaceWithComment(functionNode, newFunction);
}
 
Example 2
Source File: DeclarationGenerator.java    From clutz with MIT License 6 votes vote down vote up
/** Gets the string name from a function parameter node, or "" if we cannot find one. */
private String getParameterName(Node node) {
  if (node.isDefaultValue()) {
    node = node.getFirstChild();
  }
  if (node.isRest()) {
    node = node.getOnlyChild();
  }

  if (node.isName()) {
    return node.getString();
  } else {
    // Use a simple invalid name for complex parameters.
    return "";
  }
}