Skip to content

Instantly share code, notes, and snippets.

@kizu
Last active April 17, 2018 12:03
Show Gist options
  • Save kizu/41f40714ea533ee1f876 to your computer and use it in GitHub Desktop.
Save kizu/41f40714ea533ee1f876 to your computer and use it in GitHub Desktop.
/* Foo */
.hello
width: 10px
/*
Bar
*/
&:after
height: 30px /* Baz */
var fs = require('fs');
var Parser = require('stylus').Parser;
var stylContent = fs.readFileSync('_test.styl', 'utf8');
var parser = new Parser(stylContent);
var ast = parser.parse();
console.log(require('util').inspect(ast, true, 100));
{ nodes:
[ { lineno: 1,
column: 1,
filename: undefined,
str: '/* Foo */',
suppress: true,
inline: false },
{ lineno: 1,
column: 10,
filename: undefined,
nodes:
[ { lineno: 2,
column: 1,
filename: undefined,
inherits: true,
segments:
[ { lineno: 2,
column: 1,
filename: undefined,
val: '.',
string: '.',
prefixed: false },
{ lineno: 2,
column: 2,
filename: undefined,
val: 'hello',
string: 'hello',
prefixed: false },
[length]: 2 ],
block:
{ lineno: 2,
column: 2,
filename: undefined,
nodes:
[ { lineno: 3,
column: 3,
filename: undefined,
segments:
[ { lineno: 3,
column: 3,
filename: undefined,
name: 'width',
string: 'width',
val: null,
mixin: false },
[length]: 1 ],
expr:
{ lineno: 3,
column: 10,
filename: undefined,
nodes:
[ { lineno: 3,
column: 10,
filename: undefined,
val: 10,
type: 'px',
raw: '10px' },
[length]: 1 ],
isList: undefined } },
{ lineno: 5,
column: 3,
filename: undefined,
str: '/*\nBar\n */',
suppress: true,
inline: false },
{ lineno: 7,
column: 14,
filename: undefined,
nodes:
[ { lineno: 8,
column: 3,
filename: undefined,
inherits: true,
segments:
[ { lineno: 8,
column: 3,
filename: undefined,
val: '&',
string: '&',
prefixed: false },
{ lineno: 8,
column: 4,
filename: undefined,
val: ':',
string: ':',
prefixed: false },
{ lineno: 8,
column: 5,
filename: undefined,
val: 'after',
string: 'after',
prefixed: false },
[length]: 3 ],
block:
{ lineno: 8,
column: 5,
filename: undefined,
nodes:
[ { lineno: 9,
column: 5,
filename: undefined,
segments:
[ { lineno: 9,
column: 5,
filename: undefined,
name: 'height',
string: 'height',
val: null,
mixin: false },
[length]: 1 ],
expr:
{ lineno: 9,
column: 13,
filename: undefined,
nodes:
[ { lineno: 9,
column: 13,
filename: undefined,
val: 30,
type: 'px',
raw: '30px ' },
[length]: 1 ],
isList: undefined } },
[length]: 1 ],
parent: [Circular],
node: [Circular],
scope: true } },
[length]: 1 ],
extends: [ [length]: 0 ] },
[length]: 3 ],
parent: [Circular],
node: [Circular],
scope: true } },
[length]: 1 ],
extends: [ [length]: 0 ] },
[length]: 2 ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment