Skip to content

Commit a58846c

Browse files
MErge
1 parent 4ef0025 commit a58846c

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

packages/firestore/src/core/query.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ export class FieldFilter extends Filter {
526526
'Comparing on key with IN, but filter value not an ArrayValue'
527527
);
528528
assert(
529-
(value.arrayValue!.values || []).every(elem =>
529+
(value.arrayValue.values || []).every(elem =>
530530
isReferenceValue(elem)
531531
),
532532
'Comparing on key with IN, but an array value was not a RefValue'
@@ -654,7 +654,7 @@ export class KeyFieldFilter extends FieldFilter {
654654
constructor(field: FieldPath, op: Operator, value: api.Value) {
655655
super(field, op, value);
656656
assert(isReferenceValue(value), 'KeyFieldFilter expects a ReferenceValue');
657-
this.key = DocumentKey.fromName(value.referenceValue!);
657+
this.key = DocumentKey.fromName(value.referenceValue);
658658
}
659659

660660
matches(doc: Document): boolean {
@@ -670,7 +670,7 @@ export class KeyFieldInFilter extends FieldFilter {
670670
constructor(field: FieldPath, value: api.Value) {
671671
super(field, Operator.IN, value);
672672
assert(isArray(value), 'KeyFieldInFilter expects an ArrayValue');
673-
this.keys = (value.arrayValue!.values || []).map(v => {
673+
this.keys = (value.arrayValue.values || []).map(v => {
674674
assert(
675675
isReferenceValue(v),
676676
'Comparing on key with IN, but an array value was not a ReferenceValue'
@@ -692,7 +692,7 @@ export class ArrayContainsFilter extends FieldFilter {
692692

693693
matches(doc: Document): boolean {
694694
const other = doc.field(this.field);
695-
return isArray(other) && contains(other!.arrayValue!, this.value);
695+
return isArray(other) && contains(other.arrayValue, this.value);
696696
}
697697
}
698698

@@ -721,7 +721,7 @@ export class ArrayContainsAnyFilter extends FieldFilter {
721721
if (!isArray(other)) {
722722
return false;
723723
}
724-
for (const val of other!.arrayValue!.values || []) {
724+
for (const val of other.arrayValue.values || []) {
725725
if (contains(this.value.arrayValue!, val)) {
726726
return true;
727727
}
@@ -794,7 +794,7 @@ export class Bound {
794794
'Bound has a non-key value where the key path is being used.'
795795
);
796796
comparison = DocumentKey.comparator(
797-
DocumentKey.fromName(component.referenceValue!),
797+
DocumentKey.fromName(component.referenceValue),
798798
doc.key
799799
);
800800
} else {

packages/firestore/src/model/field_value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class ObjectValueBuilder {
277277
const resultAtPath = isMapValue(existingValue)
278278
? // If there is already data at the current path, base our
279279
// modifications on top of the existing data.
280-
{ ...existingValue!.mapValue!.fields }
280+
{ ...existingValue.mapValue.fields }
281281
: {};
282282

283283
currentOverlays.forEach((value, pathSegment) => {

packages/firestore/src/model/transform_operation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class NumericIncrementTransformOperation implements TransformOperation {
244244

245245
function coercedFieldValuesArray(value: api.Value | null): api.Value[] {
246246
if (isArray(value)) {
247-
return value!.arrayValue?.values || [];
247+
return value.arrayValue.values || [];
248248
} else {
249249
// coerce to empty array.
250250
return [];

packages/firestore/src/model/values.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import { forEach, keys, size } from '../util/obj';
2323
import { ByteString } from '../util/byte_string';
2424
import { DocumentKey } from './document_key';
2525
import {
26-
numericComparator,
27-
numericEquals,
2826
primitiveComparator
2927
} from '../util/misc';
28+
import {isNegativeZero} from "../util/types";
3029

3130
// A RegExp matching ISO 8601 UTC timestamps with optional fraction.
3231
const ISO_TIMESTAMP_REG_EXP = new RegExp(
@@ -137,15 +136,19 @@ function blobEquals(left: api.Value, right: api.Value): boolean {
137136

138137
export function numberEquals(left: api.Value, right: api.Value): boolean {
139138
if ('integerValue' in left && 'integerValue' in right) {
140-
return numericEquals(
141-
normalizeNumber(left.integerValue),
142-
normalizeNumber(right.integerValue)
139+
return (
140+
normalizeNumber(left.integerValue) === normalizeNumber(right.integerValue)
143141
);
144142
} else if ('doubleValue' in left && 'doubleValue' in right) {
145-
return numericEquals(
146-
normalizeNumber(left.doubleValue),
147-
normalizeNumber(right.doubleValue)
148-
);
143+
const n1 = normalizeNumber(left.doubleValue!);
144+
const n2 = normalizeNumber(right.doubleValue!);
145+
146+
if (isNegativeZero(n1)) {
147+
return isNegativeZero(n2);
148+
} else {
149+
// NaN == NaN
150+
return n1 !== n1 && n2 !== n2;
151+
}
149152
}
150153

151154
return false;
@@ -228,7 +231,21 @@ function compareNumbers(left: api.Value, right: api.Value): number {
228231
'doubleValue' in right
229232
? normalizeNumber(right.doubleValue)
230233
: normalizeNumber(right.integerValue);
231-
return numericComparator(leftNumber, rightNumber);
234+
235+
if (leftNumber < rightNumber) {
236+
return -1;
237+
} else if (leftNumber > rightNumber) {
238+
return 1;
239+
} else if (leftNumber === rightNumber) {
240+
return 0;
241+
} else {
242+
// one or both are NaN.
243+
if (isNaN(leftNumber)) {
244+
return isNaN(rightNumber) ? 0 : -1;
245+
} else {
246+
return 1;
247+
}
248+
}
232249
}
233250

234251
function compareTimestamps(left: api.Timestamp, right: api.Timestamp): number {

0 commit comments

Comments
 (0)