From cf1854be7cf9dabb47f776d2717cc1b6ad873d64 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Mon, 29 Jul 2024 03:39:18 +0000 Subject: [PATCH] feat(semantic): remove `ReferenceFlags::Value` from non-type-only exports that referenced type binding (#4511) ```ts type T = 0; export { T } ^ ReferenceFlags::Type | ReferenceFlags::Read ``` The export `T` only referenced type binding. We should remove `ReferenceFlags::Read` for it. --- crates/oxc_semantic/src/builder.rs | 3 +++ .../tests/fixtures/typescript-eslint/export/equals3-type.snap | 2 +- .../tests/fixtures/typescript-eslint/export/named2-type.snap | 2 +- .../tests/fixtures/typescript-eslint/export/named3-type.snap | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 01af805d74121..5fb8865f972f4 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -442,6 +442,9 @@ impl<'a> SemanticBuilder<'a> { // If the symbol is a value symbol and reference flag is not type-only, remove the type flag. if symbol_flag.is_value() && !flag.is_type_only() { *self.symbols.references[*id].flag_mut() -= ReferenceFlag::Type; + } else { + // If the symbol is a type symbol and reference flag is not type-only, remove the value flag. + *self.symbols.references[*id].flag_mut() -= ReferenceFlag::Value; } // import type { T } from './mod'; type A = typeof T diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap index aab4be670cbc6..6eda2799cf581 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3-type.snap @@ -24,7 +24,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/equals3- "node": "TSInterfaceDeclaration", "references": [ { - "flag": "ReferenceFlag(Read | Type)", + "flag": "ReferenceFlag(Type)", "id": 0, "name": "Foo", "node_id": 11 diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.snap index 0933fd799ccee..8ba38319647ed 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-type.snap @@ -24,7 +24,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named2-t "node": "TSTypeAliasDeclaration", "references": [ { - "flag": "ReferenceFlag(Read | Type)", + "flag": "ReferenceFlag(Type)", "id": 0, "name": "A", "node_id": 8 diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.snap index f65c9f2d9c7ff..ef7516964bb6c 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-type.snap @@ -24,7 +24,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/named3-t "node": "TSTypeAliasDeclaration", "references": [ { - "flag": "ReferenceFlag(Read | Type)", + "flag": "ReferenceFlag(Type)", "id": 0, "name": "V", "node_id": 8