New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programmatic usage of the parser #2777
Comments
Would this help you? https://github.com/matthew-dean/postcss-less/blob/master/lib/render.js I was able to get the evaluated AST tree this way, and I believe the evaluated tree contains a reference to the un-evaluated tree. |
It should be no difference for imports, just make sure you don't miss:
in programmatic-usage (more details in #2342 (comment)).
Not really. importManager is (roughly) a part of the parser and all of imports are (normally) handled within the parser itself. |
Thank you, guys. Problem solved :) I'm putting the actual code here, that works to get the AST, in case someone will be facing the same hurdle and comes across this issue.
|
Is that possible that the parse function could offers an option that ignoring the imporation? In my case, I have some special rules for import paths, so the internal importation process of less.js wouldn't adpated. Could we just parse the string to AST without any evaluation? |
I just read the source code and I found that I could pass less.parse(content, { processImports: false }, (e, tree) => {
if (e) { return console.error(e) };
return console.log(tree);
}) |
any one know how to stringify the ast back? Seems like there is no less.stringify or ast.toString() function |
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:
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?
The text was updated successfully, but these errors were encountered: