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 351ecf2 commit c362bf7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 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();
}
5 changes: 2 additions & 3 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 12619ffe

Passed: 472/927
Passed: 473/927

# All Passed:
* babel-preset-react
Expand Down Expand Up @@ -445,15 +445,14 @@ 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
* enum/ts5.0-const-foldable/input.ts
* 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
Expand Down

0 comments on commit c362bf7

Please sign in to comment.