Skip to content

Commit

Permalink
Change ["to-string", null] from "null" to "" (#6534)
Browse files Browse the repository at this point in the history
* Change ["to-string", null] from "null" to ""

Closes #6533

* Update changelog and style-spec docs

Cherry-picked from d5c5ef5.
  • Loading branch information
anandthakker authored and 1ec5 committed May 14, 2018
1 parent 6b96d69 commit cc3bb6a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/style-spec/expression/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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();
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
}
}

0 comments on commit cc3bb6a

Please sign in to comment.