Skip to content

Commit 23e52b3

Browse files
committed
Prefer const over let
1 parent 3ffc652 commit 23e52b3

2 files changed

Lines changed: 74 additions & 74 deletions

File tree

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Trie {
4040
define (pattern) {
4141
if (typeof pattern !== 'string') throw new TypeError('Pattern must be string.')
4242
if (pattern.includes('//')) throw new Error('Multi-slash existhis.')
43-
let _pattern = pattern.replace(trimSlashReg, '')
44-
let node = defineNode(this.root, _pattern.split('/'), this.ignoreCase)
43+
const _pattern = pattern.replace(trimSlashReg, '')
44+
const node = defineNode(this.root, _pattern.split('/'), this.ignoreCase)
4545

4646
if (node.pattern === '') node.pattern = pattern
4747
return node
@@ -60,8 +60,8 @@ class Trie {
6060
}
6161

6262
let start = 1
63-
let end = path.length
64-
let matched = new Matched()
63+
const end = path.length
64+
const matched = new Matched()
6565
let parent = this.root
6666
for (let i = 1; i <= end; i++) {
6767
if (i < end && path[i] !== '/') continue
@@ -179,8 +179,8 @@ class Node {
179179
}
180180

181181
function defineNode (parent, segments, ignoreCase) {
182-
let segment = segments.shift()
183-
let child = parseNode(parent, segment, ignoreCase)
182+
const segment = segments.shift()
183+
const child = parseNode(parent, segment, ignoreCase)
184184

185185
if (!segments.length) {
186186
child.endpoint = true
@@ -196,7 +196,7 @@ function matchNode (parent, segment) {
196196
if (parent.children[segment] != null) {
197197
return parent.children[segment]
198198
}
199-
for (let child of parent.varyChildren) {
199+
for (const child of parent.varyChildren) {
200200
let _segment = segment
201201
if (child.suffix !== '') {
202202
if (segment === child.suffix || !segment.endsWith(child.suffix)) {
@@ -223,7 +223,7 @@ function parseNode (parent, segment, ignoreCase) {
223223

224224
if (parent.children[_segment] != null) return parent.children[_segment]
225225

226-
let node = new Node(parent)
226+
const node = new Node(parent)
227227

228228
if (segment === '') {
229229
parent.children[''] = node
@@ -241,7 +241,7 @@ function parseNode (parent, segment, ignoreCase) {
241241
node.wildcard = true
242242
break
243243
default:
244-
let i = name.search(suffixReg)
244+
const i = name.search(suffixReg)
245245
if (i >= 0) {
246246
node.suffix = name.slice(i + 1)
247247
name = name.slice(0, i)
@@ -251,9 +251,9 @@ function parseNode (parent, segment, ignoreCase) {
251251
}
252252

253253
if (name[name.length - 1] === ')') {
254-
let i = name.indexOf('(')
254+
const i = name.indexOf('(')
255255
if (i > 0) {
256-
let regex = name.slice(i + 1, name.length - 1)
256+
const regex = name.slice(i + 1, name.length - 1)
257257
if (regex.length > 0) {
258258
name = name.slice(0, i)
259259
node.regex = new RegExp(regex)
@@ -270,7 +270,7 @@ function parseNode (parent, segment, ignoreCase) {
270270
}
271271
node.name = name
272272

273-
for (let child of parent.varyChildren) {
273+
for (const child of parent.varyChildren) {
274274
if (child.wildcard) {
275275
if (!node.wildcard) {
276276
throw new Error(`can't define "${node.getSegments()}" after "${child.getSegments()}"`)

0 commit comments

Comments
 (0)