computedPropNames.js (1923B)
1 // |reftest| skip-if(!xulRuntime.shell) 2 function test() { 3 4 // Bug 924688: computed property names 5 assertExpr('a= {[field1]: "a", [field2=1]: "b"}', 6 aExpr("=", ident("a"), 7 objExpr([{ key: computedName(ident("field1")), value: lit("a")}, 8 { key: computedName(aExpr("=", ident("field2"), lit(1))), 9 value: lit("b")}]))); 10 11 assertExpr('a= {["field1"]: "a", field2 : "b"}', 12 aExpr("=", ident("a"), 13 objExpr([{ key: computedName(lit("field1")), value: lit("a") }, 14 { key: ident("field2"), value: lit("b") }]))); 15 16 assertExpr('a= {[1]: 1, 2 : 2}', 17 aExpr("=", ident("a"), 18 objExpr([{ key: computedName(lit(1)), value: lit(1) }, 19 { key: lit(2), value: lit(2) }]))); 20 21 // Bug 924688: computed property names - location information 22 var node = Reflect.parse("a = {[field1]: 5}"); 23 Pattern({ body: [ { expression: { right: { properties: [ {key: { loc: 24 { start: { line: 1, column: 6 }, end: { line: 1, column: 14 }}}}]}}}]}).match(node); 25 26 // Bug 1048384 - Getter/setter syntax with computed names 27 assertExpr("b = { get [meth]() { } }", aExpr("=", ident("b"), 28 objExpr([{ key: computedName(ident("meth")), value: funExpr(null, [], blockStmt([])), 29 method: false, kind: "get"}]))); 30 assertExpr("b = { set [meth](a) { } }", aExpr("=", ident("b"), 31 objExpr([{ key: computedName(ident("meth")), value: funExpr(null, [ident("a")], 32 blockStmt([])), method: false, kind: "set"}]))); 33 34 // Bug 1220702 - If it's not written as a method, `.method` should be false. 35 assertExpr("({[x]: function () {}})", 36 objExpr([{ 37 key: computedName(ident("x")), 38 value: funExpr(null, [], blockStmt([])), 39 method: false, 40 kind: "init" 41 }])); 42 43 } 44 45 runtest(test);