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

fix(es/compat): Hoist arguments in object method while lowering async functions #10167

Merged
merged 3 commits into from
Mar 10, 2025

Conversation

magic-akari
Copy link
Member

@magic-akari magic-akari requested a review from a team as a code owner March 8, 2025 13:49
@magic-akari
Copy link
Member Author

magic-akari commented Mar 8, 2025

During my investigation of this issue, I discovered that esbuild employs a more streamlined approach compared to Babel. Rather than hoisting this and arguments, esbuild directly passes the current this and arguments to the function __async, then utilizes apply internally to properly bind them.

Here's a code example demonstrating this approach:

var foo = {
  bar(_0) {
    return __async(this, arguments, function* ({ name }) {
      console.log("arguments.length", arguments.length);
    });
  }
};

This optimization eliminates the hoisting process for this and arguments, though super references still require hoisting. I'm currently evaluating the possibility of adopting esbuild's transformation strategy for our implementation.


Maybe in another PR.

@kdy1 kdy1 self-assigned this Mar 9, 2025
@kdy1 kdy1 added this to the Planned milestone Mar 9, 2025
kdy1
kdy1 previously approved these changes Mar 9, 2025
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset bot is refusing to work 🤣
I'll add them manually

@Austaras
Copy link
Member

Austaras commented Mar 9, 2025

Why isn't this implemented using FnEnvHoister?

@kdy1 kdy1 requested a review from a team as a code owner March 10, 2025 03:03
Copy link

changeset-bot bot commented Mar 10, 2025

🦋 Changeset detected

Latest commit: 96ef752

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kdy1 kdy1 merged commit e764df2 into swc-project:main Mar 10, 2025
18 checks passed
@kdy1
Copy link
Member

kdy1 commented Mar 10, 2025

Oh I forgot the comment. @magic-akari Is there a particular reason?

@magic-akari
Copy link
Member Author

Oh I forgot the comment. @magic-akari Is there a particular reason?

Are you referring to esbuild's approach?
From my observations, esbuild's output tends to be more consistent and simpler than Babel's across various scenarios.
I generally favor simpler implementations as they tend to be easier to maintain and less prone to bugs.

@magic-akari
Copy link
Member Author

Why isn't this implemented using FnEnvHoister?

Do you mean wasn't? It is implemented using FnEnvHoister now.
I have no idea why it wasn't implemented that way originally. It might have simply been overlooked.

@kdy1
Copy link
Member

kdy1 commented Mar 10, 2025

Sorry, you are right. Now it uses the FnEnvHoister and I think the previous implementation is from old days.

@magic-akari magic-akari deleted the fix/issue-10149 branch March 10, 2025 05:47
@Austaras
Copy link
Member

Do you mean wasn't? It is implemented using FnEnvHoister now. I have no idea why it wasn't implemented that way originally. It might have simply been overlooked.

That's good.

From my observations, esbuild's output tends to be more consistent

I don't like apply and bind. IIRC they may introduce some nasty problems.

@kdy1 kdy1 modified the milestones: Planned, v1.11.9 Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

arguments is not transform correct in async function
3 participants