{"version":3,"file":"validate_expression.mjs","names":[],"sources":["../../src/validate/validate_expression.ts"],"sourcesContent":["import {ValidationError} from '../error/validation_error';\n\nimport {createExpression, createPropertyExpression} from '../expression';\nimport {deepUnbundle} from '../util/unbundle_jsonlint';\n\nimport {\n    isFeatureConstant,\n    isGlobalPropertyConstant,\n    isStateConstant\n} from '../expression/compound_expression';\n\nimport {Expression} from '../expression/expression';\n\nexport function validateExpression(options: any): Array<ValidationError> {\n    const expression = (\n        options.expressionContext === 'property' ? createPropertyExpression : createExpression\n    )(deepUnbundle(options.value), options.key, options.valueSpec);\n    if (expression.result === 'error') {\n        return expression.value.map((error) => {\n            return new ValidationError(`${options.key}${error.key}`, options.value, error.message);\n        });\n    }\n\n    const expressionObj: Expression =\n        (expression.value as any).expression ||\n        (expression.value as any)._styleExpression.expression;\n\n    if (\n        options.expressionContext === 'property' &&\n        options.propertyKey === 'text-font' &&\n        !expressionObj.outputDefined()\n    ) {\n        return [\n            new ValidationError(\n                options.key,\n                options.value,\n                `Invalid data expression for \"${options.propertyKey}\". Output values must be contained as literals within the expression.`\n            )\n        ];\n    }\n\n    if (\n        options.expressionContext === 'property' &&\n        options.propertyType === 'layout' &&\n        !isStateConstant(expressionObj)\n    ) {\n        return [\n            new ValidationError(\n                options.key,\n                options.value,\n                '\"feature-state\" data expressions are not supported with layout properties.'\n            )\n        ];\n    }\n\n    if (options.expressionContext === 'filter' && !isStateConstant(expressionObj)) {\n        return [\n            new ValidationError(\n                options.key,\n                options.value,\n                '\"feature-state\" data expressions are not supported with filters.'\n            )\n        ];\n    }\n\n    if (options.expressionContext && options.expressionContext.indexOf('cluster') === 0) {\n        if (!isGlobalPropertyConstant(expressionObj, ['zoom', 'feature-state'])) {\n            return [\n                new ValidationError(\n                    options.key,\n                    options.value,\n                    '\"zoom\" and \"feature-state\" expressions are not supported with cluster properties.'\n                )\n            ];\n        }\n        if (options.expressionContext === 'cluster-initial' && !isFeatureConstant(expressionObj)) {\n            return [\n                new ValidationError(\n                    options.key,\n                    options.value,\n                    'Feature data expressions are not supported with initial expression part of cluster properties.'\n                )\n            ];\n        }\n    }\n\n    return [];\n}\n"],"mappings":";;;;;AAaA,SAAgB,mBAAmB,SAAsC;CACrE,MAAM,cACF,QAAQ,sBAAsB,aAAa,2BAA2B,iBAAA,CACxE,aAAa,QAAQ,KAAK,GAAG,QAAQ,KAAK,QAAQ,SAAS;CAC7D,IAAI,WAAW,WAAW,SACtB,OAAO,WAAW,MAAM,KAAK,UAAU;EACnC,OAAO,IAAI,gBAAgB,GAAG,QAAQ,MAAM,MAAM,OAAO,QAAQ,OAAO,MAAM,OAAO;CACzF,CAAC;CAGL,MAAM,gBACD,WAAW,MAAc,cACzB,WAAW,MAAc,iBAAiB;CAE/C,IACI,QAAQ,sBAAsB,cAC9B,QAAQ,gBAAgB,eACxB,CAAC,cAAc,cAAc,GAE7B,OAAO,CACH,IAAI,gBACA,QAAQ,KACR,QAAQ,OACR,gCAAgC,QAAQ,YAAY,sEACxD,CACJ;CAGJ,IACI,QAAQ,sBAAsB,cAC9B,QAAQ,iBAAiB,YACzB,CAAC,gBAAgB,aAAa,GAE9B,OAAO,CACH,IAAI,gBACA,QAAQ,KACR,QAAQ,OACR,8EACJ,CACJ;CAGJ,IAAI,QAAQ,sBAAsB,YAAY,CAAC,gBAAgB,aAAa,GACxE,OAAO,CACH,IAAI,gBACA,QAAQ,KACR,QAAQ,OACR,oEACJ,CACJ;CAGJ,IAAI,QAAQ,qBAAqB,QAAQ,kBAAkB,QAAQ,SAAS,MAAM,GAAG;EACjF,IAAI,CAAC,yBAAyB,eAAe,CAAC,QAAQ,eAAe,CAAC,GAClE,OAAO,CACH,IAAI,gBACA,QAAQ,KACR,QAAQ,OACR,uFACJ,CACJ;EAEJ,IAAI,QAAQ,sBAAsB,qBAAqB,CAAC,kBAAkB,aAAa,GACnF,OAAO,CACH,IAAI,gBACA,QAAQ,KACR,QAAQ,OACR,gGACJ,CACJ;CAER;CAEA,OAAO,CAAC;AACZ"}