Skip to content

Less Language Other Compiler Features

Mária Jurčovičová edited this page Aug 14, 2013 · 10 revisions

Top Level Sorting and Removal

According to css specification, style sheet can have only one @charset declaration. In addition, css elements must be in following order:

  • @charset statement,
  • @import statements,
  • anything else.

Compiler enforce there rules by sorting top level declarations and removing all unnecessary @charset declarations.

Duplicate Declarations Detection

If the ruleset contains the same declaration twice, only the last one is printed.

Sample input:

.numbers {
  padding: 2; // this line will disappear - it is the same as the next one
  padding: 2;
  padding: 3; // this line will disappear - it is the same as the last one
  padding: 2+3; // this line will disappear - it is the same as the next one
  padding: 5;
  padding: ~"3"
}

compiles into:

.numbers {
  padding: 2;
  padding: 5;
  padding: 3;
}

Two declarations are considered equal if they would result in exactly the same line. Two lines differing only by comments are considered different. Compilation will keep this unchanged:

.numbers {
  padding: /* comment */ 2; 
  padding: /* different */ 2;
}

Cycle Detection For Variables

As variable can reference any variable accessible in its scope, it is possible to create variable cycles:

// variables cycle
@first: @second;
@second: @first + 1;
.ruleset {
  padding: @second;
}

Variables @first and @second references each other and it is impossible to evaluate their value. Less4j detects such cycles and reports them as errors:

ERROR 5:16 Cyclic references among variables: @second (5:16) -> @first (3:14) -> @second (2:13) 

Source Maps

Source map support is described on another page.

Clone this wiki locally