From 910d717f5f741c949a0f451c480a7a067e83fb5d Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Sun, 7 Feb 2016 03:57:06 +0100 Subject: [PATCH] [sass] Fix nested multiline selectors groups See #119 --- src/sass/parse.js | 4 +- test/sass/ruleset/issue-119-1.json | 364 +++++++++++++++++++ test/sass/ruleset/issue-119-1.sass | 4 + test/sass/ruleset/issue-119-2.json | 564 +++++++++++++++++++++++++++++ test/sass/ruleset/issue-119-2.sass | 7 + 5 files changed, 942 insertions(+), 1 deletion(-) create mode 100644 test/sass/ruleset/issue-119-1.json create mode 100644 test/sass/ruleset/issue-119-1.sass create mode 100644 test/sass/ruleset/issue-119-2.json create mode 100644 test/sass/ruleset/issue-119-2.sass diff --git a/src/sass/parse.js b/src/sass/parse.js index 1b772bdb..ed72c0d6 100644 --- a/src/sass/parse.js +++ b/src/sass/parse.js @@ -4250,7 +4250,8 @@ function checkSelectorsGroup(i) { let c = checkDelim(i + sb); if (!c) break; let sa = checkSC(i + sb + c); - if (l = checkSelector(i + sb + c + sa)) i += sb + c + sa + l; + let saa = sa ? checkSC(i + sb + c + sa) : 0; + if (l = checkSelector(i + sb + c + sa + saa)) i += sb + c + sa + saa + l; else break; } @@ -4268,6 +4269,7 @@ function getSelectorsGroup() { selectorsGroup = selectorsGroup.concat(getSC()); selectorsGroup.push(getDelim()); selectorsGroup = selectorsGroup.concat(getSC()); + selectorsGroup = selectorsGroup.concat(getSC()); selectorsGroup.push(getSelector()); } diff --git a/test/sass/ruleset/issue-119-1.json b/test/sass/ruleset/issue-119-1.json new file mode 100644 index 00000000..41197d88 --- /dev/null +++ b/test/sass/ruleset/issue-119-1.json @@ -0,0 +1,364 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 5 + } + }, + { + "type": "block", + "content": [ + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + }, + { + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "sass", + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 7 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "qux", + "syntax": "sass", + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 6 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 7 + } + }, + { + "type": "block", + "content": [ + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 4 + } + }, + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "content", + "syntax": "sass", + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 11 + } + } + ], + "syntax": "sass", + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 11 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "sass", + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 13 + } + }, + { + "type": "value", + "content": [ + { + "type": "string", + "content": "'fail'", + "syntax": "sass", + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 4, + "column": 19 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 4, + "column": 19 + } +} \ No newline at end of file diff --git a/test/sass/ruleset/issue-119-1.sass b/test/sass/ruleset/issue-119-1.sass new file mode 100644 index 00000000..7ffad84a --- /dev/null +++ b/test/sass/ruleset/issue-119-1.sass @@ -0,0 +1,4 @@ +.foo + .bar, + .qux + content: 'fail' diff --git a/test/sass/ruleset/issue-119-2.json b/test/sass/ruleset/issue-119-2.json new file mode 100644 index 00000000..8c833eab --- /dev/null +++ b/test/sass/ruleset/issue-119-2.json @@ -0,0 +1,564 @@ +{ + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "foo", + "syntax": "sass", + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "sass", + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 5 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 6 + } + }, + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "bar", + "syntax": "sass", + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + ], + "syntax": "sass", + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 5 + } + }, + { + "type": "block", + "content": [ + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "content", + "syntax": "sass", + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 9 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 9 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "sass", + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 10 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 11 + } + }, + { + "type": "value", + "content": [ + { + "type": "string", + "content": "'baz'", + "syntax": "sass", + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 16 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 16 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 16 + } + }, + { + "type": "declarationDelimiter", + "content": "\n", + "syntax": "sass", + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 17 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 1 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + }, + { + "type": "ruleset", + "content": [ + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "baz", + "syntax": "sass", + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 6 + } + }, + { + "type": "delimiter", + "content": ",", + "syntax": "sass", + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 7 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 8 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + }, + { + "type": "selector", + "content": [ + { + "type": "class", + "content": [ + { + "type": "ident", + "content": "qux", + "syntax": "sass", + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + ], + "syntax": "sass", + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + }, + { + "type": "space", + "content": "\n", + "syntax": "sass", + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 7 + } + }, + { + "type": "block", + "content": [ + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 4 + } + }, + { + "type": "declaration", + "content": [ + { + "type": "property", + "content": [ + { + "type": "ident", + "content": "content", + "syntax": "sass", + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 11 + } + } + ], + "syntax": "sass", + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 11 + } + }, + { + "type": "propertyDelimiter", + "content": ":", + "syntax": "sass", + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 12 + } + }, + { + "type": "space", + "content": " ", + "syntax": "sass", + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 13 + } + }, + { + "type": "value", + "content": [ + { + "type": "string", + "content": "'qux'", + "syntax": "sass", + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 7, + "column": 18 + } + } + ], + "syntax": "sass", + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 7, + "column": 18 + } +} \ No newline at end of file diff --git a/test/sass/ruleset/issue-119-2.sass b/test/sass/ruleset/issue-119-2.sass new file mode 100644 index 00000000..4cc4fe2b --- /dev/null +++ b/test/sass/ruleset/issue-119-2.sass @@ -0,0 +1,7 @@ +.foo, +.bar + content: 'baz' + + .baz, + .qux + content: 'qux'