mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(transformer/object-rest-spread): generate catch variable binding with correct SymbolFlags (#7469)
This commit is contained in:
parent
199076bd14
commit
37842c166d
2 changed files with 12 additions and 30 deletions
|
|
@ -571,7 +571,7 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform `try {} catch (...x) {}`.
|
// Transform `try {} catch ({...x}) {}`.
|
||||||
fn transform_catch_clause(clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
|
fn transform_catch_clause(clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||||
let Some(param) = &mut clause.param else { unreachable!() };
|
let Some(param) = &mut clause.param else { unreachable!() };
|
||||||
if Self::has_nested_object_rest(¶m.pattern) {
|
if Self::has_nested_object_rest(¶m.pattern) {
|
||||||
|
|
@ -589,12 +589,6 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> {
|
||||||
scope_id,
|
scope_id,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
// Add `SymbolFlags::CatchVariable`.
|
|
||||||
param.pattern.bound_names(&mut |ident| {
|
|
||||||
ctx.symbols_mut()
|
|
||||||
.get_flags_mut(ident.symbol_id())
|
|
||||||
.insert(SymbolFlags::CatchVariable);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -617,7 +611,7 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> {
|
||||||
declarator.kind,
|
declarator.kind,
|
||||||
&mut declarator.id,
|
&mut declarator.id,
|
||||||
&mut block.body,
|
&mut block.body,
|
||||||
scope_id,
|
if decl.kind.is_var() { ctx.current_hoist_scope_id() } else { scope_id },
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
// Move the bindings from the for init scope to scope of the loop body.
|
// Move the bindings from the for init scope to scope of the loop body.
|
||||||
|
|
@ -755,7 +749,13 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> {
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
ctx: &mut TraverseCtx<'a>,
|
ctx: &mut TraverseCtx<'a>,
|
||||||
) -> VariableDeclaration<'a> {
|
) -> VariableDeclaration<'a> {
|
||||||
let bound_identifier = ctx.generate_uid("ref", scope_id, kind_to_symbol_flags(kind));
|
let mut flags = kind_to_symbol_flags(kind);
|
||||||
|
if matches!(ctx.parent(), Ancestor::TryStatementHandler(_)) {
|
||||||
|
// try {} catch (ref) {}
|
||||||
|
// ^^^
|
||||||
|
flags |= SymbolFlags::CatchVariable;
|
||||||
|
}
|
||||||
|
let bound_identifier = ctx.generate_uid("ref", scope_id, flags);
|
||||||
let kind = VariableDeclarationKind::Let;
|
let kind = VariableDeclarationKind::Let;
|
||||||
let id = mem::replace(pat, bound_identifier.create_binding_pattern(ctx));
|
let id = mem::replace(pat, bound_identifier.create_binding_pattern(ctx));
|
||||||
let init = bound_identifier.create_read_expression(ctx);
|
let init = bound_identifier.create_read_expression(ctx);
|
||||||
|
|
|
||||||
|
|
@ -6733,45 +6733,27 @@ rebuilt : SymbolId(7): ScopeId(0)
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-getter.js
|
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-getter.js
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["_extends", "_objectDestructuringEmpty", "count", "iterCount", "x"]
|
after transform: ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "count", "iterCount", "x"]
|
||||||
rebuilt : ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "count", "iterCount"]
|
rebuilt : ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "count", "iterCount"]
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(1): ["_ref"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(3): []
|
after transform: ScopeId(3): []
|
||||||
rebuilt : ScopeId(3): ["x"]
|
rebuilt : ScopeId(3): ["x"]
|
||||||
Symbol scope ID mismatch for "_ref":
|
|
||||||
after transform: SymbolId(3): ScopeId(1)
|
|
||||||
rebuilt : SymbolId(4): ScopeId(0)
|
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-skip-non-enumerable.js
|
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-skip-non-enumerable.js
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["_extends", "_objectDestructuringEmpty", "iterCount", "o", "rest"]
|
after transform: ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "iterCount", "o", "rest"]
|
||||||
rebuilt : ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "iterCount", "o"]
|
rebuilt : ScopeId(0): ["_extends", "_objectDestructuringEmpty", "_ref", "iterCount", "o"]
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(1): ["_ref"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(2): []
|
after transform: ScopeId(2): []
|
||||||
rebuilt : ScopeId(2): ["rest"]
|
rebuilt : ScopeId(2): ["rest"]
|
||||||
Symbol scope ID mismatch for "_ref":
|
|
||||||
after transform: SymbolId(3): ScopeId(1)
|
|
||||||
rebuilt : SymbolId(4): ScopeId(0)
|
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-val-obj.js
|
tasks/coverage/test262/test/language/statements/for-of/dstr/var-obj-ptrn-rest-val-obj.js
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["_excluded", "_objectWithoutProperties", "a", "b", "iterCount", "rest"]
|
after transform: ScopeId(0): ["_excluded", "_objectWithoutProperties", "_ref", "a", "b", "iterCount", "rest"]
|
||||||
rebuilt : ScopeId(0): ["_excluded", "_objectWithoutProperties", "_ref", "iterCount"]
|
rebuilt : ScopeId(0): ["_excluded", "_objectWithoutProperties", "_ref", "iterCount"]
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(1): ["_ref"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(2): []
|
after transform: ScopeId(2): []
|
||||||
rebuilt : ScopeId(2): ["a", "b", "rest"]
|
rebuilt : ScopeId(2): ["a", "b", "rest"]
|
||||||
Symbol scope ID mismatch for "_ref":
|
|
||||||
after transform: SymbolId(4): ScopeId(1)
|
|
||||||
rebuilt : SymbolId(3): ScopeId(0)
|
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/statements/switch/scope-lex-async-function.js
|
tasks/coverage/test262/test/language/statements/switch/scope-lex-async-function.js
|
||||||
semantic error: Symbol flags mismatch for "x":
|
semantic error: Symbol flags mismatch for "x":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue