]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: use const statement instead of let (#1063)
authorwebfansplz <308241863@qq.com>
Thu, 5 Aug 2021 11:36:37 +0000 (19:36 +0800)
committerGitHub <noreply@github.com>
Thu, 5 Aug 2021 11:36:37 +0000 (13:36 +0200)
Co-authored-by: webfansplz <>
src/RouterLink.ts
src/devtools.ts
src/navigationGuards.ts
src/query.ts
src/scrollBehavior.ts

index 6671a0e9ae56dec1bec9db17351b92700e6a2677..236e98fe0b5b65b85e178dff4f8b273e81569ae2 100644 (file)
@@ -92,17 +92,17 @@ export function useLink(props: UseLinkOptions) {
   const route = computed(() => router.resolve(unref(props.to)))
 
   const activeRecordIndex = computed<number>(() => {
-    let { matched } = route.value
-    let { length } = matched
+    const { matched } = route.value
+    const { length } = matched
     const routeMatched: RouteRecord | undefined = matched[length - 1]
-    let currentMatched = currentRoute.matched
+    const currentMatched = currentRoute.matched
     if (!routeMatched || !currentMatched.length) return -1
-    let index = currentMatched.findIndex(
+    const index = currentMatched.findIndex(
       isSameRouteRecord.bind(null, routeMatched)
     )
     if (index > -1) return index
     // possible parent record
-    let parentRecordPath = getOriginalPath(
+    const parentRecordPath = getOriginalPath(
       matched[length - 2] as RouteRecord | undefined
     )
     return (
@@ -288,9 +288,9 @@ function includesParams(
   outer: RouteLocation['params'],
   inner: RouteLocation['params']
 ): boolean {
-  for (let key in inner) {
-    let innerValue = inner[key]
-    let outerValue = outer[key]
+  for (const key in inner) {
+    const innerValue = inner[key]
+    const outerValue = outer[key]
     if (typeof innerValue === 'string') {
       if (innerValue !== outerValue) return false
     } else {
index 2e4f48f2bf4c6f61f84138065b75d7b0b72dec72..503e19df6eefdd072c8bb2495b2c42c9b0ce0a7e 100644 (file)
@@ -532,7 +532,7 @@ function omit<T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K) {
     [K2 in Exclude<keyof T, K[number]>]: T[K2]
   }
 
-  for (let key in obj) {
+  for (const key in obj) {
     if (!keys.includes(key as any)) {
       // @ts-expect-error
       ret[key] = obj[key]
index 29b8d19f9eff3a2575bdcd01d0a94fa63fcaaae7..b8c554ccbc23eae06d9b45bc7247392e783c3256 100644 (file)
@@ -261,7 +261,7 @@ export function extractComponentsGuards(
               `"() => import('./MyPage.vue')" ? This will break in ` +
               `production if not fixed.`
           )
-          let promise = rawComponent
+          const promise = rawComponent
           rawComponent = () => promise
         } else if (
           (rawComponent as any).__asyncLoader &&
@@ -283,7 +283,7 @@ export function extractComponentsGuards(
 
       if (isRouteComponent(rawComponent)) {
         // __vccOpts is added by vue-class-component and contain the regular options
-        let options: ComponentOptions =
+        const options: ComponentOptions =
           (rawComponent as any).__vccOpts || rawComponent
         const guard = options[guardType]
         guard && guards.push(guardToPromiseFn(guard, to, from, record, name))
@@ -314,7 +314,7 @@ export function extractComponentsGuards(
             // replace the function with the resolved component
             record.components[name] = resolvedComponent
             // __vccOpts is added by vue-class-component and contain the regular options
-            let options: ComponentOptions =
+            const options: ComponentOptions =
               (resolvedComponent as any).__vccOpts || resolvedComponent
             const guard = options[guardType]
             return guard && guardToPromiseFn(guard, to, from, record, name)()
index 357e40da16895b90b70b17a0d706230ba18db11d..1074c8c72c8ee69d4cc8447477c668bf34508542 100644 (file)
@@ -55,9 +55,9 @@ export function parseQuery(search: string): LocationQuery {
     // pre decode the + into space
     const searchParam = searchParams[i].replace(PLUS_RE, ' ')
     // allow the = character
-    let eqPos = searchParam.indexOf('=')
-    let key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos))
-    let value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1))
+    const eqPos = searchParam.indexOf('=')
+    const key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos))
+    const value = eqPos < 0 ? null : decode(searchParam.slice(eqPos + 1))
 
     if (key in query) {
       // an extra variable for ts types
@@ -95,7 +95,7 @@ export function stringifyQuery(query: LocationQueryRaw): string {
       continue
     }
     // keep null values
-    let values: LocationQueryValueRaw[] = Array.isArray(value)
+    const values: LocationQueryValueRaw[] = Array.isArray(value)
       ? value.map(v => v && encodeQueryValue(v))
       : [value && encodeQueryValue(value)]
 
@@ -126,8 +126,8 @@ export function normalizeQuery(
 ): LocationQuery {
   const normalizedQuery: LocationQuery = {}
 
-  for (let key in query) {
-    let value = query[key]
+  for (const key in query) {
+    const value = query[key]
     if (value !== undefined) {
       normalizedQuery[key] = Array.isArray(value)
         ? value.map(v => (v == null ? null : '' + v))
index fe7f8dfbbe98d8f6a65f2d97fd7f3c575570c23a..8c772cb05e9e5bb707ebbc37bf88dcb9cefe2c90 100644 (file)
@@ -78,7 +78,7 @@ export function scrollToPosition(position: ScrollPosition): void {
   let scrollToOptions: ScrollPositionCoordinates
 
   if ('el' in position) {
-    let positionEl = position.el
+    const positionEl = position.el
     const isIdSelector =
       typeof positionEl === 'string' && positionEl.startsWith('#')
     /**
@@ -105,7 +105,7 @@ export function scrollToPosition(position: ScrollPosition): void {
     if (__DEV__ && typeof position.el === 'string') {
       if (!isIdSelector || !document.getElementById(position.el.slice(1))) {
         try {
-          let foundEl = document.querySelector(position.el)
+          const foundEl = document.querySelector(position.el)
           if (isIdSelector && foundEl) {
             warn(
               `The selector "${position.el}" should be passed as "el: document.querySelector('${position.el}')" because it starts with "#".`