]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(runtime-core): add `isRegExp` to check `RegExp` (#6041)
authorwebfansplz <308241863@qq.com>
Mon, 14 Nov 2022 01:14:28 +0000 (09:14 +0800)
committerGitHub <noreply@github.com>
Mon, 14 Nov 2022 01:14:28 +0000 (20:14 -0500)
packages/runtime-core/src/components/KeepAlive.ts
packages/shared/src/index.ts

index 66d0f82a10ec3449c66f6c5387984367f6a58c4c..554b9f2451c5b4c7e74a28271e4efd0bcc7f2e9c 100644 (file)
@@ -26,6 +26,7 @@ import {
 import {
   isString,
   isArray,
+  isRegExp,
   ShapeFlags,
   remove,
   invokeArrayFns
@@ -350,7 +351,7 @@ function matches(pattern: MatchPattern, name: string): boolean {
     return pattern.some((p: string | RegExp) => matches(p, name))
   } else if (isString(pattern)) {
     return pattern.split(',').includes(name)
-  } else if (pattern.test) {
+  } else if (isRegExp(pattern)) {
     return pattern.test(name)
   }
   /* istanbul ignore next */
index 8e3020f9e3741f6dac2f9856ce734e0eb30f5ed8..ff30250381925e8724f49e87445cca33687c5427 100644 (file)
@@ -54,6 +54,8 @@ export const isSet = (val: unknown): val is Set<any> =>
 
 export const isDate = (val: unknown): val is Date =>
   toTypeString(val) === '[object Date]'
+export const isRegExp = (val: unknown): val is RegExp =>
+  toTypeString(val) === '[object RegExp]'
 export const isFunction = (val: unknown): val is Function =>
   typeof val === 'function'
 export const isString = (val: unknown): val is string => typeof val === 'string'