Repository navigation
fix(functions): leave min()/max() intact when args contain CSS vars #4549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,17 +57,55 @@ const minMax = function (isMin, args) { | |
| return new Anonymous(`${isMin ? 'min' : 'max'}(${args})`); | ||
| }; | ||
|
|
||
| export default { | ||
| min: function(...args) { | ||
| try { | ||
| return minMax.call(this, true, args); | ||
| } catch (e) {} | ||
| }, | ||
| max: function(...args) { | ||
| /** | ||
| * Evaluate min/max arguments lazily. When an argument contains CSS-native | ||
| * constructs (e.g. var()) that cannot participate in Less math, re-evaluate | ||
| * it in calc context so Less variables resolve while operations pass through, | ||
| * and emit the CSS min()/max() call (#3777). | ||
| */ | ||
| function minMaxLazy(context, isMin, args) { | ||
| const evaluated = []; | ||
| for (let i = 0; i < args.length; i++) { | ||
| try { | ||
| return minMax.call(this, false, args); | ||
| } catch (e) {} | ||
| }, | ||
| evaluated.push(args[i].eval(context)); | ||
| } catch (e) { | ||
| if (e && e.type === 'Operation') { | ||
| const prevMathOn = context.mathOn; | ||
| context.mathOn = false; | ||
| try { | ||
| evaluated.push(args[i].eval(context)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis
Restore When the first evaluation fails inside a parenthesized expression, 🐛 Suggested fix
🤖 Prompt for AI Agents
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis
Clear the variable evaluation flag when evaluation throws. When a variable's value throws during evaluation, Reset the flag in a 🐛 Suggested fix
🤖 Prompt for AI Agents
|
||
| } finally { | ||
| context.mathOn = prevMathOn; | ||
| } | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
| try { | ||
| return minMax.call({ context }, isMin, evaluated); | ||
| } catch (e) { | ||
| if (e && e.type === 'Argument' && e.message === 'incompatible types') { | ||
| const rendered = evaluated.map(a => a.toCSS(context)).join(context.compress ? ',' : ', '); | ||
| return new Anonymous(`${isMin ? 'min' : 'max'}(${rendered})`); | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| function min(context, ...args) { | ||
| return minMaxLazy(context, true, args); | ||
| } | ||
| min.evalArgs = false; | ||
|
|
||
| function max(context, ...args) { | ||
| return minMaxLazy(context, false, args); | ||
| } | ||
| max.evalArgs = false; | ||
|
|
||
| export default { | ||
| min, | ||
| max, | ||
| convert: function (val, unit) { | ||
| return val.convertTo(unit.value); | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.