Skip to content

Commit 1f41bb6

Browse files
authored
fix: nullable property types (#1349)
1 parent e879554 commit 1f41bb6

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/printer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,9 @@ function printNode(path, options, print) {
17641764
case "property":
17651765
return group(
17661766
concat([
1767-
node.type ? concat([path.call(print, "type"), " "]) : "",
1767+
node.type
1768+
? concat([node.nullable ? "?" : "", path.call(print, "type"), " "])
1769+
: "",
17681770
"$",
17691771
path.call(print, "name"),
17701772
node.value

tests/class/__snapshots__/jsfmt.spec.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,9 @@ abstract class BaseClass extends MyOtherClass implements MyInterface, MyOtherInt
919919
class User {
920920
public int $id;
921921
public string $name;
922+
public ?string $b = 'foo';
923+
private Foo $prop;
924+
protected static string $static = 'default';
922925
923926
public function __construct(int $id, string $name) {
924927
$this->id = $id;
@@ -1420,6 +1423,9 @@ class User
14201423
{
14211424
public int $id;
14221425
public string $name;
1426+
public ?string $b = 'foo';
1427+
private Foo $prop;
1428+
protected static string $static = 'default';
14231429
14241430
public function __construct(int $id, string $name)
14251431
{

tests/class/class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ abstract class BaseClass extends MyOtherClass implements MyInterface, MyOtherInt
284284
class User {
285285
public int $id;
286286
public string $name;
287+
public ?string $b = 'foo';
288+
private Foo $prop;
289+
protected static string $static = 'default';
287290

288291
public function __construct(int $id, string $name) {
289292
$this->id = $id;

0 commit comments

Comments
 (0)