object-spread.js (1292B)
1 // |reftest| skip-if(!xulRuntime.shell) 2 3 function property(key, value = key, shorthand = key === value) { 4 return { key, value, shorthand }; 5 } 6 7 function test() { 8 // Any expression can be spreaded. 9 assertExpr("({...x})", objExpr([spread(ident("x"))])); 10 assertExpr("({...f()})", objExpr([spread(callExpr(ident("f"), []))])); 11 assertExpr("({...123})", objExpr([spread(lit(123))])); 12 13 // Multiple spread expression are allowed. 14 assertExpr("({...x, ...obj.p})", objExpr([spread(ident("x")), spread(dotExpr(ident("obj"), ident("p")))])); 15 16 // Spread expression can appear anywhere in an object literal. 17 assertExpr("({p, ...x})", objExpr([property(ident("p")), spread(ident("x"))])); 18 assertExpr("({p: a, ...x})", objExpr([property(ident("p"), ident("a")), spread(ident("x"))])); 19 assertExpr("({...x, p: a})", objExpr([spread(ident("x")), property(ident("p"), ident("a"))])); 20 21 // Trailing comma after spread expression is allowed. 22 assertExpr("({...x,})", objExpr([spread(ident("x"))])); 23 24 // __proto__ is not special in spread expressions. 25 assertExpr("({...__proto__})", objExpr([spread(ident("__proto__"))])); 26 assertExpr("({...__proto__, ...__proto__})", objExpr([spread(ident("__proto__")), spread(ident("__proto__"))])); 27 } 28 29 runtest(test);