diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-09-14 14:08:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 18:08:59 +0000 |
commit | 6dc8682b9acabea56fd69a25c28b6a8f95c2ce26 (patch) | |
tree | 944784e77b1008bd2bc3e2673927ddf6f896c5c6 /cli/tests | |
parent | e66d3c2c2e287879a757e12943a6d240981cb9e8 (diff) |
feat: explicit resource management in TypeScript (#20506)
This adds support for `using` and `await using` declarations in
TypeScript only. We need to wait for v8 to support it for this to work
in JS.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/run_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/run/explicit_resource_management/main.out | 5 | ||||
-rw-r--r-- | cli/tests/testdata/run/explicit_resource_management/main.ts | 21 |
3 files changed, 31 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index be9bc554a..0a5e86b1f 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -4701,3 +4701,8 @@ console.log(returnsHi());"#, ") .assert_exit_code(1); } + +itest!(explicit_resource_management { + args: "run --quiet --check run/explicit_resource_management/main.ts", + output: "run/explicit_resource_management/main.out", +}); diff --git a/cli/tests/testdata/run/explicit_resource_management/main.out b/cli/tests/testdata/run/explicit_resource_management/main.out new file mode 100644 index 000000000..ff5ac4b59 --- /dev/null +++ b/cli/tests/testdata/run/explicit_resource_management/main.out @@ -0,0 +1,5 @@ +A +Disposed +B +Async disposed +C diff --git a/cli/tests/testdata/run/explicit_resource_management/main.ts b/cli/tests/testdata/run/explicit_resource_management/main.ts new file mode 100644 index 000000000..0201a51f9 --- /dev/null +++ b/cli/tests/testdata/run/explicit_resource_management/main.ts @@ -0,0 +1,21 @@ +class Resource { + [Symbol.dispose]() { + console.log("Disposed"); + } +} +class AsyncResource { + async [Symbol.asyncDispose]() { + await new Promise((resolve) => setTimeout(resolve, 10)); + console.log("Async disposed"); + } +} + +{ + using resource = new Resource(); + console.log("A"); +} +{ + await using resource = new AsyncResource(); + console.log("B"); +} +console.log("C"); |