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

Wrong transpilation: return inside while from ES5-transpiled generator/async functions #7622

Closed
mlcui-corp opened this issue Jul 4, 2023 · 1 comment · Fixed by #7624
Closed
Assignees
Labels
Milestone

Comments

@mlcui-corp
Copy link

Describe the bug

return obj; inside a while in ES5-transpiled generators are not being transpiled to return [2, obj];, potentially causing infinite loops. As async functions are transpiled using generators, this also affects async functions.

(Thank you oka@chromium.org for finding this bug: https://crrev.com/c/4659623)

Input code

async function asyncWhile() {
    while (true) {
        return {};
    }
}

function* generatorWhile() {
    while (true) {
        return {};
    }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAA0ssrsxLVkgrzUsuyczPU0gEccMzMnNSNTQVqrkUgKAcxFPQKCkqTYUJgUBRaklpUZ5Cda01WKiWq5aLC2aMlkJ6al5qUWJJfhG5ZgEALxL9bJgAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BCIOhERP9mOVBTl7oUE0maH3xszsA5KwcwGnmotxzIkTYx0ziXhHER%2FSgKSE7IhmwRuvRWu1agd4x5tRwOiaUKpW8j3hoOLkbHjLfM22DH%2FC030iZD5ClZUh8nhVTc0Jfj4XvayfaQ%2B9tA%2F4Ad12XkxWH71TaEFh%2B0LYuVI0xQBAAA%3D

Expected behavior

Both functions in the example immediately return an empty object after calling .next() / awaiting.

Actual behavior

Both functions in the example run infinitely.

Version

1.3.66

Additional context

No response

@kdy1 kdy1 self-assigned this Jul 4, 2023
@kdy1 kdy1 added this to the Planned milestone Jul 4, 2023
@kdy1 kdy1 closed this as completed in #7624 Jul 6, 2023
kdy1 added a commit that referenced this issue Jul 6, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.69 Jul 13, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 12, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants