bar", "" ), array( "--> Foo", "" ), array( "x --> y", "x-->y" ), // Semicolon insertion array( "(function(){return\nx;})", "(function(){return\nx;})" ), array( "throw\nx;", "throw\nx;" ), array( "while(p){continue\nx;}", "while(p){continue\nx;}" ), array( "while(p){break\nx;}", "while(p){break\nx;}" ), array( "var\nx;", "var x;" ), array( "x\ny;", "x\ny;" ), array( "x\n++y;", "x\n++y;" ), array( "x\n!y;", "x\n!y;" ), array( "x\n{y}", "x\n{y}" ), array( "x\n+y;", "x+y;" ), array( "x\n(y);", "x(y);" ), array( "5.\nx;", "5.\nx;" ), array( "0xFF.\nx;", "0xFF.x;" ), array( "5.3.\nx;", "5.3.x;" ), // Semicolon insertion between an expression having an inline // comment after it, and a statement on the next line (bug 27046). array( "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 array( array( // This one gets interpreted all together by the prior code; // no break at the 'E' happens. '1.23456789E55', ), array( // This one breaks under the bad code; splits between 'E' and '+' '1.23456789E+5', ), array( // 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" ); } }