@@ -300,20 +300,21 @@ function initSearch(rawSearchIndex) {
300300 * @return {integer }
301301 */
302302 function getIdentEndPosition ( parserState ) {
303+ const start = parserState . pos ;
303304 let end = parserState . pos ;
304- let foundExclamation = false ;
305+ let foundExclamation = - 1 ;
305306 while ( parserState . pos < parserState . length ) {
306307 const c = parserState . userQuery [ parserState . pos ] ;
307308 if ( ! isIdentCharacter ( c ) ) {
308309 if ( c === "!" ) {
309- if ( foundExclamation ) {
310+ if ( foundExclamation !== - 1 ) {
310311 throw new Error ( "Cannot have more than one `!` in an ident" ) ;
311312 } else if ( parserState . pos + 1 < parserState . length &&
312313 isIdentCharacter ( parserState . userQuery [ parserState . pos + 1 ] )
313314 ) {
314315 throw new Error ( "`!` can only be at the end of an ident" ) ;
315316 }
316- foundExclamation = true ;
317+ foundExclamation = parserState . pos ;
317318 } else if ( isErrorCharacter ( c ) ) {
318319 throw new Error ( `Unexpected \`${ c } \`` ) ;
319320 } else if (
@@ -326,16 +327,35 @@ function initSearch(rawSearchIndex) {
326327 if ( ! isPathStart ( parserState ) ) {
327328 break ;
328329 }
330+ if ( foundExclamation !== - 1 ) {
331+ if ( start <= ( end - 2 ) ) {
332+ throw new Error ( "Cannot have associated items in macros" ) ;
333+ } else {
334+ // if start == end - 1, we got the never type
335+ // while the never type has no associated macros, we still
336+ // can parse a path like that
337+ foundExclamation = - 1 ;
338+ }
339+ }
329340 // Skip current ":".
330341 parserState . pos += 1 ;
331- foundExclamation = false ;
332342 } else {
333343 throw new Error ( `Unexpected \`${ c } \`` ) ;
334344 }
335345 }
336346 parserState . pos += 1 ;
337347 end = parserState . pos ;
338348 }
349+ // if start == end - 1, we got the never type
350+ if ( foundExclamation !== - 1 && start <= ( end - 2 ) ) {
351+ if ( parserState . typeFilter === null ) {
352+ parserState . typeFilter = "macro" ;
353+ } else if ( parserState . typeFilter !== "macro" ) {
354+ throw new Error ( `Invalid search type: macro \`!\` and ` +
355+ `\`${ parserState . typeFilter } \` both specified` ) ;
356+ }
357+ end = foundExclamation ;
358+ }
339359 return end ;
340360 }
341361
0 commit comments