@@ -57,8 +57,18 @@ export function toPath(path) {
57
57
throw new Error ( `Invalid path: ${ path } \n` + `${ ' ' . repeat ( 14 + i ) } ^` )
58
58
}
59
59
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
62
72
if ( prevIsIdent ) {
63
73
partEnd = i
64
74
}
@@ -78,17 +88,6 @@ export function toPath(path) {
78
88
parts . push ( path . slice ( partStart , partEnd ) )
79
89
}
80
90
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
-
92
91
// Bracket bookkeeping
93
92
if ( curr === '[' ) {
94
93
inBrackets = true
@@ -137,7 +136,7 @@ export function toPathFull(path) {
137
136
let error = ( ) => {
138
137
throw new Error ( `Invalid path: ${ path } \n` + `${ ' ' . repeat ( 14 + i ) } ^` )
139
138
}
140
- let startNew = ( ) => ( partStart = partEnd = i )
139
+ let startNew = ( ) => ( partStart = i )
141
140
let advance = ( ) => ( partEnd = i )
142
141
let setInBrackets = ( v ) => ( inBrackets = v )
143
142
let capture = ( ) => parts . push ( path . slice ( partStart , partEnd ) )
0 commit comments