Skip to content

Commit

Permalink
fail on bad selector instead of selector dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Oct 18, 2016
1 parent ae1f83f commit e7fdf9f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 82 deletions.
17 changes: 8 additions & 9 deletions lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function getSelector() {
var selectors = new List();
var simpleSelector;
var isBadSelector = false;
var lastComma = true;
var lastComma = -2;

scan:
while (!scanner.eof) {
Expand All @@ -268,28 +268,27 @@ function getSelector() {
break scan;

case COMMA:
if (lastComma) {
isBadSelector = true;
if (lastComma !== -1) {
scanner.error('Unexpected comma');
}

lastComma = true;
lastComma = scanner.tokenStart;
scanner.next();
break;

default:
lastComma = false;
lastComma = -1;
simpleSelector = getSimpleSelector();
selectors.appendData(simpleSelector);

if (simpleSelector.sequence.isEmpty()) {
isBadSelector = true;
scanner.error('Simple selector expected');
}
}
}

if (lastComma) {
isBadSelector = true;
// scanner.error('Unexpected trailing comma');
if (lastComma !== -1 && lastComma !== -2) { // TODO: fail on empty selector rules?
scanner.error('Unexpected trailing comma', lastComma);
}

if (isBadSelector) {
Expand Down
93 changes: 20 additions & 73 deletions test/fixture/parse/selector/Selector.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,91 +60,38 @@
}
},
"bad selector #1": {
"source": "a,",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
},
"bad selector #2": {
"source": "a,,",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
},
"bad selector #3": {
"source": "a, ",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": " ^",
"error": "Simple selector expected"
},
"bad selector #4": {
"bad selector #2": {
"source": "a,, ",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": " ^",
"error": "Unexpected comma"
},
"bad selector #5": {
"bad selector #3": {
"source": "a,,b",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": " ^",
"error": "Unexpected comma"
},
"bad selector #6": {
"source": ",b",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
},
"bad selector #7": {
"source": ",,b",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
},
"bad selector #8": {
"bad selector #4": {
"source": ",b",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": "^",
"error": "Unexpected comma"
},
"bad selector #9": {
"bad selector #5": {
"source": ",,b",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": "^",
"error": "Unexpected comma"
},
"bad selector #10": {
"bad selector #6": {
"source": ",",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": "^",
"error": "Unexpected comma"
},
"bad selector #11": {
"bad selector #7": {
"source": ",,",
"translate": "",
"ast": {
"type": "Selector",
"selectors": []
}
"offset": "^",
"error": "Unexpected comma"
}
}
24 changes: 24 additions & 0 deletions test/fixture/parse/stylesheet/StyleSheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@
"rules": []
}
},
"whitespace only": {
"source": " ",
"translate": "",
"ast": {
"type": "StyleSheet",
"rules": []
}
},
"comment only": {
"source": "/* no css */",
"translate": "",
"ast": {
"type": "StyleSheet",
"rules": []
}
},
"comment and whitespaces only": {
"source": " /* no css */ ",
"translate": "",
"ast": {
"type": "StyleSheet",
"rules": []
}
},
"BOM.1": {
"source": "\uFEFF",
"translate": "",
Expand Down

0 comments on commit e7fdf9f

Please sign in to comment.