Skip to content

Commit

Permalink
refactor(transformer): arrow function transform: ignore type fields w…
Browse files Browse the repository at this point in the history
…hen 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`. #5850 (review)
  • Loading branch information
overlookmotel committed Sep 21, 2024
1 parent 9076dee commit 155d7fc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -281,6 +282,7 @@ impl<'a> ArrowFunctions<'a> {
// d() { this }
// static e() { this }
// #f() { this }
// g(x = this) {}
// static { this }
// }
// ```
Expand All @@ -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())
}
Expand Down

0 comments on commit 155d7fc

Please sign in to comment.