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

Bug: dispose hooks not called with using keyword #9576

Closed
marvinhagemeister opened this issue Sep 20, 2024 · 2 comments · Fixed by #9585
Closed

Bug: dispose hooks not called with using keyword #9576

marvinhagemeister opened this issue Sep 20, 2024 · 2 comments · Fixed by #9585
Assignees
Labels
Milestone

Comments

@marvinhagemeister
Copy link
Contributor

Describe the bug

Investigation denoland/deno#25757 lead to realizing that the transpilation of the using keyword in SWC doesn't seem to call the dispose hooks when inside a loop. Running the reproduction snippet should log that all dispose methods are called, but they're never called with the transpiled variant.

Input code

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")
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "transform": {
      "react": {
        "importSource": "npm:react",
        "runtime": "automatic"
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.26&code=H4sIAAAAAAAAA52QPW4CMRCFe59itJWXwtAjiki5AeVqFZnFS6w4O5HHCCG0JRegRkqVi%2BUEOQKzDj%2FeFUWIO%2FvNm%2Bf3VU4TwbOlDyS9cAZ2AmAZr2YJM6i1IzMV%2FFjMt%2B8LdOosljKPs90Jr5ZUYgp%2BbVhqRStEhQ2F88YugFgvGrNJMmVeClGjB7km26zgBbBOHRw0HoFSCkZj3mhrkIlaTMpr9u%2BXukh0Rjlcyez7uL%2F0AXzLctGC4Uq9QeM9epn9fB6%2BuLB1XCLgxdVZuEbk9ETbpnoElr4ZHiSm%2B1FXbIMv3NjpjbYBEoLDDXcwDkf%2BwDJa%2Fkm0541cT19Nfi1%2FAgAA&config=H4sIAAAAAAAAA1WQPQ7CMAyFd05ReWZAHRi4AxMnsIJbBTU%2Fsh2JCvXuJOn%2FEiXfe8%2BO%2Fbs0DXzEwKP55Wt%2BRGQh3t6ZyOgVv5mAjpHEsI0K11VVKZJyokqmWQBF7klLiKS9te0SgCEEoYw7HIQW5qy33XhsaYKLTCJnY7Gi74ctf%2B7I6KUL7I6FmNDoAWRkXQysr5DYlELgo3vMtutu4uTVuqpj0uBQrYFFni7rWVuDC%2B9U%2F7RssGxpHvwOu2mdcZsHrDzXZF3f9Ae8XWptjQEAAA%3D%3D

SWC Info output

No response

Expected behavior

The reproduction snippet should log out that the dispose hooks are called.

Actual behavior

No response

Version

1.7.26

Additional context

No response

@jtbandes
Copy link

Was this actually fixed? I am still seeing issues in 1.7.39: #9673

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants