Skip to content

Commit

Permalink
Fix esm2js transform when export destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 14, 2024
1 parent 1528980 commit 5b10f3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const {foo} = {foo: 1};
export const [bar] = [2];
8 changes: 8 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5238,6 +5238,14 @@ describe('javascript', function () {
assert.deepEqual(res, {ns: {a: 4, default: 1}});
});

it('should support export declarations with destructuring', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-export-destructuring/index.js'),
);
let res = await run(b);
assert.deepEqual(res, {foo: 1, bar: 2});
});

it('should support export default declarations', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-export-default/index.js'),
Expand Down
13 changes: 1 addition & 12 deletions packages/transformers/js/core/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,24 +585,13 @@ impl Fold for ESMFold {

fn fold_binding_ident(&mut self, node: BindingIdent) -> BindingIdent {
if self.in_export_decl {
// export const {foo} = ...;
self.create_export(node.id.sym.clone(), Expr::Ident(node.id.clone()), DUMMY_SP);
}

node.fold_children_with(self)
}

fn fold_assign_pat_prop(&mut self, node: AssignPatProp) -> AssignPatProp {
if self.in_export_decl {
self.create_export(
node.key.sym.clone(),
Expr::Ident(node.key.id.clone()),
DUMMY_SP,
);
}

node.fold_children_with(self)
}

modules_visit_fn!(fold_function, Function);
modules_visit_fn!(fold_class, Class);
modules_visit_fn!(fold_getter_prop, GetterProp);
Expand Down

0 comments on commit 5b10f3a

Please sign in to comment.