Exemplo n.º 1
0
 public void testJSDocAttachment6() {
   AstRoot root = parse("({1: /** don't attach me */ 2, 3: 4});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   for (ObjectProperty el : lit.getElements()) {
     assertNull(el.getLeft().getJsDoc());
     assertNull(el.getRight().getJsDoc());
   }
 }
Exemplo n.º 2
0
  public void testObjectLitLocation() {
    AstNode root =
        parse(
            "\nvar foo =\n"
                + "{ \n"
                + "'A' : 'A', \n"
                + "'B' : 'B', \n"
                + "'C' : \n"
                + "      'C' \n"
                + "};\n");

    VariableDeclaration firstVarDecl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = firstVarDecl.getVariables();
    VariableInitializer firstInitializer = vars1.get(0);
    Name firstVarName = (Name) firstInitializer.getTarget();

    ObjectLiteral objectLiteral = (ObjectLiteral) firstInitializer.getInitializer();
    List<ObjectProperty> props = objectLiteral.getElements();
    ObjectProperty firstObjectLit = props.get(0);
    ObjectProperty secondObjectLit = props.get(1);
    ObjectProperty thirdObjectLit = props.get(2);

    AstNode firstKey = firstObjectLit.getLeft();
    AstNode firstValue = firstObjectLit.getRight();
    AstNode secondKey = secondObjectLit.getLeft();
    AstNode secondValue = secondObjectLit.getRight();
    AstNode thirdKey = thirdObjectLit.getLeft();
    AstNode thirdValue = thirdObjectLit.getRight();

    assertEquals(1, firstVarName.getLineno());
    assertEquals(2, objectLiteral.getLineno());
    assertEquals(3, firstObjectLit.getLineno());
    assertEquals(3, firstKey.getLineno());
    assertEquals(3, firstValue.getLineno());

    assertEquals(4, secondKey.getLineno());
    assertEquals(4, secondValue.getLineno());

    assertEquals(5, thirdKey.getLineno());
    assertEquals(6, thirdValue.getLineno());
  }
Exemplo n.º 3
0
 private ObjectProperty objectProperty(CharSequence name, AstNode value) {
   ObjectProperty prop = new ObjectProperty();
   prop.setLeft(name(name));
   prop.setRight(value);
   return prop;
 }