refactor(semantic): simplify checking if function is part of if statement#18290
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the is_function_part_of_if_statement function to use a simpler and more straightforward approach for checking if a function declaration is the consequent or alternate of an IfStatement. The refactoring removes pointer equality checks and leverages the fact that function declarations can only appear in specific positions within an IfStatement.
Changes:
- Simplified logic by first checking if the function is a declaration, then checking parent node kind
- Removed
std::ptrimport and pointer equality comparisons - Added clarifying comments explaining the logic and strict mode optimization
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
64ed030 to
22b4d39
Compare
…tement (#18290) `is_function_part_of_if_statement` had some convoluted code to check if a `Function` is the `consequent` or `alternate` of an `IfStatement`. Simplify it by checking if the `Function` is a function declaration, then just a check for whether the parent node is an `IfStatement`. Rationale is: * If a `Function` is a declaration, it can only be the `consequent` or `alternate` of an `IfStatement`. It can't be the `test`, because that's an expression not a declaration. So if a function declaration's parent is an `IfStatement`, it's definitely either the `consequent` or `alternate`. * If a `Function` is an expression, it's parent can't be `consequent` or `alternate` of an `IfStatement` because the function would need to be wrapped in some other node e.g. `ExpressionStatement` (and then `IfStatement` wouldn't be the function's parent). Also add a comment explaining why we do the check for strict/sloppy mode too.
3f602f0 to
90e93ab
Compare
…tement (#18290) `is_function_part_of_if_statement` had some convoluted code to check if a `Function` is the `consequent` or `alternate` of an `IfStatement`. Simplify it by checking if the `Function` is a function declaration, then just a check for whether the parent node is an `IfStatement`. Rationale is: * If a `Function` is a declaration, it can only be the `consequent` or `alternate` of an `IfStatement`. It can't be the `test`, because that's an expression not a declaration. So if a function declaration's parent is an `IfStatement`, it's definitely either the `consequent` or `alternate`. * If a `Function` is an expression, it's parent can't be `consequent` or `alternate` of an `IfStatement` because the function would need to be wrapped in some other node e.g. `ExpressionStatement` (and then `IfStatement` wouldn't be the function's parent). Also add a comment explaining why we do the check for strict/sloppy mode too.
90e93ab to
fde1dc7
Compare

is_function_part_of_if_statementhad some convoluted code to check if aFunctionis theconsequentoralternateof anIfStatement.Simplify it by checking if the
Functionis a function declaration, then just a check for whether the parent node is anIfStatement.Rationale is:
Functionis a declaration, it can only be theconsequentoralternateof anIfStatement. It can't be thetest, because that's an expression not a declaration. So if a function declaration's parent is anIfStatement, it's definitely either theconsequentoralternate.Functionis an expression, it's parent can't beconsequentoralternateof anIfStatementbecause the function would need to be wrapped in some other node e.g.ExpressionStatement(and thenIfStatementwouldn't be the function's parent).Also add a comment explaining why we do the check for strict/sloppy mode too.