Skip to content

Commit

Permalink
fix(semantic): align visit_arrow_function_expression field visit or…
Browse files Browse the repository at this point in the history
…der with ast (#4366)

related: #4364
  • Loading branch information
Dunqing committed Jul 19, 2024
1 parent f68b659 commit 6ffce86
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 25 deletions.
11 changes: 8 additions & 3 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,10 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.enter_node(kind);
self.enter_scope(ScopeFlags::Function | ScopeFlags::Arrow, &expr.scope_id);

if let Some(parameters) = &expr.type_parameters {
self.visit_ts_type_parameter_declaration(parameters);
}

self.visit_formal_parameters(&expr.params);

/* cfg */
Expand All @@ -1581,6 +1585,10 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
));
/* cfg */

if let Some(return_type) = &expr.return_type {
self.visit_ts_type_annotation(return_type);
}

self.visit_function_body(&expr.body);

/* cfg */
Expand All @@ -1592,9 +1600,6 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
});
/* cfg */

if let Some(parameters) = &expr.type_parameters {
self.visit_ts_type_parameter_declaration(parameters);
}
self.leave_node(kind);
self.leave_scope();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"id": 1,
"node": "ArrowFunctionExpression",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable)",
"id": 1,
"name": "x",
"node": "VariableDeclarator",
"references": []
},
{
"flag": "SymbolFlags(TypeParameter)",
"id": 2,
"id": 1,
"name": "T",
"node": "TSTypeParameter",
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 13
"node_id": 16
}
]
},
{
"flag": "SymbolFlags(BlockScopedVariable)",
"id": 2,
"name": "x",
"node": "VariableDeclarator",
"references": []
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"node": "ArrowFunctionExpression",
"symbols": [
{
"flag": "SymbolFlags(FunctionScopedVariable)",
"flag": "SymbolFlags(TypeParameter)",
"id": 1,
"name": "a",
"node": "FormalParameter",
"references": []
"name": "T",
"node": "TSTypeParameter",
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 14
}
]
},
{
"flag": "SymbolFlags(TypeParameter)",
"flag": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"name": "T",
"node": "TSTypeParameter",
"name": "a",
"node": "FormalParameter",
"references": []
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"id": 1,
"name": "T",
"node": "TSTypeParameter",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 12
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 14
"node_id": 12
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"id": 0,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 18
}
]
},
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "arg",
"node_id": 14
"node_id": 18
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "arg",
"node_id": 17
"node_id": 23
}
]
}
Expand All @@ -44,7 +44,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow
"id": 0,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 18
}
]
},
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
Expand Down

0 comments on commit 6ffce86

Please sign in to comment.