mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer): shorten code in arrow functions transform (#5826)
Use `unwrap()` on `scope_id` field of `ArrowFunctionExpression`. Previously we had errors in other transforms which did not set `scope_id` correctly, but this appears to now be fixed.
This commit is contained in:
parent
d74c7fa0c9
commit
01c5b7cb4b
1 changed files with 4 additions and 17 deletions
|
|
@ -273,22 +273,9 @@ impl<'a> ArrowFunctions<'a> {
|
||||||
body.statements.push(return_statement);
|
body.statements.push(return_statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// There shouldn't need to be a conditional here. Every arrow function should have a scope ID.
|
let scope_id = arrow_function_expr.scope_id.get().unwrap();
|
||||||
// But at present TS transforms don't seem to set `scope_id` in some cases, so this test case
|
let flags = ctx.scopes_mut().get_flags_mut(scope_id);
|
||||||
// fails if just unwrap `scope_id`:
|
*flags &= !ScopeFlags::Arrow;
|
||||||
// `typescript/tests/cases/compiler/classFieldSuperAccessible.ts`.
|
|
||||||
// ```ts
|
|
||||||
// class D {
|
|
||||||
// accessor b = () => {}
|
|
||||||
// }
|
|
||||||
// ```
|
|
||||||
// TODO: Change to `arrow_function_expr.scope_id.get().unwrap()` once scopes are correct
|
|
||||||
// in TS transforms.
|
|
||||||
let scope_id = arrow_function_expr.scope_id.get();
|
|
||||||
if let Some(scope_id) = scope_id {
|
|
||||||
let flags = ctx.scopes_mut().get_flags_mut(scope_id);
|
|
||||||
*flags &= !ScopeFlags::Arrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_function = ctx.ast.function(
|
let new_function = ctx.ast.function(
|
||||||
FunctionType::FunctionExpression,
|
FunctionType::FunctionExpression,
|
||||||
|
|
@ -303,7 +290,7 @@ impl<'a> ArrowFunctions<'a> {
|
||||||
arrow_function_expr.return_type,
|
arrow_function_expr.return_type,
|
||||||
Some(body),
|
Some(body),
|
||||||
);
|
);
|
||||||
new_function.scope_id.set(scope_id);
|
new_function.scope_id.set(Some(scope_id));
|
||||||
|
|
||||||
Expression::FunctionExpression(self.ctx.ast.alloc(new_function))
|
Expression::FunctionExpression(self.ctx.ast.alloc(new_function))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue