Repository: prettier/plugin-php
Pull request #530 (2018-08-10 16:09:39)

fix: empty php tag
We respect php tags on difference lines and one, if somebody want change behavior we can discuss about this in issue.


Patch:
diff --git a/src/parser.js b/src/parser.js
index dff4016..e5e8f4e 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -1,13 +1,9 @@
 "use strict";
 const engine = require("php-parser");
 
-function inBetweenLines(line, node, nextNode) {
-  return (
-    nextNode && node.loc.end.line <= line && nextNode.loc.start.line > line
-  );
-}
-
 function parse(text) {
+  text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___<?");
+
   // initialize a new parser instance
   const parser = new engine({
     parser: {
@@ -22,31 +18,6 @@ function parse(text) {
 
   const ast = parser.parseCode(text);
 
-  // parser doesn't create `inline` node between `?>\n<?`, so we add them manually
-  const missingLinebreaks = ast.tokens.filter((token, index, tokens) => {
-    return (
-      token[0] === "T_CLOSE_TAG" &&
-      token[1] === "?>\n" &&
-      tokens[index + 1] &&
-      tokens[index + 1][0] === "T_OPEN_TAG"
-    );
-  });
-  const lines = missingLinebreaks.map(token => token[2]);
-
-  const astIndices = ast.children.reduce((acc, child, index, children) => {
-    if (lines.find(line => inBetweenLines(line, child, children[index + 1]))) {
-      acc.push(index + 1);
-    }
-    return acc;
-  }, []);
-  astIndices.forEach((i, j) => {
-    ast.children.splice(i + j, 0, {
-      kind: "inline",
-      raw: "\n",
-      value: ""
-    });
-  });
-
   // https://github.com/glayzzle/php-parser/issues/155
   // currently inline comments include the line break at the end, we need to
   // strip those out and update the end location for each comment manually
@@ -60,6 +31,7 @@ function parse(text) {
       comment.loc.end.offset = comment.loc.end.offset - 1;
     }
   });
+
   return ast;
 }
 
diff --git a/src/printer.js b/src/printer.js
index f7006c2..67cdf83 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -859,8 +859,6 @@ function printExpression(path, options, print) {
         // indented accordingly. We should indent sub-expressions where the first case isn't indented.
         const shouldNotIndent =
           parent.kind === "return" ||
-          parent.kind === "echo" ||
-          parent.kind === "print" ||
           parent.kind === "retif" ||
           // return (
           //   $someCondition ||
@@ -1066,7 +1064,10 @@ function printExpression(path, options, print) {
             : ""
         ]);
       case "inline":
-        return join(literalline, node.raw.split("\n"));
+        return join(
+          literalline,
+          node.raw.replace("___PSEUDO_INLINE_PLACEHOLDER___", "").split("\n")
+        );
       case "magic":
         // for magic constant we prefer upper case
         return node.value.toUpperCase();
@@ -1407,12 +1408,13 @@ function printLines(path, options, print, childrenAttribute = "children") {
       const between = originalText.trim().match(/^<\?(php|=)(\s+)?\S/);
 
       if (between && between[2]) {
-        afterOpenTag = between[2].includes("\n")
-          ? concat([
-              hardline,
-              between[2].split("\n").length > 2 ? hardline : ""
-            ])
-          : " ";
+        afterOpenTag =
+          between[2].includes("\n") && wrappedParts.length > 0
+            ? concat([
+                hardline,
+                between[2].split("\n").length > 2 ? hardline : ""
+              ])
+            : " ";
       }
     }
 
@@ -1420,7 +1422,11 @@ function printLines(path, options, print, childrenAttribute = "children") {
       const between = originalText.trim().match(/\S(\s*)?\?>$/);
 
       beforeCloseTag =
-        between && between[1] && between[1].includes("\n") ? hardline : " ";
+        between && between[1] && between[1].includes("\n")
+          ? hardline
+          : wrappedParts.length > 0
+            ? " "
+            : "";
     }
 
     return concat([
@@ -1489,12 +1495,16 @@ function printStatement(path, options, print) {
   function printSys(node) {
     switch (node.kind) {
       case "echo": {
-        const printedArguments = path.map(argumentPath => {
-          const node = argumentPath.getValue();
-          return node.kind === "bin"
-            ? print(argumentPath)
-            : dedent(print(argumentPath));
+        const printedArguments = path.map((argumentPath, index) => {
+          let printed = print(argumentPath);
+
+          if (index === 0) {
+            printed = dedent(printed);
+          }
+
+          return printed;
         }, "arguments");
+
         return indent(
           group(
             concat([
@@ -1505,13 +1515,7 @@ function printStatement(path, options, print) {
         );
       }
       case "print": {
-        const printedArguments = path.call(print, "arguments");
-        return concat([
-          "print ",
-          node.arguments.kind === "bin"
-            ? indent(printedArguments)
-            : printedArguments
-        ]);
+        return concat(["print ", path.call(print, "arguments")]);
       }
       case "list":
       case "isset":
@@ -2515,7 +2519,7 @@ function printNode(path, options, print) {
           concat([
             path.call(print, "key"),
             " =>",
-            ["array", "call", "closure"].includes(node.value.kind)
+            ["array", "call", "closure", "retif"].includes(node.value.kind)
               ? concat([" ", printed])
               : indent(concat([line, printed]))
           ])


Test patch:
diff --git a/tests/array/__snapshots__/jsfmt.spec.js.snap b/tests/array/__snapshots__/jsfmt.spec.js.snap
index 74fa6c2..9e0ec42 100644
--- a/tests/array/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/array/__snapshots__/jsfmt.spec.js.snap
@@ -433,6 +433,19 @@ $collapse = [
 ];
 $collapse = ["not", "associative"
 ];
+
+$array = [
+    'key-one' => true ? 1 : 2,
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' ? 1 : 2,
+    'key-two' => true ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' : 2,
+    'key-two' => true ? 1 : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString',
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+        'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString',
+];
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -649,4 +662,23 @@ $arr = [
 $collapse = ["not", "associative"];
 $collapse = ["not", "associative"];
 
+$array = [
+    'key-one' => true ? 1 : 2,
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        ? 1
+        : 2,
+    'key-two' => true
+        ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        : 2,
+    'key-two' => true
+        ? 1
+        : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString',
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+    'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+];
+
 `;
diff --git a/tests/array/arrays.php b/tests/array/arrays.php
index 1239c8d..64dcceb 100644
--- a/tests/array/arrays.php
+++ b/tests/array/arrays.php
@@ -430,3 +430,16 @@ $collapse = [
 ];
 $collapse = ["not", "associative"
 ];
+
+$array = [
+    'key-one' => true ? 1 : 2,
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' ? 1 : 2,
+    'key-two' => true ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' : 2,
+    'key-two' => true ? 1 : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString',
+    'key-two' => 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+        'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        ? 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString'
+        : 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString' .
+            'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString',
+];
diff --git a/tests/echo/__snapshots__/jsfmt.spec.js.snap b/tests/echo/__snapshots__/jsfmt.spec.js.snap
index bd90826..02f4e50 100644
--- a/tests/echo/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/echo/__snapshots__/jsfmt.spec.js.snap
@@ -64,6 +64,98 @@ echo "\\n\\n";
 echo "Foo", f("bar"), "Foo";
 
 echo "Loop start!\\n", sleep(1);
+
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\\n\\n";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\\n\\n", "string";
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ) . "\\n\\n", "string" . "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ), "string", "string";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+),
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ),
+    "string",
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 
@@ -181,4 +273,101 @@ echo "Foo", f("bar"), "Foo";
 
 echo "Loop start!\\n", sleep(1);
 
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\\n\\n";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\\n\\n",
+    "string";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\\n\\n",
+    "string" .
+        "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+),
+    "string",
+    "string";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+),
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                    'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+),
+    "string",
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                    'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
+
 `;
diff --git a/tests/echo/echo.php b/tests/echo/echo.php
index 33e79b6..aae9edb 100644
--- a/tests/echo/echo.php
+++ b/tests/echo/echo.php
@@ -61,3 +61,95 @@ echo "\n\n";
 echo "Foo", f("bar"), "Foo";
 
 echo "Loop start!\n", sleep(1);
+
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\n\n";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+) . "\n\n", "string";
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ) . "\n\n", "string" . "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ), "string", "string";
+echo esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+),
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
+echo esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    ),
+    "string",
+    esc_html(
+        sprintf(
+            __(
+                'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+                'woocommerce'
+            ),
+            get_option('blogname')
+        )
+    );
diff --git a/tests/inline/__snapshots__/jsfmt.spec.js.snap b/tests/inline/__snapshots__/jsfmt.spec.js.snap
index 7f17943..8a29b8d 100644
--- a/tests/inline/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/inline/__snapshots__/jsfmt.spec.js.snap
@@ -1321,10 +1321,8 @@ exports[`mixed-32.php 1`] = `
     <?php echo 'test'; ?>
 <div></div>
 <div></div>
-<?php
-if (true);
-echo 'test';
-?>
+<?php if (true); ?>
+<?php echo 'test'; ?>
 <div></div>
 
 `;
@@ -1356,6 +1354,128 @@ exports[`mixed-34.php 1`] = `
 } ?>
 <div></div>
 
+`;
+
+exports[`mixed-35.php 1`] = `
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php
+
+function test()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php
+}
+
+function testTwo()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+    <?php } ?>
+    <?php
+}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php
+function test()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php
+}
+function testTwo()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+    <?php } ?>
+    <?php
+}
+
+
 `;
 
 exports[`only-html.php 1`] = `
diff --git a/tests/inline/mixed-35.php b/tests/inline/mixed-35.php
new file mode 100644
index 0000000..4f42194
--- /dev/null
+++ b/tests/inline/mixed-35.php
@@ -0,0 +1,59 @@
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php if (!is_ajax()) { ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+<?php } ?>
+
+<?php
+
+function test()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+    <?php } ?>
+    <?php
+}
+
+function testTwo()
+{
+    ?>
+    <?php if (!is_ajax()) { ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+        <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php if (!is_ajax()) { ?>
+            <?php do_action('woocommerce_review_order_after_payment'); ?>
+        <?php } ?>
+    <?php } ?>
+    <?php
+}
diff --git a/tests/print/__snapshots__/jsfmt.spec.js.snap b/tests/print/__snapshots__/jsfmt.spec.js.snap
index da7c50f..190d0a6 100644
--- a/tests/print/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/print/__snapshots__/jsfmt.spec.js.snap
@@ -54,6 +54,17 @@ print(str_replace('test', 'test', 'test'));
 print(1);
 print (1);
 print (((1)));
+
+print esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 <?php
 print "Hello World";
@@ -132,4 +143,15 @@ print 1;
 print 1;
 print 1;
 
+print esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+                'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
+
 `;
diff --git a/tests/print/print.php b/tests/print/print.php
index 679d256..7f9cbb2 100644
--- a/tests/print/print.php
+++ b/tests/print/print.php
@@ -51,3 +51,14 @@ print(str_replace('test', 'test', 'test'));
 print(1);
 print (1);
 print (((1)));
+
+print esc_html(
+    sprintf(
+        __(
+            'Hi there. Your recent order on %s has been completed. ' .
+            'Your order details are shown below for your reference:',
+            'woocommerce'
+        ),
+        get_option('blogname')
+    )
+);
diff --git a/tests/program/__snapshots__/jsfmt.spec.js.snap b/tests/program/__snapshots__/jsfmt.spec.js.snap
index e1a4ea0..0351a85 100644
--- a/tests/program/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/program/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,42 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`empty-open-and-close-php-tag.php 1`] = `
+<?php
+?>
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+?>
+
+`;
+
+exports[`empty-open-and-close-php-tag-1.php 1`] = `
+<?php
+
+?>
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+?>
+
+`;
+
+exports[`empty-open-and-close-php-tag-2.php 1`] = `
+<?php
+
+
+?>
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php
+?>
+
+`;
+
+exports[`empty-open-and-close-php-tag-3.php 1`] = `
+<?php ?>
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<?php ?>
+
+`;
+
 exports[`newline.php 1`] = `
 <?php
 
diff --git a/tests/program/empty-open-and-close-php-tag-1.php b/tests/program/empty-open-and-close-php-tag-1.php
new file mode 100644
index 0000000..62a2de0
--- /dev/null
+++ b/tests/program/empty-open-and-close-php-tag-1.php
@@ -0,0 +1,3 @@
+<?php
+
+?>
diff --git a/tests/program/empty-open-and-close-php-tag-2.php b/tests/program/empty-open-and-close-php-tag-2.php
new file mode 100644
index 0000000..6eff33c
--- /dev/null
+++ b/tests/program/empty-open-and-close-php-tag-2.php
@@ -0,0 +1,4 @@
+<?php
+
+
+?>
diff --git a/tests/program/empty-open-and-close-php-tag-3.php b/tests/program/empty-open-and-close-php-tag-3.php
new file mode 100644
index 0000000..7ccbe49
--- /dev/null
+++ b/tests/program/empty-open-and-close-php-tag-3.php
@@ -0,0 +1,1 @@
+<?php ?>
diff --git a/tests/program/empty-open-and-close-php-tag.php b/tests/program/empty-open-and-close-php-tag.php
new file mode 100644
index 0000000..acb6c35
--- /dev/null
+++ b/tests/program/empty-open-and-close-php-tag.php
@@ -0,0 +1,2 @@
+<?php
+?>