Skip to content

Commit 8861ef5

Browse files
authored
perf(path): simplified code (#3933)
1 parent 5a126e2 commit 8861ef5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/path/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ export class Path {
400400
if (this.isMatchPattern) {
401401
throw new Error(`${this.entire} cannot be transformed`)
402402
}
403-
const args = this.segments.reduce((buf, key) => {
404-
return new RegExp(regexp).test(key as string) ? buf.concat(key) : buf
405-
}, [])
403+
const reg = new RegExp(regexp)
404+
const args = this.segments.filter((key) =>
405+
reg.test(key as string)
406+
) as string[]
406407
return callback(...args)
407408
}
408409

0 commit comments

Comments
 (0)