-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Expose Less parsing as a top level feature of the less package #2319
Conversation
My vision of this is that currently the AST is just too complex for any use outside of the compiler itself (almost every entity there requires all that knowledge of all those specific things Less syntax consists of). So in this context I wonder what would be typical use of the AST in its current state (I can imagine some for earlier days of Less when the AST was young and simple but for now it looks like it's nearly impossible to do something valuable with it w/o duplicating almost half of the compiler code). |
Yes, i agree Max. But, also im fine with this refactor - it seems harmless? |
Yes, I guess the changes in the PR itself are fine on their own. I just wondered of "worthy of being easily accessible to consumers of less.js". |
@seven-phases-max I could probably word that better as "accessible to developers". I cannot speak for others, but I am currently tinkering with a checkstyle program for less documents, and this PR makes it very straightforward to call I'm not sure that the complexity of the AST is reason enough to keep it under wraps; I would argue that it's worth making it accessible and then seeing if that results in either new less-related modules and programs and/or new issues and pull requests to improve the AST. Either would be a valid indication that the parse tree is useful to developers. @lukeapage In addition to your recommendation about recreating |
The To not sound unreasonable, here's basic example:
Take a look at the AST of the above code and try to imagine how much code you would need to write for a module to even simply "understand" what's happening there (before it can analyse for the coding style). |
I don't disagree that less syntax can get complicated. Was the de-publicizing of |
Converting a Less stylesheet into an AST is a valuable piece of functionality, and worthy of being easily accessible to consumers of less.js.
7a52d32
to
cf54e01
Compare
It was done to |
Expose Less parsing as a top level feature of the less package
I've merged it in, its a good refactor and I don't see any harm in exposing the parseTree (it will not be useful to most people but we do expose the parse tree for visitor plugins already) |
@seven-phases-max I don't get this at all. What harm is it to anyone else if someone "misuses" a JavaScript file? If it's from a support / question answering perspective, we can always have a "public / supported" API, yet still expose all parts of the library so that makers / developers can create unique and unexpected extensions to less without having to fork / alter the core library. Less.js devs have no obligation to provide support for third-party plugins, and we can provide fair warning that "private" methods may change, so wouldn't that be sufficient? @lukeapage 👍 saw you merged this in as I was typing. |
@matthew-dean What I mean is that by keeping some code there "just in case" (i.e. it does not have any specific purpose except "maybe someday someone may find some use of it") we just make unnecessary complications there (so when we'll need some similar API for something a bit more real we'll come to this with this not necessary luggage of functions/interfaces we'll had to keep at least some backward-compatibility with while as it always happens that new stuff will need different functions/interfaces). Not really a big deal (since it is already been there anyway, just a matter of keeping things simple, just one of those time-saver deveopment rules: "never make an API before you know how exactly you're going to use it" :). |
Converting a Less stylesheet into an AST is a valuable piece of functionality, and worthy of being easily accessible to consumers of less.js. There have been issues submitted in the past about accessing the AST generated by the LESS parser, and without copy/pasting much of the code found within
lib/render.js
, it has thus far been a difficult task.This pull request strips the parsing functionality out of
render.js
and moves it toparse.js
, making it a top level property of theless
module. In the same way thatless.render
takes a less string and returns a css string,less.parse
takes a less string and returns a less AST.I would also like to propose having the option to have extra data attached to this AST (for example, line/column location information for tokens like rules, imports, variables, mixin calls, etc), but before I started working on that, I wanted to get your opinion on this feature first.
Thanks.