From 1443646268465b8930c9a7f2f8ff1a51453796d1 Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Thu, 6 Jul 2017 14:26:43 +0200 Subject: [PATCH] Fix newline trimming around tilde Fixed #185 --- data/js/operators_after.txt | 1 - src/JS.php | 6 +++--- tests/js/JSTest.php | 11 +++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/data/js/operators_after.txt b/data/js/operators_after.txt index 7592656..71a9b70 100644 --- a/data/js/operators_after.txt +++ b/data/js/operators_after.txt @@ -18,7 +18,6 @@ & | ^ -~ << >> >>> diff --git a/src/JS.php b/src/JS.php index 7a95600..c683243 100644 --- a/src/JS.php +++ b/src/JS.php @@ -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 @@ -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 (), ... diff --git a/tests/js/JSTest.php b/tests/js/JSTest.php index 0828647..71c2a50 100644 --- a/tests/js/JSTest.php +++ b/tests/js/JSTest.php @@ -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');