From 7c915f466515aba00cfdb6a9cc15dab1de618f74 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:47:28 +0000 Subject: [PATCH] fix(isolated-declarations): binding elements with export should report an error (#4025) close: #3976 --- .../src/declaration.rs | 12 +++++------- .../fixtures/non-exported-binding-elements.ts | 4 +++- .../non-exported-binding-elements.snap | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/crates/oxc_isolated_declarations/src/declaration.rs b/crates/oxc_isolated_declarations/src/declaration.rs index cfc2291254011..8c03073269147 100644 --- a/crates/oxc_isolated_declarations/src/declaration.rs +++ b/crates/oxc_isolated_declarations/src/declaration.rs @@ -49,13 +49,11 @@ impl<'a> IsolatedDeclarations<'a> { check_binding: bool, ) -> Option> { if decl.id.kind.is_destructuring_pattern() { - if check_binding { - decl.id.bound_names(&mut |id| { - if self.scope.has_reference(&id.name) { - self.error(binding_element_export(id.span)); - } - }); - } + decl.id.bound_names(&mut |id| { + if !check_binding || self.scope.has_reference(&id.name) { + self.error(binding_element_export(id.span)); + } + }); return None; } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts b/crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts index 0e41ea05a2fc8..22f6d6a8021f5 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding-elements.ts @@ -7,4 +7,6 @@ export function foo(): number { // Incorrect const { c, d } = { c: 1, d: 2 }; const [ e ] = [4]; -export { c, d, e } \ No newline at end of file +export { c, d, e } + +export const { f, g } = { f: 5, g: 6 }; \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/non-exported-binding-elements.snap b/crates/oxc_isolated_declarations/tests/snapshots/non-exported-binding-elements.snap index 50d585442beef..53339fc66da77 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/non-exported-binding-elements.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/non-exported-binding-elements.snap @@ -6,10 +6,27 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/non-exported-binding export declare function foo(): number; export { c, d, e }; +export declare const; ==================== Errors ==================== + x TS9019: Binding elements can't be exported directly with + | --isolatedDeclarations. + ,-[12:16] + 11 | + 12 | export const { f, g } = { f: 5, g: 6 }; + : ^ + `---- + + x TS9019: Binding elements can't be exported directly with + | --isolatedDeclarations. + ,-[12:19] + 11 | + 12 | export const { f, g } = { f: 5, g: 6 }; + : ^ + `---- + x TS9019: Binding elements can't be exported directly with | --isolatedDeclarations. ,-[8:9]