From 2c092f6b39807871fc687e52dc673c0f0c156dff Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Sun, 5 Mar 2017 23:31:32 +0100 Subject: [PATCH] Support multiple values/operands --- lib/carto/tree/value.js | 4 +++- test/rendering_js.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/carto/tree/value.js b/lib/carto/tree/value.js index 7e74e76..e12619b 100644 --- a/lib/carto/tree/value.js +++ b/lib/carto/tree/value.js @@ -36,7 +36,9 @@ tree.Value.prototype = { v = "'" + v + "'"; } else if (val.is === 'field') { // 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') { v = JSON.stringify({ name: val.name, diff --git a/test/rendering_js.test.js b/test/rendering_js.test.js index 5e5694b..b716c63 100644 --- a/test/rendering_js.test.js +++ b/test/rendering_js.test.js @@ -183,4 +183,16 @@ describe('RenderingJS', function() { 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); + }); + });