@@ -89,14 +89,9 @@ function _testQuery(doubleTestTrue, doubleTestFalse, singleTest) {
89
89
* @return {boolean }
90
90
*/
91
91
return function ( query ) {
92
- let result ;
93
-
94
- if ( doubleTestTrue . test ( query ) ) result = true ;
95
- else if ( doubleTestFalse . test ( query ) ) result = false ;
96
- else result = singleTest . test ( query ) ;
97
-
98
- /** Not keyword inverts the whole query */
99
- return query . includes ( 'not' ) ? ! result : result ;
92
+ if ( doubleTestTrue . test ( query ) ) return true ;
93
+ else if ( doubleTestFalse . test ( query ) ) return false ;
94
+ else return singleTest . test ( query ) ;
100
95
} ;
101
96
}
102
97
@@ -144,6 +139,9 @@ function _testIsPrint(a, b) {
144
139
module . exports = function createSort ( configuration ) {
145
140
const config = configuration || { } ;
146
141
const UNITLESS_MQ_ALWAYS_FIRST = config . unitlessMqAlwaysFirst ;
142
+ const min = ( query ) => isMinWidth ( query ) || isMinHeight ( query ) ;
143
+ const max = ( query ) => isMaxWidth ( query ) || isMaxHeight ( query ) ;
144
+ const not = ( query ) => query . includes ( 'not' ) ;
147
145
148
146
/**
149
147
* Sorting an array with media queries
@@ -158,11 +156,11 @@ module.exports = function createSort(configuration) {
158
156
return testIsPrint ;
159
157
}
160
158
161
- const minA = isMinWidth ( a ) || isMinHeight ( a ) ;
162
- const maxA = isMaxWidth ( a ) || isMaxHeight ( a ) ;
159
+ const minA = not ( a ) ? max ( a ) : min ( a ) ;
160
+ const maxA = not ( a ) ? min ( a ) : max ( a ) ;
163
161
164
- const minB = isMinWidth ( b ) || isMinHeight ( b ) ;
165
- const maxB = isMaxWidth ( b ) || isMaxHeight ( b ) ;
162
+ const minB = not ( b ) ? max ( b ) : min ( b ) ;
163
+ const maxB = not ( b ) ? min ( b ) : max ( b ) ;
166
164
167
165
if ( UNITLESS_MQ_ALWAYS_FIRST && ( ( ! minA && ! maxA ) || ( ! minB && ! maxB ) ) ) {
168
166
if ( ! minA && ! maxA && ! minB && ! maxB ) {
@@ -219,11 +217,11 @@ module.exports = function createSort(configuration) {
219
217
return testIsPrint ;
220
218
}
221
219
222
- const minA = isMinWidth ( a ) || isMinHeight ( a ) ;
223
- const maxA = isMaxWidth ( a ) || isMaxHeight ( a ) ;
220
+ const minA = not ( a ) ? max ( a ) : min ( a ) ;
221
+ const maxA = not ( a ) ? min ( a ) : max ( a ) ;
224
222
225
- const minB = isMinWidth ( b ) || isMinHeight ( b ) ;
226
- const maxB = isMaxWidth ( b ) || isMaxHeight ( b ) ;
223
+ const minB = not ( b ) ? max ( b ) : min ( b ) ;
224
+ const maxB = not ( b ) ? min ( b ) : max ( b ) ;
227
225
228
226
if ( UNITLESS_MQ_ALWAYS_FIRST && ( ( ! minA && ! maxA ) || ( ! minB && ! maxB ) ) ) {
229
227
if ( ! minA && ! maxA && ! minB && ! maxB ) {
0 commit comments