Skip to content

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

Merged
kdy1 merged 3 commits intoswc-project:mainfrom
magic-akari:fix/issue-10149
Mar 10, 2025
Merged

fix(es/compat): Hoist arguments in object method while lowering async functions#10167
kdy1 merged 3 commits intoswc-project:mainfrom
magic-akari:fix/issue-10149

Conversation

@magic-akari
Copy link
Copy Markdown
Member

@magic-akari magic-akari requested a review from a team as a code owner March 8, 2025 13:49
@magic-akari
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@changeset-bot
Copy link
Copy Markdown

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
@kdy1
Copy link
Copy Markdown
Member

kdy1 commented Mar 10, 2025

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

@magic-akari
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

arguments is not transform correct in async function

3 participants