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

Fix optional catch binding #70

Merged
merged 3 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/attachScopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] : [],
block: true
});
}
Expand Down
38 changes: 38 additions & 0 deletions test/attachScopes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});