Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Support for top-level await #10

Open
PaulLeCam opened this issue Aug 14, 2020 · 11 comments
Open

Support for top-level await #10

PaulLeCam opened this issue Aug 14, 2020 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@PaulLeCam
Copy link

Hey, thanks for this project, it looks like a great way to bring nice Deno code to the browser!

Is your feature request related to a problem? Please describe.

I'd like to use denopack to bundle any deno std library not using the Deno APIs.

I tried bundling a project but it fails with Uncaught Error: Terser is not supposed to return nothing!.
I narrowed down the problem to having export { createHash } from 'https://deno.land/[email protected]/hash/mod.ts' in my deps.ts file and my assumption, comparing with other imports from std that can get compiled correctly, is that it's because the std/hash module uses WASM imports.

Describe the solution you'd like

Rollup has a WASM plugin that would be great to support in denopack, either as a plugin or in core.
Alternatively, if there is an easy way to convert/wrap existing Rollup plugins to denopack ones it could be a good option.

Describe alternatives you've considered

Using deno bundle + minifier

Thanks!

@jeroenptrs
Copy link
Collaborator

Hey @PaulLeCam what version of denopack are you using? Could you share your denopack config?
I'm not 100% certain, but I think the issue isn't necessarily the fact that it's using WASM, so I'd like to investigate it further.

@jeroenptrs jeroenptrs added the enhancement New feature or request label Aug 14, 2020
@PaulLeCam
Copy link
Author

Yes WASM is my assumption but that might be something else, this was just the most obvious difference I found between std/hash and other std libraries.

Here is a simple way I could reproduce the issue (I'm using Deno 1.3.0):

File test.ts:

export { createHash } from 'https://deno.land/[email protected]/hash/mod.ts'

And running:

deno run --unstable --allow-env --allow-net --allow-read --allow-write https://deno.land/x/[email protected]/cli.ts bundle -i test.ts

@jeroenptrs jeroenptrs added bug Something isn't working and removed enhancement New feature or request labels Aug 16, 2020
@jeroenptrs
Copy link
Collaborator

@PaulLeCam I have some good news and bad news:
the good news is that as far as I know, this is not related to WASM, and I'm fairly certain bundling WASM should work.
the bad news however is that this is related to the fact that Terser does not support top level awaits yet and this is used inside of the implementation of std/hash.

https://deno.land/[email protected]/hash/_wasm/hash.ts {
  error: SyntaxError: Unexpected await identifier inside strict mode

I will leave this issue open as this is fairly annoying to anyone wanting to use std/hash

@PaulLeCam
Copy link
Author

Thanks for investigating!
Too bad about Terser, I guess it's even a larger problem than std/hash because any module could possibly user a top-level await.

@PaulLeCam PaulLeCam changed the title WASM support Support for top-level await Aug 17, 2020
@jeroenptrs
Copy link
Collaborator

Yep, I'm thinking of a good way to support this going forward. I think I might need to change the Terser plugin back to minifying the bundle chunks instead of as a transform hook or something similar. Will test some approaches this week after I finished up the plugins I've been working on 😄

@jeroenptrs
Copy link
Collaborator

Thanks for renaming the issue btw 👍

@jeroenptrs jeroenptrs self-assigned this Aug 17, 2020
@lucacasonato
Copy link
Collaborator

I think I fixed this in a terser update a few weeks ago.

@jeroenptrs
Copy link
Collaborator

Does Terser 5 support TLA now?

@lucacasonato
Copy link
Collaborator

I think that is why I updated it in the first place... can't remember now though. I'll check real quick.

@lucacasonato
Copy link
Collaborator

Oh never mind - I updated because optional chaining... so this is not fixed yet.

@jeroenptrs
Copy link
Collaborator

Yeah I just checked and the issue regarding awaits on Terser's github is still open :c sucks but we'll keep an eye out on it ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants