From: wangjiahan Date: Tue, 22 Dec 2020 13:02:58 +0000 (+0800) Subject: fix: spread operator compatible X-Git-Tag: v4.0.2~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2f3e91cb3e3ae61118d803ce938d6f4eea76116;p=thirdparty%2Fvuejs%2Frouter.git fix: spread operator compatible --- 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 +}