From 6ffce865d1f46660d0bbe87644ed406937892c6f Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:51:59 +0000 Subject: [PATCH] fix(semantic): align `visit_arrow_function_expression` field visit order with ast (#4366) related: #4364 --- crates/oxc_semantic/src/builder.rs | 11 +++++++--- .../arrow/type-parameters/body-reference.snap | 18 ++++++++-------- .../type-parameters/param-reference.snap | 21 ++++++++++++------- .../return-value-reference.snap | 9 +++++++- .../type-parameters/type-param-reference.snap | 2 +- .../arrow/type-predicate-asserts2.snap | 9 +++++++- .../functions/arrow/type-predicate1.snap | 2 +- .../functions/arrow/type-predicate2.snap | 11 ++++++++-- 8 files changed, 58 insertions(+), 25 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index b843701f95e1d..a9245cbd1b76c 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -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 */ @@ -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 */ @@ -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(); } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap index 67d62d7dc93ab..48d1aab3fea31 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap @@ -11,16 +11,9 @@ 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": [ @@ -28,9 +21,16 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "flag": "ReferenceFlag(Type)", "id": 0, "name": "T", - "node_id": 13 + "node_id": 16 } ] + }, + { + "flag": "SymbolFlags(BlockScopedVariable)", + "id": 2, + "name": "x", + "node": "VariableDeclarator", + "references": [] } ] } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap index 25b4dded27cc3..6d00a545c8809 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap @@ -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": [] } ] diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap index 290f38c09d5ec..c6effd8d5d759 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap @@ -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 + } + ] } ] } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap index 414ecbc641f68..0e8a06646f6f1 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap @@ -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 } ] }, diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap index a4de68bff9836..9b41bfb55f3e7 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap @@ -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)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap index 253283bed8846..fb85d7d1434e8 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap @@ -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 } ] } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap index b965f03d3b3d1..e5d974e5b8566 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap @@ -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 } ] } @@ -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)",