Example #1
0
  public void testLinenoVarDecl() {
    AstRoot root = parse("\nvar\n" + "    a =\n" + "    3\n");

    VariableDeclaration decl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars = decl.getVariables();
    VariableInitializer init = vars.get(0);
    AstNode declName = init.getTarget();
    AstNode expr = init.getInitializer();

    assertEquals(1, decl.getLineno());
    assertEquals(2, init.getLineno());
    assertEquals(2, declName.getLineno());
    assertEquals(3, expr.getLineno());
  }
Example #2
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());
  }