Skip to content

Commit

Permalink
replace Negation type for PseudoClass and change format a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 14, 2017
1 parent 6ba79d3 commit f7cc7c9
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 103 deletions.
53 changes: 6 additions & 47 deletions lib/parser/index.js
Expand Up @@ -1065,55 +1065,14 @@ function getFunctionArguments(scope) {
return children;
}

function getVarFunction(scope, info, name) {
return getFunctionInternal(getVarFunctionArguments, scope, info, name);
}

// TODO: -> getSimpleSelectorList
function getNotFunctionArguments() {
var args = new List();
var wasSelector = false;

scan:
while (!scanner.eof) {
switch (scanner.tokenType) {
case RIGHTPARENTHESIS:
if (!wasSelector) {
scanner.error('Simple selector is expected');
}

break scan;

case COMMA:
if (!wasSelector) {
scanner.error('Simple selector is expected');
}

wasSelector = false;
scanner.next();
break;

default:
wasSelector = true;
args.appendData(getSimpleSelector(NESTED));
}
}

return args;
function getNotFunction(scope, info, name) {
return getFunctionInternal(function() {
return new List().appendData(getSelector(true));
}, scope, info, name);
}

function getNotFunction(scope, info) {
var children;

scanner.eat(LEFTPARENTHESIS);
children = getNotFunctionArguments(scope);
scanner.eat(RIGHTPARENTHESIS);

return {
type: 'Negation',
info: info,
children: children
};
function getVarFunction(scope, info, name) {
return getFunctionInternal(getVarFunctionArguments, scope, info, name);
}

// var '(' ident (',' <declaration-value>)? ')'
Expand Down
114 changes: 82 additions & 32 deletions test/fixture/parse/simpleSelector/Negation.json
Expand Up @@ -2,18 +2,24 @@
"basic negation": {
"source": ":not(el.class-postfix)",
"ast": {
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Type",
"name": "el"
},
{
"type": "Class",
"name": "class-postfix"
"type": "SimpleSelector",
"children": [
{
"type": "Type",
"name": "el"
},
{
"type": "Class",
"name": "class-postfix"
}
]
}
]
}
Expand All @@ -23,23 +29,29 @@
"negation with selector group": {
"source": ":not(.a,.b)",
"ast": {
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "Class",
"name": "b"
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
}
Expand All @@ -50,23 +62,61 @@
"source": ":not( .a , .b )",
"translate": ":not(.a,.b)",
"ast": {
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Class",
"name": "a"
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
},
}
]
}
},
"should be case insensitive": {
"source": ":NoT(.a,.b)",
"ast": {
"type": "PseudoClass",
"name": "NoT",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Class",
"name": "b"
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "a"
}
]
},
{
"type": "SimpleSelector",
"children": [
{
"type": "Class",
"name": "b"
}
]
}
]
}
Expand All @@ -81,17 +131,17 @@
"error #2": {
"source": ":not(,.b)",
"offset": " ^",
"error": "Simple selector is expected"
"error": "Unexpected comma"
},
"error #3": {
"source": ":not(.a,)",
"offset": " ^",
"error": "Simple selector is expected"
"offset": " ^",
"error": "Unexpected trailing comma"
},
"error #4": {
"source": ":not(.a,,)",
"offset": " ^",
"error": "Simple selector is expected"
"error": "Unexpected comma"
},
"error #5": {
"source": ":not(.a,.b{)",
Expand Down
40 changes: 26 additions & 14 deletions test/fixture/parse/simpleSelector/SimpleSelector.json
Expand Up @@ -120,14 +120,20 @@
"name": "*|*"
},
{
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Universal",
"name": "*"
"type": "SimpleSelector",
"children": [
{
"type": "Universal",
"name": "*"
}
]
}
]
}
Expand All @@ -146,20 +152,26 @@
"name": "x"
},
{
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Attribute",
"name": {
"type": "Identifier",
"name": "ABC"
},
"operator": null,
"value": null,
"flags": null
"type": "SimpleSelector",
"children": [
{
"type": "Attribute",
"name": {
"type": "Identifier",
"name": "ABC"
},
"operator": null,
"value": null,
"flags": null
}
]
}
]
}
Expand Down
26 changes: 16 additions & 10 deletions test/fixture/parse/stylesheet/StyleSheet.json
Expand Up @@ -87,20 +87,26 @@
"name": "body"
},
{
"type": "Negation",
"type": "PseudoClass",
"name": "not",
"children": [
{
"type": "SimpleSelector",
"type": "Selector",
"children": [
{
"type": "Attribute",
"name": {
"type": "Identifier",
"name": "x|x"
},
"operator": null,
"value": null,
"flags": null
"type": "SimpleSelector",
"children": [
{
"type": "Attribute",
"name": {
"type": "Identifier",
"name": "x|x"
},
"operator": null,
"value": null,
"flags": null
}
]
}
]
}
Expand Down

0 comments on commit f7cc7c9

Please sign in to comment.