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

SWC misunderstands precedence when using yield* expression #5530

Closed
danieltroger opened this issue Aug 17, 2022 · 3 comments · Fixed by #5533
Closed

SWC misunderstands precedence when using yield* expression #5530

danieltroger opened this issue Aug 17, 2022 · 3 comments · Fixed by #5533
Labels
Milestone

Comments

@danieltroger
Copy link

danieltroger commented Aug 17, 2022

Describe the bug

Given this expression yield* (0, async_iterator) SWC will remove the parentheses and turn it into yield* 0, async_iterator, probably in an effort to remove bytes.

However, the precedence makes that actually say (yield* 0), async_iterator which is wrong and causing issues.

Input code

async function* level1(){
  yield 1;
  yield 2;
  yield 3;
}

async function* level2(){
  yield* (0, level1());
}

(async () => {
for await(const v of level2()){
  console.log(v);
}
})();

Config

Using parcel, I can share parcel config if needed. The issue is also reproducible on the REPL, please see attached link.

Playground link

https://play.swc.rs/?version=1.2.237&code=H4sIAAAAAAAAA23MwQrCMBCE4XueYo67RcTWY9B3CTGRwJIFGyOl9N2LEaIHb8PA%2F7l5yR7xmX1JmgdIqEFG4tUASwpyw2j7nL7zbM1mjPtXTz%2F1ADodOsotok9FjMsVq4n6gHu5VMhrngsqNHaoSe9fJRxF71SbsTGx3QGHOfQjuwAAAA%3D%3D&config=H4sIAAAAAAAAA02OsQ6DMAxEfwV5ZmgZOjB37UdYwUGpQoxsFxWh%2FHsTCmo3%2B3z3fBs81UG%2FwYyiJHXSNRm%2BoQdbZ1InYTZowbRIHqNSLotgUs8yVX%2BkEd16J8eCxgVh8qIWhlN4kOGAhn9xlJGsfCDtLt210COz0mFoYQop%2BLWyHU%2BzkOrvhGmMpzMX1sTDqwrbXndn3iD%2FGEcu6OMwfttRWvbM3qTgIaJac218EPL8bhYSDZwg5w%2Bx293IIgEAAA%3D%3D

Expected behavior

When exececuted, logs

1
2
3

to the console

Expected output code by SWC:

async function* level1() {
    yield 1;
    yield 2;
    yield 3;
}
async function* level2() {
    yield* (0, level1());
}
(async ()=>{
    for await (const v of level2()){
        console.log(v);
    }
})();

Actual behavior

When executed throws with: Uncaught (in promise) TypeError: 0 is not iterable

Actual output code by SWC:

async function* level1() {
    yield 1;
    yield 2;
    yield 3;
}
async function* level2() {
    yield* 0, level1();
}
(async ()=>{
    for await (const v of level2()){
        console.log(v);
    }
})();

Version

1.2.237

Additional context

This only happened by "doing a second pass" of SWC I guess?
So we built code to a library using parcel (parcel build with scope hoisting). Then we included that library in a project and built (parcel serve) it again and everything fell apart due to the aforementioned issue.

@danieltroger
Copy link
Author

Thank you for the quick fix! @mischnic should I open a parcel issue to bump SWC version?

@kdy1 kdy1 modified the milestones: Planned, v1.2.238, v1.2.239 Aug 17, 2022
@mischnic
Copy link
Contributor

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 16, 2022

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 Oct 16, 2022
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.

4 participants