fix(semantic): incorrect resolve references for TSInterfaceHeritage (#4311)

related issue: https://github.com/oxc-project/oxc/issues/3963
fixes: https://github.com/oxc-project/monitor-oxc/actions/runs/9960183591/job/27518854841
This commit is contained in:
Dunqing 2024-07-17 03:33:02 +00:00
parent 351ecf2707
commit c362bf7edf
5 changed files with 40 additions and 7 deletions

View file

@ -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(
@ -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;
@ -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;

View file

@ -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)",

View file

@ -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)",

View file

@ -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();
}

View file

@ -1,6 +1,6 @@
commit: 12619ffe
Passed: 472/927
Passed: 473/927
# All Passed:
* babel-preset-react
@ -445,7 +445,7 @@ Passed: 472/927
* opts/optimizeConstEnums/input.ts
* opts/rewriteImportExtensions/input.ts
# babel-plugin-transform-typescript (128/151)
# babel-plugin-transform-typescript (129/151)
* class/accessor-allowDeclareFields-false/input.ts
* class/accessor-allowDeclareFields-true/input.ts
* enum/mix-references/input.ts
@ -453,7 +453,6 @@ Passed: 472/927
* exports/declared-types/input.ts
* exports/interface/input.ts
* imports/elide-typeof/input.ts
* imports/elision-locations/input.ts
* imports/only-remove-type-imports/input.ts
* imports/type-only-export-specifier-2/input.ts
* imports/type-only-import-specifier-4/input.ts