From b757de13b5b4e044d20991131e3ceaba1bbe51e7 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Wed, 18 Apr 2018 12:28:44 -0400 Subject: [PATCH 1/2] Change ["to-string", null] from "null" to "" Closes #6533 --- src/style-spec/expression/definitions/index.js | 4 +++- test/integration/expression-tests/to-string/basic/test.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/style-spec/expression/definitions/index.js b/src/style-spec/expression/definitions/index.js index 4bb480b278b..9dc48cecb94 100644 --- a/src/style-spec/expression/definitions/index.js +++ b/src/style-spec/expression/definitions/index.js @@ -112,7 +112,9 @@ CompoundExpression.register(expressions, { (ctx, [v]) => { v = v.evaluate(ctx); const type = typeof v; - if (v === null || type === 'string' || type === 'number' || type === 'boolean') { + if (v === null) { + return ''; + } else if (type === 'string' || type === 'number' || type === 'boolean') { return String(v); } else if (v instanceof Color) { return v.toString(); diff --git a/test/integration/expression-tests/to-string/basic/test.json b/test/integration/expression-tests/to-string/basic/test.json index c5252ea7856..7a17dc320b3 100644 --- a/test/integration/expression-tests/to-string/basic/test.json +++ b/test/integration/expression-tests/to-string/basic/test.json @@ -15,7 +15,7 @@ "isZoomConstant": true, "type": "string" }, - "outputs": ["1", "false", "null", "string", "[1,2]", "{\"y\":1}"], + "outputs": ["1", "false", "", "string", "[1,2]", "{\"y\":1}"], "serialized": ["to-string", ["get", "x"]] } } From 4ff3629789262850e62b7dd5c797dc69844264ca Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Wed, 18 Apr 2018 12:45:40 -0400 Subject: [PATCH 2/2] Update changelog and style-spec docs --- CHANGELOG.md | 1 + src/style-spec/reference/v8.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1e5fa9ff2a..32fbf8394d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### ⚠️ Breaking changes * `Evented` is no longer publicly exported, and `Evented#fire` and `Evented#listens` are now private. If you are writing a class that needs event emitting functionality, consider using [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) or similar libraries instead. +* The `"to-string"` expression operator now converts `null` to an empty string rather than to `"null"`. [#6534](https://github.com/mapbox/mapbox-gl-js/pull/6534) ## 0.44.2 diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 7ca76bdcecc..e42ca203d1f 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -2173,7 +2173,7 @@ } }, "to-string": { - "doc": "Converts the input value to a string. If the input is `null`, the result is `\"null\"`. If the input is a boolean, the result is `\"true\"` or `\"false\"`. If the input is a number, it is converted to a string as specified by the [\"NumberToString\" algorithm](https://tc39.github.io/ecma262/#sec-tostring-applied-to-the-number-type) of the ECMAScript Language Specification. If the input is a color, it is converted to a string of the form `\"rgba(r,g,b,a)\"`, where `r`, `g`, and `b` are numerals ranging from 0 to 255, and `a` ranges from 0 to 1. Otherwise, the input is converted to a string in the format specified by the [`JSON.stringify`](https://tc39.github.io/ecma262/#sec-json.stringify) function of the ECMAScript Language Specification.", + "doc": "Converts the input value to a string. If the input is `null`, the result is `\"\"`. If the input is a boolean, the result is `\"true\"` or `\"false\"`. If the input is a number, it is converted to a string as specified by the [\"NumberToString\" algorithm](https://tc39.github.io/ecma262/#sec-tostring-applied-to-the-number-type) of the ECMAScript Language Specification. If the input is a color, it is converted to a string of the form `\"rgba(r,g,b,a)\"`, where `r`, `g`, and `b` are numerals ranging from 0 to 255, and `a` ranges from 0 to 1. Otherwise, the input is converted to a string in the format specified by the [`JSON.stringify`](https://tc39.github.io/ecma262/#sec-json.stringify) function of the ECMAScript Language Specification.", "group": "Types", "sdk-support": { "basic functionality": {