Knowledge Base updated: 2026-09-06
Less.js knowledge base
Orientation
Less.js is a JavaScript implementation of the Less stylesheet language. Its shared compiler parses Less source into a tree, evaluates language semantics, applies visitors and transforms, and emits CSS, errors, and optional source maps.
The compiler core lives under packages/less/lib/less/, with parser, tree-node, visitor, function, import, and environment subsystems separated from the Node.js, browser, and lessc integration layers. User-facing language behavior is implemented through the parser and evaluated tree model rather than a standalone language runtime.
Repository-level delivery state is concentrated in the root workspace manifest, package manifests, Rollup build configuration, release scripts and workflows, and the shared test-data fixture packages. Browser bundles and published package artifacts are generated from the shared compiler entry points.
System architecture
flowchart LR
Source[Less source] --> Parser[Parser]
Parser --> Tree[Tree nodes]
Tree --> ImportManager[Import manager]
ImportManager --> FileManagers[File managers]
Tree --> Eval[Evaluation contexts]
Eval --> Functions[Built-in functions]
Eval --> Plugins[Plugin manager]
Eval --> Visitors[Visitors and transforms]
Visitors --> CSS[CSS generation]
CSS --> Output[CSS, errors, source maps]
Node[Node API and lessc] --> Parser
Browser[Browser runtime] --> Parser
Build[Rollup builds] --> Browser
Workspace[Workspace manifests] --> Build
Tests[Fixtures and test runners] --> Node
flowchart LR
CLI[lessc options] --> NodeEntry[Node entry point]
NodeEntry --> Render[less.render]
BrowserEntry[Browser stylesheet discovery] --> Render
Render --> Parse[Parse and import]
Parse --> Evaluate[Evaluate tree]
Evaluate --> Transform[Visitor transforms]
Transform --> Result[CSS and source map result]
Glossary
- Tree node — An object in the parsed Less syntax tree; nodes carry semantic behavior and source-location context used throughout compilation.
- Visitor — A traversal and transformation stage applied to the evaluated tree, including selector extension, join, visibility, and CSS generation work.
- File manager — An environment-specific resolver and loader selected to satisfy an
@importor plugin request. - Detached ruleset — A ruleset value that can be stored, passed, invoked, and evaluated in an appropriate scope.
- Workspace package — A package managed from the root workspace, including the compiler, test data, and import-module test packages.
Codebase-wide invariants
- Parsing preserves source context on tree structures so later diagnostics and generated output can refer back to input locations; evidence:
packages/less/lib/less/parser/andpackages/less/lib/less/tree/**. - Environment integrations use the shared compiler pipeline instead of implementing separate language semantics; evidence:
packages/less/lib/less-node/,packages/less/lib/less-browser/, andpackages/less/lib/less/. - Import resolution is mediated through file-manager selection rather than direct parser filesystem access; evidence: packages/…/import-manager.js and
packages/less/lib/less/environment/. - Browser-distributable output is built from configured package entry points rather than maintained as independent source; evidence: packages/…/rollup.config.js and packages/…/package.json.
- Versioned workspace delivery requires coordinated package metadata; evidence: package.json, packages/…/package.json, packages/…/package.json, and packages/…/package.json.