Skip to content

Programmatic usage of the parser #2777

Closed
@vecerek

Description

@vecerek

Hi there!
I am working on a less2sass converter for my bachelor's thesis, later it should become a sass2less converter, as well. I am searching for a method to get the AST out of a less project. I have been experimenting with the following code:

var parser = new(less.Parser)({}, {contents: {}}, {});
var contents = ".foo {\
  background: #900;\
}\
@import \"import/this-is-valid.less\";";
parser.parse(contents, function (e, tree) {
   console.log(JSON.stringify(tree, null, 2));
});

I get the AST back, unless I don't try to import another less file. What I understood from the code is, that the parser should get a parameter with the used imports, that are created by the importManager, which needs the context as a parameter, etc. Could I get some hint how to get the AST of a less project, if I know its source file?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions