mirror of
https://github.com/denoland/deno.git
synced 2025-08-31 07:47:46 +00:00
fix(unstable): wrong node with shorthand ObjectPattern + AssignPattern (#28402)
We did not serialize the `AssignmentPattern` node inside `ObjectPattern` properties. ```ts ({ a = b } = {}) ``` This is a bit different in SWC and looks like I got confused with the different AST formats. Fixes https://github.com/denoland/deno/issues/28399
This commit is contained in:
parent
731a238d34
commit
7f7b51c414
3 changed files with 145 additions and 32 deletions
|
@ -1898,24 +1898,23 @@ fn serialize_pat(ctx: &mut TsEsTreeBuilder, pat: &Pat) -> NodeRef {
|
|||
)
|
||||
}
|
||||
ObjectPatProp::Assign(assign_pat_prop) => {
|
||||
let ident = serialize_binding_ident(ctx, &assign_pat_prop.key);
|
||||
let key = serialize_binding_ident(ctx, &assign_pat_prop.key);
|
||||
let mut value = serialize_binding_ident(ctx, &assign_pat_prop.key);
|
||||
|
||||
let shorthand = assign_pat_prop.value.is_none();
|
||||
let value = assign_pat_prop.value.as_ref().map_or(
|
||||
// SWC has value as optional with shorthand properties,
|
||||
// but TSESTree expects the value to be a duplicate of
|
||||
// the binding ident.
|
||||
serialize_binding_ident(ctx, &assign_pat_prop.key),
|
||||
|value| serialize_expr(ctx, value),
|
||||
);
|
||||
|
||||
if let Some(assign) = &assign_pat_prop.value {
|
||||
let expr = serialize_expr(ctx, assign);
|
||||
value = ctx.write_assign_pat(&assign_pat_prop.span, value, expr);
|
||||
}
|
||||
|
||||
ctx.write_property(
|
||||
&assign_pat_prop.span,
|
||||
&node.span,
|
||||
shorthand,
|
||||
false,
|
||||
false,
|
||||
PropertyKind::Init,
|
||||
ident,
|
||||
key,
|
||||
value,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue