@@ -34,6 +34,19 @@ var attribSelectors = {
34
34
"." : [ "class" , "element" ]
35
35
} ;
36
36
37
+ //pseudos, whose data-property is parsed as well
38
+ var unpackPseudos = {
39
+ __proto__ : null ,
40
+ "has" : true ,
41
+ "not" : true ,
42
+ "matches" : true
43
+ } ;
44
+
45
+ var stripQuotesFromPseudos = {
46
+ __proto__ : unpackPseudos ,
47
+ "contains" : true
48
+ } ;
49
+
37
50
//unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L139
38
51
function funescape ( _ , escaped , escapedWhitespace ) {
39
52
var high = "0x" + escaped - 0x10000 ;
@@ -71,7 +84,7 @@ function parse(selector, options){
71
84
tokens = [ ] ,
72
85
sawWS = false ,
73
86
data , firstChar , name ;
74
-
87
+
75
88
function getName ( ) {
76
89
var sub = selector . match ( re_name ) [ 0 ] ;
77
90
selector = selector . substr ( sub . length ) ;
@@ -154,29 +167,41 @@ function parse(selector, options){
154
167
value : unescapeCSS ( data [ 4 ] || data [ 5 ] || "" ) ,
155
168
ignoreCase : ! ! data [ 6 ]
156
169
} ) ;
157
-
170
+
158
171
} else if ( firstChar === ":" ) {
159
172
//if(selector.charAt(0) === ":"){} //TODO pseudo-element
160
173
name = getName ( ) . toLowerCase ( ) ;
161
174
data = null ;
162
-
175
+
163
176
if ( selector . charAt ( 0 ) === "(" ) {
164
177
var pos = getClosingPos ( selector ) ;
165
178
data = selector . substr ( 1 , pos - 2 ) ;
166
179
selector = selector . substr ( pos ) ;
180
+
181
+ if ( name in stripQuotesFromPseudos ) {
182
+ var quot = data . charAt ( 0 ) ;
183
+
184
+ if ( quot === data . slice ( - 1 ) && ( quot === "'" || quot === "\"" ) ) {
185
+ data = data . slice ( 1 , - 1 ) ;
186
+ }
187
+
188
+ if ( name in unpackPseudos ) {
189
+ data = parse ( data , options ) ;
190
+ }
191
+ }
167
192
}
168
-
193
+
169
194
tokens . push ( { type : "pseudo" , name : name , data : data } ) ;
170
195
} else {
171
196
//otherwise, the parser needs to throw or it would enter an infinite loop
172
197
throw new SyntaxError ( "Unmatched selector: " + firstChar + selector ) ;
173
198
}
174
199
}
175
200
}
176
-
201
+
177
202
if ( subselects . length > 0 && tokens . length === 0 ) {
178
203
throw new SyntaxError ( "empty sub-selector" ) ;
179
204
}
180
205
subselects . push ( tokens ) ;
181
206
return subselects ;
182
- }
207
+ }
0 commit comments