packages/babel-plugin-proposal-object-rest-spread/test/fixtures/object-rest/non-string-computed-exec/exec.js
raw| 1 | const a = { |
| 2 | "3": "three", |
| 3 | "foo": "bar" |
| 4 | } |
| 5 | |
| 6 | const { |
| 7 | [3]: omit, |
| 8 | ...rest |
| 9 | } = a; |
| 10 | |
| 11 | expect(rest).toEqual({"foo": "bar"}); |
| 12 | expect(omit).toBe("three"); |
| 13 | |
| 14 | const [k1, k2, k3, k4, k5] = [null, undefined, true, false, {toString() { return "warrior"; }}]; |
| 15 | const c = { |
| 16 | [k1]: "1", |
| 17 | [k2]: "2", |
| 18 | [k3]: "3", |
| 19 | [k4]: "4", |
| 20 | [k5]: "5" |
| 21 | }; |
| 22 | |
| 23 | const { |
| 24 | [k1]: v1, |
| 25 | [k2]: v2, |
| 26 | [k3]: v3, |
| 27 | [k4]: v4, |
| 28 | [k5]: v5, |
| 29 | ...vrest |
| 30 | } = c; |
| 31 | |
| 32 | expect(v1).toBe("1"); |
| 33 | expect(v2).toBe("2"); |
| 34 | expect(v3).toBe("3"); |
| 35 | expect(v4).toBe("4"); |
| 36 | expect(v5).toBe("5"); |
| 37 | expect(vrest).toEqual({}); |
| 38 | |
| 39 | // shouldn't convert symbols to strings |
| 40 | const sx = Symbol(); |
| 41 | const sy = Symbol(); |
| 42 | |
| 43 | const d = { |
| 44 | [sx]: "sx", |
| 45 | [sy]: "sy" |
| 46 | } |
| 47 | |
| 48 | const { |
| 49 | [sx]: dx, |
| 50 | [sy]: dy |
| 51 | } = d; |
| 52 | |
| 53 | expect(dx).toBe("sx"); |
| 54 | expect(dy).toBe("sy"); |