Skip to content

Commit

Permalink
fix(isolated-declarations): binding elements with export should repor…
Browse files Browse the repository at this point in the history
…t an error (#4025)

close: #3976
  • Loading branch information
Dunqing committed Jul 2, 2024
1 parent 05a047c commit 7c915f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
12 changes: 5 additions & 7 deletions crates/oxc_isolated_declarations/src/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ impl<'a> IsolatedDeclarations<'a> {
check_binding: bool,
) -> Option<VariableDeclarator<'a>> {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export function foo(): number {
// Incorrect
const { c, d } = { c: 1, d: 2 };
const [ e ] = [4];
export { c, d, e }
export { c, d, e }

export const { f, g } = { f: 5, g: 6 };
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7c915f4

Please sign in to comment.