From ae26a9c7a22bf3311648a93a3171f087490c6e4d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 30 Sep 2019 12:38:23 -0400 Subject: [PATCH] Support top-level-await in TypeScript (#3024) --- cli/tests/integration_tests.rs | 5 +++++ cli/tests/top_level_await.ts | 3 +++ js/compiler.ts | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 cli/tests/top_level_await.ts diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 99ab54a021..0e04071803 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -567,3 +567,8 @@ itest!(top_level_await { args: "--allow-read top_level_await.js", output: "top_level_await.out", }); + +itest!(top_level_await_ts { + args: "--allow-read top_level_await.ts", + output: "top_level_await.out", +}); diff --git a/cli/tests/top_level_await.ts b/cli/tests/top_level_await.ts new file mode 100644 index 0000000000..65de253eae --- /dev/null +++ b/cli/tests/top_level_await.ts @@ -0,0 +1,3 @@ +const buf: Uint8Array = await Deno.readFile("hello.txt"); +const n: number = await Deno.stdout.write(buf); +console.log(`\n\nwrite ${n}`); diff --git a/js/compiler.ts b/js/compiler.ts index 1e1fe3dd39..56804ef9fb 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -539,6 +539,9 @@ window.compilerMain = function compilerMain(): void { diagnostics = ts.getPreEmitDiagnostics(program).filter( ({ code }): boolean => { + // TS1308: 'await' expression is only allowed within an async + // function. + if (code === 1308) return false; // TS2691: An import path cannot end with a '.ts' extension. Consider // importing 'bad-module' instead. if (code === 2691) return false;