Skip to content

Commit

Permalink
Make "to-number" of null behave as documented
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Sep 12, 2018
1 parent bb5806e commit a1dca3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Coercion implements Expression {
let value = null;
for (const arg of this.args) {
value = arg.evaluate(ctx);
if (value === null) continue;
if (value === null) return 0;
const num = Number(value);
if (isNaN(num)) continue;
return num;
Expand Down
6 changes: 3 additions & 3 deletions test/integration/expression-tests/to-number/2-ary/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
1,
6.02e-23,
-1,
0,
-1,
-1,
-1,
-1,
{"error": "Could not convert \"bad fallback\" to number."}
0,
0
],
"serialized": ["to-number", ["get", "x"], ["get", "y"]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
1,
6.02e-23,
{"error": "Could not convert \"Not a number\" to number."},
{"error": "Could not convert null to number."},
0,
{"error": "Could not convert [1,2] to number."},
{"error": "Could not convert {\"y\":1} to number."}
],
Expand Down

0 comments on commit a1dca3c

Please sign in to comment.