@@ -64,6 +64,7 @@ import {
6464 CHAR_FORM_FEED ,
6565 CHAR_NEWLINE ,
6666 CHAR_SPACE ,
67+ CHAR_TAB ,
6768} from './string-utils'
6869import { ANplusBParser } from './parse-anplusb'
6970import { CSSNode } from './css-node'
@@ -219,7 +220,10 @@ export class SelectorParser {
219220 // Peek ahead for comma or end
220221 const saved = this . lexer . save_position ( )
221222 this . skip_whitespace ( )
222- if ( this . lexer . pos >= this . selector_end ) break
223+ if ( this . lexer . pos >= this . selector_end ) {
224+ this . lexer . restore_position ( saved )
225+ break
226+ }
223227
224228 this . lexer . next_token_fast ( false )
225229 let token_type = this . lexer . token_type
@@ -417,15 +421,18 @@ export class SelectorParser {
417421 while ( this . lexer . pos < this . selector_end ) {
418422 let ch = this . source . charCodeAt ( this . lexer . pos )
419423 // no calling is_whitespace() because of function call overhead
420- if ( ch === CHAR_SPACE || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED ) {
424+ if ( ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED ) {
421425 has_whitespace = true
422426 this . lexer . pos ++
423427 } else {
424428 break
425429 }
426430 }
427431
428- if ( this . lexer . pos >= this . selector_end ) return null
432+ if ( this . lexer . pos >= this . selector_end ) {
433+ this . lexer . pos = whitespace_start
434+ return null
435+ }
429436
430437 this . lexer . next_token_fast ( false )
431438
@@ -445,7 +452,7 @@ export class SelectorParser {
445452 while ( this . lexer . pos < this . selector_end ) {
446453 let ch = this . source . charCodeAt ( this . lexer . pos )
447454 // no calling is_whitespace() because of function call overhead
448- if ( ch === CHAR_SPACE || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED ) {
455+ if ( ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED ) {
449456 this . lexer . pos ++
450457 } else {
451458 break
0 commit comments