Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit c94af05

Browse files
authored
Merge pull request #70 from styfle/patch-1
Fix optional catch binding
2 parents 2d05b16 + c67f1d7 commit c94af05

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/attachScopes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc
100100
if (node.type === 'CatchClause') {
101101
newScope = new Scope({
102102
parent: scope,
103-
params: [node.param],
103+
params: node.param ? [node.param] : [],
104104
block: true
105105
});
106106
}

test/attachScopes.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,42 @@ describe('attachScopes', function() {
586586
attachScopes(ast, 'scope');
587587
}).not.toThrow();
588588
});
589+
590+
it('supports catch without a parameter', function() {
591+
const ast = {
592+
"type": "Program",
593+
"start": 0,
594+
"end": 23,
595+
"body": [
596+
{
597+
"type": "TryStatement",
598+
"start": 0,
599+
"end": 23,
600+
"block": {
601+
"type": "BlockStatement",
602+
"start": 4,
603+
"end": 10,
604+
"body": []
605+
},
606+
"handler": {
607+
"type": "CatchClause",
608+
"start": 11,
609+
"end": 23,
610+
"param": null,
611+
"body": {
612+
"type": "BlockStatement",
613+
"start": 17,
614+
"end": 23,
615+
"body": []
616+
}
617+
},
618+
"finalizer": null
619+
}
620+
],
621+
"sourceType": "script"
622+
};
623+
expect(() => {
624+
attachScopes(ast, 'scope');
625+
}).not.toThrow();
626+
});
589627
});

0 commit comments

Comments
 (0)