Skip to content

Commit a2f57e3

Browse files
committed
use context-agnostic RegExp check
1 parent 01c0002 commit a2f57e3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/core/components/keep-alive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
import { isRegExp } from 'shared/util'
34
import { getFirstComponentChild } from 'core/vdom/helpers/index'
45

56
type VNodeCache = { [key: string]: ?VNode };
@@ -13,7 +14,7 @@ function getComponentName (opts: ?VNodeComponentOptions): ?string {
1314
function matches (pattern: string | RegExp, name: string): boolean {
1415
if (typeof pattern === 'string') {
1516
return pattern.split(',').indexOf(name) > -1
16-
} else if (pattern instanceof RegExp) {
17+
} else if (isRegExp(pattern)) {
1718
return pattern.test(name)
1819
}
1920
/* istanbul ignore next */

src/shared/util.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ export function isObject (obj: mixed): boolean {
3030
return obj !== null && typeof obj === 'object'
3131
}
3232

33+
const toString = Object.prototype.toString
34+
3335
/**
3436
* Strict object type check. Only returns true
3537
* for plain JavaScript objects.
3638
*/
37-
const toString = Object.prototype.toString
38-
const OBJECT_STRING = '[object Object]'
3939
export function isPlainObject (obj: any): boolean {
40-
return toString.call(obj) === OBJECT_STRING
40+
return toString.call(obj) === '[object Object]'
41+
}
42+
43+
export function isRegExp (v: any): boolean {
44+
return toString.call(v) === '[object RegExp]'
4145
}
4246

4347
/**

0 commit comments

Comments
 (0)