Skip to content

Commit

Permalink
v3.12.0-RC.2 (#3540)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Jul 13, 2020
1 parent d5aa9d1 commit 371185c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 23 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,9 @@
## Change Log

### upcoming (2020-07-07)
### upcoming (2020-07-13)
- [#3532](https://github.com/less/less.js/pull/3532) Fixes #3371 Allow conditional evaluation of function args (#3532) (@matthew-dean)
- [#3531](https://github.com/less/less.js/pull/3531) Remove lib folder from git (#3531) (@matthew-dean)
- [#3530](https://github.com/less/less.js/pull/3530) Move changelog to root (#3530) (@matthew-dean)
- [#3529](https://github.com/less/less.js/pull/3529) Duplicate dist files in root for older links (#3529) (@matthew-dean)
- [#3525](https://github.com/less/less.js/pull/3525) Test-data module (#3525) (@matthew-dean)
- [#3523](https://github.com/less/less.js/pull/3523) Fixes #3504 / organizes tests (#3523) (@matthew-dean)
Expand Down
39 changes: 30 additions & 9 deletions dist/less.js
Expand Up @@ -3072,6 +3072,11 @@
return Boolean(this.func);
};
functionCaller.prototype.call = function (args) {
var _this = this;
var evalArgs = this.func.evalArgs;
if (evalArgs !== false) {
args = args.map(function (a) { return a.eval(_this.context); });
}
// This code is terrible and should be replaced as per this issue...
// https://github.com/less/less.js/issues/2477
if (Array.isArray(args)) {
Expand Down Expand Up @@ -3099,6 +3104,9 @@
return item;
});
}
if (evalArgs === false) {
return this.func.apply(this, __spreadArrays([this.context], args));
}
return this.func.apply(this, args);
};
return functionCaller;
Expand Down Expand Up @@ -3135,6 +3143,7 @@
// The function should receive the value, not the variable.
//
Call.prototype.eval = function (context) {
var _this = this;
/**
* Turn off math for calc(), and switch back on for evaluating nested functions
*/
Expand All @@ -3143,18 +3152,23 @@
if (this.calc || context.inCalc) {
context.enterCalc();
}
var args = this.args.map(function (a) { return a.eval(context); });
if (this.calc || context.inCalc) {
context.exitCalc();
}
context.mathOn = currentMathContext;
var exitCalc = function () {
if (_this.calc || context.inCalc) {
context.exitCalc();
}
context.mathOn = currentMathContext;
};
var result;
var funcCaller = new functionCaller(this.name, context, this.getIndex(), this.fileInfo());
if (funcCaller.isValid()) {
try {
result = funcCaller.call(args);
result = funcCaller.call(this.args);
exitCalc();
}
catch (e) {
if (e.hasOwnProperty('line') && e.hasOwnProperty('column')) {
throw e;
}
throw {
type: e.type || 'Runtime',
message: "error evaluating function `" + this.name + "`" + (e.message ? ": " + e.message : ''),
Expand All @@ -3180,6 +3194,8 @@
return result;
}
}
var args = this.args.map(function (a) { return a.eval(context); });
exitCalc();
return new Call(this.name, args, this.getIndex(), this.fileInfo());
};
Call.prototype.genCSS = function (context, output) {
Expand Down Expand Up @@ -8815,10 +8831,15 @@
function boolean(condition) {
return condition ? Keyword.True : Keyword.False;
}
function If(condition, trueValue, falseValue) {
return condition ? trueValue
: (falseValue || new Anonymous);
/**
* Functions with evalArgs set to false are sent context
* as the first argument.
*/
function If(context, condition, trueValue, falseValue) {
return condition.eval(context) ? trueValue.eval(context)
: (falseValue ? falseValue.eval(context) : new Anonymous);
}
If.evalArgs = false;
var boolean$1 = { boolean: boolean, 'if': If };

var colorFunctions;
Expand Down
2 changes: 1 addition & 1 deletion dist/less.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/less.min.js.map

Large diffs are not rendered by default.

39 changes: 30 additions & 9 deletions packages/less/dist/less.js
Expand Up @@ -3072,6 +3072,11 @@
return Boolean(this.func);
};
functionCaller.prototype.call = function (args) {
var _this = this;
var evalArgs = this.func.evalArgs;
if (evalArgs !== false) {
args = args.map(function (a) { return a.eval(_this.context); });
}
// This code is terrible and should be replaced as per this issue...
// https://github.com/less/less.js/issues/2477
if (Array.isArray(args)) {
Expand Down Expand Up @@ -3099,6 +3104,9 @@
return item;
});
}
if (evalArgs === false) {
return this.func.apply(this, __spreadArrays([this.context], args));
}
return this.func.apply(this, args);
};
return functionCaller;
Expand Down Expand Up @@ -3135,6 +3143,7 @@
// The function should receive the value, not the variable.
//
Call.prototype.eval = function (context) {
var _this = this;
/**
* Turn off math for calc(), and switch back on for evaluating nested functions
*/
Expand All @@ -3143,18 +3152,23 @@
if (this.calc || context.inCalc) {
context.enterCalc();
}
var args = this.args.map(function (a) { return a.eval(context); });
if (this.calc || context.inCalc) {
context.exitCalc();
}
context.mathOn = currentMathContext;
var exitCalc = function () {
if (_this.calc || context.inCalc) {
context.exitCalc();
}
context.mathOn = currentMathContext;
};
var result;
var funcCaller = new functionCaller(this.name, context, this.getIndex(), this.fileInfo());
if (funcCaller.isValid()) {
try {
result = funcCaller.call(args);
result = funcCaller.call(this.args);
exitCalc();
}
catch (e) {
if (e.hasOwnProperty('line') && e.hasOwnProperty('column')) {
throw e;
}
throw {
type: e.type || 'Runtime',
message: "error evaluating function `" + this.name + "`" + (e.message ? ": " + e.message : ''),
Expand All @@ -3180,6 +3194,8 @@
return result;
}
}
var args = this.args.map(function (a) { return a.eval(context); });
exitCalc();
return new Call(this.name, args, this.getIndex(), this.fileInfo());
};
Call.prototype.genCSS = function (context, output) {
Expand Down Expand Up @@ -8815,10 +8831,15 @@
function boolean(condition) {
return condition ? Keyword.True : Keyword.False;
}
function If(condition, trueValue, falseValue) {
return condition ? trueValue
: (falseValue || new Anonymous);
/**
* Functions with evalArgs set to false are sent context
* as the first argument.
*/
function If(context, condition, trueValue, falseValue) {
return condition.eval(context) ? trueValue.eval(context)
: (falseValue ? falseValue.eval(context) : new Anonymous);
}
If.evalArgs = false;
var boolean$1 = { boolean: boolean, 'if': If };

var colorFunctions;
Expand Down
2 changes: 1 addition & 1 deletion packages/less/dist/less.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/less/dist/less.min.js.map

Large diffs are not rendered by default.

0 comments on commit 371185c

Please sign in to comment.