Skip to content
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

using in a for... of loop fails to call Symbol.dispose method (+ same problem for async versions) #25757

Open
lionel-rowe opened this issue Sep 20, 2024 · 1 comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues

Comments

@lionel-rowe
Copy link
Contributor

Version: Deno 1.46.3

I initially thought this was a bug with TS, but compiling TS via the playground and running it in Chrome works correctly, as does running it in Bun.

Using using within a for... of loop fails to call the Symbol.dispose method. The same problem occurs when using awaiting using using await using using Symbol.asyncDispose:

class Disposable {
    disposed = false;

    [Symbol.dispose]() {
        this.disposed = true
    }
}

const disposables = [new Disposable()]

for (using _ of disposables) {/* ... */}

if (disposables[0]!.disposed) {
    console.log("✅ dispose ok")
} else {
    console.error("💥 failed to dispose")
}

class AsyncDisposable {
    disposed = false;

    [Symbol.asyncDispose]() {
        this.disposed = true
    }
}

const asyncDisposables = [new AsyncDisposable()]

for (await using _ of asyncDisposables) {/* ... */}

if (asyncDisposables[0]!.disposed) {
    console.log("✅ async dispose ok")
} else {
    console.error("💥 failed to async dispose")
}

Keywords: using, using using, using await using, awaiting using await using

@lucacasonato lucacasonato added bug Something isn't working correctly upstream Changes in upstream are required to solve these issues swc related to swc (bundling/transpiling) labels Sep 20, 2024
@marvinhagemeister
Copy link
Contributor

Seems like an SWC transpilation issue. I've put the reproduction code into their playground and the transpiled output matches exactly what we run in Deno. Running the transpiled output on its own inhibits the described error and the dispose hooks aren't called.

Filed an upstream issue here swc-project/swc#9576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling) upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

3 participants