@@ -248,15 +248,31 @@ export function genStaticKeys (modules: Array<ModuleOptions>): string {
248248 * Check if two values are loosely equal - that is,
249249 * if they are plain objects, do they have the same shape?
250250 */
251- export function looseEqual ( a : mixed , b : mixed ) : boolean {
251+ export function looseEqual ( a : any , b : any ) : boolean {
252+ if ( a === b ) return true
252253 const isObjectA = isObject ( a )
253254 const isObjectB = isObject ( b )
254255 if ( isObjectA && isObjectB ) {
255256 try {
256- return JSON . stringify ( a ) === JSON . stringify ( b )
257+ const isArrayA = Array . isArray ( a )
258+ const isArrayB = Array . isArray ( b )
259+ if ( isArrayA && isArrayB ) {
260+ return a . length === b . length && a . every ( ( e , i ) => {
261+ return looseEqual ( e , b [ i ] )
262+ } )
263+ } else if ( ! isArrayA && ! isArrayB ) {
264+ const keysA = Object . keys ( a )
265+ const keysB = Object . keys ( b )
266+ return keysA . length === keysB . length && keysA . every ( key => {
267+ return looseEqual ( a [ key ] , b [ key ] )
268+ } )
269+ } else {
270+ /* istanbul ignore next */
271+ return false
272+ }
257273 } catch ( e ) {
258- // possible circular reference
259- return a === b
274+ /* istanbul ignore next */
275+ return false
260276 }
261277 } else if ( ! isObjectA && ! isObjectB ) {
262278 return String ( a ) === String ( b )
0 commit comments