Skip to content

Commit

Permalink
fix(semantic): IdentifierReference within PropertySignature cannot re…
Browse files Browse the repository at this point in the history
…ference type import binding
  • Loading branch information
Dunqing committed Sep 4, 2024
1 parent 10279f5 commit 3aee756
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
12 changes: 11 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,14 @@ impl<'a> SemanticBuilder<'a> {
AstKind::TSInterfaceHeritage(_) => {
self.current_reference_flags = ReferenceFlags::Type;
}
AstKind::TSPropertySignature(signature) => {
if signature.key.is_expression() {
// interface A { [prop]: string }
// ^^^^^ The property can reference value or [`SymbolFlags::TypeImport`] symbol
self.current_reference_flags =
ReferenceFlags::Read | ReferenceFlags::TSTypeQuery; // TODO: Should use another flag
}
}
AstKind::TSTypeQuery(_) => {
// type A = typeof a;
// ^^^^^^^^
Expand Down Expand Up @@ -1962,8 +1970,10 @@ impl<'a> SemanticBuilder<'a> {
}
}
AstKind::MemberExpression(_)
| AstKind::ExportNamedDeclaration(_)
| AstKind::TSTypeQuery(_)
| AstKind::ExportNamedDeclaration(_) => {
// Clear the reference flags that are set in AstKind::PropertySignature
| AstKind::PropertyKey(_) => {
self.current_reference_flags = ReferenceFlags::empty();
}
AstKind::AssignmentTarget(_) => self.current_reference_flags -= ReferenceFlags::Write,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts
---
[
{
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 1,
"node": "TSTypeAliasDeclaration",
"symbols": []
},
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 2,
"node": "TSInterfaceDeclaration",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(TypeImport)",
"id": 0,
"name": "X",
"node": "ImportDefaultSpecifier",
"references": [
{
"flags": "ReferenceFlags(Type | TSTypeQuery)",
"id": 0,
"name": "X",
"node_id": 15
}
]
},
{
"flags": "SymbolFlags(TypeAlias)",
"id": 1,
"name": "B",
"node": "TSTypeAliasDeclaration",
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "B",
"node_id": 19
}
]
},
{
"flags": "SymbolFlags(Export | Interface)",
"id": 2,
"name": "A",
"node": "TSInterfaceDeclaration",
"references": []
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type X from 'mod';

type B = number;

export interface A {
[X]: B
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"node": "VariableDeclarator(x)",
"references": [
{
"flags": "ReferenceFlags(Read)",
"flags": "ReferenceFlags(Read | TSTypeQuery)",
"id": 0,
"name": "x",
"node_id": 14
Expand Down

0 comments on commit 3aee756

Please sign in to comment.