Skip to content

Instantly share code, notes, and snippets.

@shellscape
Last active October 29, 2015 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shellscape/bb8e35c3b38a2a953174 to your computer and use it in GitHub Desktop.
Save shellscape/bb8e35c3b38a2a953174 to your computer and use it in GitHub Desktop.
Evaluating AST Tree of PostCSS
var postcss = require('postcss'),
fs = require('fs'),
path = require('path'),
css = fs.readFileSync(path.join(__dirname, 'lesstest.less'), 'utf-8'),
root = postcss.parse(css);
console.log(require('util').inspect(root, { depth: 6 }));
.foo {
border: none;
}
.mixin (...) {
&[input],
[input]& {
border: 0;
}
}
{ raws: { semicolon: false, after: '\n' },
type: 'root',
nodes:
[ { raws: { before: '', between: ' ', semicolon: false, after: '\n' },
type: 'rule',
nodes:
[ { raws: { before: '\n ', between: ' ', semicolon: true, after: '\n ' },
type: 'rule',
nodes:
[ { raws: { before: '\n ', between: ': ' },
type: 'decl',
parent: [Circular],
source:
{ start: { line: 4, column: 5 },
input:
{ css: '.mixin (...) {\n &[input],\n [input]& {\n border: 0;\n }\n}\n',
id: '<input css 1>' },
end: { line: 4, column: 14 } },
prop: 'border',
value: '0' } ],
parent: [Circular],
source:
{ start: { line: 2, column: 3 },
input:
{ css: '.mixin (...) {\n &[input],\n [input]& {\n border: 0;\n }\n}\n',
id: '<input css 1>' },
end: { line: 5, column: 3 } },
selector: '&[input],\n [input]&' } ],
parent: [Circular],
source:
{ start: { line: 1, column: 1 },
input:
{ css: '.mixin (...) {\n &[input],\n [input]& {\n border: 0;\n }\n}\n',
id: '<input css 1>' },
end: { line: 6, column: 1 } },
selector: '.mixin (...)' } ],
source:
{ input:
{ css: '.mixin (...) {\n &[input],\n [input]& {\n border: 0;\n }\n}\n',
id: '<input css 1>' },
start: { line: 1, column: 1 } } }
{ raws: { semicolon: false, after: '\n' },
type: 'root',
nodes:
[ { raws: { before: '', between: ' ', semicolon: true, after: '\n' },
type: 'rule',
nodes:
[ { raws: { before: '\n ', between: ': ' },
type: 'decl',
parent: [Circular],
source:
{ start: { line: 2, column: 3 },
input: { css: '.foo {\n border: none;\n}\n', id: '<input css 1>' },
end: { line: 2, column: 15 } },
prop: 'border',
value: 'none' } ],
parent: [Circular],
source:
{ start: { line: 1, column: 1 },
input: { css: '.foo {\n border: none;\n}\n', id: '<input css 1>' },
end: { line: 3, column: 1 } },
selector: '.foo' } ],
source:
{ input: { css: '.foo {\n border: none;\n}\n', id: '<input css 1>' },
start: { line: 1, column: 1 } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment