Skip to content

Commit

Permalink
fix: introduces expressionNames to improve check
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Volland committed May 26, 2023
1 parent 0fbe561 commit 75922ed
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion src/Expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,88 @@ import {
StyleFunction
} from 'mapbox-gl';

const expressionNames: ExpressionName[] = ['array',
'boolean',
'collator',
'format',
'literal',
'number',
'number-format',
'object',
'string',
'image',
'to-boolean',
'to-color',
'to-number',
'to-string',
'typeof',
'feature-state',
'geometry-type',
'id',
'line-progress',
'properties',
'at',
'get',
'has',
'in',
'index-of',
'length',
'slice',
'!',
'!=',
'<',
'<=',
'==',
'>',
'>=',
'all',
'any',
'case',
'match',
'coalesce',
'within',
'interpolate',
'interpolate-hcl',
'interpolate-lab',
'step',
'let',
'var',
'concat',
'downcase',
'is-supported-script',
'resolved-locale',
'upcase',
'rgb',
'rgba',
'to-rgba',
'-',
'*',
'/',
'%',
'^',
'+',
'abs',
'acos',
'asin',
'atan',
'ceil',
'cos',
'e',
'floor',
'ln',
'ln2',
'log10',
'log2',
'max',
'min',
'pi',
'round',
'sin',
'sqrt',
'tan',
'zoom',
'heatmap-density'];

const functionNameMap: Record<GeoStylerFunction['name'], ExpressionName | null> = {
// ---- string ----
numberFormat: null,
Expand Down Expand Up @@ -139,7 +221,7 @@ export function mb2gsExpression<T extends PropertyType>(mbExpression?: MbInput):

// TODO: is this check valid ?
// fails for arrays like offset = [10, 20]
if (!(Array.isArray(mbExpression) && mbExpression[0])) {
if (!(Array.isArray(mbExpression) && expressionNames.includes(mbExpression[0]))) {
return mbExpression as GeoStylerExpression<T> | undefined;
}

Expand Down

0 comments on commit 75922ed

Please sign in to comment.