Skip to content

Commit 9c0cf14

Browse files
authored
Fix inline with precomment adding unnecessary open tags
Fixes #1338
1 parent 8049d30 commit 9c0cf14

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

src/printer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,10 @@ function printLines(path, options, print, childrenAttribute = "children") {
10141014
const beforeInline =
10151015
childNode.leadingComments && childNode.leadingComments.length
10161016
? concat([
1017-
isFirstNode && node.kind !== "namespace" ? openTag : "",
1018-
hardline,
1017+
isFirstNode && node.kind !== "namespace" && !isBlockNestedNode
1018+
? openTag
1019+
: "",
1020+
node.kind === "namespace" || !isBlockNestedNode ? hardline : "",
10191021
comments.printComments(childNode.leadingComments, options),
10201022
"?>"
10211023
])

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,48 @@ $var = 2;
23052305
================================================================================
23062306
`;
23072307

2308+
exports[`mixed-53.php 1`] = `
2309+
====================================options=====================================
2310+
parsers: ["php"]
2311+
printWidth: 80
2312+
| printWidth
2313+
=====================================input======================================
2314+
<?php
2315+
try {
2316+
// comment
2317+
?>
2318+
Foo bar
2319+
<?php
2320+
} catch (Exception $e) {
2321+
?>
2322+
Foo bar
2323+
<?php
2324+
} finally {
2325+
?>
2326+
Foo bar
2327+
<?php
2328+
}
2329+
2330+
=====================================output=====================================
2331+
<?php
2332+
try {
2333+
// comment
2334+
?>
2335+
Foo bar
2336+
<?php
2337+
} catch (Exception $e) {
2338+
?>
2339+
Foo bar
2340+
<?php
2341+
} finally {
2342+
?>
2343+
Foo bar
2344+
<?php
2345+
}
2346+
2347+
================================================================================
2348+
`;
2349+
23082350
exports[`namespace-1.php 1`] = `
23092351
====================================options=====================================
23102352
parsers: ["php"]

tests/inline/mixed-53.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
try {
3+
// comment
4+
?>
5+
Foo bar
6+
<?php
7+
} catch (Exception $e) {
8+
?>
9+
Foo bar
10+
<?php
11+
} finally {
12+
?>
13+
Foo bar
14+
<?php
15+
}

0 commit comments

Comments
 (0)