Skip to content

Commit

Permalink
Provide some help for migrating "curve"
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 31, 2017
1 parent 0e0bc5e commit 646fca8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/style-spec/expression/definitions/curve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @flow

import type { Expression } from '../expression';
import type ParsingContext from '../parsing_context';
import type { Type } from '../types';

class Curve implements Expression {
key: string;
type: Type;

static parse(args: Array<mixed>, context: ParsingContext) {
const [ , interpolation, input, ...rest] = args;
if ((interpolation: any)[0] === "step") {
return context.error(`"curve" has been replaced by "step" and "interpolate". Replace this expression with ${
JSON.stringify(["step", input, ...rest])}`, 0);
} else {
return context.error(`"curve" has been replaced by "step" and "interpolate". Replace this expression with ${
JSON.stringify(["interpolate", interpolation, input, ...rest])}`, 0);
}
}

evaluate() {}
eachChild() {}
}

module.exports = Curve;
2 changes: 2 additions & 0 deletions src/style-spec/expression/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Coercion = require('./coercion');
const At = require('./at');
const Match = require('./match');
const Case = require('./case');
const Curve = require('./curve');
const Step = require('./step');
const Interpolate = require('./interpolate');
const Coalesce = require('./coalesce');
Expand All @@ -47,6 +48,7 @@ const expressions: { [string]: Class<Expression> } = {
'case': Case,
'match': Match,
'coalesce': Coalesce,
'curve': Curve,
'step': Step,
'interpolate': Interpolate
};
Expand Down
15 changes: 15 additions & 0 deletions test/integration/expression-tests/curve/interpolate/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"expression": ["curve", ["linear"], 0, 1, 2, 3, 4],
"inputs": [[{}, {}]],
"expected": {
"compiled": {
"result": "error",
"errors": [
{
"key": "[0]",
"error": "\"curve\" has been replaced by \"step\" and \"interpolate\". Replace this expression with [\"interpolate\",[\"linear\"],0,1,2,3,4]"
}
]
}
}
}
15 changes: 15 additions & 0 deletions test/integration/expression-tests/curve/step/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"expression": ["curve", ["step"], 0, 1, 2, 3, 4, 5],
"inputs": [[{}, {}]],
"expected": {
"compiled": {
"result": "error",
"errors": [
{
"key": "[0]",
"error": "\"curve\" has been replaced by \"step\" and \"interpolate\". Replace this expression with [\"step\",0,1,2,3,4,5]"
}
]
}
}
}

0 comments on commit 646fca8

Please sign in to comment.