JavaScriptMinifier: Add test case for another line-break bug
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 11 Aug 2018 23:24:56 +0000 (00:24 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 11 Aug 2018 23:24:56 +0000 (00:24 +0100)
Discovered by adding a test case that uses file_get_contents()
to pass jquery.js, and then scan the PHPUnit output for an entry
containing `return` by itself on a line where the next line
is isn't `;` - then reducing it to a test case as small as possible.

This was reduced from the definition of jQuery.event.addProp.

Bug: T201606
Change-Id: I1f907436c32630102e60e3ded7092dbeb9669fe8

tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index ce8bb06..16048bf 100644 (file)
@@ -261,6 +261,7 @@ class JavaScriptMinifierTest extends PHPUnit\Framework\TestCase {
                        [
                                // Regression test for T201606.
                                // Must not break between 'return' and Expression.
                        [
                                // Regression test for T201606.
                                // Must not break between 'return' and Expression.
+                               // Was caused by bad state after '{}' in property value.
                                <<<JAVASCRIPT
                        call( function () {
                                try {
                                <<<JAVASCRIPT
                        call( function () {
                                try {
@@ -312,7 +313,41 @@ JAVASCRIPT
                                        ')',
                                        ';',
                                ]
                                        ')',
                                        ';',
                                ]
-                       ]
+                       ],
+                       [
+                               // Regression test for T201606.
+                               // Must not break between 'return' and Expression.
+                               // FIXME: Cause?
+                               <<<JAVASCRIPT
+call( {
+       key: 1 ? 0 : function () {
+               return this;
+       }
+} );
+JAVASCRIPT
+                               ,
+                               [
+                                       'call',
+                                       '(',
+                                       '{',
+                                       'key',
+                                       ':',
+                                       '1',
+                                       '?',
+                                       '0',
+                                       ':',
+                                       'function',
+                                       '(',
+                                       ')',
+                                       '{',
+                                       'return', 'this', // FIXME
+                                       ';',
+                                       '}',
+                                       '}',
+                                       ')',
+                                       ';',
+                               ]
+                       ],
                ];
        }
 
                ];
        }