File tree 2 files changed +19
-27
lines changed
2 files changed +19
-27
lines changed Original file line number Diff line number Diff line change @@ -9,27 +9,17 @@ var hash = '#'.charCodeAt(0);
9
9
10
10
/* Parse a simple CSS selector into a HAST node. */
11
11
function parse ( selector ) {
12
- var id = null ;
13
- var className = [ ] ;
14
12
var value = selector || '' ;
15
13
var name = 'div' ;
16
- var node ;
17
- var type = null ;
14
+ var props = { } ;
18
15
var index = - 1 ;
19
- var code ;
20
16
var length = value . length ;
17
+ var className ;
18
+ var type ;
19
+ var code ;
21
20
var subvalue ;
22
21
var lastIndex ;
23
22
24
- node = {
25
- type : 'element' ,
26
- tagName : null ,
27
- properties : { } ,
28
- children : [ ]
29
- } ;
30
-
31
- type = null ;
32
-
33
23
while ( ++ index <= length ) {
34
24
code = value . charCodeAt ( index ) ;
35
25
@@ -38,9 +28,13 @@ function parse(selector) {
38
28
39
29
if ( subvalue ) {
40
30
if ( type === dot ) {
41
- className . push ( subvalue ) ;
31
+ if ( className ) {
32
+ className . push ( subvalue ) ;
33
+ } else {
34
+ className = props . className = [ subvalue ] ;
35
+ }
42
36
} else if ( type === hash ) {
43
- id = subvalue ;
37
+ props . id = subvalue ;
44
38
} else {
45
39
name = subvalue ;
46
40
}
@@ -51,15 +45,10 @@ function parse(selector) {
51
45
}
52
46
}
53
47
54
- node . tagName = name ;
55
-
56
- if ( id ) {
57
- node . properties . id = id ;
58
- }
59
-
60
- if ( className . length !== 0 ) {
61
- node . properties . className = className ;
62
- }
63
-
64
- return node ;
48
+ return {
49
+ type : 'element' ,
50
+ tagName : name ,
51
+ properties : props ,
52
+ children : [ ]
53
+ } ;
65
54
}
Original file line number Diff line number Diff line change 42
42
},
43
43
"xo" : {
44
44
"space" : true ,
45
+ "rules" : {
46
+ "max-depth" : " off"
47
+ },
45
48
"ignores" : [
46
49
" hast-util-parse-selector.js"
47
50
]
You can’t perform that action at this time.
0 commit comments