Package com.google.javascript.rhino

Examples of com.google.javascript.rhino.Node.addChildToBack()


      current = new Node(Token.ADD, current);

      // 1000 is printed as 1E3, and screws up our test.
      int num = i % 1000;
      numbers.add(String.valueOf(num));
      current.addChildToBack(Node.newNumber(num));
    }

    String expected = Joiner.on("+").join(numbers);
    String actual = printNode(current).replace("\n", "");
    assertEquals(expected, actual);
View Full Code Here


        if (forCondition.isEmpty()) {
          n.replaceChild(forCondition, fixedIfCondition);
        } else {
          Node replacement = new Node(Token.AND);
          n.replaceChild(forCondition, replacement);
          replacement.addChildToBack(forCondition);
          replacement.addChildToBack(fixedIfCondition);
        }

        reportCodeChange();
      }
View Full Code Here

          n.replaceChild(forCondition, fixedIfCondition);
        } else {
          Node replacement = new Node(Token.AND);
          n.replaceChild(forCondition, replacement);
          replacement.addChildToBack(forCondition);
          replacement.addChildToBack(fixedIfCondition);
        }

        reportCodeChange();
      }
    }
View Full Code Here

            //   if (x||y) return 1;
            child.detachFromParent();
            child.detachChildren();
            Node newCond = new Node(Token.OR, cond);
            nextNode.replaceChild(nextCond, newCond);
            newCond.addChildToBack(nextCond);
            reportCodeChange();
          } else if (nextElse != null
              && thenBranch.isEquivalentToTyped(nextElse)) {
            // Transform
            //   if (x) return 1; if (y) foo() else return 1;
View Full Code Here

            child.detachFromParent();
            child.detachChildren();
            Node newCond = new Node(Token.AND,
                IR.not(cond).srcref(cond));
            nextNode.replaceChild(nextCond, newCond);
            newCond.addChildToBack(nextCond);
            reportCodeChange();
          }
        } else if (nextNode != null && elseBranch == null &&
            isReturnBlock(thenBranch) && isReturnExpression(nextNode)) {
          Node thenExpr = null;
View Full Code Here

    Node node = new Node(Token.CONTINUE);
    Scope localScope = context.scopeManager.localScope();
    double toLabel = getOwnConfig().get("toLabel").getAsDouble();
    if (budget > 1 && !localScope.loopLabels.isEmpty()
        && context.random.nextDouble() < toLabel) {
      node.addChildToBack(
          Node.newString(Token.LABEL_NAME,
              localScope.randomLabelForContinue(context.random)));
    }
    return node;
  }
View Full Code Here

    protected void insertAliasDeclaration(Node codeRoot) {
      Node varNode = new Node(Token.VAR);
      Node value = new Node(getTokenId());
      Node name = NodeUtil.newName(
          compiler, getAliasName(), varNode, getAliasName());
      name.addChildToBack(value);
      varNode.addChildToBack(name);
      codeRoot.addChildrenToFront(varNode);
    }
  }
View Full Code Here

  @Override
  protected Node generate(int budget, Set<Type> types) {
    Node node = new Node(Token.RETURN);
    if (budget > 1 &&
        context.random.nextDouble() < getOwnConfig().get("hasValue").getAsDouble()) {
      node.addChildToBack(
          new ExpressionFuzzer(context).
          generate(budget - 1));
    }
    return node;
  }
View Full Code Here

    protected void insertAliasDeclaration(Node codeRoot) {
      Node varNode = new Node(Token.VAR);
      Node value = IR.voidNode(IR.number(0));
      Node name = NodeUtil.newName(
          compiler, getAliasName(), varNode, getAliasName());
      name.addChildToBack(value);
      varNode.addChildToBack(name);
      codeRoot.addChildrenToFront(varNode);
    }
  }
View Full Code Here

    // Split the string and convert the returned array into JS nodes
    String[] stringArray = jsSplit(stringValue, separator, limit);
    Node arrayOfStrings = IR.arraylit();
    for (int i = 0; i < stringArray.length; i++) {
      arrayOfStrings.addChildToBack(
          IR.string(stringArray[i]).srcref(stringNode));
    }

    Node parent = n.getParent();
    parent.replaceChild(n, arrayOfStrings);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.