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
4 changes: 4 additions & 0 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,10 @@ function printNode(path, options, print) {
parent.curly) ||
(parentParent &&
parent.kind === "offsetlookup" &&
// Only the base variable of the lookup follows the `${` printed
// by the encapsedpart; a variable in the offset position is a
// nested variable and keeps its own `$`.
parent.what === node &&
parentParent.kind === "encapsedpart" &&
parentParent.syntax === "simple" &&
parentParent.curly)
Expand Down
4 changes: 4 additions & 0 deletions tests/encapsed/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ echo "text \${foo['foo']} text";
echo "text \${foo[foo]} text";
echo "text \${foo[call()]} text";
echo "text \${foo[$var ? 'foo' : 'bar']} text";
echo "text \${foo[$index_var]} text";

// T_CURLY_OPEN variable '}'
echo "text {$var} text";
Expand Down Expand Up @@ -952,6 +953,7 @@ echo "text \${foo["foo"]} text";
echo "text \${foo[foo]} text";
echo "text \${foo[call()]} text";
echo "text \${foo[$var ? "foo" : "bar"]} text";
echo "text \${foo[$index_var]} text";

// T_CURLY_OPEN variable '}'
echo "text {$var} text";
Expand Down Expand Up @@ -1449,6 +1451,7 @@ echo "text \${foo['foo']} text";
echo "text \${foo[foo]} text";
echo "text \${foo[call()]} text";
echo "text \${foo[$var ? 'foo' : 'bar']} text";
echo "text \${foo[$index_var]} text";

// T_CURLY_OPEN variable '}'
echo "text {$var} text";
Expand Down Expand Up @@ -1988,6 +1991,7 @@ echo "text \${foo["foo"]} text";
echo "text \${foo[foo]} text";
echo "text \${foo[call()]} text";
echo "text \${foo[$var ? "foo" : "bar"]} text";
echo "text \${foo[$index_var]} text";

// T_CURLY_OPEN variable '}'
echo "text {$var} text";
Expand Down
1 change: 1 addition & 0 deletions tests/encapsed/encapsed.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ function foo1(
echo "text ${foo[foo]} text";
echo "text ${foo[call()]} text";
echo "text ${foo[$var ? 'foo' : 'bar']} text";
echo "text ${foo[$index_var]} text";

// T_CURLY_OPEN variable '}'
echo "text {$var} text";
Expand Down