Explorar o código

use context-agnostic RegExp check

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
a2f57e3c52
Modificáronse 2 ficheiros con 9 adicións e 4 borrados
  1. 2 1
      src/core/components/keep-alive.js
  2. 7 3
      src/shared/util.js

+ 2 - 1
src/core/components/keep-alive.js

@@ -1,5 +1,6 @@
 /* @flow */
 
+import { isRegExp } from 'shared/util'
 import { getFirstComponentChild } from 'core/vdom/helpers/index'
 
 type VNodeCache = { [key: string]: ?VNode };
@@ -13,7 +14,7 @@ function getComponentName (opts: ?VNodeComponentOptions): ?string {
 function matches (pattern: string | RegExp, name: string): boolean {
   if (typeof pattern === 'string') {
     return pattern.split(',').indexOf(name) > -1
-  } else if (pattern instanceof RegExp) {
+  } else if (isRegExp(pattern)) {
     return pattern.test(name)
   }
   /* istanbul ignore next */

+ 7 - 3
src/shared/util.js

@@ -30,14 +30,18 @@ export function isObject (obj: mixed): boolean {
   return obj !== null && typeof obj === 'object'
 }
 
+const toString = Object.prototype.toString
+
 /**
  * Strict object type check. Only returns true
  * for plain JavaScript objects.
  */
-const toString = Object.prototype.toString
-const OBJECT_STRING = '[object Object]'
 export function isPlainObject (obj: any): boolean {
-  return toString.call(obj) === OBJECT_STRING
+  return toString.call(obj) === '[object Object]'
+}
+
+export function isRegExp (v: any): boolean {
+  return toString.call(v) === '[object RegExp]'
 }
 
 /**