Iterated string interpolation

Solves issue #2094 .
This commit is contained in:
jurcovicovam
2014-09-05 16:47:37 +02:00
parent 10f882411b
commit 796d37cc66
3 changed files with 43 additions and 8 deletions

View File

@@ -20,14 +20,21 @@ tree.Quoted.prototype = {
},
toCSS: tree.toCSS,
eval: function (env) {
var that = this;
var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
}).replace(/@\{([\w-]+)\}/g, function (_, name) {
var v = new(tree.Variable)('@' + name, that.index, that.currentFileInfo).eval(env, true);
return (v instanceof tree.Quoted) ? v.value : v.toCSS();
});
return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index, this.currentFileInfo);
var that = this;
var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
});
var evaluatedValue = value;
var interpolationReplacementFnc = 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;
return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index, this.currentFileInfo);
},
compare: function (x) {
if (!x.toCSS) {