Skip to content

Commit

Permalink
add support for :matches (fixes #28)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 14, 2017
1 parent f7cc7c9 commit 07942ae
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/parser/index.js
Expand Up @@ -52,7 +52,8 @@ var SCOPE_ATRULE_EXPRESSION = {
};
var SCOPE_SELECTOR = {
url: getUri,
not: getNotFunction
not: getSelectorFunction,
matches: getSelectorFunction
};
var SCOPE_VALUE = {
url: getUri,
Expand Down Expand Up @@ -1065,7 +1066,7 @@ function getFunctionArguments(scope) {
return children;
}

function getNotFunction(scope, info, name) {
function getSelectorFunction(scope, info, name) {
return getFunctionInternal(function() {
return new List().appendData(getSelector(true));
}, scope, info, name);
Expand Down
161 changes: 161 additions & 0 deletions test/fixture/parse/simpleSelector/pseudo-matches.json
@@ -0,0 +1,161 @@
{
"basic negation": {
"source": ":matches(el.class-postfix)",
"ast": {
"type": "PseudoClass",
"name": "matches",
"children": [
{
"type": "Selector",
"children": [
{
"type": "SimpleSelector",
"children": [
{
"type": "Type",
"name": "el"
},
{
"type": "Class",
"name": "class-postfix"
}
]
}
]
}
]
}
},
"negation with selector group": {
"source": ":matches(.a,.b)",
"ast": {
"type": "PseudoClass",
"name": "matches",
"children": [
{
"type": "Selector",
"children": [
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
}
]
}
},
"negation with selector group and spaces": {
"source": ":matches( .a , .b )",
"translate": ":matches(.a,.b)",
"ast": {
"type": "PseudoClass",
"name": "matches",
"children": [
{
"type": "Selector",
"children": [
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
}
]
}
},
"should be case insensitive": {
"source": ":MatcheS(.a,.b)",
"ast": {
"type": "PseudoClass",
"name": "MatcheS",
"children": [
{
"type": "Selector",
"children": [
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
}
]
}
},
"error #1": {
"source": ":matches(.a{)",
"offset": " ^",
"error": "Unexpected input"
},
"error #2": {
"source": ":matches(,.b)",
"offset": " ^",
"error": "Unexpected comma"
},
"error #3": {
"source": ":matches(.a,)",
"offset": " ^",
"error": "Unexpected trailing comma"
},
"error #4": {
"source": ":matches(.a,,)",
"offset": " ^",
"error": "Unexpected comma"
},
"error #5": {
"source": ":matches(.a,.b{)",
"offset": " ^",
"error": "Unexpected input"
},
"error #6": {
"source": ":matches(--test) {}",
"offset": " ^",
"error": "Identifier is expected"
},
"error #7": {
"source": ":matches(var(--test)) {}",
"offset": " ^",
"error": "Unexpected input"
}
}

0 comments on commit 07942ae

Please sign in to comment.