for-loop-destructuring.js (2771B)
1 // |reftest| skip-if(!xulRuntime.shell) 2 function test() { 3 4 // destructuring in for-in and for-of loop heads 5 6 var axbycz = objPatt([assignProp("a", ident("x")), 7 assignProp("b", ident("y")), 8 assignProp("c", ident("z"))]); 9 var xyz = arrPatt([assignElem("x"), assignElem("y"), assignElem("z")]); 10 11 assertStmt("for (var {a:x,b:y,c:z} in foo);", forInStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 12 assertStmt("for (let {a:x,b:y,c:z} in foo);", forInStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 13 assertStmt("for ({a:x,b:y,c:z} in foo);", forInStmt(axbycz, ident("foo"), emptyStmt)); 14 assertStmt("for (var [x,y,z] in foo);", forInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 15 assertStmt("for (let [x,y,z] in foo);", forInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 16 assertStmt("for ([x,y,z] in foo);", forInStmt(xyz, ident("foo"), emptyStmt)); 17 assertStmt("for (var {a:x,b:y,c:z} of foo);", forOfStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 18 assertStmt("for (let {a:x,b:y,c:z} of foo);", forOfStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 19 assertStmt("for ({a:x,b:y,c:z} of foo);", forOfStmt(axbycz, ident("foo"), emptyStmt)); 20 assertStmt("for (var [x,y,z] of foo);", forOfStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 21 assertStmt("for (let [x,y,z] of foo);", forOfStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 22 assertStmt("for ([x,y,z] of foo);", forOfStmt(xyz, ident("foo"), emptyStmt)); 23 24 assertStmt("for (const x in foo);", 25 forInStmt(constDecl([{ id: ident("x"), init: null }]), ident("foo"), emptyStmt)); 26 assertStmt("for (const {a:x,b:y,c:z} in foo);", 27 forInStmt(constDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 28 assertStmt("for (const [x,y,z] in foo);", 29 forInStmt(constDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 30 31 assertStmt("for (const x of foo);", 32 forOfStmt(constDecl([{id: ident("x"), init: null }]), ident("foo"), emptyStmt)); 33 assertStmt("for (const {a:x,b:y,c:z} of foo);", 34 forOfStmt(constDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt)); 35 assertStmt("for (const [x,y,z] of foo);", 36 forOfStmt(constDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt)); 37 38 assertError("for (x = 22 in foo);", SyntaxError);- 39 assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError); 40 assertError("for ([x,y,z] = 22 in foo);", SyntaxError); 41 assertError("for (const x = 22 in foo);", SyntaxError); 42 assertError("for (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError); 43 assertError("for (const [x,y,z] = 22 in foo);", SyntaxError); 44 45 } 46 47 runtest(test);