diff --git a/src/style-spec/expression/definitions/formatted.js b/src/style-spec/expression/definitions/formatted.js index d6e517479b1..ef4a74b86c3 100644 --- a/src/style-spec/expression/definitions/formatted.js +++ b/src/style-spec/expression/definitions/formatted.js @@ -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'; @@ -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 ) diff --git a/test/integration/expression-tests/formatted/basic/test.json b/test/integration/expression-tests/format/basic/test.json similarity index 100% rename from test/integration/expression-tests/formatted/basic/test.json rename to test/integration/expression-tests/format/basic/test.json diff --git a/test/integration/expression-tests/format/coercion/test.json b/test/integration/expression-tests/format/coercion/test.json new file mode 100644 index 00000000000..e7570b146ab --- /dev/null +++ b/test/integration/expression-tests/format/coercion/test.json @@ -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"], + {} + ] + } +} diff --git a/test/integration/expression-tests/formatted/to-string/test.json b/test/integration/expression-tests/format/to-string/test.json similarity index 100% rename from test/integration/expression-tests/formatted/to-string/test.json rename to test/integration/expression-tests/format/to-string/test.json