From: webfansplz <308241863@qq.com> Date: Thu, 5 Aug 2021 11:36:37 +0000 (+0800) Subject: chore: use const statement instead of let (#1063) X-Git-Tag: v4.0.11~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21ea143a318009520ca809b3825dc9e3518c104a;p=thirdparty%2Fvuejs%2Frouter.git chore: use const statement instead of let (#1063) Co-authored-by: webfansplz <> --- diff --git a/src/RouterLink.ts b/src/RouterLink.ts index 6671a0e9..236e98fe 100644 --- a/src/RouterLink.ts +++ b/src/RouterLink.ts @@ -92,17 +92,17 @@ export function useLink(props: UseLinkOptions) { const route = computed(() => router.resolve(unref(props.to))) const activeRecordIndex = computed(() => { - 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 { diff --git a/src/devtools.ts b/src/devtools.ts index 2e4f48f2..503e19df 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -532,7 +532,7 @@ function omit(obj: T, keys: K) { [K2 in Exclude]: 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] diff --git a/src/navigationGuards.ts b/src/navigationGuards.ts index 29b8d19f..b8c554cc 100644 --- a/src/navigationGuards.ts +++ b/src/navigationGuards.ts @@ -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)() diff --git a/src/query.ts b/src/query.ts index 357e40da..1074c8c7 100644 --- a/src/query.ts +++ b/src/query.ts @@ -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)) diff --git a/src/scrollBehavior.ts b/src/scrollBehavior.ts index fe7f8dfb..8c772cb0 100644 --- a/src/scrollBehavior.ts +++ b/src/scrollBehavior.ts @@ -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 "#".`