From: Eduardo San Martin Morote Date: Thu, 21 Apr 2022 14:31:36 +0000 (+0200) Subject: refactor: use native symbols X-Git-Tag: v4.1.0~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eab9829d6ca4c6dc7a4375fe4fcbe9743c26dd65;p=thirdparty%2Fvuejs%2Frouter.git refactor: use native symbols Native symbols are already used by Vue so it makes no sense to fallback in vue router --- diff --git a/src/errors.ts b/src/errors.ts index 1168a7eb..c466f9a3 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -5,7 +5,6 @@ import { RouteLocationNormalized, } from './types' import { assign } from './utils' -import { PolySymbol } from './injectionSymbols' /** * Flags so we can combine them when checking for multiple errors @@ -20,9 +19,7 @@ export const enum ErrorTypes { NAVIGATION_DUPLICATED = 16, } -const NavigationFailureSymbol = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'navigation failure' : 'nf' -) +const NavigationFailureSymbol = Symbol(__DEV__ ? 'navigation failure' : '') export interface MatcherError extends Error { type: ErrorTypes.MATCHER_NOT_FOUND diff --git a/src/injectionSymbols.ts b/src/injectionSymbols.ts index 60838fdf..4114db88 100644 --- a/src/injectionSymbols.ts +++ b/src/injectionSymbols.ts @@ -3,16 +3,6 @@ import { RouteLocationNormalizedLoaded } from './types' import { Router } from './router' import { RouteRecordNormalized } from './matcher/types' -export const hasSymbol = - typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol' - -export const PolySymbol = (name: string) => - // vr = vue router - hasSymbol - ? Symbol(__DEV__ ? '[vue-router]: ' + name : name) - : (__DEV__ ? '[vue-router]: ' : '_vr_') + name - -// rvlm = Router View Location Matched /** * RouteRecord being rendered by the closest ancestor Router View. Used for * `onBeforeRouteUpdate` and `onBeforeRouteLeave`. rvlm stands for Router View @@ -20,8 +10,8 @@ export const PolySymbol = (name: string) => * * @internal */ -export const matchedRouteKey = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'router view location matched' : 'rvlm' +export const matchedRouteKey = Symbol( + __DEV__ ? 'router view location matched' : '' ) as InjectionKey> /** @@ -30,8 +20,8 @@ export const matchedRouteKey = /*#__PURE__*/ PolySymbol( * * @internal */ -export const viewDepthKey = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'router view depth' : 'rvd' +export const viewDepthKey = Symbol( + __DEV__ ? 'router view depth' : '' ) as InjectionKey | number> /** @@ -40,9 +30,7 @@ export const viewDepthKey = /*#__PURE__*/ PolySymbol( * * @internal */ -export const routerKey = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'router' : 'r' -) as InjectionKey +export const routerKey = Symbol(__DEV__ ? 'router' : '') as InjectionKey /** * Allows overriding the current route returned by `useRoute` in tests. rl @@ -50,8 +38,8 @@ export const routerKey = /*#__PURE__*/ PolySymbol( * * @internal */ -export const routeLocationKey = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'route location' : 'rl' +export const routeLocationKey = Symbol( + __DEV__ ? 'route location' : '' ) as InjectionKey /** @@ -60,6 +48,6 @@ export const routeLocationKey = /*#__PURE__*/ PolySymbol( * * @internal */ -export const routerViewLocationKey = /*#__PURE__*/ PolySymbol( - __DEV__ ? 'router view location' : 'rvl' +export const routerViewLocationKey = Symbol( + __DEV__ ? 'router view location' : '' ) as InjectionKey> diff --git a/src/utils/index.ts b/src/utils/index.ts index 59078e4a..a961bc17 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,10 +1,9 @@ import { RouteParams, RouteComponent, RouteParamsRaw } from '../types' -import { hasSymbol } from '../injectionSymbols' export * from './env' export function isESModule(obj: any): obj is { default: RouteComponent } { - return obj.__esModule || (hasSymbol && obj[Symbol.toStringTag] === 'Module') + return obj.__esModule || obj[Symbol.toStringTag] === 'Module' } export const assign = Object.assign