diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index eec2eab1a..7b168a3b8 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -1,4 +1,4 @@ -import { isObject, toTypeString } from '@vue/shared' +import { isObject, toRawType } from '@vue/shared' import { mutableHandlers, readonlyHandlers } from './baseHandlers' import { mutableCollectionHandlers, @@ -29,16 +29,14 @@ const nonReactiveValues = new WeakSet() const collectionTypes = new Set([Set, Map, WeakMap, WeakSet]) const isObservableType = /*#__PURE__*/ makeMap( - ['Object', 'Array', 'Map', 'Set', 'WeakMap', 'WeakSet'] - .map(t => `[object ${t}]`) - .join(',') + 'Object,Array,Map,Set,WeakMap,WeakSet' ) const canObserve = (value: any): boolean => { return ( !value._isVue && !value._isVNode && - isObservableType(toTypeString(value)) && + isObservableType(toRawType(value)) && !nonReactiveValues.has(value) ) } diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 8f9e603e2..146e0ff3c 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -10,7 +10,7 @@ import { isObject, isReservedProp, hasOwn, - toTypeString, + toRawType, PatchFlags, makeMap } from '@vue/shared' @@ -390,10 +390,6 @@ function styleValue(value: unknown, type: string): string { } } -function toRawType(value: unknown): string { - return toTypeString(value).slice(8, -1) -} - function isExplicable(type: string): boolean { const explicitTypes = ['string', 'number', 'boolean'] return explicitTypes.some(elem => type.toLowerCase() === elem) diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 5c7cc6a2e..38b1e2920 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -48,6 +48,10 @@ export const objectToString = Object.prototype.toString export const toTypeString = (value: unknown): string => objectToString.call(value) +export function toRawType(value: unknown): string { + return toTypeString(value).slice(8, -1) +} + export const isPlainObject = (val: unknown): val is object => toTypeString(val) === '[object Object]'