Skip to content

Commit 20337de

Browse files
rix0rrrgithub-actions
and
github-actions
authored
fix(toolkit): doesn't load on platforms without the Disposable API (#309)
Toolkit classes reference the public static `Symbol.asyncDispose` symbol, but that is only defined on runtimes that are implementing the new Disposable API yet. On platforms that don't know that API, that constant doesn't exist and the class definition fails. Polyfill it. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent 445fd71 commit 20337de

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/@aws-cdk/toolkit-lib/lib/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* @module toolkit-lib
33
*/
44

5+
// Polyfills first
6+
import './private/dispose-polyfill';
7+
58
// The main show
69
export * from './toolkit';
710
export * from './actions';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file needs to be imported as one of the first files in the library.
2+
// It polyfills some symbols that the new JavaScript "Disposable" API introduces.
3+
//
4+
// See <https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html>
5+
//
6+
// In short, the new proposal is a `using`/`await using` statement, which will automatically
7+
// call methods named `[Symbol.dispose]` and `[Symbol.asyncDispose]` on objects.
8+
//
9+
// TypeScript knows about those symbols, and it will downlevel the `using` syntax to
10+
// plain JavaScript... but it doesn't define the Symbols themselves! They must exist
11+
// in the environment, or code defining objects using those Symbol names will fail.
12+
//
13+
// MDN doesn't even know that Node 22 has them already; for broadest compatibility,
14+
// we just polyfill them here. Their value doesn't matter, they just need to exist
15+
// and be unique symbols.
16+
(Symbol as any).dispose ??= Symbol('Symbol.dispose');
17+
(Symbol as any).asyncDispose ??= Symbol('Symbol.asyncDispose');

0 commit comments

Comments
 (0)