Skip to content

Commit

Permalink
to-color should be idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Sep 11, 2018
1 parent e682aa6 commit bb155fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/style-spec/expression/definitions/coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class Coercion implements Expression {
for (const arg of this.args) {
input = arg.evaluate(ctx);
error = null;
if (typeof input === 'string') {
if (input instanceof Color) {
return input;
} else if (typeof input === 'string') {
const c = ctx.parseColor(input);
if (c) return c;
} else if (Array.isArray(input)) {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/expression-tests/to-color/color/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"expression": ["to-color", ["rgba", 0, 0, 0, 1]],
"inputs": [
[{}, {}]
],
"expected": {
"compiled": {
"result": "success",
"isFeatureConstant": true,
"isZoomConstant": true,
"type": "color"
},
"outputs": [
[0, 0, 0, 1]
],
"serialized": ["rgba", 0, 0, 0, 1]
}
}

0 comments on commit bb155fe

Please sign in to comment.