summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/parser/letContextualKeyword.js
blob: 8bccfacf0f0d987bd375e78edd1968703677a8ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function expectError(str) {
  var log = "";
  try {
    eval(str);
  } catch (e) {
    log += "e";
    assertEq(e instanceof SyntaxError, true);
  }
  assertEq(log, "e");
}

eval(`let x = 42; assertEq(x, 42);`);
eval(`var let = 42; assertEq(let, 42);`);
eval(`let;`);
eval(`[...let] = [];`);
eval(`function let() { return 42; } assertEq(let(), 42);`)
eval(`let {x:x} = {x:42}; assertEq(x, 42);`);
eval(`let [x] = [42]; assertEq(x, 42);`);

eval(`for (let x in [1]) { assertEq(x, "0"); }`);
eval(`for (const x in [1]) { assertEq(x, "0"); }`);

eval(`for (let x of [1]) { assertEq(x, 1); }`);
eval(`for (const x of [1]) { assertEq(x, 1); }`);

eval(`for (let i = 0; i < 1; i++) { assertEq(i, 0); }`);
eval(`var done = false; for (const i = 0; !done; done = true) { assertEq(i, 0); }`);

eval(`for (let of of [1]) { assertEq(of, 1); }`);
eval(`for (const of of [1]) { assertEq(of, 1); }`);

eval(`try { throw 17; } catch (let) { assertEq(let, 17); }`);
eval(`try { throw [17]; } catch ([let]) { assertEq(let, 17); }`);
eval(`try { throw { x: 17 }; } catch ({ x: let }) { assertEq(let, 17); }`);
eval(`try { throw {}; } catch ({ x: let = 17 }) { assertEq(let, 17); }`);

expectError(`try { throw [17, 42]; } catch ([let, let]) {}`);

eval(`for (let in [1]) { assertEq(let, "0"); }`);
eval(`for (let / 1; ; ) { break; }`);
expectError(`let = {}; for (let.x of;;);`);
expectError(`for (let of [1]) { }`);

expectError(`for (let let in [1]) { }`);
expectError(`for (const let in [1]) { }`);

expectError(`for (let let of [1]) { }`);
expectError(`for (const let of [1]) { }`);

expectError(`for (let let = 17; false; ) { }`);
expectError(`for (const let = 17; false; ) { }`);

expectError(`for (let [let] = 17; false; ) { }`);
expectError(`for (const [let] = 17; false; ) { }`);

expectError(`for (let [let = 42] = 17; false; ) { }`);
expectError(`for (const [let = 42] = 17; false; ) { }`);

expectError(`for (let { x: let } = 17; false; ) { }`);
expectError(`for (const { x: let } = 17; false; ) { }`);

expectError(`for (let { x: let = 42 } = 17; false; ) { }`);
expectError(`for (const { x: let = 42 } = 17; false; ) { }`);

expectError("let\nlet;");
expectError("const\nlet;");

expectError(`let let = 17;`);
expectError(`const let = 17;`);

expectError(`let [let] = 17;`);
expectError(`const [let] = 17;`);

expectError(`let [let = 42] = 17;`);
expectError(`const [let = 42] = 17;`);

expectError(`let {let} = 17;`);
expectError(`const {let} = 17;`);

expectError(`let { let = 42 } = 17;`);
expectError(`const { let = 42 } = 17;`);

expectError(`let { x: let } = 17;`);
expectError(`const { x: let } = 17;`);

expectError(`let { x: let = 42 } = 17;`);
expectError(`const { x: let = 42 } = 17;`);

expectError(`let { ['y']: let } = 17;`);
expectError(`const { ['y']: let } = 17;`);

expectError(`let { ['y']: let = 42 } = 17;`);
expectError(`const { ['y']: let = 42 } = 17;`);

expectError(`let { x: [let] } = { x: 17 };`);
expectError(`const { x: [let] } = { x: 17 };`);

expectError(`let { x: [let = 42] } = { x: 17 };`);
expectError(`const { x: [let = 42] } = { x: 17 };`);

expectError(`let [foo, let] = 42;`);
expectError(`const [foo, let] = 42;`);

expectError(`let [foo, { let }] = [17, {}];`);
expectError(`const [foo, { let }] = [17, {}];`);

expectError(`"use strict"; var let = 42;`);
expectError(`"use strict"; function let() {}`);
expectError(`"use strict"; for (let of [1]) {}`);
expectError(`"use strict"; try {} catch (let) {}`);