Minification removes class identifiers causing observable runtime change in Class.name
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript
- 領域
- build-system, tooling
調査の方向性
Start with the linked StackBlitz reproduction and inspect dist/main.js to confirm how the named class is transformed and how its name is observed at runtime. Review @rollup/plugin-terser's handling of class names and the documented keep_classnames workaround; done means the production output no longer causes the reported runtime difference, with regression coverage for class and constructor names.
索引モデルが issue の本文から書いたものです。
説明
- Rollup Plugin Name: @rollup/plugin-terser
- Rollup Plugin Version: 1.0.0
- Rollup Version: 4.59.0
- Operating System (or Browser): any
- Node Version: 22.19.0
- Link to reproduction: https://stackblitz.com/edit/rollup-repro-dxhgy1x9?file=dist%2Fmain.js
Description
When using @rollup/plugin-terser, named class declarations are transformed into anonymous class expressions during minification. This causes clazz.name and this.constructor.name to return an empty string ("") instead of the original class name. This results in observable runtime differences between development and production builds.
Behavior
Terser removes the class identifier and converts:
class MyClass {}
into:
class {}
This creates an anonymous class expression.
According to the ECMAScript specification:
ClassDeclaration → has a name
Anonymous ClassExpression → name === ""
Therefore:
clazz.name === ""
this.constructor.name === ""
Why This Is Problematic
This is not just cosmetic minification.
Class.name and constructor.name are frequently used for:
- logging
- debugging
- dependency injection
- metadata systems
- serialization
- runtime introspection
This creates:
- different runtime behavior in dev vs prod
- silent semantic changes
- hard-to-debug production issues
Important Note
I understand that Terser does not guarantee preservation of Function.name.
However, this transformation introduces observable semantic differences between builds, not just identifier mangling.
Workaround
Setting:
terser({ keep_classnames: true })
preserves the expected behavior.
- 主要言語
- JavaScript
- スター
- 3.8k
- フォーク
- 635
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rollup/plugins のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
Support js-yaml v5 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
getsentry/sentry-javascript#24577 · コメント 1 件 ·
-
curation good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
amponce/archive-movie-browser#186 ·
-
light
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
aemdemos/patients-stryker#253 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
clerk/javascript#9852 ·