mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Cleaned up and added iteration for javascript too.
This commit is contained in:
@@ -20,20 +20,24 @@ tree.Quoted.prototype = {
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
var that = this;
|
||||
var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
|
||||
var that = this, value = this.value;
|
||||
var javascriptReplacement = function (_, exp) {
|
||||
return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
|
||||
});
|
||||
var evaluatedValue = value;
|
||||
var interpolationReplacementFnc = function (_, name) {
|
||||
};
|
||||
var interpolationReplacement = function (_, name) {
|
||||
var v = new(tree.Variable)('@' + name, that.index, that.currentFileInfo).eval(env, true);
|
||||
return (v instanceof tree.Quoted) ? v.value : v.toCSS();
|
||||
};
|
||||
do {
|
||||
value = evaluatedValue;
|
||||
evaluatedValue = value.replace(/@\{([\w-]+)\}/g, interpolationReplacementFnc);
|
||||
} while (value!==evaluatedValue);
|
||||
value = evaluatedValue;
|
||||
function iterativeReplace(value, regexp, replacementFnc) {
|
||||
var evaluatedValue = value;
|
||||
do {
|
||||
value = evaluatedValue;
|
||||
evaluatedValue = value.replace(regexp, replacementFnc);
|
||||
} while (value!==evaluatedValue);
|
||||
return evaluatedValue;
|
||||
}
|
||||
value = iterativeReplace(value, /`([^`]+)`/g, javascriptReplacement);
|
||||
value = iterativeReplace(value, /@\{([\w-]+)\}/g, interpolationReplacement);
|
||||
return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index, this.currentFileInfo);
|
||||
},
|
||||
compare: function (x) {
|
||||
|
||||
Reference in New Issue
Block a user