Skip to content

Commit

Permalink
Add a newline between scripts being joined
Browse files Browse the repository at this point in the history
Fixes issue #35
  • Loading branch information
matthiasmullie committed Feb 6, 2015
1 parent 471f982 commit 5d1886a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ public function minify($path = null)

// loop files
foreach ($this->data as $source => $js) {
// combine js (separate sources with semicolon)
$content .= $js . ';';
/*
* Combine js: separating the scripts by a ;
* I'm also adding a newline: it will be eaten when whitespace is
* stripped, but we need to make sure we're not just appending
* a new script right after a previous script that ended with a
* singe-line comment on the last line (in which case it would also
* be seen as part of that comment)
*/
$content .= $js . "\n;";
}

/*
Expand Down
14 changes: 13 additions & 1 deletion tests/js/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ protected function tearDown()
*/
public function minify($input, $expected)
{
$this->minifier->add($input);
$input = (array) $input;
foreach ($input as $js) {
$this->minifier->add($js);
}
$result = $this->minifier->minify();

$this->assertEquals($expected, $result);
Expand Down Expand Up @@ -458,6 +461,15 @@ function foo(a,b){return a/b}',
'a.replace("\\\\","");hi="This is a string"',
);

// https://github.com/matthiasmullie/minify/issues/35
$tests[] = array(
array(
'// script that ends with comment',
'var test=1',
),
'var test=1',
);

return $tests;
}
}

0 comments on commit 5d1886a

Please sign in to comment.