Skip to content

Commit

Permalink
Auto-convert format arguments to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Sep 13, 2018
1 parent 1ff116c commit 3b480cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/style-spec/expression/definitions/formatted.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { NumberType, ValueType, FormattedType, array, StringType } from '../types';

import { toString } from '../values';

import type { Expression } from '../expression';
import type EvaluationContext from '../evaluation_context';
Expand Down Expand Up @@ -101,7 +101,7 @@ export class FormatExpression implements Expression {
return new Formatted(
this.sections.map(section =>
new FormattedSection(
section.text.evaluate(ctx) || "",
toString(section.text.evaluate(ctx)),
section.scale ? section.scale.evaluate(ctx) : null,
section.font ? section.font.evaluate(ctx).join(',') : null
)
Expand Down
50 changes: 50 additions & 0 deletions test/integration/expression-tests/format/coercion/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"expression": [
"format",
["get", "a"],
{},
["get", "1"],
{},
["get", "true"],
{}
],
"inputs": [[{}, {"properties": {"a": "a", "1": 1, "true": true}}]],
"expected": {
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "formatted"
},
"outputs": [
{
"sections": [
{
"text": "a",
"scale": null,
"fontStack": null
},
{
"text": "1",
"scale": null,
"fontStack": null
},
{
"text": "true",
"scale": null,
"fontStack": null
}
]
}
],
"serialized": [
"format",
["get", "a"],
{},
["get", "1"],
{},
["get", "true"],
{}
]
}
}

0 comments on commit 3b480cd

Please sign in to comment.