Skip to content

fix: dispose polyfill fallback logic #4

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

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/tcpip/polyfills/disposable.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/**
* Scoped polyfill for `Symbol.dispose` and `Symbol.asyncDispose` without
* polluting the global scope. Required for the `using` keyword which we
* use internally.
* Scoped polyfill for `Symbol.dispose` without polluting the global scope.
* Required for the `using` keyword which we use internally.
*
* We export these symbols as 'Symbol.dispose' and 'Symbol.asyncDispose'
* which tells ESBuild to inject them into the output bundle.
* We export this symbol as 'Symbol.dispose' which tells ESBuild to inject
* it into the output bundle.
*
* The below works because Typescript's `using` implementation falls back to
* `Symbol.for("Symbol.dispose")` and `Symbol.for("Symbol.asyncDispose")` if the
* built-in `Symbol.dispose` and `Symbol.asyncDispose` are not available.
* `Symbol.for("Symbol.dispose")` if the built-in `Symbol.dispose` is not available.
*/

const DisposeSymbol = Symbol.for('Symbol.dispose');
const AsyncDisposeSymbol = Symbol.for('Symbol.asyncDispose');
const DisposeSymbol = 'dispose' in (Symbol as object) ? Symbol.dispose : Symbol.for('Symbol.dispose');

export {
DisposeSymbol as 'Symbol.dispose',
AsyncDisposeSymbol as 'Symbol.asyncDispose'
DisposeSymbol as 'Symbol.dispose'
};