| 1 |
// |reftest| slow skip-if(!xulRuntime.shell) |
| 2 |
function test() { |
| 3 |
|
| 4 |
function testVarPatternCombinations(makePattSrc, makePattPatt) { |
| 5 |
var pattSrcs = makePatternCombinations(n => ("x" + n), makePattSrc); |
| 6 |
var pattPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: null }), makePattPatt); |
| 7 |
// It's illegal to have uninitialized const declarations, so we need a |
| 8 |
// separate set of patterns and sources. |
| 9 |
var constSrcs = makePatternCombinations(n => ("x" + n + " = undefined"), makePattSrc); |
| 10 |
var constPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: ident("undefined") }), makePattPatt); |
| 11 |
|
| 12 |
for (var i = 0; i < pattSrcs.length; i++) { |
| 13 |
// variable declarations in blocks |
| 14 |
assertDecl("var " + pattSrcs[i].join(",") + ";", varDecl(pattPatts[i])); |
| 15 |
|
| 16 |
assertGlobalDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); |
| 17 |
assertLocalDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); |
| 18 |
assertBlockDecl("let " + pattSrcs[i].join(",") + ";", letDecl(pattPatts[i])); |
| 19 |
|
| 20 |
assertDecl("const " + constSrcs[i].join(",") + ";", constDecl(constPatts[i])); |
| 21 |
|
| 22 |
// variable declarations in for-loop heads |
| 23 |
assertStmt("for (var " + pattSrcs[i].join(",") + "; foo; bar);", |
| 24 |
forStmt(varDecl(pattPatts[i]), ident("foo"), ident("bar"), emptyStmt)); |
| 25 |
assertStmt("for (let " + pattSrcs[i].join(",") + "; foo; bar);", |
| 26 |
forStmt(letDecl(pattPatts[i]), ident("foo"), ident("bar"), emptyStmt)); |
| 27 |
assertStmt("for (const " + constSrcs[i].join(",") + "; foo; bar);", |
| 28 |
forStmt(constDecl(constPatts[i]), ident("foo"), ident("bar"), emptyStmt)); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
testVarPatternCombinations(n => ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"), |
| 33 |
n => ({ id: objPatt([assignProp("a" + n, ident("x" + n)), |
| 34 |
assignProp("b" + n, ident("y" + n)), |
| 35 |
assignProp("c" + n, ident("z" + n))]), |
| 36 |
init: lit(0) })); |
| 37 |
|
| 38 |
testVarPatternCombinations(n => ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10} = 0"), |
| 39 |
n => ({ id: objPatt([assignProp("a" + n, ident("x" + n), lit(10)), |
| 40 |
assignProp("b" + n, ident("y" + n), lit(10)), |
| 41 |
assignProp("c" + n, ident("z" + n), lit(10))]), |
| 42 |
init: lit(0) })); |
| 43 |
|
| 44 |
testVarPatternCombinations(n => ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0"), |
| 45 |
n => ({ id: arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)]), |
| 46 |
init: lit(0) })); |
| 47 |
|
| 48 |
testVarPatternCombinations(n => ("[a" + n + ", ..." + "b" + n + "] = 0"), |
| 49 |
n => ({ id: arrPatt([assignElem("a" + n), spread(ident("b" + n))]), |
| 50 |
init: lit(0) })); |
| 51 |
|
| 52 |
testVarPatternCombinations(n => ("[a" + n + ", " + "b" + n + " = 10] = 0"), |
| 53 |
n => ({ id: arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))]), |
| 54 |
init: lit(0) })); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
runtest(test); |