File tree Expand file tree Collapse file tree 2 files changed +19
-27
lines changed
Expand file tree Collapse file tree 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);
99
1010/* Parse a simple CSS selector into a HAST node. */
1111function parse ( selector ) {
12- var id = null ;
13- var className = [ ] ;
1412 var value = selector || '' ;
1513 var name = 'div' ;
16- var node ;
17- var type = null ;
14+ var props = { } ;
1815 var index = - 1 ;
19- var code ;
2016 var length = value . length ;
17+ var className ;
18+ var type ;
19+ var code ;
2120 var subvalue ;
2221 var lastIndex ;
2322
24- node = {
25- type : 'element' ,
26- tagName : null ,
27- properties : { } ,
28- children : [ ]
29- } ;
30-
31- type = null ;
32-
3323 while ( ++ index <= length ) {
3424 code = value . charCodeAt ( index ) ;
3525
@@ -38,9 +28,13 @@ function parse(selector) {
3828
3929 if ( subvalue ) {
4030 if ( type === dot ) {
41- className . push ( subvalue ) ;
31+ if ( className ) {
32+ className . push ( subvalue ) ;
33+ } else {
34+ className = props . className = [ subvalue ] ;
35+ }
4236 } else if ( type === hash ) {
43- id = subvalue ;
37+ props . id = subvalue ;
4438 } else {
4539 name = subvalue ;
4640 }
@@ -51,15 +45,10 @@ function parse(selector) {
5145 }
5246 }
5347
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+ } ;
6554}
Original file line number Diff line number Diff line change 4242 },
4343 "xo" : {
4444 "space" : true ,
45+ "rules" : {
46+ "max-depth" : " off"
47+ },
4548 "ignores" : [
4649 " hast-util-parse-selector.js"
4750 ]
You can’t perform that action at this time.
0 commit comments