Skip to content

Commit 0f063dc

Browse files
feat: better print property node (prettier#567)
1 parent d399810 commit 0f063dc

4 files changed

Lines changed: 120 additions & 1 deletion

File tree

β€Žsrc/printer.jsβ€Ž

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,17 @@ function printNode(path, options, print) {
14221422
node.isStatic ? "static " : "",
14231423
"$",
14241424
node.name,
1425-
node.value ? concat([" = ", path.call(print, "value")]) : ""
1425+
node.value
1426+
? concat([
1427+
" =",
1428+
printAssignmentRight(
1429+
node.name,
1430+
node.value,
1431+
path.call(print, "value"),
1432+
options
1433+
)
1434+
])
1435+
: ""
14261436
])
14271437
);
14281438
case "interface":
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`property.php 1`] = `
4+
<?php
5+
6+
class Foo
7+
{
8+
var $var0 = 'foo';
9+
public $var1 = 'hello ' . 'world';
10+
public $var1_0 = 'veryVeryVeryVeryVeryLongString ' . 'veryVeryVeryVeryVeryLongString';
11+
public $var1_1 = 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString ' . 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
12+
public $var2 = <<<EOD
13+
hello world
14+
EOD;
15+
public $var3 = 1+2;
16+
public $var6 = myConstant;
17+
public $var7 = array(true, false);
18+
public $var7_1 = [true, false];
19+
public $var7_2 = ['key' => 'value', 'other_key' => 'other_value'];
20+
public $var7_3 = ['very_very_very_long_key' => 'very_very_very_long_value', 'very_very_very_long_other_key' => 'very_very_very_long_other_value'];
21+
public $var8 = <<<'EOD'
22+
hello world
23+
EOD;
24+
public $var9 = 11111111111111111111111111111111111111111111111111111111111111111111;
25+
public $var10 = 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
26+
public $var11 = true;
27+
public $public = 'Public';
28+
protected $protected = 'Protected';
29+
private $private = 'Private';
30+
public $prop;
31+
private static $static_property;
32+
public static $my_static = 'foo';
33+
static $my_static_1 = 'foo';
34+
public static $my_public_static='bar';
35+
}
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
<?php
38+
39+
class Foo
40+
{
41+
public $var0 = 'foo';
42+
public $var1 = 'hello ' . 'world';
43+
public $var1_0 =
44+
'veryVeryVeryVeryVeryLongString ' . 'veryVeryVeryVeryVeryLongString';
45+
public $var1_1 =
46+
'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString ' .
47+
'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
48+
public $var2 = <<<EOD
49+
hello world
50+
EOD;
51+
public $var3 = 1 + 2;
52+
public $var6 = myConstant;
53+
public $var7 = array(true, false);
54+
public $var7_1 = [true, false];
55+
public $var7_2 = ['key' => 'value', 'other_key' => 'other_value'];
56+
public $var7_3 = [
57+
'very_very_very_long_key' => 'very_very_very_long_value',
58+
'very_very_very_long_other_key' => 'very_very_very_long_other_value'
59+
];
60+
public $var8 = <<<'EOD'
61+
hello world
62+
EOD;
63+
public $var9 = 11111111111111111111111111111111111111111111111111111111111111111111;
64+
public $var10 = 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
65+
public $var11 = true;
66+
public $public = 'Public';
67+
protected $protected = 'Protected';
68+
private $private = 'Private';
69+
public $prop;
70+
private static $static_property;
71+
public static $my_static = 'foo';
72+
static $my_static_1 = 'foo';
73+
public static $my_public_static = 'bar';
74+
}
75+
76+
`;

β€Žtests/property/jsfmt.spec.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname, ["php"]);

β€Žtests/property/property.phpβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
var $var0 = 'foo';
6+
public $var1 = 'hello ' . 'world';
7+
public $var1_0 = 'veryVeryVeryVeryVeryLongString ' . 'veryVeryVeryVeryVeryLongString';
8+
public $var1_1 = 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString ' . 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
9+
public $var2 = <<<EOD
10+
hello world
11+
EOD;
12+
public $var3 = 1+2;
13+
public $var6 = myConstant;
14+
public $var7 = array(true, false);
15+
public $var7_1 = [true, false];
16+
public $var7_2 = ['key' => 'value', 'other_key' => 'other_value'];
17+
public $var7_3 = ['very_very_very_long_key' => 'very_very_very_long_value', 'very_very_very_long_other_key' => 'very_very_very_long_other_value'];
18+
public $var8 = <<<'EOD'
19+
hello world
20+
EOD;
21+
public $var9 = 11111111111111111111111111111111111111111111111111111111111111111111;
22+
public $var10 = 'veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString';
23+
public $var11 = true;
24+
public $public = 'Public';
25+
protected $protected = 'Protected';
26+
private $private = 'Private';
27+
public $prop;
28+
private static $static_property;
29+
public static $my_static = 'foo';
30+
static $my_static_1 = 'foo';
31+
public static $my_public_static='bar';
32+
}

0 commit comments

Comments
 (0)