Bug 763755 - Support the spread operator in Reflect.parse. r=dherman

This commit is contained in:
Benjamin Peterson 2012-06-12 20:07:46 -04:00
Родитель 7b10e8a0a8
Коммит d9b043c61f
3 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -28,6 +28,7 @@ ASTDEF(AST_CALL_EXPR, "CallExpression", "callExpressi
ASTDEF(AST_MEMBER_EXPR, "MemberExpression", "memberExpression")
ASTDEF(AST_FUNC_EXPR, "FunctionExpression", "functionExpression")
ASTDEF(AST_ARRAY_EXPR, "ArrayExpression", "arrayExpression")
ASTDEF(AST_SPREAD_EXPR, "SpreadExpression", "spreadExpression")
ASTDEF(AST_OBJECT_EXPR, "ObjectExpression", "objectExpression")
ASTDEF(AST_THIS_EXPR, "ThisExpression", "thisExpression")
ASTDEF(AST_GRAPH_EXPR, "GraphExpression", "graphExpression")

Просмотреть файл

@ -537,6 +537,8 @@ class NodeBuilder
bool arrayExpression(NodeVector &elts, TokenPos *pos, Value *dst);
bool spreadExpression(Value expr, TokenPos *pos, Value *dst);
bool objectExpression(NodeVector &elts, TokenPos *pos, Value *dst);
bool thisExpression(TokenPos *pos, Value *dst);
@ -1097,6 +1099,14 @@ NodeBuilder::arrayExpression(NodeVector &elts, TokenPos *pos, Value *dst)
return listNode(AST_ARRAY_EXPR, "elements", elts, pos, dst);
}
bool
NodeBuilder::spreadExpression(Value expr, TokenPos *pos, Value *dst)
{
return newNode(AST_SPREAD_EXPR, pos,
"expression", expr,
dst);
}
bool
NodeBuilder::propertyPattern(Value key, Value patt, TokenPos *pos, Value *dst)
{
@ -2516,7 +2526,8 @@ ASTSerializer::expression(ParseNode *pn, Value *dst)
return pn->isKind(PNK_NEW)
? builder.newExpression(callee, args, &pn->pn_pos, dst)
: builder.callExpression(callee, args, &pn->pn_pos, dst);
: builder.callExpression(callee, args, &pn->pn_pos, dst);
}
case PNK_DOT:
@ -2555,6 +2566,13 @@ ASTSerializer::expression(ParseNode *pn, Value *dst)
return builder.arrayExpression(elts, &pn->pn_pos, dst);
}
case PNK_SPREAD:
{
Value expr;
return expression(pn->pn_kid, &expr) &&
builder.spreadExpression(expr, &pn->pn_pos, dst);
}
case PNK_RC:
{
/* The parser notes any uninitialized properties by setting the PNX_DESTRUCT flag. */

Просмотреть файл

@ -24,6 +24,7 @@ function throwStmt(expr) Pattern({ type: "ThrowStatement", argument: expr })
function returnStmt(expr) Pattern({ type: "ReturnStatement", argument: expr })
function yieldExpr(expr) Pattern({ type: "YieldExpression", argument: expr })
function lit(val) Pattern({ type: "Literal", value: val })
function spread(val) Pattern({ type: "SpreadExpression", expression: val})
var thisExpr = Pattern({ type: "ThisExpression" });
function funDecl(id, params, body, defaults=[], rest=null) Pattern(
{ type: "FunctionDeclaration",
@ -329,6 +330,8 @@ assertExpr("[,,,1,2,3,]", arrExpr([,,,lit(1),lit(2),lit(3),]));
assertExpr("[,,,1,2,3,,]", arrExpr([,,,lit(1),lit(2),lit(3),,]));
assertExpr("[,,,1,2,3,,,]", arrExpr([,,,lit(1),lit(2),lit(3),,,]));
assertExpr("[,,,,,]", arrExpr([,,,,,]));
assertExpr("[1, ...a, 2]", arrExpr([lit(1), spread(ident("a")), lit(2)]));
assertExpr("[,, ...a,, ...b, 42]", arrExpr([,, spread(ident("a")),, spread(ident("b")), lit(42)]));
assertExpr("({})", objExpr([]));
assertExpr("({x:1})", objExpr([{ key: ident("x"), value: lit(1) }]));
assertExpr("({x:1, y:2})", objExpr([{ key: ident("x"), value: lit(1) },