@@ -38,7 +38,7 @@ const regExpFilter = (regExp, separator) => {
3838} ;
3939
4040const filterBase =
41- ( { specialAction = 'accept' , defaultAction = 'ignore' , nonCheckableAction = 'ignore ' , transition} = { } ) =>
41+ ( { specialAction = 'accept' , defaultAction = 'ignore' , nonCheckableAction = 'process-key ' , transition} = { } ) =>
4242 options => {
4343 const once = options ?. once ,
4444 separator = options ?. pathSeparator || '.' ;
@@ -70,20 +70,35 @@ const filterBase =
7070 // process the optional value token (unfinished)
7171 if ( optionalToken ) {
7272 if ( optionalToken === chunk . name ) {
73- const returnToken = state === 'accept-value' ? chunk : none ;
73+ let returnToken = none ;
74+ switch ( state ) {
75+ case 'accept-value' :
76+ returnToken = chunk ;
77+ state = once ? 'pass' : 'check' ;
78+ break ;
79+ case 'process-key' :
80+ stack [ stack . length - 1 ] = chunk . value ;
81+ state = 'check' ;
82+ break ;
83+ default :
84+ state = once ? 'pass' : 'check' ;
85+ break ;
86+ }
7487 optionalToken = '' ;
75- state = once ? 'pass' : 'check' ;
7688 return returnToken ;
7789 }
7890 optionalToken = '' ;
79- state = once ? 'pass' : 'check' ;
91+ state = once && state !== 'process-key' ? 'pass' : 'check' ;
8092 }
8193
8294 let returnToken = none ;
8395
8496 recheck: for ( ; ; ) {
8597 // accept/reject tokens
8698 switch ( state ) {
99+ case 'process-key' :
100+ if ( chunk . name === 'endKey' ) optionalToken = 'keyValue' ;
101+ return none ;
87102 case 'pass' :
88103 return none ;
89104 case 'accept' :
@@ -170,13 +185,17 @@ const filterBase =
170185
171186 endToken = stopTokens [ chunk . name ] || '' ;
172187 switch ( action ) {
188+ case 'process-key' :
189+ if ( chunk . name === 'startKey' ) {
190+ state = 'process-key' ;
191+ continue recheck;
192+ }
193+ break ;
173194 case 'accept-token' :
174- if ( endToken ) {
175- if ( optionalTokens [ endToken ] ) {
176- state = 'accept-value' ;
177- startTransition = ! ! transition ;
178- continue recheck;
179- }
195+ if ( endToken && optionalTokens [ endToken ] ) {
196+ state = 'accept-value' ;
197+ startTransition = ! ! transition ;
198+ continue recheck;
180199 }
181200 if ( transition ) returnToken = transition ( stack , chunk , action , sanitizedOptions ) ;
182201 if ( returnToken === none ) {
0 commit comments