From a653e202fab490f40810899a0f3c49d2c244f30c Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 13 Sep 2019 09:24:41 -0400 Subject: [PATCH 1/3] Fix optional catch binding --- src/attachScopes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attachScopes.ts b/src/attachScopes.ts index c633035..a38c347 100644 --- a/src/attachScopes.ts +++ b/src/attachScopes.ts @@ -100,7 +100,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc if (node.type === 'CatchClause') { newScope = new Scope({ parent: scope, - params: [node.param], + params: node.param ? [node.param] : undefined, block: true }); } From ea6ed78feef84dd558cb1b1e712b065044a2b4bc Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 13 Sep 2019 12:19:01 -0400 Subject: [PATCH 2/3] Add test --- test/attachScopes.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/attachScopes.test.ts b/test/attachScopes.test.ts index 16a5a75..c02307b 100644 --- a/test/attachScopes.test.ts +++ b/test/attachScopes.test.ts @@ -586,4 +586,42 @@ describe('attachScopes', function() { attachScopes(ast, 'scope'); }).not.toThrow(); }); + + it('supports catch without a parameter', function() { + const ast = { + "type": "Program", + "start": 0, + "end": 23, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 23, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 10, + "body": [] + }, + "handler": { + "type": "CatchClause", + "start": 11, + "end": 23, + "param": null, + "body": { + "type": "BlockStatement", + "start": 17, + "end": 23, + "body": [] + } + }, + "finalizer": null + } + ], + "sourceType": "script" + }; + expect(() => { + attachScopes(ast, 'scope'); + }).not.toThrow(); + }); }); From c67f1d70ddcd732f566481cea99d57cf67a89273 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 13 Sep 2019 13:28:43 -0400 Subject: [PATCH 3/3] Use empty array --- src/attachScopes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attachScopes.ts b/src/attachScopes.ts index a38c347..0809039 100644 --- a/src/attachScopes.ts +++ b/src/attachScopes.ts @@ -100,7 +100,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc if (node.type === 'CatchClause') { newScope = new Scope({ parent: scope, - params: node.param ? [node.param] : undefined, + params: node.param ? [node.param] : [], block: true }); }