diff --git a/src/scss/parse.js b/src/scss/parse.js index 5dfb341b..d6204a18 100644 --- a/src/scss/parse.js +++ b/src/scss/parse.js @@ -5215,38 +5215,68 @@ function checkSelectorsGroup(i) { const start = i; let l; + let selectorCounter = 0; + let delimCounter = 0; - if (l = checkSelector(i)) i += l; - else return 0; + if (l = checkSelector(i)) { + i += l; + selectorCounter++; + } else return 0; while (i < tokensLength) { - const spaceBefore = checkSC(i); - const comma = checkDelim(i + spaceBefore); - if (!comma) break; + const tempStart = i; + let tempIndex = i; + let tempLength; - const spaceAfter = checkSC(i + spaceBefore + comma); - if (l = checkSelector(i + spaceBefore + comma + spaceAfter)) { - i += spaceBefore + comma + spaceAfter + l; - } else break; + let spaceBefore = checkSC(tempIndex); + + if (tempLength = checkDelim(tempIndex + spaceBefore)) { + tempIndex += spaceBefore + tempLength; + delimCounter++; + + if (tempLength = checkSC(tempIndex)) tempIndex += tempLength; + if (tempLength = checkSelector(tempIndex)) { + tempIndex += tempLength; + selectorCounter++; + } + } + else break; + + i += tempIndex - tempStart; } tokens[start].selectorsGroupEnd = i; + tokens[start].selectorsGroupSelectorCount = selectorCounter; + tokens[start].selectorsGroupDelimCount = delimCounter; + return i - start; } function getSelectorsGroup() { let selectorsGroup = []; + let selectorCounter = 0; + let delimCounter = 0; + const selectorsGroupEnd = tokens[pos].selectorsGroupEnd; + const selectorCount = tokens[pos].selectorsGroupSelectorCount; + const delimCount = tokens[pos].selectorsGroupDelimCount; selectorsGroup.push(getSelector()); + selectorCounter++; while (pos < selectorsGroupEnd) { - selectorsGroup = selectorsGroup.concat( - getSC(), - getDelim(), - getSC(), - getSelector() - ); + if (delimCounter < delimCount) { + selectorsGroup = selectorsGroup.concat(getSC()); + selectorsGroup = selectorsGroup.concat(getDelim()); + delimCounter++; + + selectorsGroup = selectorsGroup.concat(getSC()); + + if (selectorCounter < selectorCount) { + selectorsGroup = selectorsGroup.concat(getSelector()); + selectorCounter++; + } + } } return selectorsGroup; diff --git a/test/scss/ruleset/6.json b/test/scss/ruleset/6.json new file mode 100644 index 00000000..11404617 --- /dev/null +++ b/test/scss/ruleset/6.json @@ -0,0 +1,163 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "typeSelector", + "content": [ + { + "type": "ident", + "content": "s", + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 2 + } + }, + { + "type": "block", + "content": [ + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "p", + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 4 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 4 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 5 + } + }, + { + "type": "value", + "content": [ + { + "type": "ident", + "content": "v", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 6 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 6 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 6 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 7 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } +} diff --git a/test/scss/ruleset/6.scss b/test/scss/ruleset/6.scss new file mode 100644 index 00000000..61fbd852 --- /dev/null +++ b/test/scss/ruleset/6.scss @@ -0,0 +1 @@ +s,{p:v} diff --git a/test/scss/ruleset/7.json b/test/scss/ruleset/7.json new file mode 100644 index 00000000..e1c519a0 --- /dev/null +++ b/test/scss/ruleset/7.json @@ -0,0 +1,215 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "typeSelector", + "content": [ + { + "type": "ident", + "content": "s", + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 2 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + }, + { + "type": "block", + "content": [ + { + "type": "space", + "content": "\n ", + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "p", + "syntax": "scss", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 3 + } + } + ], + "syntax": "scss", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 3 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "scss", + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 4 + } + }, + { + "type": "value", + "content": [ + { + "type": "ident", + "content": "v", + "syntax": "scss", + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 5 + } + } + ], + "syntax": "scss", + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 5 + } + } + ], + "syntax": "scss", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 5 + } + }, + { + "type": "declarationDelimiter", + "content": ";", + "syntax": "scss", + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 6 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "scss", + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 7 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 1 + } +} diff --git a/test/scss/ruleset/7.scss b/test/scss/ruleset/7.scss new file mode 100644 index 00000000..9275ab12 --- /dev/null +++ b/test/scss/ruleset/7.scss @@ -0,0 +1,3 @@ +s, { + p:v; +} diff --git a/test/scss/ruleset/8.json b/test/scss/ruleset/8.json new file mode 100644 index 00000000..e00049f8 --- /dev/null +++ b/test/scss/ruleset/8.json @@ -0,0 +1,189 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "typeSelector", + "content": [ + { + "type": "ident", + "content": "s", + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 2 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 4 + } + }, + { + "type": "block", + "content": [ + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "p", + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 6 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 6 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "scss", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 7 + } + }, + { + "type": "value", + "content": [ + { + "type": "ident", + "content": "v", + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 9 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } +} diff --git a/test/scss/ruleset/8.scss b/test/scss/ruleset/8.scss new file mode 100644 index 00000000..fce2e405 --- /dev/null +++ b/test/scss/ruleset/8.scss @@ -0,0 +1 @@ +s,,,{p:v} diff --git a/test/scss/ruleset/c.4.json b/test/scss/ruleset/c.4.json new file mode 100644 index 00000000..cb7cf1d1 --- /dev/null +++ b/test/scss/ruleset/c.4.json @@ -0,0 +1,280 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "typeSelector", + "content": [ + { + "type": "ident", + "content": "s", + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "scss", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 10 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "scss", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 18 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 19 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 20 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "scss", + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 28 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 29 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + }, + { + "type": "multilineComment", + "content": "test", + "syntax": "scss", + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 39 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + } + }, + { + "type": "block", + "content": [ + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "p", + "syntax": "scss", + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 43 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 43 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "scss", + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 44 + } + }, + { + "type": "value", + "content": [ + { + "type": "ident", + "content": "v", + "syntax": "scss", + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 45 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 45 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 45 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 46 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 46 + } +} diff --git a/test/scss/ruleset/c.4.scss b/test/scss/ruleset/c.4.scss new file mode 100644 index 00000000..3567ffb6 --- /dev/null +++ b/test/scss/ruleset/c.4.scss @@ -0,0 +1 @@ +s/*test*/,/*test*/ ,/*test*/, /*test*/ {p:v} diff --git a/test/scss/ruleset/s.6.json b/test/scss/ruleset/s.6.json new file mode 100644 index 00000000..59464ac0 --- /dev/null +++ b/test/scss/ruleset/s.6.json @@ -0,0 +1,241 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "typeSelector", + "content": [ + { + "type": "ident", + "content": "s", + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 2 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 6 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 7 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 8 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "scss", + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 9 + } + }, + { + "type": "space", + "content": " ", + "syntax": "scss", + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + { + "type": "block", + "content": [ + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "p", + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 14 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 14 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "scss", + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 15 + } + }, + { + "type": "value", + "content": [ + { + "type": "ident", + "content": "v", + "syntax": "scss", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + } + ], + "syntax": "scss", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 17 + } +} diff --git a/test/scss/ruleset/s.6.scss b/test/scss/ruleset/s.6.scss new file mode 100644 index 00000000..855704c0 --- /dev/null +++ b/test/scss/ruleset/s.6.scss @@ -0,0 +1 @@ +s , , , {p:v} diff --git a/test/scss/ruleset/test.coffee b/test/scss/ruleset/test.coffee index b863ac5d..18fe9731 100644 --- a/test/scss/ruleset/test.coffee +++ b/test/scss/ruleset/test.coffee @@ -6,11 +6,15 @@ describe 'scss/ruleset >>', -> it '3', -> this.shouldBeOk() it '4', -> this.shouldBeOk() it '5', -> this.shouldBeOk() + it '6', -> this.shouldBeOk() + it '7', -> this.shouldBeOk() + it '8', -> this.shouldBeOk() it 'c.0', -> this.shouldBeOk() it 'c.1', -> this.shouldBeOk() it 'c.2', -> this.shouldBeOk() it 'c.3', -> this.shouldBeOk() + it 'c.4', -> this.shouldBeOk() it 'color.ident.0', -> this.shouldBeOk() it 'color.ident.1', -> this.shouldBeOk() @@ -21,3 +25,4 @@ describe 'scss/ruleset >>', -> it 's.3', -> this.shouldBeOk() it 's.4', -> this.shouldBeOk() it 's.5', -> this.shouldBeOk() + it 's.6', -> this.shouldBeOk()