diff --git a/src/util/toPath.js b/src/util/toPath.js index 090b66cfdb8f..3f1f5f653a9b 100644 --- a/src/util/toPath.js +++ b/src/util/toPath.js @@ -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 } @@ -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 @@ -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))