Permalink
Browse files

Fix rule/decl separation on pseudoclasses

  • Loading branch information...
1 parent a23085b commit 8916552048c374e8d3cd7891125fbb21f0d2ec4d @ai ai committed Mar 9, 2016
Showing with 417 additions and 10 deletions.
  1. +10 −6 preprocess.es6
  2. +26 −0 test/cases/colons.css
  3. +323 −0 test/cases/colons.json
  4. +19 −0 test/cases/colons.sss
  5. +39 −4 test/preprocess.js
View
@@ -56,14 +56,18 @@ export default function preprocess(input, lines) {
atrule = tokens[0][0] === 'at-word';
let brackets = 0;
- colon = tokens.some(j => {
- if ( j[0] === '(' ) {
- brackets += 1;
- } else if ( j[0] === ')' ) {
+ for ( let i = 0; i < tokens.length - 1; i++ ) {
+ let type = tokens[i][0];
+ let next = tokens[i + 1][0];
+ if ( type === '(' ) {
brackets += 1;
+ } else if ( type === ')' ) {
+ brackets -= 1;
+ } else if ( type === ':' && brackets === 0 &&
+ (next === 'space' || next === 'newline') ) {
+ colon = true;
}
- return j[0] === ':' && brackets === 0;
- });
+ }
}
let last = tokens[tokens.length - 1];
View
@@ -0,0 +1,26 @@
+@custom-selector :--heading h1, h2;
+
+font: {
+ size: 16px
+}
+
+a:--any-link {
+ color: blue
+}
+a:--any-link {
+ &.is-disabled {
+ color: gray
+ }
+}
+
+article :--heading {
+ color: #000
+}
+
+:root {
+ --red: #F00
+}
+
+body {
+ color: var(--red)
+}
View
@@ -0,0 +1,323 @@
+{
+ "raws": {
+ "indent": " ",
+ "after": "\n"
+ },
+ "type": "root",
+ "nodes": [
+ {
+ "raws": {
+ "before": "",
+ "afterName": " "
+ },
+ "type": "atrule",
+ "name": "custom-selector",
+ "source": {
+ "start": {
+ "line": 1,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 1,
+ "column": 34
+ }
+ },
+ "params": ":--heading h1, h2"
+ },
+ {
+ "raws": {
+ "before": "\n\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 4,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 4,
+ "column": 12
+ }
+ },
+ "prop": "size",
+ "value": "16px"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 3,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {}
+ },
+ "selector": "font:"
+ },
+ {
+ "raws": {
+ "before": "\n\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 7,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 7,
+ "column": 13
+ }
+ },
+ "prop": "color",
+ "value": "blue"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 6,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 6,
+ "column": 12
+ }
+ },
+ "selector": "a:--any-link"
+ },
+ {
+ "raws": {
+ "before": "\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n "
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 10,
+ "column": 5
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 10,
+ "column": 15
+ }
+ },
+ "prop": "color",
+ "value": "gray"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 9,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 9,
+ "column": 15
+ }
+ },
+ "selector": "&.is-disabled"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 8,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 8,
+ "column": 12
+ }
+ },
+ "selector": "a:--any-link"
+ },
+ {
+ "raws": {
+ "before": "\n\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 13,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 13,
+ "column": 13
+ }
+ },
+ "prop": "color",
+ "value": "#000"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 12,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 12,
+ "column": 18
+ }
+ },
+ "selector": "article :--heading"
+ },
+ {
+ "raws": {
+ "before": "\n\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 16,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 16,
+ "column": 13
+ }
+ },
+ "prop": "--red",
+ "value": "#F00"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 15,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 15,
+ "column": 5
+ }
+ },
+ "selector": ":root"
+ },
+ {
+ "raws": {
+ "before": "\n\n"
+ },
+ "type": "rule",
+ "nodes": [
+ {
+ "raws": {
+ "before": "\n ",
+ "between": ": "
+ },
+ "type": "decl",
+ "source": {
+ "start": {
+ "line": 19,
+ "column": 3
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 19,
+ "column": 19
+ }
+ },
+ "prop": "color",
+ "value": "var(--red)"
+ }
+ ],
+ "source": {
+ "start": {
+ "line": 18,
+ "column": 1
+ },
+ "input": {
+ "file": "colons.sss"
+ },
+ "end": {
+ "line": 18,
+ "column": 4
+ }
+ },
+ "selector": "body"
+ }
+ ],
+ "source": {
+ "input": {
+ "file": "colons.sss"
+ },
+ "start": {
+ "line": 1,
+ "column": 1
+ }
+ }
+}
View
@@ -0,0 +1,19 @@
+@custom-selector :--heading h1, h2
+
+font:
+ size: 16px
+
+a:--any-link
+ color: blue
+a:--any-link
+ &.is-disabled
+ color: gray
+
+article :--heading
+ color: #000
+
+:root
+ --red: #F00
+
+body
+ color: var(--red)
Oops, something went wrong.

0 comments on commit 8916552

Please sign in to comment.