mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(semantic): missing references when export {} references a type-only binding and a normal (#7812)
https://playground.oxc.rs/#eNpdTzEOgzAM/AryzFAqdUHq2rlD1YklUIMihTiyTQGh/L0BBEMn31l35/MCDZTQkBfNXmRE3xbHQKzZPSsqX3mcNrZkOgfcJU+mIPmfPEIOBOUCPPh1yOzVTFAqD5iDs14PLA0FPMnc1+QOpmy8tMT9vog5BMOCnAITXkMOfCq3BajhDtMFQLleihskRUMf7HDtkkhvvW3tYU7vKpN7OBpX8xe5JkmVWuMEY4w/P71iMw== Current: <img width="876" alt="image" src="https://github.com/user-attachments/assets/58327920-44ef-469d-8c7c-a2d7b17da717" /> Expected: https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=false&spec=false&loose=false&code_lz=MYewdgzgLgBAKiAhtAagSwKYHcAOIBOsAvDAIwBQ5UAnjhvEtAAr4g4QwkXkYAeehGAG8YNOg2RQWbCABoJqTLgKwAvkA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Ctypescript&prettier=false&targets=&version=7.26.4&externalPlugins=&assumptions=%7B%7D <img width="877" alt="image" src="https://github.com/user-attachments/assets/9b847baa-5b5a-43be-b77d-d529fb3f8026" /> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Dunqing <dengqing0821@gmail.com>
This commit is contained in:
parent
25bb6daa40
commit
9479e2b0a2
7 changed files with 81 additions and 14 deletions
|
|
@ -490,6 +490,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
|
||||
references.retain(|&reference_id| {
|
||||
let reference = &mut self.symbols.references[reference_id];
|
||||
|
||||
let flags = reference.flags();
|
||||
if flags.is_type() && symbol_flags.can_be_referenced_by_type()
|
||||
|| flags.is_value() && symbol_flags.can_be_referenced_by_value()
|
||||
|
|
@ -1852,15 +1853,15 @@ impl<'a> SemanticBuilder<'a> {
|
|||
self.current_reference_flags = ReferenceFlags::Read | ReferenceFlags::Type;
|
||||
}
|
||||
}
|
||||
AstKind::ExportNamedDeclaration(decl) => {
|
||||
if decl.export_kind.is_type() {
|
||||
self.current_reference_flags = ReferenceFlags::Type;
|
||||
}
|
||||
}
|
||||
AstKind::ExportSpecifier(s) => {
|
||||
if self.current_reference_flags.is_type() || s.export_kind.is_type() {
|
||||
if s.export_kind.is_type()
|
||||
|| matches!(self.nodes.parent_kind(self.current_node_id), Some(AstKind::ExportNamedDeclaration(decl)) if decl.export_kind.is_type())
|
||||
{
|
||||
self.current_reference_flags = ReferenceFlags::Type;
|
||||
} else {
|
||||
// If the export specifier is not a explicit type export, we consider it as a potential
|
||||
// type and value reference. If it references to a value in the end, we would delete the
|
||||
// `ReferenceFlags::Type` flag in `fn resolve_references_for_current_scope`.
|
||||
self.current_reference_flags = ReferenceFlags::Read | ReferenceFlags::Type;
|
||||
}
|
||||
self.current_node_flags |= NodeFlags::ExportSpecifier;
|
||||
|
|
@ -2023,9 +2024,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
self.class_table_builder.pop_class();
|
||||
}
|
||||
AstKind::ExportSpecifier(_) => {
|
||||
if !self.current_reference_flags.is_type_only() {
|
||||
self.current_reference_flags = ReferenceFlags::empty();
|
||||
}
|
||||
self.current_reference_flags = ReferenceFlags::empty();
|
||||
self.current_node_flags -= NodeFlags::ExportSpecifier;
|
||||
}
|
||||
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
|
||||
|
|
|
|||
50
crates/oxc_semantic/tests/fixtures/oxc/ts/export/named/type-and-non-type.snap
vendored
Normal file
50
crates/oxc_semantic/tests/fixtures/oxc/ts/export/named/type-and-non-type.snap
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
source: crates/oxc_semantic/tests/main.rs
|
||||
input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/export/named/type-and-non-type.ts
|
||||
---
|
||||
[
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"children": [],
|
||||
"flags": "ScopeFlags(StrictMode)",
|
||||
"id": 1,
|
||||
"node": "TSTypeAliasDeclaration",
|
||||
"symbols": []
|
||||
}
|
||||
],
|
||||
"flags": "ScopeFlags(StrictMode | Top)",
|
||||
"id": 0,
|
||||
"node": "Program",
|
||||
"symbols": [
|
||||
{
|
||||
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
|
||||
"id": 0,
|
||||
"name": "ToastViewport",
|
||||
"node": "VariableDeclarator(ToastViewport)",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Read)",
|
||||
"id": 1,
|
||||
"name": "ToastViewport",
|
||||
"node_id": 14
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"flags": "SymbolFlags(TypeAlias)",
|
||||
"id": 1,
|
||||
"name": "ToastProps",
|
||||
"node": "TSTypeAliasDeclaration",
|
||||
"references": [
|
||||
{
|
||||
"flags": "ReferenceFlags(Type)",
|
||||
"id": 0,
|
||||
"name": "ToastProps",
|
||||
"node_id": 11
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
4
crates/oxc_semantic/tests/fixtures/oxc/ts/export/named/type-and-non-type.ts
vendored
Normal file
4
crates/oxc_semantic/tests/fixtures/oxc/ts/export/named/type-and-non-type.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
const ToastViewport = 1;
|
||||
type ToastProps = string;
|
||||
|
||||
export { type ToastProps, ToastViewport };
|
||||
|
|
@ -25302,15 +25302,15 @@ tasks/coverage/typescript/tests/cases/compiler/noCircularDefinitionOnExportOfPri
|
|||
semantic error: Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||
rebuilt : ScopeId(0): [ScopeId(1)]
|
||||
Symbol reference IDs mismatch for "cat":
|
||||
after transform: SymbolId(0): [ReferenceId(1)]
|
||||
rebuilt : SymbolId(0): []
|
||||
Symbol flags mismatch for "Foo":
|
||||
after transform: SymbolId(1): SymbolFlags(Class | NameSpaceModule | Ambient)
|
||||
rebuilt : SymbolId(1): SymbolFlags(Class)
|
||||
Symbol redeclarations mismatch for "Foo":
|
||||
after transform: SymbolId(1): [Span { start: 61, end: 64 }]
|
||||
rebuilt : SymbolId(1): []
|
||||
Unresolved references mismatch:
|
||||
after transform: ["cat", "module"]
|
||||
rebuilt : ["module"]
|
||||
|
||||
tasks/coverage/typescript/tests/cases/compiler/noCollisionThisExpressionAndLocalVarInFunction.ts
|
||||
semantic error: Scope children mismatch:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
commit: 54a8389f
|
||||
|
||||
Passed: 108/121
|
||||
Passed: 108/122
|
||||
|
||||
# All Passed:
|
||||
* babel-plugin-transform-class-static-block
|
||||
|
|
@ -33,7 +33,7 @@ rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), R
|
|||
x Output mismatch
|
||||
|
||||
|
||||
# babel-plugin-transform-typescript (2/9)
|
||||
# babel-plugin-transform-typescript (2/10)
|
||||
* class-property-definition/input.ts
|
||||
Unresolved references mismatch:
|
||||
after transform: ["const"]
|
||||
|
|
@ -144,6 +144,14 @@ Reference symbol mismatch for "Name":
|
|||
after transform: SymbolId(7) "Name"
|
||||
rebuilt : SymbolId(5) "Name"
|
||||
|
||||
* exports/type-and-non-type/input.ts
|
||||
Bindings mismatch:
|
||||
after transform: ScopeId(0): ["ToastProps", "ToastViewport"]
|
||||
rebuilt : ScopeId(0): ["ToastViewport"]
|
||||
Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1)]
|
||||
rebuilt : ScopeId(0): []
|
||||
|
||||
* redeclarations/input.ts
|
||||
Scope children mismatch:
|
||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
const ToastViewport = 1;
|
||||
type ToastProps = string;
|
||||
|
||||
export { type ToastProps, ToastViewport };
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
const ToastViewport = 1;
|
||||
export { ToastViewport };
|
||||
Loading…
Reference in a new issue