|
@@ -248,15 +248,31 @@ export function genStaticKeys (modules: Array<ModuleOptions>): string {
|
|
|
* Check if two values are loosely equal - that is,
|
|
* Check if two values are loosely equal - that is,
|
|
|
* if they are plain objects, do they have the same shape?
|
|
* if they are plain objects, do they have the same shape?
|
|
|
*/
|
|
*/
|
|
|
-export function looseEqual (a: mixed, b: mixed): boolean {
|
|
|
|
|
|
|
+export function looseEqual (a: any, b: any): boolean {
|
|
|
|
|
+ if (a === b) return true
|
|
|
const isObjectA = isObject(a)
|
|
const isObjectA = isObject(a)
|
|
|
const isObjectB = isObject(b)
|
|
const isObjectB = isObject(b)
|
|
|
if (isObjectA && isObjectB) {
|
|
if (isObjectA && isObjectB) {
|
|
|
try {
|
|
try {
|
|
|
- return JSON.stringify(a) === JSON.stringify(b)
|
|
|
|
|
|
|
+ const isArrayA = Array.isArray(a)
|
|
|
|
|
+ const isArrayB = Array.isArray(b)
|
|
|
|
|
+ if (isArrayA && isArrayB) {
|
|
|
|
|
+ return a.length === b.length && a.every((e, i) => {
|
|
|
|
|
+ return looseEqual(e, b[i])
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (!isArrayA && !isArrayB) {
|
|
|
|
|
+ const keysA = Object.keys(a)
|
|
|
|
|
+ const keysB = Object.keys(b)
|
|
|
|
|
+ return keysA.length === keysB.length && keysA.every(key => {
|
|
|
|
|
+ return looseEqual(a[key], b[key])
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ /* istanbul ignore next */
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- // possible circular reference
|
|
|
|
|
- return a === b
|
|
|
|
|
|
|
+ /* istanbul ignore next */
|
|
|
|
|
+ return false
|
|
|
}
|
|
}
|
|
|
} else if (!isObjectA && !isObjectB) {
|
|
} else if (!isObjectA && !isObjectB) {
|
|
|
return String(a) === String(b)
|
|
return String(a) === String(b)
|