mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(semantic): typeof operator cannot reference type-only import (#4500)
This commit is contained in:
parent
ef0e953702
commit
cb2fa4924e
4 changed files with 34 additions and 3 deletions
|
|
@ -436,6 +436,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
references.retain(|(id, flag)| {
|
||||
if flag.is_type() && symbol_flag.can_be_referenced_by_type()
|
||||
|| flag.is_value() && symbol_flag.can_be_referenced_by_value()
|
||||
|| flag.is_ts_type_query() && symbol_flag.is_import()
|
||||
{
|
||||
// The non type-only ExportSpecifier can reference a type/value symbol,
|
||||
// If the symbol is a value symbol and reference flag is not type-only, remove the type flag.
|
||||
|
|
@ -443,6 +444,15 @@ impl<'a> SemanticBuilder<'a> {
|
|||
*self.symbols.references[*id].flag_mut() -= ReferenceFlag::Type;
|
||||
}
|
||||
|
||||
// import type { T } from './mod'; type A = typeof T
|
||||
// ^ can reference type-only import
|
||||
// If symbol is type-import, we need to replace the ReferenceFlag::Value with ReferenceFlag::Type
|
||||
if flag.is_ts_type_query() && symbol_flag.is_type_import() {
|
||||
let reference_flag = self.symbols.references[*id].flag_mut();
|
||||
*reference_flag -= ReferenceFlag::Value;
|
||||
*reference_flag |= ReferenceFlag::Type;
|
||||
}
|
||||
|
||||
self.symbols.references[*id].set_symbol_id(symbol_id);
|
||||
resolved_references.push(*id);
|
||||
false
|
||||
|
|
|
|||
|
|
@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-def
|
|||
"id": 0,
|
||||
"name": "foo",
|
||||
"node": "ImportDefaultSpecifier",
|
||||
"references": []
|
||||
"references": [
|
||||
{
|
||||
"flag": "ReferenceFlag(Type | TSTypeQuery)",
|
||||
"id": 0,
|
||||
"name": "foo",
|
||||
"node_id": 10
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"flag": "SymbolFlags(TypeAlias)",
|
||||
|
|
|
|||
|
|
@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inl
|
|||
"id": 0,
|
||||
"name": "foo",
|
||||
"node": "ImportSpecifier",
|
||||
"references": []
|
||||
"references": [
|
||||
{
|
||||
"flag": "ReferenceFlag(Type | TSTypeQuery)",
|
||||
"id": 0,
|
||||
"name": "foo",
|
||||
"node_id": 11
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"flag": "SymbolFlags(TypeAlias)",
|
||||
|
|
|
|||
|
|
@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-nam
|
|||
"id": 0,
|
||||
"name": "foo",
|
||||
"node": "ImportSpecifier",
|
||||
"references": []
|
||||
"references": [
|
||||
{
|
||||
"flag": "ReferenceFlag(Type | TSTypeQuery)",
|
||||
"id": 0,
|
||||
"name": "foo",
|
||||
"node_id": 11
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"flag": "SymbolFlags(TypeAlias)",
|
||||
|
|
|
|||
Loading…
Reference in a new issue