From 99f0ba8106d72b9c83b7d9a2425256d2f792c306 Mon Sep 17 00:00:00 2001 From: Ritvik718 Date: Mon, 15 Jun 2026 18:37:26 +0530 Subject: [PATCH 1/2] fix: resolve lint and style errors in compiler and build tools --- packages/less/benchmark/benchmark-runner.js | 219 ++++++++++---------- packages/less/build/rollup.js | 2 +- 2 files changed, 110 insertions(+), 111 deletions(-) diff --git a/packages/less/benchmark/benchmark-runner.js b/packages/less/benchmark/benchmark-runner.js index 685a0385a..ae3233dcd 100644 --- a/packages/less/benchmark/benchmark-runner.js +++ b/packages/less/benchmark/benchmark-runner.js @@ -14,58 +14,58 @@ var extraOpts = {}; // Parse --key=value options from remaining args for (var ai = 5; ai < process.argv.length; ai++) { - var optMatch = process.argv[ai].match(/^--([a-z-]+)=(.*)$/); - if (optMatch) { extraOpts[optMatch[1]] = optMatch[2]; } + var optMatch = process.argv[ai].match(/^--([a-z-]+)=(.*)$/); + if (optMatch) { extraOpts[optMatch[1]] = optMatch[2]; } } if (!file) { - console.error('Usage: node benchmark-runner.js [runs] [warmup]'); - process.exit(1); + console.error('Usage: node benchmark-runner.js [runs] [warmup]'); + process.exit(1); } // Find Less compiler - try multiple paths for different version eras var less; var lessPath = ''; var tryPaths = [ - // v4.x monorepo (after build) - './packages/less', - // v3.x / v2.x (lib in repo) - '.', - './lib/less-node', - // Fallback - 'less' + // v4.x monorepo (after build) + './packages/less', + // v3.x / v2.x (lib in repo) + '.', + './lib/less-node', + // Fallback + 'less' ]; for (var i = 0; i < tryPaths.length; i++) { - try { - var p = tryPaths[i]; - // Use path.resolve for relative paths, but keep bare package names for Node resolution - var mod = require(p.startsWith('.') ? path.resolve(p) : p); - // Handle both direct export and .default (ESM interop) - less = mod && mod.default ? mod.default : mod; - if (less && (less.render || less.parse)) { - lessPath = p; - break; - } - less = null; - } catch (e) { + try { + var p = tryPaths[i]; + // Use path.resolve for relative paths, but keep bare package names for Node resolution + var mod = require(p.startsWith('.') ? path.resolve(p) : p); + // Handle both direct export and .default (ESM interop) + less = mod && mod.default ? mod.default : mod; + if (less && (less.render || less.parse)) { + lessPath = p; + break; + } + less = null; + } catch (e) { // try next - } + } } if (!less) { - console.error(JSON.stringify({ error: 'Could not find Less compiler', tried: tryPaths })); - process.exit(2); + console.error(JSON.stringify({ error: 'Could not find Less compiler', tried: tryPaths })); + process.exit(2); } // Determine version var version = 'unknown'; if (less.version) { - if (Array.isArray(less.version)) { - version = less.version.join('.'); - } else { - version = String(less.version); - } + if (Array.isArray(less.version)) { + version = less.version.join('.'); + } else { + version = String(less.version); + } } var filePath = path.resolve(file); @@ -74,102 +74,101 @@ var fileDir = path.dirname(filePath); // Use less.render() - stable across all versions var renderTimes = []; -var parseTimes = []; var completed = 0; var errors = []; function hrNow() { - var hr = process.hrtime(); - return hr[0] * 1000 + hr[1] / 1e6; + var hr = process.hrtime(); + return hr[0] * 1000 + hr[1] / 1e6; } function runOnce(callback) { - var start = hrNow(); - var opts = { - filename: filePath, - paths: [fileDir] - }; - // Forward extra options (e.g. --math=always) - for (var key in extraOpts) { opts[key] = extraOpts[key]; } - less.render(data, opts, function (err, output) { - var end = hrNow(); - if (err) { - errors.push({ run: completed, error: err.message || String(err) }); - callback(err); - return; - } - renderTimes.push(end - start); - completed++; - callback(null); - }); + var start = hrNow(); + var opts = { + filename: filePath, + paths: [fileDir] + }; + // Forward extra options (e.g. --math=always) + for (var key in extraOpts) { opts[key] = extraOpts[key]; } + less.render(data, opts, function (err) { + var end = hrNow(); + if (err) { + errors.push({ run: completed, error: err.message || String(err) }); + callback(err); + return; + } + renderTimes.push(end - start); + completed++; + callback(null); + }); } function runAll(i) { - if (i >= totalRuns) { - reportResults(); - return; - } - runOnce(function (err) { - if (err && errors.length > 3) { - // Too many errors, bail - reportResults(); - return; + if (i >= totalRuns) { + reportResults(); + return; } - runAll(i + 1); - }); + runOnce(function (err) { + if (err && errors.length > 3) { + // Too many errors, bail + reportResults(); + return; + } + runAll(i + 1); + }); } function analyze(times, skipWarmup) { - var start = skipWarmup ? warmupRuns : 0; - if (times.length <= start) return null; - var effective = times.slice(start); - var total = 0, min = Infinity, max = 0; - for (var i = 0; i < effective.length; i++) { - total += effective[i]; - min = Math.min(min, effective[i]); - max = Math.max(max, effective[i]); - } - var avg = total / effective.length; - - // Median - var sorted = effective.slice().sort(function (a, b) { return a - b; }); - var mid = Math.floor(sorted.length / 2); - var median = sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2; - - // Standard deviation and coefficient of variation - var sumSqDiff = 0; - for (var i = 0; i < effective.length; i++) { - sumSqDiff += (effective[i] - avg) * (effective[i] - avg); - } - var stddev = Math.sqrt(sumSqDiff / effective.length); - var variancePct = avg === 0 ? 0 : (stddev / avg) * 100; - - return { - min: Math.round(min * 100) / 100, - max: Math.round(max * 100) / 100, - avg: Math.round(avg * 100) / 100, - median: Math.round(median * 100) / 100, - stddev: Math.round(stddev * 100) / 100, - variance_pct: Math.round(variancePct * 100) / 100, - samples: effective.length, - throughput_kbs: Math.round(1000 / avg * data.length / 1024) - }; + var start = skipWarmup ? warmupRuns : 0; + if (times.length <= start) return null; + var effective = times.slice(start); + var total = 0, min = Infinity, max = 0; + for (var i = 0; i < effective.length; i++) { + total += effective[i]; + min = Math.min(min, effective[i]); + max = Math.max(max, effective[i]); + } + var avg = total / effective.length; + + // Median + var sorted = effective.slice().sort(function (a, b) { return a - b; }); + var mid = Math.floor(sorted.length / 2); + var median = sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2; + + // Standard deviation and coefficient of variation + var sumSqDiff = 0; + for (i = 0; i < effective.length; i++) { + sumSqDiff += (effective[i] - avg) * (effective[i] - avg); + } + var stddev = Math.sqrt(sumSqDiff / effective.length); + var variancePct = avg === 0 ? 0 : (stddev / avg) * 100; + + return { + min: Math.round(min * 100) / 100, + max: Math.round(max * 100) / 100, + avg: Math.round(avg * 100) / 100, + median: Math.round(median * 100) / 100, + stddev: Math.round(stddev * 100) / 100, + variance_pct: Math.round(variancePct * 100) / 100, + samples: effective.length, + throughput_kbs: Math.round(1000 / avg * data.length / 1024) + }; } function reportResults() { - var result = { - version: version, - lessPath: lessPath, - file: path.basename(file), - fileSize: data.length, - fileSizeKB: Math.round(data.length / 1024 * 10) / 10, - totalRuns: totalRuns, - warmupRuns: warmupRuns, - completedRuns: completed, - errors: errors.length > 0 ? errors : undefined, - render: analyze(renderTimes, true) - }; - console.log(JSON.stringify(result)); + var result = { + version: version, + lessPath: lessPath, + file: path.basename(file), + fileSize: data.length, + fileSizeKB: Math.round(data.length / 1024 * 10) / 10, + totalRuns: totalRuns, + warmupRuns: warmupRuns, + completedRuns: completed, + errors: errors.length > 0 ? errors : undefined, + render: analyze(renderTimes, true) + }; + console.log(JSON.stringify(result)); } runAll(0); diff --git a/packages/less/build/rollup.js b/packages/less/build/rollup.js index 36c5313eb..279fdd4da 100644 --- a/packages/less/build/rollup.js +++ b/packages/less/build/rollup.js @@ -28,7 +28,7 @@ function moduleShim() { }, load(id) { if (id === '\0module') { - return `export function createRequire() { return require; }`; + return 'export function createRequire() { return require; }'; } return null; } From a1edc9ceb65c21ff76a19d2a6fabab709d20b457 Mon Sep 17 00:00:00 2001 From: Ritvik718 Date: Mon, 15 Jun 2026 18:57:37 +0530 Subject: [PATCH 2/2] feat: add inequality comparison operator (!=) --- packages/less/lib/less/parser/parser.js | 3 +++ packages/less/lib/less/tree/condition.js | 6 +++--- .../test-data/tests-unit/css-guards/css-guards.css | 6 ++++++ .../test-data/tests-unit/css-guards/css-guards.less | 13 +++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/less/lib/less/parser/parser.js b/packages/less/lib/less/parser/parser.js index 2e3edb2a8..19ed519fa 100644 --- a/packages/less/lib/less/parser/parser.js +++ b/packages/less/lib/less/parser/parser.js @@ -2547,6 +2547,9 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) { op = '<'; } } else + if (parserInput.$str('!=')) { + op = '!='; + } else if (parserInput.$char('=')) { if (parserInput.$char('>')) { op = '=>'; diff --git a/packages/less/lib/less/tree/condition.js b/packages/less/lib/less/tree/condition.js index 0637a3eb9..e79de865d 100644 --- a/packages/less/lib/less/tree/condition.js +++ b/packages/less/lib/less/tree/condition.js @@ -45,16 +45,16 @@ class Condition extends Node { default: switch (Node.compare(a, b)) { case -1: - result = this.op === '<' || this.op === '=<' || this.op === '<='; + result = this.op === '<' || this.op === '=<' || this.op === '<=' || this.op === '!='; break; case 0: result = this.op === '=' || this.op === '>=' || this.op === '=<' || this.op === '<='; break; case 1: - result = this.op === '>' || this.op === '>='; + result = this.op === '>' || this.op === '>=' || this.op === '!='; break; default: - result = false; + result = this.op === '!='; } } diff --git a/packages/test-data/tests-unit/css-guards/css-guards.css b/packages/test-data/tests-unit/css-guards/css-guards.css index d4649084f..e9cec6e6e 100644 --- a/packages/test-data/tests-unit/css-guards/css-guards.css +++ b/packages/test-data/tests-unit/css-guards/css-guards.css @@ -35,3 +35,9 @@ sub-prop: 2px; prop: 1px; } +.inequality-test-1 { + color: green; +} +.inequality-test-3 { + color: green; +} diff --git a/packages/test-data/tests-unit/css-guards/css-guards.less b/packages/test-data/tests-unit/css-guards/css-guards.less index 8a097ae4d..0639ef856 100644 --- a/packages/test-data/tests-unit/css-guards/css-guards.less +++ b/packages/test-data/tests-unit/css-guards/css-guards.less @@ -101,4 +101,17 @@ } a:hover when (2 = true) {5:-} +.inequality-test-1 when (2 != 1) { + color: green; +} +.inequality-test-2 when (2 != 2) { + color: red; +} +.inequality-test-3 when (@b != 1) { + color: green; +} +.inequality-test-4 when (@b != 2) { + color: red; +} +