Skip to content

Commit

Permalink
[sass] Parse multiple selectors in extends
Browse files Browse the repository at this point in the history
Also fix the issue when selectors in extends were not wrapped in
`selector` node.

See #21
  • Loading branch information
tonyganch committed Oct 19, 2015
1 parent b59c0d4 commit 7300918
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 26 deletions.
28 changes: 14 additions & 14 deletions src/sass/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ function checkExtend1(i) {
if (l = checkSC(i)) i += l;
else return 0;

if (l = checkCompoundSelector(i)) i += l;
if (l = checkSelectorsGroup(i)) i += l;
else return 0;

if (l = checkSC(i)) i += l;
Expand All @@ -1600,13 +1600,13 @@ function checkExtend1(i) {

function getExtend1() {
let startPos = pos;
let x = [];

x.push(getAtkeyword());
x = x.concat(getSC());
x = x.concat(getCompoundSelector());
x = x.concat(getSC());
x.push(getOptional());
let x = [].concat(
[getAtkeyword()],
getSC(),
getSelectorsGroup(),
getSC(),
getOptional()
);

var token = tokens[startPos];
return newNode(NodeType.ExtendType, x, token.ln, token.col);
Expand All @@ -1630,19 +1630,19 @@ function checkExtend2(i) {
if (l = checkSC(i)) i += l;
else return 0;

if (l = checkCompoundSelector(i)) i += l;
if (l = checkSelectorsGroup(i)) i += l;
else return 0;

return i - start;
}

function getExtend2() {
let startPos = pos;
let x = [];

x.push(getAtkeyword());
x = x.concat(getSC());
x = x.concat(getCompoundSelector());
let x = [].concat(
[getAtkeyword()],
getSC(),
getSelectorsGroup()
);

var token = tokens[startPos];
return newNode(NodeType.ExtendType, x, token.ln, token.col);
Expand Down
22 changes: 18 additions & 4 deletions test/sass/extend/0.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,29 @@
}
},
{
"type": "placeholder",
"type": "selector",
"content": [
{
"type": "ident",
"content": "nani",
"type": "placeholder",
"content": [
{
"type": "ident",
"content": "nani",
"syntax": "sass",
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 10
"column": 9
},
"end": {
"line": 1,
Expand Down
22 changes: 18 additions & 4 deletions test/sass/extend/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,29 @@
}
},
{
"type": "class",
"type": "selector",
"content": [
{
"type": "ident",
"content": "panda",
"type": "class",
"content": [
{
"type": "ident",
"content": "panda",
"syntax": "sass",
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 14
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 10
"column": 9
},
"end": {
"line": 1,
Expand Down
162 changes: 162 additions & 0 deletions test/sass/extend/issue-21.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"type": "extend",
"content": [
{
"type": "atkeyword",
"content": [
{
"type": "ident",
"content": "extend",
"syntax": "sass",
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 7
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 7
}
},
{
"type": "space",
"content": " ",
"syntax": "sass",
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 8
}
},
{
"type": "selector",
"content": [
{
"type": "class",
"content": [
{
"type": "ident",
"content": "icon",
"syntax": "sass",
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 13
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 13
}
},
{
"type": "delimiter",
"content": ",",
"syntax": "sass",
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 14
}
},
{
"type": "space",
"content": " ",
"syntax": "sass",
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 15
}
},
{
"type": "selector",
"content": [
{
"type": "class",
"content": [
{
"type": "ident",
"content": "icon-search",
"syntax": "sass",
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 27
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 27
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 27
}
}
],
"syntax": "sass",
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 27
}
}
1 change: 1 addition & 0 deletions test/sass/extend/issue-21.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@extend .icon, .icon-search
2 changes: 2 additions & 0 deletions test/sass/extend/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ describe 'sass/extend >>', ->

it '0', -> this.shouldBeOk()
it '1', -> this.shouldBeOk()

it 'issue-21', -> this.shouldBeOk()
22 changes: 18 additions & 4 deletions test/sass/stylesheet/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,29 @@
}
},
{
"type": "class",
"type": "selector",
"content": [
{
"type": "ident",
"content": "nani",
"type": "class",
"content": [
{
"type": "ident",
"content": "nani",
"syntax": "sass",
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 13
}
}
],
"syntax": "sass",
"start": {
"line": 3,
"column": 10
"column": 9
},
"end": {
"line": 3,
Expand Down

0 comments on commit 7300918

Please sign in to comment.