Skip to content

Basic Less types for plugin authors (Quick Reference Card) #446

Open
@seven-phases-max

Description

@seven-phases-max

Posting this WIP here (per discussion at less/less.js@809dc50)


Trivial type Less tree type Less value example Corresponding plugin code (less.tree prefix omitted)
number Dimension 12.34 new Dimension(12.34)
42px new Dimension(42, 'px')
identifier Keyword left new Keyword('left')
background-color new Keyword('background-color')
string Quoted "Hello, World!" new Quoted('', '"Hello, World!"') see [1]
'Hello, World!' new Quoted('', "'Hello, World!'") see [1]
boolean Keyword true new Keyword('true')
false new Keyword('false') see [2]
color Color #369 new Color('369')
rgba(11, 22, 33, 0.5) new Color([11, 22, 33], .5)
red Color.fromKeyword('red')
comma list Value foo, 42 new Value([new Keyword('foo'), new Dimension(42)])
space list Expression foo 42 new Expression([new Keyword('foo'), new Dimension(42)])
arbitrary text Anonymous ~'foo$bar .baz' new Anonymous('foo$bar .baz')
e('#$@&%*!') new Anonymous('#$@&%*!')

Notes:

  1. Quoted constructor is definitely broken, it does not do what you expect by looking at its code (the first parameter is in fact never used most likely because of later eval code involving only content/value value).
  2. Or any other value. Basically, in when guards (so far they are the only statement where boolean values do matter) anything but Keyword('true') counts as false.

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