File tree 1 file changed +17
-8
lines changed
1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -34,27 +34,36 @@ const charsToEscapeInName = new Set(
34
34
*/
35
35
export function stringify ( selector : Selector [ ] [ ] ) : string {
36
36
return selector
37
- . map ( ( token ) => token . map ( ( t ) => stringifyToken ( t ) ) . join ( "" ) )
37
+ . map ( ( token ) => token . map ( stringifyToken ) . join ( "" ) )
38
38
. join ( ", " ) ;
39
39
}
40
40
41
- function stringifyToken ( token : Selector ) : string {
41
+ function stringifyToken (
42
+ token : Selector ,
43
+ index : number ,
44
+ arr : Selector [ ]
45
+ ) : string {
42
46
switch ( token . type ) {
43
47
// Simple types
44
48
case SelectorType . Child :
45
- return " > " ;
49
+ return index === 0 ? "> " : " > " ;
46
50
case SelectorType . Parent :
47
- return " < " ;
51
+ return index === 0 ? "< " : " < " ;
48
52
case SelectorType . Sibling :
49
- return " ~ " ;
53
+ return index === 0 ? "~ " : " ~ " ;
50
54
case SelectorType . Adjacent :
51
- return " + " ;
55
+ return index === 0 ? "+ " : " + " ;
52
56
case SelectorType . Descendant :
53
57
return " " ;
54
58
case SelectorType . ColumnCombinator :
55
- return " || " ;
59
+ return index === 0 ? "|| " : " || " ;
56
60
case SelectorType . Universal :
57
- return `${ getNamespace ( token . namespace ) } *` ;
61
+ // Return an empty string if the selector isn't needed.
62
+ return token . namespace === "*" &&
63
+ index + 1 < arr . length &&
64
+ "name" in arr [ index + 1 ]
65
+ ? ""
66
+ : `${ getNamespace ( token . namespace ) } *` ;
58
67
59
68
case SelectorType . Tag :
60
69
return getNamespacedName ( token ) ;
You can’t perform that action at this time.
0 commit comments