-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Incorrect polyfill __knownSymbol lookups for Symbol.dispose (and probably others) #3920
Comments
Sorry, I don't understand. You need to polyfill Symbol.dispose ??= Symbol("Symbol.dispose");
function demo() {
class Foo {
constructor() { console.log('constructor') }
[Symbol.dispose]() { console.log('dispose') }
}
using foo = new Foo
}
demo() If you build this with esbuild and run it, it will output the following:
So everything already appears to be working correctly. This happens because You have to polyfill
|
@evanw Thank you for the clarification. UPD: Symbol.dispose ??= Symbol.for('Symbol.dispose') |
Problem statement
Esbuild uses
__knownSymbol
in generated code forSymbol
lookups, that relies onSymbol.for()
esbuild/internal/runtime/runtime.go
Line 78 in d34e79e
However, the property
dispose
does not get set on globalSymbol
by the generated code.This results in
Symbol.dispose
resolving toundefined
in the generated code, thus making the objects non-disposable.Which further causes the
TypeError: Object not disposable
runtime error (Firefox 131.0b9 & Chromium 129.0.6668.58 tested, but sure the others will fail as well). Error is produced by this fragment:esbuild/internal/runtime/runtime.go
Lines 510 to 514 in d34e79e
Temporary (and hackish) solutions right now
One possible solution will be to polyfill the
Symbol.dispose
in TS ourselves, like the following:But:
Symbol(key)
is guaranteed to return a distinct object every time, even for the same keyProper fix proposal
Add to the generated code a procedure to test&set
dispose
property onSymbol
object, something like:Examples
Generated code (as of now):
esbuild dispose.ts --target=es2022 --outfile=dispose.js
Please find the TS input and the corresponding Esbuild JS output attached
(built with
esbuild dispose.ts --target=es2022 --outfile=dispose.out.js
) :dispose.ts.txt
dispose.out.js.txt
The text was updated successfully, but these errors were encountered: