-
Notifications
You must be signed in to change notification settings - Fork 17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to get this merged asap, thanks for the PR.
src/attachScopes.ts
Outdated
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be the empty array? Just seems like it would need a lot of guards for the params: undefined
case, but if that is already handled then that is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guybedford I have no idea. This prevented the code from throwing TypeError: Cannot read property 'type' of null
when I changed it.
I was following the example above for BlockStatement
which does not assign params
.
If you think an empty array is better, that seems to work too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the current implementation, it does not really matter what you do, but again I would love to see a test to make sure this keeps working in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukastaegert Thanks, I added a test 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this null
instead of undefined
to match the ESTree approach then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guybedford It can't be null due to the interface:
interface ScopeOptions {
parent?: AttachedScope;
block?: boolean;
params?: Array<Node>;
}
It can only be undefined
or Array
. I'll change it to []
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test would be nice
@lukastaegert I added a test but Windows CI is failing with the following:
|
It looks like pushing again solved the CI issue ✅ |
Released in 2.8.2. |
This fixes the scenario where the catch clause does not have a parameter defined.
For example:
This feature moved to stage 4 last year and is supported since Node 10 and Chrome 66.