Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Dec 15, 2021
1 parent 202e710 commit 9580b5e
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/util/toPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@ export function toPath(path) {
throw new Error(`Invalid path: ${path}\n` + `${' '.repeat(14 + i)}^`)
}

// The last thing we looked at was an ident so we ened to keep looking for more
// Later scans will identify the end of the ident
// Whenever we go from a non-ident to ident we start capturing a new part
// We also capture start -> lb for initial empty strings generated by `[]`
if (
(prev === undefined && curr === '[') ||
(prev === '.' && !inBrackets && currIsIdent) ||
(prev === '[' && currIsIdent) ||
(prev === ']' && curr === '.')
) {
partStart = i
}

// Make sure we capture the last character of the part
if (prevIsIdent) {
partEnd = i
}
Expand All @@ -78,17 +88,6 @@ export function toPath(path) {
parts.push(path.slice(partStart, partEnd))
}

// Whenever we go from a non-ident to ident we start capturing a new part
// We also capture start -> lb for initial empty strings generated by `[]`
if (
(prev === undefined && curr === '[') ||
(prev === '.' && !inBrackets && currIsIdent) ||
(prev === '[' && currIsIdent) ||
(prev === ']' && curr === '.')
) {
partStart = partEnd = i
}

// Bracket bookkeeping
if (curr === '[') {
inBrackets = true
Expand Down Expand Up @@ -137,7 +136,7 @@ export function toPathFull(path) {
let error = () => {
throw new Error(`Invalid path: ${path}\n` + `${' '.repeat(14 + i)}^`)
}
let startNew = () => (partStart = partEnd = i)
let startNew = () => (partStart = i)
let advance = () => (partEnd = i)
let setInBrackets = (v) => (inBrackets = v)
let capture = () => parts.push(path.slice(partStart, partEnd))
Expand Down

0 comments on commit 9580b5e

Please sign in to comment.