]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: use native symbols
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 21 Apr 2022 14:31:36 +0000 (16:31 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 30 Jun 2022 07:59:00 +0000 (09:59 +0200)
Native symbols are already used by Vue so it makes no sense to fallback in vue router

src/errors.ts
src/injectionSymbols.ts
src/utils/index.ts

index 1168a7eb34ad788dac0889bfdb5bd0533f0d4936..c466f9a3b9747a9801af32f5288d5ebaa3a0d096 100644 (file)
@@ -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
index 60838fdff705ca7e05fa368aa7b2ef12405c6fd6..4114db88103b47d5865cbdf25826e8a86df1ec30 100644 (file)
@@ -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<ComputedRef<RouteRecordNormalized | undefined>>
 
 /**
@@ -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<Ref<number> | number>
 
 /**
@@ -40,9 +30,7 @@ export const viewDepthKey = /*#__PURE__*/ PolySymbol(
  *
  * @internal
  */
-export const routerKey = /*#__PURE__*/ PolySymbol(
-  __DEV__ ? 'router' : 'r'
-) as InjectionKey<Router>
+export const routerKey = Symbol(__DEV__ ? 'router' : '') as InjectionKey<Router>
 
 /**
  * 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<RouteLocationNormalizedLoaded>
 
 /**
@@ -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<Ref<RouteLocationNormalizedLoaded>>
index 59078e4ab56957f006cbcf1b3d46dc869edcdc10..a961bc17a3818d6b03e137589836fe0824b4bdb8 100644 (file)
@@ -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