Skip to content

Commit

Permalink
add loc to Nth
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 27, 2017
1 parent adc2305 commit 2bf4c11
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,11 @@ function getNthSelector(allowOfClause) {
readSC();

var nthStart = scanner.tokenStart;
var nthEnd;

if (scanner.lookupValue(0, 'odd') || scanner.lookupValue(0, 'even')) {
scanner.next();
nthEnd = scanner.tokenStart;
query = {
type: 'Identifier',
loc: getLocation(nthStart, scanner.tokenStart),
Expand Down Expand Up @@ -1656,6 +1658,7 @@ function getNthSelector(allowOfClause) {
b = prefix;
}

nthEnd = scanner.tokenStart;
query = {
type: 'An+B',
loc: getLocation(nthStart, scanner.tokenStart),
Expand All @@ -1669,6 +1672,7 @@ function getNthSelector(allowOfClause) {
if (allowOfClause && scanner.lookupValue(0, 'of')) {
scanner.next();
selector = getSelectorList(NESTED);
nthEnd = scanner.tokenStart;
}

scanner.eat(RIGHTPARENTHESIS);
Expand All @@ -1679,6 +1683,7 @@ function getNthSelector(allowOfClause) {
name: name,
children: new List().appendData({ // TODO: add loc
type: 'Nth',
loc: getLocation(nthStart, nthEnd),
nth: query,
selector: selector
})
Expand Down
54 changes: 53 additions & 1 deletion test/fixture/stringify.ast
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,19 @@
"children": [
{
"type": "Nth",
"loc": {
"source": "stringify.css",
"start": {
"offset": 233,
"line": 12,
"column": 95
},
"end": {
"offset": 236,
"line": 12,
"column": 98
}
},
"nth": {
"type": "Identifier",
"loc": {
Expand Down Expand Up @@ -1040,6 +1053,19 @@
"children": [
{
"type": "Nth",
"loc": {
"source": "stringify.css",
"start": {
"offset": 248,
"line": 12,
"column": 110
},
"end": {
"offset": 254,
"line": 12,
"column": 116
}
},
"nth": {
"type": "An+B",
"loc": {
Expand Down Expand Up @@ -1224,6 +1250,19 @@
"children": [
{
"type": "Nth",
"loc": {
"source": "stringify.css",
"start": {
"offset": 298,
"line": 13,
"column": 42
},
"end": {
"offset": 310,
"line": 13,
"column": 54
}
},
"nth": {
"type": "Identifier",
"loc": {
Expand Down Expand Up @@ -1352,6 +1391,19 @@
"children": [
{
"type": "Nth",
"loc": {
"source": "stringify.css",
"start": {
"offset": 322,
"line": 13,
"column": 66
},
"end": {
"offset": 335,
"line": 13,
"column": 79
}
},
"nth": {
"type": "An+B",
"loc": {
Expand Down Expand Up @@ -2460,4 +2512,4 @@
}
}
]
}
}

0 comments on commit 2bf4c11

Please sign in to comment.