Merge pull request #30 from CartoDB/support-multiple-values

Support multiple values/operands
This commit is contained in:
Daniel 2017-03-07 11:03:23 +01:00 committed by GitHub
commit decdcc5d46
2 changed files with 29 additions and 15 deletions

View File

@ -36,7 +36,9 @@ tree.Value.prototype = {
v = "'" + v + "'"; v = "'" + v + "'";
} else if (val.is === 'field') { } else if (val.is === 'field') {
// replace [variable] by ctx['variable'] // replace [variable] by ctx['variable']
v = v.replace(/\[(.*)\]/g, "data['$1']"); v = v.replace(/\[([^\]]*)\]/g, function(matched) {
return matched.replace(/\[(.*)\]/g, "data['$1']");
});
}else if (val.is === 'call') { }else if (val.is === 'call') {
v = JSON.stringify({ v = JSON.stringify({
name: val.name, name: val.name,

View File

@ -183,6 +183,18 @@ describe('RenderingJS', function() {
assert.equal(st.args[2].args[0].value, 10); assert.equal(st.args[2].args[0].value, 10);
}); });
it("should work with multiple operands", function(){
var css = [
'#layer {',
' marker-width: [value] * [value] * 0.5;',
'}'
].join('\n');
var shader = (new carto.RendererJS({ debug: false })).render(css);
var layer = shader.getLayers()[0];
var width = layer.shader['marker-width'].style({value: 4}, {zoom: 1});
assert.equal(width, 8);
});
it("should not throw `ReferenceError` with `=~` operator", function(){ it("should not throw `ReferenceError` with `=~` operator", function(){
var css = [ var css = [
'#layer[name=~".*wadus*"] {', '#layer[name=~".*wadus*"] {',