Skip to content

Commit

Permalink
Simplify how token strings are converted
Browse files Browse the repository at this point in the history
No longer need to-string when using concat. However, it is still needed if the token string consists of a single token.
  • Loading branch information
jfirebaugh committed Sep 13, 2018
1 parent 4256281 commit 1ff116c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/style-spec/function/convert.js
Expand Up @@ -226,7 +226,7 @@ export function convertTokenString(s: string) {
const literal = s.slice(pos, re.lastIndex - match[0].length);
pos = re.lastIndex;
if (literal.length > 0) result.push(literal);
result.push(['to-string', ['get', match[1]]]);
result.push(['get', match[1]]);
}

if (result.length === 1) {
Expand All @@ -236,7 +236,7 @@ export function convertTokenString(s: string) {
if (pos < s.length) {
result.push(s.slice(pos));
} else if (result.length === 2) {
return result[1];
return ['to-string', result[1]];
}

return result;
Expand Down
@@ -1,8 +1,8 @@
{
"expression": {"type": "interval", "stops": [[0, "0 {a}"], [1, "1 {b}"]]},
"expression": {"type": "interval", "stops": [[0, "0 {a}"], [1, "{b}"]]},
"inputs": [
[{"zoom": 0}, {"properties": {"a": "a", "b": "b"}}],
[{"zoom": 1}, {"properties": {"a": "a", "b": "b"}}],
[{"zoom": 0}, {"properties": {"a": "a", "b": 2}}],
[{"zoom": 1}, {"properties": {"a": "a", "b": 2}}],
[{"zoom": 0}, {"properties": {}}]
],
"propertySpec": {
Expand All @@ -18,13 +18,13 @@
"isZoomConstant": false,
"type": "string"
},
"outputs": ["0 a", "1 b", "0 "],
"outputs": ["0 a", "2", "0 "],
"serialized": [
"step",
["zoom"],
["concat", "0 ", ["to-string", ["get", "a"]]],
["concat", "0 ", ["get", "a"]],
1,
["concat", "1 ", ["to-string", ["get", "b"]]]
["to-string", ["get", "b"]]
]
}
}
6 changes: 3 additions & 3 deletions test/unit/style-spec/migrate.test.js
Expand Up @@ -36,11 +36,11 @@ t('converts token strings to expressions', (t) => {
layers: [{
id: '1',
type: 'symbol',
layout: {'text-field': 'a{x}', 'icon-image': 'b{y}'}
layout: {'text-field': 'a{x}', 'icon-image': '{y}'}
}]
}, spec.latest.$version);
t.deepEqual(migrated.layers[0].layout['text-field'], ['concat', 'a', ['to-string', ['get', 'x']]]);
t.deepEqual(migrated.layers[0].layout['icon-image'], ['concat', 'b', ['to-string', ['get', 'y']]]);
t.deepEqual(migrated.layers[0].layout['text-field'], ['concat', 'a', ['get', 'x']]);
t.deepEqual(migrated.layers[0].layout['icon-image'], ['to-string', ['get', 'y']]);
t.end();
});

Expand Down

0 comments on commit 1ff116c

Please sign in to comment.