* Initial plan
* Fix: not keyword now works without parentheses in guard conditions
Previously, `boolean(not false)` silently ignored the `not` keyword
while `boolean(not (false))` worked correctly.
The `negatedCondition` parser function consumed the `not` keyword but
only tried `parenthesisCondition`, which requires `(`. With no parens,
it returned undefined with `not` already consumed, causing silent skip.
Fix: fall back to `atomicCondition` when `parenthesisCondition` fails,
allowing both `not false` and `not (false)` to work consistently.
Co-authored-by: matthew-dean <414752+matthew-dean@users.noreply.github.com>
* Restrict not-without-parens to simple values only (keywords/variables)
Complex conditions like `not 2 < 1` still require parentheses,
keeping alignment with CSS media query syntax. Only simple bare
values (keywords, variables, quoted strings) are allowed after
`not` without parens: `not false`, `not @var`.
Remove the `boolean(not 2 < 1)` test case that relied on the
broader atomicCondition fallback.
Co-authored-by: matthew-dean <414752+matthew-dean@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: matthew-dean <414752+matthew-dean@users.noreply.github.com>
Co-authored-by: Matthew Dean <matthew-dean@users.noreply.github.com>
* fix: webpack browser build - use UMD dist/less.js, add CJS bundle (#4423)
- Browser exports point to dist/less.js (UMD) instead of less-node
- Add CJS bundle (dist/less-node.cjs) for Node require() with module shim
- Remove dead index.js; index.cjs re-exports CJS bundle
- Add export tests: import-patterns, webpack-browser, test-cjs-suite
- CI and publish workflows run test:node (build + CJS + ESM tests)
* Beta publish script
* chore: clarify test:node runs ESM + CJS in workflow labels
* fix: normalize path separators in rollup plugin for Windows CI
The inlinePackageVersion plugin used forward-slash path check that
failed on Windows where rollup passes backslash-separated IDs,
leaving the require('../../package.json') unresolved at runtime.
* chore: bump version to 4.6.3 for release
* docs: enrich npm README with usage examples and feature highlights
version: 4.6.0
* fix: update README and tests to show ESM + promise/await usage
The package is ESM-only ("type": "module"), so the README now correctly
shows `import less from 'less'` with `await` instead of CJS `require()`.
The ES6 test now verifies both promise/await and callback APIs.
version: 4.6.0
* fix: add CJS compatibility wrapper so require('less') works
Adds index.cjs as a one-line wrapper that re-exports the ESM default.
The exports field now has both import and require conditions.
Adds test-cjs.cjs to verify CJS consumption alongside the existing
ESM test.
version: 4.6.0
* fix: lazy Proxy CJS wrapper for Node 18+ compatibility
Node 22+ uses native require(esm). Node 18-20 uses a lazy Proxy with
dynamic import() — transparent because render()/parse() already return
promises. Tested with render, callback, and version property access.
* fix: include Node 20.19+ in native require(esm) path
* fix: add alt text to README images for accessibility
* fix: preserve alpha 0 for fully transparent hex colors
#0000 and #00000000 parsed alpha as 0 which was treated as falsy by
the || operator, causing it to fall back to 1 (opaque). Use typeof
check instead so alpha 0 is preserved.
* fix: selector getElements callback `this` binding and forEach lint
- Capture `this._fileInfo` and `this.parse.imports` into locals before
the plain function callback in Selector.getElements(), where `this`
is undefined in strict mode (ES modules)
- Use explicit block in forEach to avoid implicit return of assignment
* fix: preserve full error context when rethrowing mixin call errors
The catch block in MixinCall.eval() only copied message and stack,
dropping type, extract, callLine, and other LessError fields. This
caused all mixin call errors to be reported as SyntaxError regardless
of their actual type (e.g. NameError). Use spread to preserve all
fields while still overriding index/filename to the call site.
* fix: guard functionRegistry.inherit() and fix atrule parenting
- Container and Media eval() now guard functionRegistry before calling
.inherit(), matching mixin-definition.js defensive pattern
- AtRule constructor: remove dead setParent(selectors) on orphaned local,
parent this.declarations and this.rules with null checks
* feat: add JSDoc type annotations with @ts-check to all tree node files
Add proper JSDoc type annotations to all 44 files in lib/less/tree/,
enabling per-file TypeScript checking via @ts-check. No {*} or {any}
casts — all types are derived from reading the actual code.
Key changes:
- Shared types (EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo) defined in node.js
- Node.value typed as union: Node | Node[] | string | number | undefined
- Node.prototype.parse declared for parser-injected prototype property
- Constructor properties explicitly declared with proper types
- Inline casts used to narrow union types at usage sites
- Widened base class params where subclasses pass different types
Also adds typecheck to prepublishOnly and pre-commit hook to catch
regressions as more files are annotated toward global checkJs: true.
All 139 tests pass, zero TypeScript errors.
* fix: remove duplicate JSDoc type annotation in ruleset.js
* refactor: convert prototype-based tree nodes to ES6 classes
Convert all 30 tree node files from `Object.assign(new Node(), {...})`
prototype pattern to proper `class extends Node` syntax. This enables
TypeScript to understand the inheritance chain, reducing checkJs errors
from 2756 to 0.
- All tree nodes now use `class X extends Node` (or appropriate parent)
- Node.type converted from instance property to getter for clean override
- Factory functions in index.js updated to use `new` instead of
Object.create + apply (required for ES6 class compatibility)
- Benchmark script converted to ESM
- Added @types/node devDependency for checkJs support
- Enabled checkJs in tsconfig.json
- Added JSDoc types to node.js base class and several utility files
No behavioral changes - all 139 tests pass, benchmark performance
unchanged vs historical baselines (avg 36-39ms for 104KB).
* fix: @plugin deprecation says "replaced" not "removed"
* fix: use constructor params for AtRule selectors, path.resolve in benchmark
* fix: align @types/node with engines.node >=18 floor
* feat: migrate to native ESM with no build step
- Rename src/ to lib/ — source files are shipped directly, no compilation
- Add "type": "module" to package.json for native ESM support (Node 18+)
- Convert bin/lessc, test files, and build scripts from CJS to ESM
- Rename Gruntfile.js and .eslintrc.js to .cjs (must remain CommonJS)
- Add .js extensions to all relative import paths for ESM resolution
- Use createRequire() for optional dependency resolution (npm packages, JSON)
- Configure TypeScript for check-only mode (noEmit: true, allowJs: true)
- Update Rollup config to read from lib/ directly
- Update CI matrix to drop Node 16 (minimum Node 18+)
- Browser build is smaller: 500KB (was 509KB), minified 153KB (was 158KB)
- All 139 tests pass
* chore: fix trailing semicolons from linter
* chore: gitignore generated .css.map files in lib/
* fix(ci): restore lts/-3 to test matrix
* chore: stop tracking dist/ build artifacts
Generated browser bundles don't need to be in source control — they're
built during publish and included in the npm package via the files field.
Removes duplicate copies from both root dist/ and packages/less/dist/.
* fix(ci): use pnpm exec for playwright install
npx doesn't reliably find binaries with pnpm. Since playwright is
already a devDependency, use pnpm exec to run the installed version.
* fix(ci): use pnpm --filter for playwright, disable fail-fast
pnpm exec at workspace root can't find playwright binary since it's a
devDependency of the less package. Use --filter to run in that context.
Also disable fail-fast so all matrix jobs complete independently.
* fix(ci): move playwright to root devDependencies
Makes pnpm exec playwright work from workspace root in CI.
* fix: upgrade copy-anything to v3 for ESM compat, fix Windows test paths
copy-anything v2 lacks "type": "module", causing named import failures
on Node 18. v3 has proper ESM exports.
Revert testFolder to absolute path (matching original behavior) so debug
test path replacements match Less compiler output on Windows.
* chore: add CodeRabbit config to raise file review limit
* fix: add files field to package.json, remove postinstall from published package
Restricts npm package to only bin/, lib/, dist/, index.js, and README.md.
Previously shipped test files, Gruntfile, eslint config, etc.
Removes postinstall script (Playwright browser install) which only applies
in the monorepo dev environment and fails when installed from npm.
Verified: npm pack --dry-run shows 120 files (was 229), lessc CLI and
API both work from a clean tarball install.
* fix(benchmark): fix division in benchmark files for v4 math defaults
Wrap bare divisions inside percentage() calls in extra parens so
benchmarks work with v4's default parens-division math mode. Add
--math option passthrough to benchmark-runner.js and pass
--math=always in run-historical.sh for consistent cross-version results.
* perf: remove unnecessary closures in hot paths
- Remove `extendVisitor` alias in findMatch, use `this` directly
- Replace IIFE closure for functionRegistry lookup in Ruleset.eval
with inline loop
~5% improvement on main benchmark (median 38.6ms → 37.1ms)
* perf: replace forEach/map closures with for loops in hot paths
- Selector.eval: replace map() closures with pre-allocated for loops
- Ruleset transformDeclaration: replace forEach with for loop
- extend-visitor visitRuleset: replace forEach with for loop, cache
extend and pathCount to reduce repeated property access
Combined with previous commit: ~8% improvement on 104KB benchmark
(median 38.6ms → 36.4ms)
* fix(benchmark): handle all v3.12+/v4.x build scenarios
- Use pnpm for v4.3+ (workspace: protocol)
- Fallback tsc installation when npm can't install locally
- Install runtime deps separately when npm fails due to
unpublished workspace packages (@less/test-import-module)
- Use last patch version of each minor release
- Skip v3.13.x (broken source: missing tree/util.js)
* bench: update benchmark results after hot-path optimizations
Median: 39.07ms → 34.32ms (~12% improvement)
Throughput: 2,495 KB/s → 2,828 KB/s
System: macbook-pro arm64
* bench: add historical benchmark results and track runs in git
- Add historical benchmark data (v3.5–v4.2) to results/runs/
- Update latest/ with all versions including v4.5.0-dev optimized results
- Format JSON with 2-space indentation
- Update .gitignore to track runs/ (historical records belong in git)
* bench: full historical benchmark run (v2.0–v4.5, 23 versions)
Apple M4 Pro, arm64, Node v18/v20/v24
Key findings:
- v2.4-v2.5 fastest era (~31ms median on 104KB file)
- v3.10-v3.12 massive regression (3-5x slower, 126-185ms)
- v4.0 recovered to ~40ms
- v4.2 fastest v4.x (35.4ms)
- v4.5.1 current master: 42.2ms
* bench: prune version list to significant performance changes
Reduced from 23 to 15 versions based on full benchmark data.
Dropped versions with <5% difference from their predecessor:
- v2.1 (broken), v2.5, v2.7 (plateau with v2.4/v2.6)
- v3.6–v3.9 (all within 1ms, flat ~41ms)
- v4.1 (identical to v4.0)
The full set can still be run with --versions flag.
* fix: correct import and error handling in style() function
- Fix incorrect import: `Anonymous` was imported from '../tree/variable'
instead of '../tree/anonymous' (worked by accident since Variable
was imported on the line above)
- Simplify switch/case with single case 0 to a plain if statement
- Add explanatory comment to the catch block documenting why it exists
(CSS pass-through for @container style() queries)
* refactor: remove dead boolean logic in evalRoot()
- Remove `allAmpersands` variable that was initialized to false and
never set to true, making it dead code
- Replace string-based ampersand detection (genCSS + regex) with
direct element value checks, avoiding unnecessary AST-to-string
conversion
- Simplify boolean conditions that referenced the dead variable
* fix: add missing parserInput.forget() in colorOperand
The colorOperand parser rule called parserInput.save() but only called
restore() on failure, missing the forget() call on the success path.
* refactor: QueryInParens eval() returns new node instead of mutating this
QueryInParens.eval() was mutating `this` directly instead of returning
a new node, violating the core Less.js tree pattern. It also used a
brittle queue pattern where deep copies were pushed to an `mvalues`
array during eval() and shifted off during genCSS().
Now eval() creates and returns a new QueryInParens with evaluated
children, and genCSS() reads directly from the node's properties.
The `copy-anything` import is removed from this file (still used
elsewhere in the codebase).
* refactor: extract mergeRules into shared utility to fix AtRule layering violation
AtRule.eval() was directly calling ToCSSVisitor.prototype._mergeRules,
which breaks the architectural boundary between tree nodes and visitors.
Extract the merge logic into a standalone utility (merge-rules.js) that
both AtRule.eval() and ToCSSVisitor can use without coupling.
* fix: remove Container copy-paste duplication and fix evalNested splice index bug
Container was overriding evalNested, permute, and bubbleSelectors with
identical copies of the methods already provided by NestableAtRulePrototype.
Remove the redundant overrides so Container properly inherits from the
shared prototype.
Also fix a bug in NestableAtRulePrototype.evalNested where
context.mediaBlocks.splice(i, 1) used `i` (the index into `path`) to
splice `mediaBlocks`. These are different arrays with different contents,
so the index was wrong. Use indexOf(this) to find the correct position.
* fix(#4331): exclude CSS at-rule keywords from declarationCall parsing
* fix(#4331): normalize spacing after CSS at-rule keywords in media queries
When `and`, `or`, `not`, or `only` keywords appear without a space
before `(` in media queries, ensure spacing is added in the output
to produce valid CSS.
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
Follows-up a38f8a1eb7, which introduced
this as part of implementing property accessors. The method was not
used there, and hasn't been used elsewhere since then either.
Ref https://github.com/less/less.js/pull/3163.
Deprecation warnings from flags like --js, --line-numbers, and
--math=always were printed immediately during arg parsing, so
--quiet-deprecations only worked if it appeared before the deprecated
flag. Now all CLI deprecation messages are queued and flushed after
parsing completes, respecting --silent, --quiet, and
--quiet-deprecations regardless of flag order.
variance_pct was computing (max-min)/avg which is range-over-mean.
Now uses stddev/avg (coefficient of variation) which is a proper
variability statistic.
path.resolve('less') turns the package name into an absolute filesystem
path, preventing Node's package resolution from finding npm-installed
versions. Only resolve relative paths starting with '.'.
* Set up alpha branch and auto-publishing
* Restore 4.5.0 version number
* Set up post-merge hook to stablize version and fix tests
* Restore .gitattributes
* Fix to publish.yml
* Revert PNPM version to version 8 for Node 16 compatibility
* Another attempt to resolve PNPM version
* Another attempt to resolve PNPM version
* Migrate Less to use valid CSS
* Re-organize test structure
* Lots of test refactoring
* More test updates
* Add restructured tests
* WIP
Signed-off-by: Matthew Dean <matthew-dean@users.noreply.github.com>
* More fixes to tests
* More test fixes
* All tests passing
* WIP fix tests
* Finished fixing browser tests
* Improve test coverage
* Add debug tests
* Add back debug tests to show equal test coverage
* Fix browser tests
* More test coverage
* Fix sourcemap absolute path for CI
* More source map normalization for Windows
* Fix source map normalization
* Another attempted fix for Windows
---------
Signed-off-by: Matthew Dean <matthew-dean@users.noreply.github.com>
* Fixes#4362 which is a regression introduced by an attempt to create improved and generalized function parsing. Set the no spacing flag for comma separated lists and add test.
* feat: add support for CSS scroll state container
* Add support for CSS scroll state container queries.
* Improve at-rule function handling.
* chore: clean up scroll-state solution
* Clean up scroll-state solution code for merge.
* fix(issue#4242): add support for layer at-rule
* Add support for layer at-rule.
* Add tests for layer at-rule.
* feat: add support for layer import syntax
* Add support for layer import at-rule syntax. See: https://developer.mozilla.org/en-US/docs/Web/CSS/@import
* chore: cleanup layer import solution
* Cleanup layer import at-rule solution before merge.
* fix(issue#4242): fix for media query list
* Add fix for media query list parsing in import.
* Add test for import with media query list syntax.
* fix(issue:4267) support starting-style at-rule
* Add support for the starting-style at-rule.
* fix(issue:4267) improve comment and call handling
* Improve at-rule comment and call handling and add more starting-style
at-rule tests.
* refactor(issue:4267) refactor starting-style code
* Refactor new code introduced to broaded at-rule support for
starting-syle at-rule and other at-rules.
* chore(issue:4267) cleanup at-rule enhancement
* Cleanup at-rule enhancement code for starting-style at-rule support.
* fix: pin Playwright to exact version
* Pin Playwright to exact version to try to resolve CI issues.