Skip to content
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

v3.12.0-RC.2 #3540

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.