@@ -6,132 +6,83 @@ import gonzales from '../../../lib/core/gonzales';
6
6
import { eliminateGlobals } from '../../../lib/core/traversalUtils' ;
7
7
8
8
describe ( 'eliminateGlobals()' , ( ) => {
9
- it ( 'should remove :global block ', ( ) => {
10
- const content = `
11
- :global {
12
- .foo {}
13
- } `;
9
+ describe ( 'resolving :global pseudo class ', ( ) => {
10
+ it ( 'should remove :global operator and the global class' , ( ) => {
11
+ const content = `
12
+ :global .global {}
13
+ `;
14
14
15
- const ast = gonzales . parse (
16
- content ,
17
- { syntax : 'scss' }
18
- ) ;
15
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
19
16
20
- eliminateGlobals ( ast ) ;
17
+ eliminateGlobals ( ast ) ;
21
18
22
- expect ( ast . toString ( ) ) . to . be . equal ( '\n' ) ;
23
- } ) ;
24
-
25
- it ( 'should remove :global block, but not local' , ( ) => {
26
- const content = `
27
- .bar {}
28
-
29
- :global {
30
- .foo {}
31
- }` ;
32
-
33
- const ast = gonzales . parse (
34
- content ,
35
- { syntax : 'scss' }
36
- ) ;
37
-
38
- eliminateGlobals ( ast ) ;
39
-
40
- expect ( ast . toString ( ) ) . to . be . equal (
41
- `
42
- .bar {}
43
-
44
- `
45
- ) ;
46
- } ) ;
47
-
48
- it ( 'should remove nested :global block' , ( ) => {
49
- const content = `
50
- .bar {}
19
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal ( '' ) ;
20
+ } ) ;
51
21
52
- .baz {
53
- :global {
54
- .foo {}
55
- }
56
- }` ;
22
+ it ( 'should remove :global operator and the global classes' , ( ) => {
23
+ const content = `
24
+ :global .global1 .global2 .global3.global4 {}
25
+ ` ;
57
26
58
- const ast = gonzales . parse (
59
- content ,
60
- { syntax : 'scss' }
61
- ) ;
27
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
62
28
63
- eliminateGlobals ( ast ) ;
29
+ eliminateGlobals ( ast ) ;
64
30
65
- expect ( ast . toString ( ) ) . to . be . equal (
66
- `
67
- .bar {}
68
-
69
- .baz {
70
-
71
- }`
72
- ) ;
73
- } ) ;
31
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal ( '' ) ;
32
+ } ) ;
74
33
75
- it ( 'should remove :global selector' , ( ) => {
76
- const content = `
77
- .bar {}
34
+ it ( 'should only remove :global operator and the global classes' , ( ) => {
35
+ const content = `
36
+ .local1 :global .global1 :local(.local2) .global2 :local(.local3), .local4 {}
37
+ ` ;
78
38
79
- :global .baz {}` ;
39
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
80
40
81
- const ast = gonzales . parse (
82
- content ,
83
- { syntax : 'scss' }
84
- ) ;
41
+ eliminateGlobals ( ast ) ;
85
42
86
- eliminateGlobals ( ast ) ;
87
-
88
- expect ( ast . toString ( ) ) . to . be . equal (
89
- `
90
- .bar {}
91
-
92
- `
93
- ) ;
43
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal (
44
+ '.local1 :local(.local2) :local(.local3), .local4 {}'
45
+ ) ;
46
+ } ) ;
94
47
} ) ;
95
48
96
- it ( 'should remove :global selector with multiple classes' , ( ) => {
97
- const content = `
98
- .bar {}
49
+ describe ( 'resolving :global() pseudo class' , ( ) => {
50
+ it ( 'should remove :global() pseudo class and its argument class' , ( ) => {
51
+ const content = `
52
+ :global(.global1) {}
53
+ ` ;
99
54
100
- :global .baz.foo {}` ;
55
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
101
56
102
- const ast = gonzales . parse (
103
- content ,
104
- { syntax : 'scss' }
105
- ) ;
57
+ eliminateGlobals ( ast ) ;
106
58
107
- eliminateGlobals ( ast ) ;
59
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal ( '' ) ;
60
+ } ) ;
108
61
109
- expect ( ast . toString ( ) ) . to . be . equal (
110
- `
111
- .bar {}
62
+ it ( 'should remove :global() pseudo class and its argument classes' , ( ) => {
63
+ const content = `
64
+ :global(.global1) :global(.global2, .global3), :global(.global4.global5) {}
65
+ ` ;
112
66
113
- `
114
- ) ;
115
- } ) ;
67
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
116
68
117
- it ( 'should remove classes wrapped in :global()' , ( ) => {
118
- const content = `
119
- .bar {}
69
+ eliminateGlobals ( ast ) ;
120
70
121
- :global(.bar.foo) {}` ;
71
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal ( '' ) ;
72
+ } ) ;
122
73
123
- const ast = gonzales . parse (
124
- content ,
125
- { syntax : 'scss' }
126
- ) ;
74
+ it ( 'should only remove :global() pseudo class and its argument classes' , ( ) => {
75
+ const content = `
76
+ .local1 :global(.global1) .local2, .local3 :global(.global2, .global3).local4 { }
77
+ ` ;
127
78
128
- eliminateGlobals ( ast ) ;
79
+ const ast = gonzales . parse ( content , { syntax : 'scss' } ) ;
129
80
130
- expect ( ast . toString ( ) ) . to . be . equal (
131
- `
132
- .bar {}
81
+ eliminateGlobals ( ast ) ;
133
82
134
- `
135
- ) ;
83
+ expect ( ast . toString ( ) . trim ( ) ) . to . be . equal (
84
+ '.local1 .local2, .local3 .local4 {}'
85
+ ) ;
86
+ } ) ;
136
87
} ) ;
137
88
} ) ;
0 commit comments