Skip to content

Commit

Permalink
Fix newline trimming around tilde
Browse files Browse the repository at this point in the history
Fixed #185
  • Loading branch information
matthiasmullie committed Jul 6, 2017
1 parent 0bb72d8 commit 1443646
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion data/js/operators_after.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
&
|
^
~
<<
>>
>>>
Expand Down
6 changes: 3 additions & 3 deletions src/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class JS extends Minify
* them. Some end of lines are not the end of a statement, like with these
* operators.
*
* Note: Most operators are fine, we've only removed !, ++ and --.
* There can't be a newline separating ! and whatever it is negating.
* Note: Most operators are fine, we've only removed ++ and --.
* ++ & -- have to be joined with the value they're in-/decrementing.
*
* Will be loaded from /data/js/operators_before.txt
Expand All @@ -97,7 +96,8 @@ class JS extends Minify
* them. Some end of lines are not the end of a statement, like when
* continued by one of these operators on the newline.
*
* Note: Most operators are fine, we've only removed ), ], ++ and --.
* Note: Most operators are fine, we've only removed ), ], ++, --, ! and ~.
* There can't be a newline separating ! or ~ and whatever it is negating.
* ++ & -- have to be joined with the value they're in-/decrementing.
* ) & ] are "special" in that they have lots or usecases. () for example
* is used for function calls, for grouping, in if () and for (), ...
Expand Down
11 changes: 11 additions & 0 deletions tests/js/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,17 @@ function otherFuncName() {
this.length=this.elements.length}',
);

// https://github.com/matthiasmullie/minify/issues/185
$tests[] = array(
'var thisPos = indexOf(stack, this);
~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
if (~indexOf(stack, value)) value = cycleReplacer.call(this, key, value)',
'var thisPos=indexOf(stack,this);~thisPos?stack.splice(thisPos+1):stack.push(this)
~thisPos?keys.splice(thisPos,Infinity,key):keys.push(key)
if(~indexOf(stack,value))value=cycleReplacer.call(this,key,value)',
);

// known minified files to help doublecheck changes in places not yet
// anticipated in these tests
$files = glob(__DIR__.'/sample/minified/*.js');
Expand Down

0 comments on commit 1443646

Please sign in to comment.