@Override
 public AstNode object(Iterable<NameValue<AstNode>> props) {
   ObjectLiteral object = new ObjectLiteral();
   for (NameValue<AstNode> prop : props) {
     object.addElement(objectProperty(prop.getName(), prop.getValue()));
   }
   return object;
 }
示例#2
0
 public void testJSDocAttachment13() {
   AstRoot root = parse("({/** attach me */ get 'foo'() {}});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   StringLiteral stringLit = (StringLiteral) lit.getElements().get(0).getLeft();
   assertNotNull(stringLit.getJsDoc());
 }
示例#3
0
 public void testJSDocAttachment10() {
   AstRoot root = parse("({foo: /** attach me */ (bar)});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   ParenthesizedExpression parens = (ParenthesizedExpression) lit.getElements().get(0).getRight();
   assertNotNull(parens.getJsDoc());
 }
示例#4
0
 public void testJSDocAttachment9() {
   AstRoot root = parse("({/** attach me */ foo: 2});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   Name objLitKey = (Name) lit.getElements().get(0).getLeft();
   assertNotNull(objLitKey.getJsDoc());
 }
示例#5
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());
   }
 }
示例#6
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());
  }