-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Top-level for-await not working in bundles #4207
Comments
Please read the typescript release notes : https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#top-level-await Top level avait only work for modules |
@ecyrbe Thanks, however this is a module, and it does work correctly with a regular |
@davidbailey00 Can you append "in bundles" to the title? Better repro: for await (const _ of []);
export {};
|
This may be an upstream bug with TypeScript - adding
|
Top level A work around for now would be to use a top level await in the module somewhere else, that would trigger TypeScript to emit the execute as an async function and everything else should work. |
I was wrong, it is part of the Stage 3 proposal. I just got confused because it was implemented in V8 separately. The TypeScript implementation is incomplete and I have opened microsoft/TypeScript#37402. |
There is a PR open and pending review, which has been assigned. Hopefully it will get merged soon, but might not make TS 3.9. |
I use Deno 1.0.0 with TS 3.9 and I can still reproduce this issue with the example above. |
@StarpTech the issue is still open because the upstream bug is not fixed. |
@kitsonk yes I saw it afterward. What's missing there? It looks like the PR is stale for 2 months. |
🤷 I am not able to comment on why PRs are or are not merged in TypeScript. |
try this hacking is work: change execute: async function () {
s = server_ts_2.serve({ port: 8000 });
console.log("servce on http://localhost:8000");
for await (const req of s) {
req.respond({ body: "hhhhhh" });
}
}, |
Line 996 in 1be7ec4
is that anybody working on this? |
@ZenLiuCN This is an upstream bug in TypeScript. We can not speed up TypeScript's development. |
would be good to change server example in the docs, because right now first code you run and do |
Surrounding the for-await block with main function seems working around the problem. import { serve } from "https://deno.land/std@0.55.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
async function main() {
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
}
main()
|
Apologies if this has been discussed in the past, but Dart doesn't have top level code, instead it uses a |
Fixed with swc bundler. |
Steps to reproduce
Create
server.js
with the following content:Run
deno bundle server.js out.js
Run
deno out.js
Expected result
The code runs
Actual result
Notes
Adding
await console.log("test");
or any otherawait
statement is detected by the bundler and allows thefor-await
block to work properly. (See #4206)The text was updated successfully, but these errors were encountered: