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

Deno bundle regression in both 1.5.4 and 1.6.0 when a module re-exports both * and default #8679

Closed
nktpro opened this issue Dec 8, 2020 · 4 comments · Fixed by #8901
Closed
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@nktpro
Copy link

nktpro commented Dec 8, 2020

I've managed to narrow this issue down to a bare-minimal reproducer: Given 3 files:

one.ts

export default "one";
export const one = "one";

two.ts

export * from "./one.ts";
export { default } from "./one.ts";

three.ts

import two from "./two.ts";
console.log(two);

Only deno 1.4.x would produce a valid bundle for three.ts (very verbose output but valid regardless, since we didn't have bundle tree-shaking until 1.5.x)

deno bundle ./three.ts

The bundle output of deno 1.5.4 will simply contain a single invalid statement of:

console.log(__default);

The bundle output of deno 1.6.0 is also invalid, in a slightly different way:

console.log(__default);
const __default = __default;
const __default = __default;

It's worth noting that the re-exporting pattern in two.ts is basically what skypack.dev does, so this issue would usually manifest in the wild by importing some libraries via skypack.

@kitsonk kitsonk added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Dec 8, 2020
@kitsonk
Copy link
Contributor

kitsonk commented Dec 8, 2020

cc/ @kdy1

@nktpro nktpro changed the title Deno bundle regression in both 1.5.x and 1.6.0 when a module re-exports both * and default Deno bundle regression in both 1.5.4 and 1.6.0 when a module re-exports both * and default Dec 8, 2020
kdy1 added a commit to kdy1/swc that referenced this issue Dec 9, 2020
@kdy1
Copy link

kdy1 commented Dec 9, 2020

The problem is that a module exports default multiple times.
I think a removing default from export * could be a solution.

@nktpro
Copy link
Author

nktpro commented Dec 9, 2020

@kdy1 As per the example on MDN export * from ... re-exports everything except the default export. If swc exports default as well as part of export * from ... then perhaps it didn't implement ES specification correctly?

@kdy1
Copy link

kdy1 commented Dec 10, 2020

@nktpro Oh, thanks! I didn't know it. Then fixing it will be much easier.
I just normalized all imports to ease handling and as a result default was exported too.

kdy1 added a commit to kdy1/swc that referenced this issue Dec 26, 2020
kdy1 added a commit to swc-project/swc that referenced this issue Dec 27, 2020
swc_bundler:
 - Reduce binary size by reducing usage of visitor / folders.
 - Handle `export *` and `export { default }` from same source. (denoland/deno#8530, denoland/deno#8679)
 - Fix ordering of statements. (denoland/deno#8545)
 - Sort statements in wrapped modules. (denoland/deno#8211 (comment))
 - Exclude default export while handling `export *`.
 - Exclude `export { default }` and `export { foo as default }` while handling `export *`.
 - Make statements from same module to be injected together. (denoland/deno#8620)

swc_ecma_transforms:
 - fixer: Handle assignments in the callee of `new`  correctly.
 - fixer: Handle seqence expression in the callee of `new`  correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants