@@ -34,21 +34,13 @@ const updateSelectorBoundaries = (
3434 */
3535const parser = ( processor : Processor ) : void => {
3636 let selectorBoundaries : Array < Boundaries > = [ ] ;
37- let globalSelectors : Array < TemplateNode > = [ ] ;
3837
3938 walk ( processor . ast , {
4039 enter ( node : TemplateNode ) {
4140 if ( node . type === 'Script' || node . type === 'Fragment' ) {
4241 this . skip ( ) ;
4342 }
4443 if ( node . type === 'Selector' ) {
45- globalSelectors = [
46- ...globalSelectors ,
47- ...node . children . filter (
48- ( item ) => item . name === 'global' && item . type === 'PseudoClassSelector'
49- ) ,
50- ] ;
51-
5244 let start = 0 ;
5345 let end = 0 ;
5446
@@ -58,20 +50,20 @@ const parser = (processor: Processor): void => {
5850 ( item . name === 'global' || item . name === 'local' ) &&
5951 item . type === 'PseudoClassSelector'
6052 ) {
61- if ( start > 0 ) {
53+ if ( start > 0 && end > 0 ) {
6254 selectorBoundaries = updateSelectorBoundaries ( selectorBoundaries , start , end ) ;
6355 hasPushed = true ;
6456 }
6557 start = item . end + 1 ;
6658 end = 0 ;
67- } else {
59+ } else if ( item . start && item . end ) {
6860 if ( start === 0 ) {
6961 start = item . start ;
7062 }
7163 end = item . end ;
7264 }
7365
74- if ( ! hasPushed && index === node . children . length - 1 ) {
66+ if ( ! hasPushed && index === node . children . length - 1 && end > 0 ) {
7567 selectorBoundaries = updateSelectorBoundaries ( selectorBoundaries , start , end ) ;
7668 }
7769 } ) ;
@@ -88,13 +80,8 @@ const parser = (processor: Processor): void => {
8880 } ) ;
8981
9082 selectorBoundaries . forEach ( ( boundary ) => {
91- const hasClassSelector = globalSelectors . filter (
92- ( item ) => boundary . start <= item . start && boundary . end >= item . end
93- ) ;
94- if ( hasClassSelector . length < 1 ) {
95- processor . magicContent . appendLeft ( boundary . start , ':global(' ) ;
96- processor . magicContent . appendRight ( boundary . end , ')' ) ;
97- }
83+ processor . magicContent . appendLeft ( boundary . start , ':global(' ) ;
84+ processor . magicContent . appendRight ( boundary . end , ')' ) ;
9885 } ) ;
9986} ;
10087
@@ -106,7 +93,6 @@ const nativeProcessor = async (
10693) : Promise < string > => {
10794 const processor = new Processor ( ast , content , filename , options , parser ) ;
10895 const processedContent = processor . parse ( ) ;
109- console . log ( processedContent ) ;
11096 return processedContent ;
11197} ;
11298
0 commit comments