From a2f3e91cb3e3ae61118d803ce938d6f4eea76116 Mon Sep 17 00:00:00 2001 From: wangjiahan Date: Tue, 22 Dec 2020 21:02:58 +0800 Subject: [PATCH] fix: spread operator compatible --- src/devtools.ts | 10 +++++----- src/utils/index.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/devtools.ts b/src/devtools.ts index 165b14fd..5fae1944 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -15,18 +15,18 @@ import { RouteRecordMatcher } from './matcher/pathMatcher' import { PathParser } from './matcher/pathParserRanker' import { Router } from './router' import { RouteLocationNormalized } from './types' +import { assign, omit } from './utils' function formatRouteLocation( routeLocation: RouteLocationNormalized, tooltip?: string ) { - const copy = { - ...routeLocation, + const copy = assign({}, routeLocation, { // remove variables that can contain vue instances - matched: routeLocation.matched.map( - ({ instances, children, aliasOf, ...rest }) => rest + matched: routeLocation.matched.map(matched => + omit(matched, ['instances', 'children', 'aliasOf']) ), - } + }) return { _custom: { diff --git a/src/utils/index.ts b/src/utils/index.ts index 35a2b8d0..957c8b05 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -24,3 +24,20 @@ export function applyToParams( } export let noop = () => {} + +export const omit = >( + object: T, + paths: Array +) => { + const result: Record = {} + for (let key in object) { + if ( + paths.indexOf(key) >= 0 || + !Object.prototype.hasOwnProperty.call(object, key) + ) { + continue + } + result[key] = object[key] + } + return result +} -- 2.47.3