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

feat: Top-Level awaitに対応 #1374

Merged
merged 10 commits into from
Jan 7, 2022
Merged

feat: Top-Level awaitに対応 #1374

merged 10 commits into from
Jan 7, 2022

Conversation

azu
Copy link
Collaborator

@azu azu commented Jan 5, 2022

Top-Level await

https://jsprimer.net/basic/async/#top-level-await-in-module

ES2021までは、await式はAsync Functionの直下でのみしか利用できませんでした。
ES2022には、これに加えてModuleの直下ではAsync Functionで囲まなくてもawait式が利用できます。

console.log("start");
// awaitを使って1秒待つ
await new Promise(resolve => setTimeout(resolve, 1000));
console.log("end");

fix #1373
fix #1365

@bot-user
Copy link

bot-user commented Jan 5, 2022

✔️ Deploy Preview for js-primer ready!

🔨 Explore the source changes: 941f2a6

🔍 Inspect the deploy log: https://app.netlify.com/sites/js-primer/deploys/61d83df6e23c18000827f07c

😎 Browse the preview: https://deploy-preview-1374--js-primer.netlify.app

@azu
Copy link
Collaborator Author

azu commented Jan 5, 2022

Top-Level await という言葉を使うべきかは微妙。
Proposal名もそうだけど、仕様ではAsync FunctionのTop-Levelみたいな言い方もしている。
この書籍だとTop-Levelはほんとにトップレベル(ファイルの直下のスコープ)を言ってる。

https://tc39.es/ecma262/#sec-async-function-definitions


<!-- Top-Level awaitをVM2がサポートしていないため -->
<!-- js-console:{ "type": "module" } -->
<!-- doctest:disable -->
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VM2で結局実行できないので

@azu azu merged commit 8472e4c into asciidwango:master Jan 7, 2022
@azu azu added the Lang: ES2022 ECMAScript 2022 label Jan 7, 2022
@azu azu deleted the feature/1365 branch January 7, 2022 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang: ES2022 ECMAScript 2022
Projects
None yet
2 participants