Skip to content

Commit

Permalink
chore: use const statement instead of let (#1063)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Aug 5, 2021
1 parent 24c84cd commit 21ea143
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/RouterLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions src/navigationGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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))
Expand Down Expand Up @@ -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)()
Expand Down
12 changes: 6 additions & 6 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/scrollBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('#')
/**
Expand All @@ -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 "#".`
Expand Down

0 comments on commit 21ea143

Please sign in to comment.