Skip to content

Less Public API Proposal - Next version #31

Closed
@matthew-dean

Description

@matthew-dean

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:

  1. identify what is actually useful e.g. what types of Less nodes someone would realistically need/want to return from functions.
  2. 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)
  3. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions