File tree 4 files changed +51
-1
lines changed
4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -514,7 +514,7 @@ exports.file_list = [
514
514
//"language/statements/block/scope-lex-open.js",
515
515
"language/statements/for-of/scope-head-lex-open.js" ,
516
516
"language/statements/for-of/scope-body-lex-open.js" ,
517
- "language/statements/try/scope-catch-param-lex-open.js" ,
517
+ // "language/statements/try/scope-catch-param-lex-open.js",
518
518
//"language/statements/try/scope-catch-block-lex-open.js",
519
519
//"language/expressions/class/scope-name-lex-close.js",
520
520
//"language/expressions/call/scope-lex-close.js",
Original file line number Diff line number Diff line change
1
+ import Node from '../Node.js' ;
2
+ import Scope from '../Scope.js' ;
3
+
4
+ export default class CatchClause extends Node {
5
+ initialise ( transforms ) {
6
+ this . createdDeclarations = [ ] ;
7
+ this . scope = new Scope ( {
8
+ block : true ,
9
+ parent : this . parent . findScope ( false ) ,
10
+ declare : id => this . createdDeclarations . push ( id )
11
+ } ) ;
12
+
13
+ this . scope . addDeclaration ( this . param , 'catch' ) ;
14
+
15
+ super . initialise ( transforms ) ;
16
+ this . scope . consolidate ( ) ;
17
+ }
18
+
19
+ findScope ( functionScope ) {
20
+ return functionScope
21
+ ? this . parent . findScope ( functionScope )
22
+ : this . scope ;
23
+ }
24
+ }
25
+
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import AwaitExpression from './AwaitExpression.js';
5
5
import BinaryExpression from './BinaryExpression.js' ;
6
6
import BreakStatement from './BreakStatement.js' ;
7
7
import CallExpression from './CallExpression.js' ;
8
+ import CatchClause from './CatchClause.js' ;
8
9
import ClassBody from './ClassBody.js' ;
9
10
import ClassDeclaration from './ClassDeclaration.js' ;
10
11
import ClassExpression from './ClassExpression.js' ;
@@ -55,6 +56,7 @@ export default {
55
56
BinaryExpression,
56
57
BreakStatement,
57
58
CallExpression,
59
+ CatchClause,
58
60
ClassBody,
59
61
ClassDeclaration,
60
62
ClassExpression,
Original file line number Diff line number Diff line change @@ -185,5 +185,28 @@ module.exports = [
185
185
return bar;
186
186
}
187
187
`
188
+ } ,
189
+
190
+ {
191
+ description : 'catch clauses have their own scope' ,
192
+ input : `
193
+ const l = 2;
194
+ try {
195
+ throw new Error();
196
+ } catch(l) {
197
+ l = 1;
198
+ alert(l);
199
+ }
200
+ ` ,
201
+ output : `
202
+ var l = 2;
203
+ try {
204
+ throw new Error();
205
+ } catch(l$1) {
206
+ l$1 = 1;
207
+ alert(l$1);
208
+ }
209
+ `
188
210
}
211
+
189
212
] ;
You can’t perform that action at this time.
0 commit comments