Skip to content

Commit

Permalink
feat(semantic): remove ReferenceFlags::Value from non-type-only exp…
Browse files Browse the repository at this point in the history
…orts 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.
  • Loading branch information
Dunqing committed Jul 29, 2024
1 parent 43f2df8 commit cf1854b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf1854b

Please sign in to comment.