Merge pull request #42 from CartoDB/dasharrayJSsupport

Cover 'numbers' type, like in line-dasharray
This commit is contained in:
David M 2017-09-01 17:33:15 +02:00 committed by GitHub
commit cbe66020f9
2 changed files with 18 additions and 0 deletions

View File

@ -34,6 +34,12 @@ tree.Value.prototype = {
var v = val.toString(); var v = val.toString();
if(val.is === "color" || val.is === 'uri' || val.is === 'string' || val.is === 'keyword') { if(val.is === "color" || val.is === 'uri' || val.is === 'string' || val.is === 'keyword') {
v = "'" + v + "'"; v = "'" + v + "'";
} else if (Array.isArray(this.value) && this.value.length > 1) {
// This covers something like `line-dasharray: 5, 10;`
// where the return _value has more than one element.
// Without this the generated code will look like:
// _value = 5, 10; which will ignore the 10.
v = '[' + this.value.join(',') + ']';
} else if (val.is === 'field') { } else if (val.is === 'field') {
// replace [variable] by ctx['variable'] // replace [variable] by ctx['variable']
v = v.replace(/\[([^\]]*)\]/g, function(matched) { v = v.replace(/\[([^\]]*)\]/g, function(matched) {

View File

@ -195,6 +195,18 @@ describe('RenderingJS', function() {
assert.equal(width, 8); assert.equal(width, 8);
}); });
it("should work with numbers", function(){
var css = [
'#layer {',
' line-dasharray: 5, 10;',
'}'
].join('\n');
var shader = (new carto.RendererJS({ debug: false })).render(css);
var layer = shader.getLayers()[0];
var dasharray = layer.shader['line-dasharray'].style({value: 4}, {zoom: 1});
assert.deepEqual(dasharray, [5, 10]);
});
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*"] {',