-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Improve name
scope in typescript for multi-initialization statements
#1742
Comments
Would you also want the same sort of thing in Python tuple unpacking? |
Good question. My instinct is to say no. For that it's generally more useful to just target the entire left-hand side. But I think @josharian wants something like that for Go, so maybe we should discuss |
Yeah, in Go, code like this is very common: x, err := foo() and wanting to refer to just (It's not tuple unpacking, it's multiple assignment, but it's very similar.) |
I guess you'd want to be able to say eg "chuck first name", "pour last name", etc? |
Yeah, after a refactor that changes what a function returns, it's going to be very common to want to chuck or pour or clone or swap individual names. |
The problem
In code like the following:
we could improve our support for the
name
scope.The solution
We should probably handle the case of a simple initializer with only one variable separately from a multi-child one
Single-variable initializer
For example:
In this case, we want the following:
This way you could say:
"name"
from within the statement to get the name"every name"
from anywhere in the block containing the statement (including within statement itself) to get all the names in that blockMulti-variable initializer
For example:
In this case, we want the following:
aaa = 0
andbbb = 1
)This way you could say:
"name"
from within a sub-assignment to get the name of that sub-assignment"name"
from the start / end of the statement to get all the names in that statement"every name"
from anywhere in the statement to get all the names in that statement"first name"
from anywhere in the statement to get the first name in that statement"every name"
from anywhere in the block containing the statement, except within statement itself, to get all the names in that blockDiscussion
Note that we may want to use this pattern in other places
.scm
filesThe text was updated successfully, but these errors were encountered: