1
- var equalObjects = require ( './equals' ) . default ;
2
- var decode = require ( './decode' ) . default ;
3
- var ParseError = require ( './ParseError' ) . default ;
4
- var ParsePolygon = require ( './ParsePolygon' ) . default ;
5
- var ParseGeoPoint = require ( './ParseGeoPoint' ) . default ;
1
+ const equalObjects = require ( './equals' ) . default ;
2
+ const decode = require ( './decode' ) . default ;
3
+ const ParseError = require ( './ParseError' ) . default ;
4
+ const ParsePolygon = require ( './ParsePolygon' ) . default ;
5
+ const ParseGeoPoint = require ( './ParseGeoPoint' ) . default ;
6
6
7
7
/**
8
8
* contains -- Determines if an object is contained in a list with special handling for Parse pointers.
@@ -49,7 +49,7 @@ function matchesQuery(className, object, objects, query) {
49
49
q = query . toJSON ( ) . where ;
50
50
}
51
51
obj . className = className ;
52
- for ( var field in q ) {
52
+ for ( const field in q ) {
53
53
if ( ! matchesKeyConstraints ( className , obj , objects , field , q [ field ] ) ) {
54
54
return false ;
55
55
}
@@ -78,12 +78,12 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
78
78
}
79
79
if ( key . indexOf ( '.' ) >= 0 ) {
80
80
// Key references a subobject
81
- var keyComponents = key . split ( '.' ) ;
82
- var subObjectKey = keyComponents [ 0 ] ;
83
- var keyRemainder = keyComponents . slice ( 1 ) . join ( '.' ) ;
81
+ const keyComponents = key . split ( '.' ) ;
82
+ const subObjectKey = keyComponents [ 0 ] ;
83
+ const keyRemainder = keyComponents . slice ( 1 ) . join ( '.' ) ;
84
84
return matchesKeyConstraints ( className , object [ subObjectKey ] || { } , objects , keyRemainder , constraints ) ;
85
85
}
86
- var i ;
86
+ let i ;
87
87
if ( key === '$or' ) {
88
88
for ( i = 0 ; i < constraints . length ; i ++ ) {
89
89
if ( matchesQuery ( className , object , objects , constraints [ i ] ) ) {
@@ -122,7 +122,7 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
122
122
}
123
123
return object [ key ] === constraints ;
124
124
}
125
- var compareTo ;
125
+ let compareTo ;
126
126
if ( constraints . __type ) {
127
127
if ( constraints . __type === 'Pointer' ) {
128
128
return equalObjectsGeneric ( object [ key ] , constraints , function ( obj , ptr ) {
@@ -132,7 +132,7 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
132
132
return equalObjectsGeneric ( decode ( object [ key ] ) , decode ( constraints ) , equalObjects ) ;
133
133
}
134
134
// More complex cases
135
- for ( var condition in constraints ) {
135
+ for ( const condition in constraints ) {
136
136
compareTo = constraints [ condition ] ;
137
137
if ( compareTo . __type ) {
138
138
compareTo = decode ( compareTo ) ;
@@ -202,9 +202,9 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
202
202
return compareTo . test ( object [ key ] ) ;
203
203
}
204
204
// JS doesn't support perl-style escaping
205
- var expString = '' ;
206
- var escapeEnd = - 2 ;
207
- var escapeStart = compareTo . indexOf ( '\\Q' ) ;
205
+ let expString = '' ;
206
+ let escapeEnd = - 2 ;
207
+ let escapeStart = compareTo . indexOf ( '\\Q' ) ;
208
208
while ( escapeStart > - 1 ) {
209
209
// Add the unescaped portion
210
210
expString += compareTo . substring ( escapeEnd + 2 , escapeStart ) ;
@@ -219,30 +219,32 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
219
219
let modifiers = constraints . $options || '' ;
220
220
modifiers = modifiers . replace ( 'x' , '' ) . replace ( 's' , '' )
221
221
// Parse Server / Mongo support x and s modifiers but JS RegExp doesn't
222
- var exp = new RegExp ( expString , modifiers ) ;
222
+ const exp = new RegExp ( expString , modifiers ) ;
223
223
if ( ! exp . test ( object [ key ] ) ) {
224
224
return false ;
225
225
}
226
226
break ;
227
227
}
228
- case '$nearSphere' :
228
+ case '$nearSphere' : {
229
229
if ( ! compareTo || ! object [ key ] ) {
230
230
return false ;
231
231
}
232
- var distance = compareTo . radiansTo ( object [ key ] ) ;
233
- var max = constraints . $maxDistance || Infinity ;
232
+ const distance = compareTo . radiansTo ( object [ key ] ) ;
233
+ const max = constraints . $maxDistance || Infinity ;
234
234
return distance <= max ;
235
- case '$within' :
235
+ }
236
+ case '$within' : {
236
237
if ( ! compareTo || ! object [ key ] ) {
237
238
return false ;
238
239
}
239
- var southWest = compareTo . $box [ 0 ] ;
240
- var northEast = compareTo . $box [ 1 ] ;
240
+ const southWest = compareTo . $box [ 0 ] ;
241
+ const northEast = compareTo . $box [ 1 ] ;
241
242
if ( southWest . latitude > northEast . latitude || southWest . longitude > northEast . longitude ) {
242
243
// Invalid box, crosses the date line
243
244
return false ;
244
245
}
245
246
return object [ key ] . latitude > southWest . latitude && object [ key ] . latitude < northEast . latitude && object [ key ] . longitude > southWest . longitude && object [ key ] . longitude < northEast . longitude ;
247
+ }
246
248
case '$options' :
247
249
// Not a query type, but a way to add options to $regex. Ignore and
248
250
// avoid the default
@@ -346,7 +348,7 @@ function validateQuery(query: any) {
346
348
} ) ;
347
349
}
348
350
349
- var OfflineQuery = {
351
+ const OfflineQuery = {
350
352
matchesQuery : matchesQuery ,
351
353
validateQuery : validateQuery ,
352
354
} ;
0 commit comments