@@ -39,7 +39,25 @@ import {
3939 TOKEN_WHITESPACE ,
4040 TOKEN_STRING ,
4141} from './token-types'
42- import { is_whitespace as is_whitespace_char , is_vendor_prefixed } from './string-utils'
42+ import {
43+ is_whitespace as is_whitespace_char ,
44+ is_vendor_prefixed ,
45+ CHAR_PLUS ,
46+ CHAR_TILDE ,
47+ CHAR_GREATER_THAN ,
48+ CHAR_PERIOD ,
49+ CHAR_ASTERISK ,
50+ CHAR_AMPERSAND ,
51+ is_combinator ,
52+ CHAR_EQUALS ,
53+ CHAR_PIPE ,
54+ CHAR_DOLLAR ,
55+ CHAR_CARET ,
56+ CHAR_FORWARD_SLASH ,
57+ CHAR_SINGLE_QUOTE ,
58+ CHAR_DOUBLE_QUOTE ,
59+ CHAR_COLON ,
60+ } from './string-utils'
4361import { ANplusBParser } from './parse-anplusb'
4462import { CSSNode } from './css-node'
4563
@@ -166,7 +184,7 @@ export class SelectorParser {
166184 // Check if token is a combinator
167185 if ( token_type === TOKEN_DELIM ) {
168186 let ch = this . source . charCodeAt ( this . lexer . token_start )
169- if ( ch === 0x3e || ch === 0x2b || ch === 0x7e ) {
187+ if ( ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch === CHAR_TILDE ) {
170188 // Found leading combinator (>, +, ~) - this is a relative selector
171189 let combinator = this . create_combinator ( this . lexer . token_start , this . lexer . token_end )
172190 components . push ( combinator )
@@ -304,13 +322,13 @@ export class SelectorParser {
304322 case TOKEN_DELIM :
305323 // Could be: . (class), * (universal), & (nesting)
306324 let ch = this . source . charCodeAt ( start )
307- if ( ch === 0x2e ) {
325+ if ( ch === CHAR_PERIOD ) {
308326 // . - class selector
309327 return this . parse_class_selector ( start )
310- } else if ( ch === 0x2a ) {
328+ } else if ( ch === CHAR_ASTERISK ) {
311329 // * - universal selector
312330 return this . create_universal_selector ( start , end )
313- } else if ( ch === 0x26 ) {
331+ } else if ( ch === CHAR_AMPERSAND ) {
314332 // & - nesting selector
315333 return this . create_nesting_selector ( start , end )
316334 }
@@ -362,7 +380,7 @@ export class SelectorParser {
362380 // Check for explicit combinators
363381 if ( this . lexer . token_type === TOKEN_DELIM ) {
364382 let ch = this . source . charCodeAt ( this . lexer . token_start )
365- if ( ch === 0x3e || ch === 0x2b || ch === 0x7e ) {
383+ if ( is_combinator ( ch ) ) {
366384 // > + ~ (combinator text excludes leading whitespace)
367385 return this . create_combinator ( this . lexer . token_start , this . lexer . token_end )
368386 }
@@ -463,10 +481,14 @@ export class SelectorParser {
463481 continue
464482 }
465483 // Skip comments /*...*/
466- if ( ch === 0x2f /* / */ && start + 1 < end && this . source . charCodeAt ( start + 1 ) === 0x2a /* * */ ) {
484+ if ( ch === CHAR_FORWARD_SLASH && start + 1 < end && this . source . charCodeAt ( start + 1 ) === CHAR_ASTERISK ) {
467485 start += 2 // Skip /*
468486 while ( start < end ) {
469- if ( this . source . charCodeAt ( start ) === 0x2a && start + 1 < end && this . source . charCodeAt ( start + 1 ) === 0x2f ) {
487+ if (
488+ this . source . charCodeAt ( start ) === CHAR_ASTERISK &&
489+ start + 1 < end &&
490+ this . source . charCodeAt ( start + 1 ) === CHAR_FORWARD_SLASH
491+ ) {
470492 start += 2 // Skip */
471493 break
472494 }
@@ -485,10 +507,10 @@ export class SelectorParser {
485507 continue
486508 }
487509 // Skip comments /*...*/
488- if ( ch === 0x2f && end >= 2 && this . source . charCodeAt ( end - 2 ) === 0x2a ) {
510+ if ( ch === CHAR_FORWARD_SLASH && end >= 2 && this . source . charCodeAt ( end - 2 ) === CHAR_ASTERISK ) {
489511 // Find start of comment
490512 let pos = end - 2
491- while ( pos > start && ! ( this . source . charCodeAt ( pos ) === 0x2f && this . source . charCodeAt ( pos + 1 ) === 0x2a ) ) {
513+ while ( pos > start && ! ( this . source . charCodeAt ( pos ) === CHAR_FORWARD_SLASH && this . source . charCodeAt ( pos + 1 ) === CHAR_ASTERISK ) ) {
492514 pos --
493515 }
494516 if ( pos > start ) {
@@ -513,12 +535,12 @@ export class SelectorParser {
513535 let ch = this . source . charCodeAt ( name_end )
514536 if (
515537 is_whitespace_char ( ch ) ||
516- ch === 0x3d /* = */ ||
517- ch === 0x7e /* ~ */ ||
518- ch === 0x7c /* | */ ||
519- ch === 0x5e /* ^ */ ||
520- ch === 0x24 /* $ */ ||
521- ch === 0x2a /* * */
538+ ch === CHAR_EQUALS /* = */ ||
539+ ch === CHAR_TILDE /* ~ */ ||
540+ ch === CHAR_PIPE /* | */ ||
541+ ch === CHAR_CARET /* ^ */ ||
542+ ch === CHAR_DOLLAR /* $ */ ||
543+ ch === CHAR_ASTERISK /* * */
522544 ) {
523545 break
524546 }
@@ -540,10 +562,10 @@ export class SelectorParser {
540562 continue
541563 }
542564 // Skip comments
543- if ( ch === 0x2f && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x2a ) {
565+ if ( ch === CHAR_FORWARD_SLASH && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_ASTERISK ) {
544566 pos += 2
545567 while ( pos < end ) {
546- if ( this . source . charCodeAt ( pos ) === 0x2a && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x2f ) {
568+ if ( this . source . charCodeAt ( pos ) === CHAR_ASTERISK && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_FORWARD_SLASH ) {
547569 pos += 2
548570 break
549571 }
@@ -563,27 +585,27 @@ export class SelectorParser {
563585 // Parse operator
564586 let ch1 = this . source . charCodeAt ( pos )
565587
566- if ( ch1 === 0x3d ) {
588+ if ( ch1 === CHAR_EQUALS ) {
567589 // =
568590 operator_end = pos + 1
569591 this . arena . set_attr_operator ( node , ATTR_OPERATOR_EQUAL )
570- } else if ( ch1 === 0x7e && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x3d ) {
592+ } else if ( ch1 === CHAR_TILDE && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_EQUALS ) {
571593 // ~=
572594 operator_end = pos + 2
573595 this . arena . set_attr_operator ( node , ATTR_OPERATOR_TILDE_EQUAL )
574- } else if ( ch1 === 0x7c && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x3d ) {
596+ } else if ( ch1 === CHAR_PIPE && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_EQUALS ) {
575597 // |=
576598 operator_end = pos + 2
577599 this . arena . set_attr_operator ( node , ATTR_OPERATOR_PIPE_EQUAL )
578- } else if ( ch1 === 0x5e && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x3d ) {
600+ } else if ( ch1 === CHAR_CARET && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_EQUALS ) {
579601 // ^=
580602 operator_end = pos + 2
581603 this . arena . set_attr_operator ( node , ATTR_OPERATOR_CARET_EQUAL )
582- } else if ( ch1 === 0x24 && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x3d ) {
604+ } else if ( ch1 === CHAR_DOLLAR && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_EQUALS ) {
583605 // $=
584606 operator_end = pos + 2
585607 this . arena . set_attr_operator ( node , ATTR_OPERATOR_DOLLAR_EQUAL )
586- } else if ( ch1 === 0x2a && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x3d ) {
608+ } else if ( ch1 === CHAR_ASTERISK && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_EQUALS ) {
587609 // *=
588610 operator_end = pos + 2
589611 this . arena . set_attr_operator ( node , ATTR_OPERATOR_STAR_EQUAL )
@@ -602,10 +624,10 @@ export class SelectorParser {
602624 continue
603625 }
604626 // Skip comments
605- if ( ch === 0x2f && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x2a ) {
627+ if ( ch === CHAR_FORWARD_SLASH && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_ASTERISK ) {
606628 pos += 2
607629 while ( pos < end ) {
608- if ( this . source . charCodeAt ( pos ) === 0x2a && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === 0x2f ) {
630+ if ( this . source . charCodeAt ( pos ) === CHAR_ASTERISK && pos + 1 < end && this . source . charCodeAt ( pos + 1 ) === CHAR_FORWARD_SLASH ) {
609631 pos += 2
610632 break
611633 }
@@ -625,7 +647,7 @@ export class SelectorParser {
625647 value_start = pos
626648 let ch = this . source . charCodeAt ( pos )
627649
628- if ( ch === 0x22 || ch === 0x27 ) {
650+ if ( ch === CHAR_SINGLE_QUOTE || ch === CHAR_DOUBLE_QUOTE ) {
629651 // " or '
630652 // Quoted string - find matching quote
631653 let quote = ch
@@ -673,7 +695,7 @@ export class SelectorParser {
673695
674696 // Check for double colon (::)
675697 let is_pseudo_element = false
676- if ( this . lexer . pos < this . selector_end && this . source . charCodeAt ( this . lexer . pos ) === 0x3a ) {
698+ if ( this . lexer . pos < this . selector_end && this . source . charCodeAt ( this . lexer . pos ) === CHAR_COLON ) {
677699 is_pseudo_element = true
678700 this . lexer . pos ++ // skip second colon
679701 }
@@ -1032,9 +1054,8 @@ export class SelectorParser {
10321054 let ch = this . source . charCodeAt ( this . lexer . pos )
10331055 if ( is_whitespace_char ( ch ) ) {
10341056 this . lexer . pos ++
1035- } else {
1036- break
10371057 }
1058+ break
10381059 }
10391060 }
10401061}
0 commit comments