Yunfei He 2024-12-13 12:00:58 +08:00 committed by GitHub
parent 25bb6daa40
commit 9479e2b0a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 81 additions and 14 deletions

View file

@ -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(_) => {

View 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
}
]
}
]
}
]

View file

@ -0,0 +1,4 @@
const ToastViewport = 1;
type ToastProps = string;
export { type ToastProps, ToastViewport };

View file

@ -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:

View file

@ -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)]

View file

@ -0,0 +1,4 @@
const ToastViewport = 1;
type ToastProps = string;
export { type ToastProps, ToastViewport };

View file

@ -0,0 +1,2 @@
const ToastViewport = 1;
export { ToastViewport };