]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(shared): missed Symbol judge in looseEqual (#3553)
authornetcon <netcon@live.com>
Tue, 10 May 2022 02:15:26 +0000 (10:15 +0800)
committerGitHub <noreply@github.com>
Tue, 10 May 2022 02:15:26 +0000 (22:15 -0400)
packages/shared/__tests__/looseEqual.spec.ts
packages/shared/src/looseEqual.ts

index 75bb25058b735a63bda6ebed675d07fa6cc8007b..24bd48c1015996eb1150fed75b3046067638bb4f 100644 (file)
@@ -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)
index 030f0338b30e395e0496ba0dff42546e05c27e1a..387150535c7484163519136dc919a4150929d22a 100644 (file)
@@ -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
@@ -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) {