-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add references of default parameters and default values of destructuring #65
Add references of default parameters and default values of destructuring #65
Conversation
- I changed PatternVisitor to collect right-hand nodes (readonly subtrees). At Referencer.visitPattern's last, visits the right-hand nodes recursively. This logic adds readable references for identifiers in default values. - Referencer.referencingDefaultValue adds writable references for parameters/variables that has its default value. It's similar to VariableDeclarator.init. - Because there are calling visitPattern twice for same nodes, I added options (processing right-hand nodes or not) to visitPattern.
this.rightHandNodes.push(pattern.right); | ||
} finally { | ||
this.assignments.pop(); | ||
} |
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.
Why these try-finally is needed?
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.
It's to be exceptions safety.
I'm afraid to leak the resource, so I use finally
for a couple of open/close API (or processes of reverting) from long habit.
But I agree that it's redundant here.
The patch itself looks good to me. With some nits. |
Thank you for the review! |
I'm sorry, I might have found a bug. |
I have a wonder on this code: class Foo { } The global scope has a variable of This is an expected behavior? I guess related to eslint/eslint#2545 |
Yes, that is expected. Classes create two bindings: a mutable outer binding and an immutable inner binding. |
Ah thanks. Yes, that's expected behavior. |
I understood! So, I think, I completed this PR. |
try { | ||
this.visit(node.left); | ||
this.rightHandNodes.push(node.right); | ||
} finally { |
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.
Ah, let's drop this try-finally.
The other part looks very nice to me :D
Thank you for your great patch! So after fixing it, I'll merge your PR soon!
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.
Oops, sorry!
52b6167
to
766ce6c
Compare
OK, merging... |
Add references of default parameters and default values of destructuring
Thank you for your great contribution!!! |
Yeah! Thank you for reviewing and merging!! |
Hello.
I tried to implement default parameters and default values of destructuring assignments.
PatternVisitor
to collect right-hand nodes (readonly subtrees). AtReferencer.visitPattern
's last, visits the right-hand nodes recursively. This logic adds readable references for identifiers in default values.Referencer.referencingDefaultValue
adds writable references for parameters/variables that has its default value. the references are similar to references ofVariableDeclarator.init
. Patterns can be nested, can have multiple default values, so it might need an utility such asReference.isInit
.Referencer.visitPattern
, because there are callingReferencer.visitPattern
twice for same nodes.Thanks!
Note: this error has been occurring on this PR version. Umm...