Skip to content

fix(es/decorators): drop params from getter replacing decorated private method - #12161

Merged
Donny/강동윤 (kdy1) merged 2 commits into
swc-project:mainfrom
ken7253:fix/decorators-private-method-getter-params
Aug 28, 2026
Merged

fix(es/decorators): drop params from getter replacing decorated private method#12161
Donny/강동윤 (kdy1) merged 2 commits into
swc-project:mainfrom
ken7253:fix/decorators-private-method-getter-params

Conversation

@ken7253

Copy link
Copy Markdown
Contributor

Description:

Decorating a private method rewrites it into a private getter returning the extracted call target. The rewrite reset is_async and is_generator but not params, so a method with parameters produced an invalid getter:

class Foo {
  @dec
  #a(x, y) {
    return x + y;
  }
}
get #a(x, y) {  // SyntaxError: Getter must not have any formal parameters
    return _call_a;
}

Clearing params on the switch to MethodKind::Getter fixes it. The parameters remain on the extracted function.

No existing test caught this: codegen emits Function::params regardless of MethodKind, and the parser's GetterParam check is a recoverable error the fixture harness discards. Only running the output surfaces it, so the 2023-11 fixture includes an exec case.

Related issue (if exists):

None

ken7253 (ken7253) and others added 2 commits August 27, 2026 00:38
…te method

A decorated private method is rewritten into a private getter that returns
the extracted call target. The rewrite reset `is_async` and `is_generator`
but left `params` untouched, so a method declared with parameters produced
a getter with formal parameters:

    get #a(x, y) { return _call_a; }

which is a SyntaxError ("Getter must not have any formal parameters").

Nothing in the swc pipeline caught this: the transform output is only
serialized by codegen, which emits `Function::params` regardless of
`MethodKind`, and the parser's `GetterParam` check is a recoverable error
that the fixture harness discards. Only running the emitted code in a real
engine surfaces it.

Clear `params` when switching the member to `MethodKind::Getter`. The
parameters stay on the extracted function, which is where they belong.

Covered by new `private-with-params` fixtures for both decorator versions
(plain, default + rest, destructuring, and static parameters), including an
exec fixture that runs the output.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ken7253
ken7253 (ken7253) requested review from a team as code owners August 26, 2026 16:24
@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 21db9d6

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

@codspeed-hq

codspeed-hq Bot commented Aug 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 200 untouched benchmarks
⏩ 61 skipped benchmarks1


Comparing ken7253:fix/decorators-private-method-getter-params (21db9d6) with main (f6d5bd1)2

Open in CodSpeed

Footnotes

  1. 61 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (7a29dc7) during the generation of this report, so f6d5bd1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@CLAassistant

CLAassistant commented Aug 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kdy1
Donny/강동윤 (kdy1) merged commit d56f594 into swc-project:main Aug 28, 2026
82 checks passed
@github-actions github-actions Bot added this to the Planned milestone Aug 28, 2026
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.

3 participants