@@ -89,31 +89,23 @@ test "try/catch with empty catch as last statement in a function body", ->
89
89
catch err
90
90
eq nonce, fn ()
91
91
92
-
93
- # Catch leads to broken scoping: #1595
94
-
95
- test " try/catch with a reused variable name." , ->
92
+ test " #1595: try/catch with a reused variable name" , ->
93
+ # `catch` shouldn’t lead to broken scoping.
96
94
do ->
97
95
try
98
96
inner = 5
99
97
catch inner
100
98
# nothing
101
99
eq typeof inner, ' undefined'
102
100
103
-
104
- # Allowed to destructure exceptions: #2580
105
-
106
- test " try/catch with destructuring the exception object" , ->
107
-
101
+ test " #2580: try/catch with destructuring the exception object" , ->
108
102
result = try
109
103
missing .object
110
104
catch {message}
111
105
message
112
106
113
107
eq message, ' missing is not defined'
114
108
115
-
116
-
117
109
test " Try catch finally as implicit arguments" , ->
118
110
first = (x ) -> x
119
111
@@ -130,8 +122,8 @@ test "Try catch finally as implicit arguments", ->
130
122
catch e
131
123
eq bar, yes
132
124
133
- # Catch Should Not Require Param: #2900
134
- test " parameter-less catch clause " , ->
125
+ test " #2900: parameter-less catch clause " , ->
126
+ # ` catch` should not require a parameter.
135
127
try
136
128
throw new Error ' failed'
137
129
catch
@@ -140,3 +132,53 @@ test "parameter-less catch clause", ->
140
132
try throw new Error ' failed' catch finally ok true
141
133
142
134
ok try throw new Error ' failed' catch then true
135
+
136
+ test " #3709: throwing an if statement" , ->
137
+ # `throw if` should return a closure around the `if` block, so that the
138
+ # output is valid JavaScript.
139
+ try
140
+ throw if no
141
+ new Error ' drat!'
142
+ else
143
+ new Error ' no escape!'
144
+ catch err
145
+ eq err .message , ' no escape!'
146
+
147
+ try
148
+ throw if yes then new Error ' huh?' else null
149
+ catch err
150
+ eq err .message , ' huh?'
151
+
152
+ test " #3709: throwing a switch statement" , ->
153
+ i = 3
154
+ try
155
+ throw switch i
156
+ when 2
157
+ new Error ' not this one'
158
+ when 3
159
+ new Error ' oh no!'
160
+ catch err
161
+ eq err .message , ' oh no!'
162
+
163
+ test " #3709: throwing a for loop" , ->
164
+ # `throw for` should return a closure around the `for` block, so that the
165
+ # output is valid JavaScript.
166
+ try
167
+ throw for i in [0 .. 3 ]
168
+ i * 2
169
+ catch err
170
+ arrayEq err, [0 , 2 , 4 , 6 ]
171
+
172
+ test " #3709: throwing a while loop" , ->
173
+ i = 0
174
+ try
175
+ throw while i < 3
176
+ i++
177
+ catch err
178
+ eq i, 3
179
+
180
+ test " #3789: throwing a throw" , ->
181
+ try
182
+ throw throw throw new Error ' whoa!'
183
+ catch err
184
+ eq err .message , ' whoa!'
0 commit comments