Пример #1
0
  public void testLinenoFunctionCall() {
    AstNode root = parse("\nfoo.\n" + "bar.\n" + "baz(1);");

    ExpressionStatement stmt = (ExpressionStatement) root.getFirstChild();
    FunctionCall fc = (FunctionCall) stmt.getExpression();
    // Line number should get closest to the actual paren.
    assertEquals(3, fc.getLineno());
  }
Пример #2
0
 @Override
 public AstNode functionCall(AstNode target, Iterable<AstNode> arguments) {
   FunctionCall fc = new FunctionCall();
   fc.setTarget(target);
   if (!Iterables.isEmpty(arguments)) {
     fc.setArguments(list(arguments));
   }
   return fc;
 }
Пример #3
0
 public void testJSDocAttachment4() {
   AstRoot root = parse("(function() {/** should not be attached */})()");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   FunctionCall fc = (FunctionCall) st.getExpression();
   ParenthesizedExpression pe = (ParenthesizedExpression) fc.getTarget();
   assertNull(pe.getJsDoc());
 }
Пример #4
0
  public void testRegexpLocation() {
    AstNode root = parse("\nvar path =\n" + "      replace(\n" + "/a/g," + "'/');\n");

    VariableDeclaration firstVarDecl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = firstVarDecl.getVariables();
    VariableInitializer firstInitializer = vars1.get(0);
    Name firstVarName = (Name) firstInitializer.getTarget();
    FunctionCall callNode = (FunctionCall) firstInitializer.getInitializer();
    AstNode fnName = callNode.getTarget();
    List<AstNode> args = callNode.getArguments();
    RegExpLiteral regexObject = (RegExpLiteral) args.get(0);
    AstNode aString = args.get(1);

    assertEquals(1, firstVarDecl.getLineno());
    assertEquals(1, firstVarName.getLineno());
    assertEquals(2, callNode.getLineno());
    assertEquals(2, fnName.getLineno());
    assertEquals(3, regexObject.getLineno());
    assertEquals(3, aString.getLineno());
  }