Skip to content

Commit

Permalink
fix(semantic): incorrect resolve references for TSInterfaceHeritage (
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 17, 2024
1 parent 7df54c3 commit 15a2f6c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
11 changes: 9 additions & 2 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,9 @@ impl<'a> SemanticBuilder<'a> {
AstKind::ExportSpecifier(s) if s.export_kind.is_type() => {
self.current_reference_flag = ReferenceFlag::Type;
}
AstKind::TSInterfaceHeritage(_) => {
self.current_reference_flag = ReferenceFlag::Type;
}
AstKind::TSTypeName(_) => {
match self.nodes.parent_kind(self.current_node_id) {
Some(
Expand Down Expand Up @@ -1740,7 +1743,9 @@ impl<'a> SemanticBuilder<'a> {
self.reference_jsx_identifier(ident);
}
AstKind::UpdateExpression(_) => {
if self.is_not_expression_statement_parent() {
if !self.current_reference_flag.is_type()
&& self.is_not_expression_statement_parent()
{
self.current_reference_flag |= ReferenceFlag::Read;
}
self.current_reference_flag |= ReferenceFlag::Write;
Expand All @@ -1753,7 +1758,9 @@ impl<'a> SemanticBuilder<'a> {
}
}
AstKind::MemberExpression(_) => {
self.current_reference_flag = ReferenceFlag::Read;
if !self.current_reference_flag.is_type() {
self.current_reference_flag = ReferenceFlag::Read;
}
}
AstKind::AssignmentTarget(_) => {
self.current_reference_flag |= ReferenceFlag::Write;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"id": 0,
"name": "Parent",
"node": "TSInterfaceDeclaration",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "Parent",
"node_id": 6
}
]
},
{
"flag": "SymbolFlags(Interface)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"id": 0,
"name": "A",
"node": "TSInterfaceDeclaration",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "A",
"node_id": 9
}
]
},
{
"flag": "SymbolFlags(Interface)",
Expand Down
13 changes: 13 additions & 0 deletions crates/oxc_semantic/tests/integration/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,16 @@ fn test_type_query() {
.has_number_of_reads(0)
.test();
}

#[test]
fn test_ts_interface_heritage() {
SemanticTester::ts(
"
type Heritage = { x: number; y: string; };
interface A extends (Heritage.x) {}
",
)
.has_some_symbol("Heritage")
.has_number_of_references(1)
.test();
}

0 comments on commit 15a2f6c

Please sign in to comment.