Skip to content

Commit

Permalink
use context-agnostic RegExp check
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 24, 2017
1 parent 01c0002 commit a2f57e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion 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 };
Expand All @@ -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 */
Expand Down
10 changes: 7 additions & 3 deletions src/shared/util.js
Expand Up @@ -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]'
}

/**
Expand Down

0 comments on commit a2f57e3

Please sign in to comment.