Cleaned up and added iteration for javascript too.

This commit is contained in:
jurcovicovam
2014-09-05 17:04:06 +02:00
parent 796d37cc66
commit a038121676

View File

@@ -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) {