feat(traverse): introduce MaybeBoundIdentifier#7265
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @overlookmotel and the rest of your teammates on |
CodSpeed Performance ReportMerging #7265 will not alter performanceComparing Summary
|
|
@Boshen This API is intended for your spread transform use case. |
02dcd21 to
c2d693a
Compare
|
Confirmed working as intended. let maybe_bound_identifier = if let Expression::Identifier(ident) = init {
MaybeBoundIdentifier::from_identifier_reference(ident, ctx)
} else {
let bound_identifier =
ctx.generate_uid_in_current_scope_based_on_node(init, builder.symbol_flags);
let id = bound_identifier.create_binding_pattern(ctx);
let init = ctx.ast.move_expression(init);
builder.decls.push(ctx.ast.variable_declarator(SPAN, decl.kind, id, Some(init), false));
bound_identifier.to_maybe_bound_identifier()
}; |
Merge activity
|
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound). Typical usage: ```rs // Create `MaybeBoundIdentifier` from an existing `IdentifierReference` let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx); // Generate `IdentifierReference`s and insert them into AST assign_expr.left = binding.create_write_target(ctx); assign_expr.right = binding.create_read_expression(ctx); ```
c2d693a to
8c754b1
Compare
|
What's odd is that in all the other transforms, Babel generates a temp var for unbound identifiers, because accessing a global e.g. Babel REPL Not sure why that's not the case in the rest/spread transform. Strictly speaking, it's a bug. |
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound). Typical usage: ```rs // Create `MaybeBoundIdentifier` from an existing `IdentifierReference` let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx); // Generate `IdentifierReference`s and insert them into AST assign_expr.left = binding.create_write_target(ctx); assign_expr.right = binding.create_read_expression(ctx); ```
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound). Typical usage: ```rs // Create `MaybeBoundIdentifier` from an existing `IdentifierReference` let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx); // Generate `IdentifierReference`s and insert them into AST assign_expr.left = binding.create_write_target(ctx); assign_expr.right = binding.create_read_expression(ctx); ```
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound). Typical usage: ```rs // Create `MaybeBoundIdentifier` from an existing `IdentifierReference` let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx); // Generate `IdentifierReference`s and insert them into AST assign_expr.left = binding.create_write_target(ctx); assign_expr.right = binding.create_read_expression(ctx); ```

MaybeBoundIdentifieris similar toBoundIdentifier, but can be used where the identifier may or may not have have aSymbolId(may or may not be bound).Typical usage: