Skip to content

Commit

Permalink
fixes some parsing issues
Browse files Browse the repository at this point in the history
fixes webpack-contrib/css-loader#106
fixed #9
fixes #8
fixes #7
  • Loading branch information
sokra committed Jul 26, 2015
1 parent 035af45 commit 04adab2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ var parser = new Parser({
"/\\*([\\s\\S]*?)\\*/": commentMatch,
"\\.((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("class"),
"#((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("id"),
":(not|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,
":(not|matches|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,
":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(": pseudoClassStartMatch,
":((?:\\\\.|[A-Za-z_\\-0-9])+)": typeMatch("pseudo-class"),
"::((?:\\\\.|[A-Za-z_\\-0-9])+)": typeMatch("pseudo-element"),
Expand All @@ -179,7 +179,7 @@ var parser = new Parser({
"((?:\\\\.|[A-Za-z_\\-0-9])*\\|)?((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": elementMatch,
"\\[([^\\]]+)\\]": attributeMatch,
"(\\s*)\\)": nestedEnd,
"(\\s*)([>+~])(\\s*)": operatorMatch,
"(\\s*)((?:\\|\\|)|(?:>>)|[>+~])(\\s*)": operatorMatch,
"(\\s*),(\\s*)": nextSelectorMatch,
"\\s+$": irrelevantSpacingEndMatch,
"^\\s+": irrelevantSpacingStartMatch,
Expand Down
2 changes: 1 addition & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function escape(str) {
if(str === "*") {
return "*";
}
return str.replace(/(^[^A-Za-z_\\-]|[^A-Za-z_0-9\\-])/g, "\\$1");
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1");
}

function stringifyWithoutBeforeAfter(tree) {
Expand Down
33 changes: 29 additions & 4 deletions test/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ module.exports = {
])
],

"class name starting with number": [
".\\5\\#-\\.5",
"class name starting with number or dash": [
".\\5\\#-\\.5 .\\--name.-name",
singleSelector([
{ type: "class", name: "5#-.5" }
{ type: "class", name: "5#-.5" },
{ type: "spacing", value: " " },
{ type: "class", name: "--name" },
{ type: "class", name: "-name" }
])
],

Expand Down Expand Up @@ -251,7 +254,7 @@ module.exports = {
],

"pseudo class with difficult content": [
":--anything-new(/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\")",
":\\--anything-new(/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\")",
singleSelector([
{ type: "pseudo-class", name: "--anything-new", content: "/* here is difficult ')][ .content */\nurl('Hello)World'), \"Hello)\\\".World\"" }
])
Expand Down Expand Up @@ -320,6 +323,28 @@ module.exports = {
])
],

"available nested pseudo classes": [
":not(:active):matches(:focus)",
singleSelector([
{ type: "nested-pseudo-class", name: "not", nodes: [
{
type: "selector",
nodes: [
{ type: "pseudo-class", name: "active" }
]
}
] },
{ type: "nested-pseudo-class", name: "matches", nodes: [
{
type: "selector",
nodes: [
{ type: "pseudo-class", name: "focus" }
]
}
] }
])
],

"nested pseudo class with nested selectors": [
":has(h1:not(:has(:visited)))",
singleSelector([
Expand Down

0 comments on commit 04adab2

Please sign in to comment.