mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(transformer): arrow function transform: ignore type fields when finding enclosing arrow function (#5944)
Follow-on after #5850. No need to check type fields of `Function` or `ArrowFunctionExpression` when tracing up ancestors from a `this` expression - these fields cannot contain a `ThisExpression`. https://github.com/oxc-project/oxc/pull/5850#pullrequestreview-2319531991
This commit is contained in:
parent
9076deefca
commit
155d7fcba3
1 changed files with 5 additions and 12 deletions
|
|
@ -268,9 +268,10 @@ impl<'a> ArrowFunctions<'a> {
|
|||
// ```
|
||||
//
|
||||
// `this` resolves to the class / class instance (i.e. `this` defined *within* the class) in:
|
||||
// * Class method bodies
|
||||
// * Class property bodies
|
||||
// * Class static blocks
|
||||
// * Method body
|
||||
// * Method param
|
||||
// * Property value
|
||||
// * Static block
|
||||
//
|
||||
// ```js
|
||||
// // All these `this` refer to `this` defined within the class
|
||||
|
|
@ -281,6 +282,7 @@ impl<'a> ArrowFunctions<'a> {
|
|||
// d() { this }
|
||||
// static e() { this }
|
||||
// #f() { this }
|
||||
// g(x = this) {}
|
||||
// static { this }
|
||||
// }
|
||||
// ```
|
||||
|
|
@ -291,24 +293,15 @@ impl<'a> ArrowFunctions<'a> {
|
|||
// Top level
|
||||
Ancestor::ProgramBody(_)
|
||||
// Function (includes class method body)
|
||||
| Ancestor::FunctionTypeParameters(_)
|
||||
| Ancestor::FunctionThisParam(_)
|
||||
| Ancestor::FunctionParams(_)
|
||||
| Ancestor::FunctionReturnType(_)
|
||||
| Ancestor::FunctionBody(_)
|
||||
// Class property body
|
||||
| Ancestor::PropertyDefinitionValue(_)
|
||||
// Class static block
|
||||
| Ancestor::StaticBlockBody(_) => return None,
|
||||
Ancestor::ArrowFunctionExpressionTypeParameters(func) => {
|
||||
return Some(func.scope_id().get().unwrap())
|
||||
}
|
||||
Ancestor::ArrowFunctionExpressionParams(func) => {
|
||||
return Some(func.scope_id().get().unwrap())
|
||||
}
|
||||
Ancestor::ArrowFunctionExpressionReturnType(func) => {
|
||||
return Some(func.scope_id().get().unwrap())
|
||||
}
|
||||
Ancestor::ArrowFunctionExpressionBody(func) => {
|
||||
return Some(func.scope_id().get().unwrap())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue