Skip to content

Commit da8a86c

Browse files
authored
fix: formatter breaks php-view file contains phpdoc block and php short-tags (#1567)
* add tests reproducing the issue * fix: type of openTag for the first node shouldn't depend on kind of the next node * add test where file starts with shorttag
1 parent 7737511 commit da8a86c

5 files changed

Lines changed: 85 additions & 1 deletion

File tree

src/printer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ function printLines(path, options, print, childrenAttribute = "children") {
10291029
childNode.leadingComments && childNode.leadingComments.length
10301030
? concat([
10311031
isFirstNode && node.kind !== "namespace" && !isBlockNestedNode
1032-
? openTag
1032+
? "<?php"
10331033
: "",
10341034
node.kind === "namespace" || !isBlockNestedNode ? hardline : "",
10351035
comments.printComments(childNode.leadingComments, options),

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,74 @@ try {
23472347
================================================================================
23482348
`;
23492349

2350+
exports[`mixed-54.php 1`] = `
2351+
====================================options=====================================
2352+
parsers: ["php"]
2353+
printWidth: 80
2354+
| printWidth
2355+
=====================================input======================================
2356+
<?php
2357+
/**
2358+
* @var string $a
2359+
*/
2360+
?>
2361+
<?= $a ?>
2362+
<?php echo $a; ?>
2363+
2364+
=====================================output=====================================
2365+
<?php
2366+
/**
2367+
* @var string $a
2368+
*/
2369+
?>
2370+
<?= $a ?>
2371+
<?php echo $a; ?>
2372+
2373+
================================================================================
2374+
`;
2375+
2376+
exports[`mixed-55.php 1`] = `
2377+
====================================options=====================================
2378+
parsers: ["php"]
2379+
printWidth: 80
2380+
| printWidth
2381+
=====================================input======================================
2382+
<?php
2383+
/**
2384+
* @var string $a
2385+
*/
2386+
?>
2387+
<?php echo $a; ?>
2388+
<?= $a ?>
2389+
2390+
=====================================output=====================================
2391+
<?php
2392+
/**
2393+
* @var string $a
2394+
*/
2395+
?>
2396+
<?php echo $a; ?>
2397+
<?= $a ?>
2398+
2399+
================================================================================
2400+
`;
2401+
2402+
exports[`mixed-56.php 1`] = `
2403+
====================================options=====================================
2404+
parsers: ["php"]
2405+
printWidth: 80
2406+
| printWidth
2407+
=====================================input======================================
2408+
<?= $a ?>
2409+
<?php echo $a; ?>
2410+
2411+
=====================================output=====================================
2412+
<?= $a ?>
2413+
<?php echo $a; ?>
2414+
2415+
================================================================================
2416+
`;
2417+
23502418
exports[`namespace-1.php 1`] = `
23512419
====================================options=====================================
23522420
parsers: ["php"]

tests/inline/mixed-54.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* @var string $a
4+
*/
5+
?>
6+
<?= $a ?>
7+
<?php echo $a; ?>

tests/inline/mixed-55.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* @var string $a
4+
*/
5+
?>
6+
<?php echo $a; ?>
7+
<?= $a ?>

tests/inline/mixed-56.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?= $a ?>
2+
<?php echo $a; ?>

0 commit comments

Comments
 (0)