Skip to content

Commit 04adab2

Browse files
committed
fixes some parsing issues
fixes webpack-contrib/css-loader#106 fixed #9 fixes #8 fixes #7
1 parent 035af45 commit 04adab2

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

lib/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ var parser = new Parser({
169169
"/\\*([\\s\\S]*?)\\*/": commentMatch,
170170
"\\.((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("class"),
171171
"#((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("id"),
172-
":(not|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,
172+
":(not|matches|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,
173173
":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(": pseudoClassStartMatch,
174174
":((?:\\\\.|[A-Za-z_\\-0-9])+)": typeMatch("pseudo-class"),
175175
"::((?:\\\\.|[A-Za-z_\\-0-9])+)": typeMatch("pseudo-element"),
@@ -179,7 +179,7 @@ var parser = new Parser({
179179
"((?:\\\\.|[A-Za-z_\\-0-9])*\\|)?((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": elementMatch,
180180
"\\[([^\\]]+)\\]": attributeMatch,
181181
"(\\s*)\\)": nestedEnd,
182-
"(\\s*)([>+~])(\\s*)": operatorMatch,
182+
"(\\s*)((?:\\|\\|)|(?:>>)|[>+~])(\\s*)": operatorMatch,
183183
"(\\s*),(\\s*)": nextSelectorMatch,
184184
"\\s+$": irrelevantSpacingEndMatch,
185185
"^\\s+": irrelevantSpacingStartMatch,

lib/stringify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function escape(str) {
66
if(str === "*") {
77
return "*";
88
}
9-
return str.replace(/(^[^A-Za-z_\\-]|[^A-Za-z_0-9\\-])/g, "\\$1");
9+
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1");
1010
}
1111

1212
function stringifyWithoutBeforeAfter(tree) {

test/test-cases.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ module.exports = {
5555
])
5656
],
5757

58-
"class name starting with number": [
59-
".\\5\\#-\\.5",
58+
"class name starting with number or dash": [
59+
".\\5\\#-\\.5 .\\--name.-name",
6060
singleSelector([
61-
{ type: "class", name: "5#-.5" }
61+
{ type: "class", name: "5#-.5" },
62+
{ type: "spacing", value: " " },
63+
{ type: "class", name: "--name" },
64+
{ type: "class", name: "-name" }
6265
])
6366
],
6467

@@ -251,7 +254,7 @@ module.exports = {
251254
],
252255

253256
"pseudo class with difficult content": [
254-
":--anything-new(/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\")",
257+
":\\--anything-new(/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\")",
255258
singleSelector([
256259
{ type: "pseudo-class", name: "--anything-new", content: "/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\"" }
257260
])
@@ -320,6 +323,28 @@ module.exports = {
320323
])
321324
],
322325

326+
"available nested pseudo classes": [
327+
":not(:active):matches(:focus)",
328+
singleSelector([
329+
{ type: "nested-pseudo-class", name: "not", nodes: [
330+
{
331+
type: "selector",
332+
nodes: [
333+
{ type: "pseudo-class", name: "active" }
334+
]
335+
}
336+
] },
337+
{ type: "nested-pseudo-class", name: "matches", nodes: [
338+
{
339+
type: "selector",
340+
nodes: [
341+
{ type: "pseudo-class", name: "focus" }
342+
]
343+
}
344+
] }
345+
])
346+
],
347+
323348
"nested pseudo class with nested selectors": [
324349
":has(h1:not(:has(:visited)))",
325350
singleSelector([

0 commit comments

Comments
 (0)