Skip to content

Commit 9580b5e

Browse files
committed
Cleanup
1 parent 202e710 commit 9580b5e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/util/toPath.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ export function toPath(path) {
5757
throw new Error(`Invalid path: ${path}\n` + `${' '.repeat(14 + i)}^`)
5858
}
5959

60-
// The last thing we looked at was an ident so we ened to keep looking for more
61-
// Later scans will identify the end of the ident
60+
// Whenever we go from a non-ident to ident we start capturing a new part
61+
// We also capture start -> lb for initial empty strings generated by `[]`
62+
if (
63+
(prev === undefined && curr === '[') ||
64+
(prev === '.' && !inBrackets && currIsIdent) ||
65+
(prev === '[' && currIsIdent) ||
66+
(prev === ']' && curr === '.')
67+
) {
68+
partStart = i
69+
}
70+
71+
// Make sure we capture the last character of the part
6272
if (prevIsIdent) {
6373
partEnd = i
6474
}
@@ -78,17 +88,6 @@ export function toPath(path) {
7888
parts.push(path.slice(partStart, partEnd))
7989
}
8090

81-
// Whenever we go from a non-ident to ident we start capturing a new part
82-
// We also capture start -> lb for initial empty strings generated by `[]`
83-
if (
84-
(prev === undefined && curr === '[') ||
85-
(prev === '.' && !inBrackets && currIsIdent) ||
86-
(prev === '[' && currIsIdent) ||
87-
(prev === ']' && curr === '.')
88-
) {
89-
partStart = partEnd = i
90-
}
91-
9291
// Bracket bookkeeping
9392
if (curr === '[') {
9493
inBrackets = true
@@ -137,7 +136,7 @@ export function toPathFull(path) {
137136
let error = () => {
138137
throw new Error(`Invalid path: ${path}\n` + `${' '.repeat(14 + i)}^`)
139138
}
140-
let startNew = () => (partStart = partEnd = i)
139+
let startNew = () => (partStart = i)
141140
let advance = () => (partEnd = i)
142141
let setInBrackets = (v) => (inBrackets = v)
143142
let capture = () => parts.push(path.slice(partStart, partEnd))

0 commit comments

Comments
 (0)