bar", "" ], [ "--> Foo", "" ], [ "x --> y", "x-->y" ], // Semicolon insertion [ "(function(){return\nx;})", "(function(){return\nx;})" ], [ "throw\nx;", "throw\nx;" ], [ "while(p){continue\nx;}", "while(p){continue\nx;}" ], [ "while(p){break\nx;}", "while(p){break\nx;}" ], [ "var\nx;", "var x;" ], [ "x\ny;", "x\ny;" ], [ "x\n++y;", "x\n++y;" ], [ "x\n!y;", "x\n!y;" ], [ "x\n{y}", "x\n{y}" ], [ "x\n+y;", "x+y;" ], [ "x\n(y);", "x(y);" ], [ "5.\nx;", "5.\nx;" ], [ "0xFF.\nx;", "0xFF.x;" ], [ "5.3.\nx;", "5.3.x;" ], // Cover failure case for incomplete hex literal [ "0x;", false, false ], // Cover failure case for number with no digits after E [ "1.4E", false, false ], // Cover failure case for number with several E [ "1.4EE2", false, false ], [ "1.4EE", false, false ], // Cover failure case for number with several E (nonconsecutive) // FIXME: This is invalid, but currently tolerated [ "1.4E2E3", "1.4E2 E3", false ], // Semicolon insertion between an expression having an inline // comment after it, and a statement on the next line (T29046). [ "var a = this //foo bar \n for ( b = 0; c < d; b++ ) {}", "var a=this\nfor(b=0;cparse( $minified, 'minify-test.js', 1 ); } $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." ); } public static function provideExponentLineBreaking() { return [ [ // This one gets interpreted all together by the prior code; // no break at the 'E' happens. '1.23456789E55', ], [ // This one breaks under the bad code; splits between 'E' and '+' '1.23456789E+5', ], [ // This one breaks under the bad code; splits between 'E' and '-' '1.23456789E-5', ], ]; } /** * @dataProvider provideExponentLineBreaking * @covers JavaScriptMinifier::minify */ public function testExponentLineBreaking( $num ) { // Long line breaking was being incorrectly done between the base and // exponent part of a number, causing a syntax error. The line should // instead break at the start of the number. (T34548) $prefix = 'var longVarName' . str_repeat( '_', 973 ) . '='; $suffix = ',shortVarName=0;'; $input = $prefix . $num . $suffix; $expected = $prefix . "\n" . $num . $suffix; $minified = JavaScriptMinifier::minify( $input ); $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent" ); } }