From b6a9178075e1c363921641e0769ed6fd8b739587 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:19:03 +0000 Subject: [PATCH] fix(isolated-declarations): don't collect references when `ExportNamedDeclaration` has source (#5926) --- crates/oxc_isolated_declarations/src/scope.rs | 3 ++- .../tests/fixtures/eliminate-imports.ts | 2 ++ .../tests/snapshots/eliminate-imports.snap | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/oxc_isolated_declarations/src/scope.rs b/crates/oxc_isolated_declarations/src/scope.rs index 5f2b9b5b4a364..69d0f1e96cb3b 100644 --- a/crates/oxc_isolated_declarations/src/scope.rs +++ b/crates/oxc_isolated_declarations/src/scope.rs @@ -137,7 +137,8 @@ impl<'a> Visit<'a> for ScopeTree<'a> { fn visit_export_named_declaration(&mut self, decl: &ExportNamedDeclaration<'a>) { if let Some(declaration) = &decl.declaration { walk_declaration(self, declaration); - } else { + } else if decl.source.is_none() { + // export { ... } for specifier in &decl.specifiers { if let Some(name) = specifier.local.identifier_name() { self.add_type_reference(name.clone()); diff --git a/crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts b/crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts index a6bdc391eddf3..91534365f16a5 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/eliminate-imports.ts @@ -9,3 +9,5 @@ export const bar: (this: ThisType2) => void = function() {} import { type InferType1, type InferType2 } from 'infer'; export type F = X extends infer U extends InferType2 ? U : never + +export { Unused } from './unused'; \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/eliminate-imports.snap b/crates/oxc_isolated_declarations/tests/snapshots/eliminate-imports.snap index 404f2992eafe2..f048d666716a3 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/eliminate-imports.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/eliminate-imports.snap @@ -12,3 +12,4 @@ export declare function foo(this: ThisType1 ): void; export declare const bar: (this: ThisType2 ) => void; import { type InferType1, type InferType2 } from "infer"; export type F = X extends infer U extends InferType2 ? U : never; +export { Unused } from "./unused";