Skip to content

Commit

Permalink
fix(shared): missed Symbol judge in looseEqual (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
conwnet committed May 10, 2022
1 parent c355c4b commit 0aeb4bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/shared/__tests__/looseEqual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ describe('utils/looseEqual', () => {
expect(looseEqual(date1, date4)).toBe(false)
})

test('compares symbols correctly', () => {
const symbol1 = Symbol('a')
const symbol2 = Symbol('a')
const symbol3 = Symbol('b')
const notSymbol = 0

expect(looseEqual(symbol1, symbol1)).toBe(true)
expect(looseEqual(symbol1, symbol2)).toBe(false)
expect(looseEqual(symbol1, symbol3)).toBe(false)
expect(looseEqual(symbol1, notSymbol)).toBe(false)
})

test('compares files correctly', () => {
const date1 = new Date(2019, 1, 2, 3, 4, 5, 6)
const date2 = new Date(2019, 1, 2, 3, 4, 5, 7)
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/looseEqual.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, isDate, isObject } from './'
import { isArray, isDate, isObject, isSymbol } from './'

function looseCompareArrays(a: any[], b: any[]) {
if (a.length !== b.length) return false
Expand All @@ -16,6 +16,11 @@ export function looseEqual(a: any, b: any): boolean {
if (aValidType || bValidType) {
return aValidType && bValidType ? a.getTime() === b.getTime() : false
}
aValidType = isSymbol(a)
bValidType = isSymbol(b)
if (aValidType || bValidType) {
return a === b
}
aValidType = isArray(a)
bValidType = isArray(b)
if (aValidType || bValidType) {
Expand Down

0 comments on commit 0aeb4bc

Please sign in to comment.