Skip to content

fix: avoid adding parens to static property in new expression#2453

Open
fs0414 wants to merge 2 commits intoprettier:mainfrom
fs0414:issue2441/new-parsed-static-prop
Open

fix: avoid adding parens to static property in new expression#2453
fs0414 wants to merge 2 commits intoprettier:mainfrom
fs0414:issue2441/new-parsed-static-prop

Conversation

@fs0414
Copy link

@fs0414 fs0414 commented Feb 5, 2026

Summary

Fixes #2441

When formatting code like new Yii::$app->class([]), the formatter was incorrectly adding parentheses to produce new Yii::$app()->class([]). This changes the semantics from accessing a static property (Yii::$app) to calling a static method (Yii::$app()).

Changes

  • Added logic in printer.mjs to skip adding parentheses for new expressions when:
    • The new is inside a member chain (parent is a lookup node or call)
    • The constructor has no arguments
    • The original source did not have parentheses
    • The target is a staticlookup (e.g., Yii::$app)

Test plan

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.

Bug: Prettier incorrectly adds parentheses when using new with a static property

1 participant