Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array destructuring exports are removed when re-exported with export * #106

Open
yume-chan opened this issue Oct 21, 2024 · 0 comments
Open
Labels
bug 🐛 Issue is a confirmed bug bundler: webpack 📦 Issue is related to webpack bundler

Comments

@yume-chan
Copy link

Environment

  • wyw-in-js version: "@wyw-in-js/vite": "^0.5.4"
  • custom processor: "@linaria/core": "^6.2.0"
  • Bundler (+ version): "vite": "^5.4.9"
  • Node.js version: v20.16.0
  • OS: Windows 11

Description

a.ts:

export const A = 100;
export const [B] = [200];

b.ts:

import { css } from '@linaria/core';

export * from './a';

// Trigger wyw
export const className = css`width: 100px`;

main.ts

document.body.innerHTML = await import('./b').then(
  ({ A, B }) => `A: ${A}, B: ${B}`
);

Output

b.ts is rewritten to:

export { A } from "/src/a.ts";
export const className = "cxl307p";
import "/src/b.wyw-in-js.css?t=1729509504509";

export B is missing

I think it has something to do with here:

if (id.isObjectPattern()) {
// It is `export const { a, ...rest } = obj;`
return whatIsDestructed(id).reduce<Exports>(
(acc, destructed) => ({
...acc,
[destructed.as.node.name]: init,
}),
{}
);
}
// What else it can be?
debug('exportFromVariableDeclarator: unknown type of id %o', id.node.type);

But I can't understand the code, especially, what should happen to nested object/array destructuring. I think import and export should handle destructuring differently.

Reproducible Demo

https://stackblitz.com/edit/wyw-export-star?file=src%2Fmain.ts

@yume-chan yume-chan added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 21, 2024
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 21, 2024
@layershifter layershifter added bug 🐛 Issue is a confirmed bug and removed bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issue is a confirmed bug bundler: webpack 📦 Issue is related to webpack bundler
Projects
None yet
Development

No branches or pull requests

2 participants