Skip to content

fix(transform-shaker): preserve class field initializers during tree-shaking#833

Open
layershifter wants to merge 2 commits intomainfrom
fix/shaker-class-field-initializers
Open

fix(transform-shaker): preserve class field initializers during tree-shaking#833
layershifter wants to merge 2 commits intomainfrom
fix/shaker-class-field-initializers

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented Apr 8, 2026

Summary

  • The shaker's dependency graph was missing edges from PropertyDefinition nodes to their value children
  • Since PropertyDefinition is not an expression, baseVisit didn't add dependency edges automatically
  • This caused class field initializers to be removed while keeping the = sign, producing invalid syntax like field = ; which then failed in convertESMtoCJS

Root cause fix: add explicit edges from PropertyDefinition to key/value in the Class visitor, matching how ObjectExpression handles properties.

Safety net: when removing a dead PropertyDefinition value, also remove the preceding = to avoid producing invalid syntax even if the graph is incomplete.

Test plan

  • Added test: preserves class field initializers when class is alive
  • All existing shaker tests pass (35 + 1 new)
  • All transform tests pass (79)
  • Verified end-to-end: shaker → convertESMtoCJS pipeline succeeds on the failing file

🤖 Generated with Claude Code

@layershifter layershifter requested a review from a team as a code owner April 8, 2026 11:56
…shaking

The shaker's dependency graph was missing edges from PropertyDefinition nodes
to their value children. Since PropertyDefinition is not an expression,
baseVisit didn't add dependency edges automatically. This caused class field
initializers to be removed while keeping the `=` sign, producing invalid
syntax like `field = ;`.

Root cause fix: add explicit edges from PropertyDefinition to key/value in
the Class visitor, matching how ObjectExpression handles properties.

Safety net: when removing a dead PropertyDefinition value, also remove the
preceding `=` to avoid producing invalid syntax even if the graph is wrong.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

📊 Bundle size report

✅ No changes found

@layershifter layershifter force-pushed the fix/shaker-class-field-initializers branch from cf933fd to db0567f Compare April 8, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant