Description
Per discussion in #15, I created some helpers within nodes in 3.0 to cast strings in various cases to Nodes, but I think that should be changed moving forward for a public API.
That is:
- The internal nodes shouldn't have to do any "syntax checking" or casting in order to make them more "user-friendly"; as that can slow down evaluation, instead:
- The public API should be an interface that creates nodes using whatever parsing / re-parsing is necessary
In addition, there are many cases where the Less tree nodes are just not relevant for a public API. So, what I'm hoping is we can:
- identify what is actually useful e.g. what types of Less nodes someone would realistically need/want to return from functions.
- limit the
less
object namespace to just what is "public" i.e. won't change (although existing properties/methods can exist in the prototype chain for back-compat) - Deprecate demos showing
tree.Declaration
type returns from functions.
As an example of the Public API being different from the Less internal node structure, a less.tree
implementation currently looks like:
return new tree.Ruleset([ new tree.Selector([ new tree.Element("", '&') ]) ],
[new tree.Declaration("foo", new Value("bar"))])
A public API would be something like:
return less.ruleset({
selectors: "&",
rules: [
{ name: "foo", value: "bar" } // plain objects cast as declaration
]
})
One reason this is necessary: occasionally new features / parsing changes do require changes in the function arguments for less tree nodes. A Public API could however be more stable.
I would propose these are the main properties of a public API:
- Subset of Less tree nodes (TBD)
parse
render
visitors
Any others? Thoughts? If you agree, what are the internal nodes that should be exposed as a public API?