Add NodePath#getAssignmentIdentifiers#16551
Conversation
| const ids = path.getBindingIdentifiers(); | ||
| const ids = process.env.BABEL_8_BREAKING | ||
| ? path.getAssignmentIdentifiers() | ||
| : path.getBindingIdentifiers(); |
There was a problem hiding this comment.
This change is deferred to Babel 8 because plugins might be used with an old Babel core that depends on a legacy Babel traverse.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57461 |
To be clear, will this method return identifiers that are assigned to, or identifiers that can be assigned to (but don't create a new binding)? If it's the latter, is this affected by non-strict mode (where assigning to an undeclared variable creates a property on the global object)? |
Good catch. This method is supposed to return those that are assigned and it does not take into account non-strict mode. I overlooked the non-strict mode behaviour of assignment expressions. I believe this is why However, The map
As we can see,
If we introduce |
|
Here are some use cases for Babel's "BindingIdentifier" and "ReferencedIdentifier":
If we are to align current Babel definition to the spec notation, we will have to adjust case 1 and 4 since they now cover different AST structures. The case 2 will not be affected because the union set is not changed unless we want to separate I think the case 1 justifies the requirement of One of technical challenges that may block alignment is identifiers within a pattern. To determine whether such an identifier is a reference, we have to walk up to the parent of the toplevel object/array pattern, but the current |
liuxingbaoyu
left a comment
There was a problem hiding this comment.
Thank you for your detailed explanation!
09bff4f to
2a5a022
Compare
2a5a022 to
f0a5e6f
Compare
NodePath#getAssignmentIdentifiers
In this PR we introduce a new
getAssignmentIdentifiersmethod to extract identifiers allowed in the left hand side. Currently this method is a subset of thegetBindingIdentifiers, however in Babel 8 we will remove the assignment LHS support forgetBindingIdentifiers, as those are not binding identifiers per spec. This goal will be addressed in a new PR.In Babel 8,
getBindingIdentifierswill only return identifiers that will introduce new bindings, whilegetAssignmentIdentifiersonly returns identifiers that is reassigned.