Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 14 deletions.
17 changes: 8 additions & 9 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(_) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const ToastViewport = 1;
type ToastProps = string;

export { type ToastProps, ToastViewport };
6 changes: 3 additions & 3 deletions tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 54a8389f

Passed: 108/121
Passed: 108/122

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const ToastViewport = 1;
type ToastProps = string;

export { type ToastProps, ToastViewport };
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const ToastViewport = 1;
export { ToastViewport };

0 comments on commit 9479e2b

Please sign in to comment.