fix(isolated-declarations): binding elements with export should report an error (#4025)

close: #3976
This commit is contained in:
Dunqing 2024-07-02 13:47:28 +00:00
parent 05a047c17d
commit 7c915f4665
3 changed files with 25 additions and 8 deletions

View file

@ -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;
}

View file

@ -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 };

View file

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