Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(semantic): IdentifierReference within TSPropertySignature cannot reference type-only import binding #5441

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 0 additions & 18 deletions tasks/coverage/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12996,9 +12996,6 @@ rebuilt : ScopeId(0): ["A", "B"]
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(7), ScopeId(8), ScopeId(10)]
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
Reference flags mismatch:
after transform: ReferenceId(12): ReferenceFlags(Type)
rebuilt : ReferenceId(0): ReferenceFlags(Read)
Unresolved references mismatch:
after transform: ["Extract", "Parameters"]
rebuilt : []
Expand Down Expand Up @@ -14600,15 +14597,6 @@ rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(4), ScopeId(6), Sc
Symbol reference IDs mismatch:
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3)]
rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(2)]
Reference flags mismatch:
after transform: ReferenceId(1): ReferenceFlags(Type)
rebuilt : ReferenceId(0): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(2): ReferenceFlags(Type)
rebuilt : ReferenceId(1): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Type)
rebuilt : ReferenceId(2): ReferenceFlags(Read)

tasks/coverage/typescript/tests/cases/compiler/interfaceImplementation5.ts
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -31028,12 +31016,6 @@ rebuilt : SymbolId(2): []
Symbol reference IDs mismatch:
after transform: SymbolId(4): [ReferenceId(12)]
rebuilt : SymbolId(3): []
Reference flags mismatch:
after transform: ReferenceId(1): ReferenceFlags(Type)
rebuilt : ReferenceId(0): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Type)
rebuilt : ReferenceId(1): ReferenceFlags(Read)

tasks/coverage/typescript/tests/cases/conformance/classes/classExpression.ts
semantic error: Missing SymbolId: M
Expand Down