From: webfansplz <308241863@qq.com> Date: Mon, 14 Nov 2022 01:14:28 +0000 (+0800) Subject: chore(runtime-core): add `isRegExp` to check `RegExp` (#6041) X-Git-Tag: v3.2.46~86 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0187f998f76c69922272e0f17c6aa2c810143364;p=thirdparty%2Fvuejs%2Fcore.git chore(runtime-core): add `isRegExp` to check `RegExp` (#6041) --- diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index 66d0f82a10..554b9f2451 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -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 */ diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 8e3020f9e3..ff30250381 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -54,6 +54,8 @@ export const isSet = (val: unknown): val is Set => 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'