@Override public AstNode property(AstNode target, CharSequence name) { if (target == null) { return name(name); } PropertyGet prop = new PropertyGet(); prop.setTarget(target); prop.setProperty((Name) name(name)); return prop; }
public void testLinenoGetProp() { AstRoot root = parse("\nfoo.bar"); ExpressionStatement st = (ExpressionStatement) root.getFirstChild(); AstNode n = st.getExpression(); assertTrue(n instanceof PropertyGet); assertEquals(Token.GETPROP, n.getType()); assertEquals(1, n.getLineno()); PropertyGet getprop = (PropertyGet) n; AstNode m = getprop.getRight(); assertTrue(m instanceof Name); assertEquals(Token.NAME, m.getType()); // used to be Token.STRING! assertEquals(1, m.getLineno()); }
public void testLinenoDeclaration() { AstNode root = parse("\na.\n" + "b=\n" + "function() {};\n"); ExpressionStatement exprStmt = (ExpressionStatement) root.getFirstChild(); Assignment fnAssignment = (Assignment) exprStmt.getExpression(); PropertyGet aDotbName = (PropertyGet) fnAssignment.getLeft(); AstNode aName = aDotbName.getLeft(); AstNode bName = aDotbName.getRight(); FunctionNode fnNode = (FunctionNode) fnAssignment.getRight(); assertEquals(1, fnAssignment.getLineno()); assertEquals(1, aDotbName.getLineno()); assertEquals(1, aName.getLineno()); assertEquals(2, bName.getLineno()); assertEquals(3, fnNode.getLineno()); }