Skip to content

Commit 6ce4e8a

Browse files
authored
fix: don't parenthesize assign inside static variable declaration (#2463)
1 parent bc9ff79 commit 6ce4e8a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/needs-parens.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function needsParens(path, options) {
166166
return false;
167167
} else if (parent.kind === "assign") {
168168
return false;
169-
} else if (parent.kind === "static") {
169+
} else if (parent.kind === "staticvariable") {
170170
return false;
171171
} else if (
172172
["if", "do", "while", "foreach", "switch"].includes(parent.kind)

tests/static/__snapshots__/jsfmt.spec.mjs.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`static.php 1`] = `
44
====================================options=====================================
@@ -43,6 +43,8 @@ string
4343
string', $b = 'string
4444
string
4545
string';
46+
static $x = $a = 1;
47+
static $x = $a = $b = 1;
4648
4749
=====================================output=====================================
4850
<?php
@@ -121,6 +123,8 @@ string',
121123
$b = 'string
122124
string
123125
string';
126+
static $x = $a = 1;
127+
static $x = $a = $b = 1;
124128
125129
================================================================================
126130
`;

tests/static/static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
string', $b = 'string
3636
string
3737
string';
38+
static $x = $a = 1;
39+
static $x = $a = $b = 1;

0 commit comments

Comments
 (0)