MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1// ============================================
2// TEST: catch with destructuring not supported
3// ============================================
4// Bug: catch ({ prop }) and catch ([a, b]) fail with SyntaxError
5// ============================================
6
7console.log("=== CATCH DESTRUCTURING TESTS ===\n");
8
9// --- BASELINE (should work) ---
10
11console.log("1. catch with simple identifier:");
12try {
13 throw new Error("test error");
14} catch (e) {
15 console.log(" caught: " + e.message);
16}
17console.log(" PASSED\n");
18
19console.log("2. catch without parameter (ES2019):");
20try {
21 throw new Error("ignored");
22} catch {
23 console.log(" caught without param");
24}
25console.log(" PASSED\n");
26
27console.log("3. catch with manual destructuring (workaround):");
28try {
29 throw { message: "manual", code: 42 };
30} catch (e) {
31 const { message, code } = e;
32 console.log(" message: " + message + ", code: " + code);
33}
34console.log(" PASSED\n");
35
36console.log("4. catch with manual array destructuring (workaround):");
37try {
38 throw [1, 2, 3];
39} catch (e) {
40 const [a, b, c] = e;
41 console.log(" a: " + a + ", b: " + b + ", c: " + c);
42}
43console.log(" PASSED\n");
44
45// --- BUG TESTS (these should work per ES6 but fail in Ant) ---
46
47console.log("5. catch with object destructuring:");
48console.log(" expected: works per ES6 spec");
49try {
50 throw { message: "destructured", code: 99 };
51} catch ({ message, code }) {
52 console.log(" message: " + message + ", code: " + code);
53}
54console.log(" PASSED\n");
55
56console.log("6. catch with array destructuring:");
57console.log(" expected: works per ES6 spec");
58try {
59 throw [10, 20];
60} catch ([a, b]) {
61 console.log(" a: " + a + ", b: " + b);
62}
63console.log(" PASSED\n");
64
65console.log("7. catch with nested object destructuring:");
66try {
67 throw { outer: { inner: "value" } };
68} catch ({ outer: { inner } }) {
69 console.log(" inner: " + inner);
70}
71console.log(" PASSED\n");
72
73console.log("8. catch with default values:");
74try {
75 throw { a: 1 };
76} catch ({ a, b = 99 }) {
77 console.log(" a: " + a + ", b: " + b);
78}
79console.log(" PASSED\n");
80
81console.log("9. catch with renaming:");
82try {
83 throw { longPropertyName: "short" };
84} catch ({ longPropertyName: short }) {
85 console.log(" short: " + short);
86}
87console.log(" PASSED\n");
88
89console.log("10. catch with rest pattern:");
90try {
91 throw [1, 2, 3, 4, 5];
92} catch ([first, ...rest]) {
93 console.log(" first: " + first + ", rest: " + rest);
94}
95console.log(" PASSED\n");
96
97console.log("=== ALL TESTS PASSED ===");