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 has a tick too much in transpiled for await resulting in different output after transpiling #1918

Closed
danieltroger opened this issue Jul 14, 2021 · 8 comments · Fixed by #2055
Assignees
Labels
Milestone

Comments

@danieltroger
Copy link

danieltroger commented Jul 14, 2021

Describe the bug

This exact bug: babel/babel#13490 but for SWC.

See this, output after transpiling and before transpiling should be the same:

daniel@Daniels-MacBook-Pro swc-for-await % node dist/ie11.js 
0
daniel@Daniels-MacBook-Pro swc-for-await % node src/main.ts 
0
1

Input code

let resolve;
let promise = new Promise((r) => (resolve = r));
let iterable = {
  [Symbol.asyncIterator]() {
    return {
      next() {
        return promise;
      },
    };
  },
};

(async () => {
  for await (let value of iterable) {
    console.log(value);
  }
})();

(async function () {
  resolve({ value: 0, done: false });
  promise = new Promise((r) => (resolve = r));

  await null;
  resolve({ value: 1, done: false });
  promise = new Promise((r) => (resolve = r));

  resolve({ value: undefined, done: true });
})();

Config

{
  "env": {
    "shippedProposals": true
  }
}

Expected behavior
Expected behavior is for the code above to output

0
1

like it does untranspiled.

Version

@swc/cli: 0.1.46
@swc/core: 1.2.63

Additional context
I use SWC with parcel

Simple reproduction repository with SWC (kudos to @mischnic):
swc-for-await-repro.zip

Reproduction with parcel using SWC:
swc-for-await.zip

@kdy1
Copy link
Member

kdy1 commented Jul 14, 2021

I was aware of such bug as you mentioned in the babel issue, but I prefer waiting for the babel team because I want to align the helper scripts.

@danieltroger
Copy link
Author

@kdy1 could you please review this pull request then for them? babel/babel#13491 they're just waiting for a review so they can merge

@kdy1
Copy link
Member

kdy1 commented Jul 14, 2021

I'm not a babel expert, so I expect my review to be helpless.
(I barely looked at the babel source code while building swc)

@danieltroger
Copy link
Author

You know how async transpilation works and I therefore think you're one of the few people that even understand what the changes are. I think they're not merging because there's like one more person on the planet that knows what it's about and they're on vacation.

@kdy1
Copy link
Member

kdy1 commented Jul 15, 2021

But I don't want to do it.
It does not seem to be an interesting task.

@danieltroger
Copy link
Author

I see, that's fair

@kdy1 kdy1 modified the milestones: v1.2.65, v1.2.66, v1.2.67 Jul 16, 2021
@sachinraja
Copy link

Update: that PR has now been merged

@kdy1 kdy1 modified the milestones: v1.2.67, v1.2.68, v1.2.72, v1.2.73, v1.2.74, v1.2.75 Jul 31, 2021
@kdy1 kdy1 modified the milestones: v1.2.75, v1.2.76, v1.2.77 Aug 8, 2021
@kdy1 kdy1 self-assigned this Aug 11, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 12, 2021
kdy1 added a commit that referenced this issue Aug 12, 2021
swc_ecma_parser:
 - Fix panic from span assertion. (#2040)

swc_ecma_transforms_compat:
 - Fix handling of `await for`. (#1918)

swc_ecma_transforms_base:
 - Allow using decorator metadata even if `reflect-metadata` is not imported. (#1362)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 22, 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 22, 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