@@ -510,6 +510,35 @@ export interface PseudoLocationIndex {
510510 pseudoElements : Record < string , string [ ] > ;
511511}
512512
513+ const latestSyntaxDefinition = {
514+ ...selectors4SyntaxDefinition ,
515+ modules : ( Object . entries ( cssModules ) as [ CssModule , SyntaxDefinition & { latest ?: boolean } ] [ ] )
516+ . filter ( ( [ , { latest} ] ) => latest )
517+ . map ( ( [ name ] ) => name )
518+ } ;
519+
520+ const progressiveSyntaxDefinition = extendSyntaxDefinition ( latestSyntaxDefinition , {
521+ pseudoElements : {
522+ unknown : 'accept'
523+ } ,
524+ pseudoClasses : {
525+ unknown : 'accept'
526+ } ,
527+ attributes : {
528+ unknownCaseSensitivityModifiers : 'accept'
529+ }
530+ } ) ;
531+
532+ export const cssSyntaxDefinitions : Record < CssLevel , SyntaxDefinition > = {
533+ css1 : css1SyntaxDefinition ,
534+ css2 : css2SyntaxDefinition ,
535+ css3 : selectors3SyntaxDefinition ,
536+ 'selectors-3' : selectors3SyntaxDefinition ,
537+ 'selectors-4' : selectors4SyntaxDefinition ,
538+ latest : latestSyntaxDefinition ,
539+ progressive : progressiveSyntaxDefinition
540+ } ;
541+
513542/**
514543 * Builds an index of where each pseudo-class and pseudo-element is defined
515544 * (in which CSS Level or CSS Module)
@@ -519,18 +548,18 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
519548 pseudoClasses : { } ,
520549 pseudoElements : { }
521550 } ;
522-
551+
523552 // Add CSS Levels (excluding 'latest' and 'progressive')
524553 const cssLevels : CssLevel [ ] = [ 'css1' , 'css2' , 'css3' , 'selectors-3' , 'selectors-4' ] ;
525-
554+
526555 for ( const level of cssLevels ) {
527556 const syntax = cssSyntaxDefinitions [ level ] ;
528-
557+
529558 // Process pseudo-classes
530559 if ( syntax . pseudoClasses && typeof syntax . pseudoClasses === 'object' ) {
531- const { definitions } = syntax . pseudoClasses ;
560+ const { definitions} = syntax . pseudoClasses ;
532561 if ( definitions ) {
533- for ( const [ type , names ] of Object . entries ( definitions ) ) {
562+ for ( const [ , names ] of Object . entries ( definitions ) ) {
534563 for ( const name of names ) {
535564 if ( ! index . pseudoClasses [ name ] ) {
536565 index . pseudoClasses [ name ] = [ ] ;
@@ -542,10 +571,10 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
542571 }
543572 }
544573 }
545-
574+
546575 // Process pseudo-elements
547576 if ( syntax . pseudoElements && typeof syntax . pseudoElements === 'object' ) {
548- const { definitions } = syntax . pseudoElements ;
577+ const { definitions} = syntax . pseudoElements ;
549578 if ( definitions ) {
550579 if ( Array . isArray ( definitions ) ) {
551580 for ( const name of definitions ) {
@@ -557,7 +586,7 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
557586 }
558587 }
559588 } else {
560- for ( const [ type , names ] of Object . entries ( definitions ) ) {
589+ for ( const names of Object . values ( definitions ) ) {
561590 for ( const name of names ) {
562591 if ( ! index . pseudoElements [ name ] ) {
563592 index . pseudoElements [ name ] = [ ] ;
@@ -571,14 +600,17 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
571600 }
572601 }
573602 }
574-
603+
575604 // Add CSS Modules
576- for ( const [ moduleName , moduleSyntax ] of Object . entries ( cssModules ) ) {
605+ for ( const [ moduleName , moduleSyntax ] of Object . entries ( cssModules ) as [
606+ CssModule ,
607+ SyntaxDefinition & { latest ?: boolean }
608+ ] [ ] ) {
577609 // Process pseudo-classes
578610 if ( moduleSyntax . pseudoClasses && typeof moduleSyntax . pseudoClasses === 'object' ) {
579- const { definitions } = moduleSyntax . pseudoClasses ;
611+ const { definitions} = moduleSyntax . pseudoClasses ;
580612 if ( definitions ) {
581- for ( const [ type , names ] of Object . entries ( definitions ) ) {
613+ for ( const names of Object . values ( definitions ) ) {
582614 for ( const name of names ) {
583615 if ( ! index . pseudoClasses [ name ] ) {
584616 index . pseudoClasses [ name ] = [ ] ;
@@ -590,10 +622,10 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
590622 }
591623 }
592624 }
593-
625+
594626 // Process pseudo-elements
595627 if ( moduleSyntax . pseudoElements && typeof moduleSyntax . pseudoElements === 'object' ) {
596- const { definitions } = moduleSyntax . pseudoElements ;
628+ const { definitions} = moduleSyntax . pseudoElements ;
597629 if ( definitions ) {
598630 if ( Array . isArray ( definitions ) ) {
599631 for ( const name of definitions ) {
@@ -605,7 +637,7 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
605637 }
606638 }
607639 } else {
608- for ( const [ type , names ] of Object . entries ( definitions ) ) {
640+ for ( const names of Object . values ( definitions ) ) {
609641 for ( const name of names ) {
610642 if ( ! index . pseudoElements [ name ] ) {
611643 index . pseudoElements [ name ] = [ ] ;
@@ -619,38 +651,9 @@ export function buildPseudoLocationIndex(): PseudoLocationIndex {
619651 }
620652 }
621653 }
622-
654+
623655 return index ;
624656}
625657
626658// Pre-build the index for faster lookup
627659export const pseudoLocationIndex = buildPseudoLocationIndex ( ) ;
628-
629- const latestSyntaxDefinition = {
630- ...selectors4SyntaxDefinition ,
631- modules : ( Object . entries ( cssModules ) as [ CssModule , SyntaxDefinition & { latest ?: boolean } ] [ ] )
632- . filter ( ( [ , { latest} ] ) => latest )
633- . map ( ( [ name ] ) => name )
634- } ;
635-
636- const progressiveSyntaxDefinition = extendSyntaxDefinition ( latestSyntaxDefinition , {
637- pseudoElements : {
638- unknown : 'accept'
639- } ,
640- pseudoClasses : {
641- unknown : 'accept'
642- } ,
643- attributes : {
644- unknownCaseSensitivityModifiers : 'accept'
645- }
646- } ) ;
647-
648- export const cssSyntaxDefinitions : Record < CssLevel , SyntaxDefinition > = {
649- css1 : css1SyntaxDefinition ,
650- css2 : css2SyntaxDefinition ,
651- css3 : selectors3SyntaxDefinition ,
652- 'selectors-3' : selectors3SyntaxDefinition ,
653- 'selectors-4' : selectors4SyntaxDefinition ,
654- latest : latestSyntaxDefinition ,
655- progressive : progressiveSyntaxDefinition
656- } ;
0 commit comments