Skip to content

Commit 0aeb4bc

Browse files
authored
fix(shared): missed Symbol judge in looseEqual (#3553)
1 parent c355c4b commit 0aeb4bc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: packages/shared/__tests__/looseEqual.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ describe('utils/looseEqual', () => {
4949
expect(looseEqual(date1, date4)).toBe(false)
5050
})
5151

52+
test('compares symbols correctly', () => {
53+
const symbol1 = Symbol('a')
54+
const symbol2 = Symbol('a')
55+
const symbol3 = Symbol('b')
56+
const notSymbol = 0
57+
58+
expect(looseEqual(symbol1, symbol1)).toBe(true)
59+
expect(looseEqual(symbol1, symbol2)).toBe(false)
60+
expect(looseEqual(symbol1, symbol3)).toBe(false)
61+
expect(looseEqual(symbol1, notSymbol)).toBe(false)
62+
})
63+
5264
test('compares files correctly', () => {
5365
const date1 = new Date(2019, 1, 2, 3, 4, 5, 6)
5466
const date2 = new Date(2019, 1, 2, 3, 4, 5, 7)

Diff for: packages/shared/src/looseEqual.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isDate, isObject } from './'
1+
import { isArray, isDate, isObject, isSymbol } from './'
22

33
function looseCompareArrays(a: any[], b: any[]) {
44
if (a.length !== b.length) return false
@@ -16,6 +16,11 @@ export function looseEqual(a: any, b: any): boolean {
1616
if (aValidType || bValidType) {
1717
return aValidType && bValidType ? a.getTime() === b.getTime() : false
1818
}
19+
aValidType = isSymbol(a)
20+
bValidType = isSymbol(b)
21+
if (aValidType || bValidType) {
22+
return a === b
23+
}
1924
aValidType = isArray(a)
2025
bValidType = isArray(b)
2126
if (aValidType || bValidType) {

0 commit comments

Comments
 (0)