Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ function isSimpleCallArgument(node, depth = 2) {

return (
parts.length <= depth &&
(node.arguments ?? []).every(isChildSimple) &&
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my understanding, does any of the new test cases cover this new bit of logic?

parts.every((node) =>
isLookupNode(node)
? isChildSimple(node.offset)
Expand Down
14 changes: 14 additions & 0 deletions tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ $var = Foo::keys($items)->filter(function ($x) { return $x > 2; })->map(function
VarDumper::dump($item);
});

$a->foo(get())->bar()->baz();
$a->foo($b->method())->bar()->baz();
$a->foo(fn() => 1)->bar()->baz();
$a->foo(fn($x) => $x * 2)->bar()->baz();
$a->foo(get(inner(deepest())))->bar()->baz();

=====================================output=====================================
<?php

Expand Down Expand Up @@ -593,6 +599,14 @@ new static(func_get_args())
VarDumper::dump($item);
});

$a->foo(get())->bar()->baz();
$a->foo($b->method())->bar()->baz();
$a->foo(fn() => 1)->bar()->baz();
$a->foo(fn($x) => $x * 2)->bar()->baz();
$a->foo(get(inner(deepest())))
->bar()
->baz();

================================================================================
`;

Expand Down
6 changes: 6 additions & 0 deletions tests/member_chain/member_chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@
(new static(func_get_args()))->offset(10)->push($this)->each(function ($item) {
VarDumper::dump($item);
});

$a->foo(get())->bar()->baz();
$a->foo($b->method())->bar()->baz();
$a->foo(fn() => 1)->bar()->baz();
$a->foo(fn($x) => $x * 2)->bar()->baz();
$a->foo(get(inner(deepest())))->bar()->baz();
Loading