Skip to content

Commit

Permalink
Don't shorten bools if they're object literal keys
Browse files Browse the repository at this point in the history
Fixes issue #134
  • Loading branch information
matthiasmullie committed Sep 14, 2016
1 parent 9e0dfaf commit f03da3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ protected function propertyNotation($content)
*/
protected function shortenBools($content)
{
$content = preg_replace('/\btrue\b/', '!0', $content);
$content = preg_replace('/\bfalse\b/', '!1', $content);
$content = preg_replace('/\btrue\b(?!:)/', '!0', $content);
$content = preg_replace('/\bfalse\b(?!:)/', '!1', $content);

// for(;;) is exactly the same as while(true)
$content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content);
Expand Down
6 changes: 6 additions & 0 deletions tests/js/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ function otherFuncName() {
'if(args.message instanceof Array){args.message=args.message.join(\' \')}',
);

// https://github.com/matthiasmullie/minify/issues/134
$tests[] = array(
'e={true:!0,false:!1}',
'e={true:!0,false:!1}',
);

// update tests' expected results for cross-system compatibility
foreach ($tests as &$test) {
if (!empty($test[1])) {
Expand Down

0 comments on commit f03da3f

Please sign in to comment.