is there there way to access stylus AST

323 views Asked by At

I need to access the abstract-syntax-tree (AST) of the CSS style generated by stylus without parsing it again (through css-parse). I wondering if the AST of the generated styles is publicly available.

1

There are 1 answers

0
kizu On BEST ANSWER

There is a partial support for accessing AST. It's incomplete, but still could be used in some cases.

Here is a basic example of how to do this — https://gist.github.com/kizu/41f40714ea533ee1f876

The crucial part is:

var Parser = require('stylus').Parser;
var parser = new Parser(stylContent);
var ast = parser.parse();

And you'll get the AST from the stylContent that contains the Stylus code.

In the future (Stylus 1.0.0) we're planning to make accessing AST easier and it would be more complete.