123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- /**
- * AUTO-GENERATED FILE. DO NOT MODIFY.
- */
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- import { keys, isArray, map, isObject, isString, isRegExp, isArrayLike, hasOwn, isNumber } from 'zrender/lib/core/util.js';
- import { throwError, makePrintable } from './log.js';
- import { getRawValueParser, createFilterComparator } from '../data/helper/dataValueHelper.js';
- ;
- var RELATIONAL_EXPRESSION_OP_ALIAS_MAP = {
- value: 'eq',
- // PENDING: not good for literal semantic?
- '<': 'lt',
- '<=': 'lte',
- '>': 'gt',
- '>=': 'gte',
- '=': 'eq',
- '!=': 'ne',
- '<>': 'ne' // Might be misleading for sake of the difference between '==' and '===',
- // so don't support them.
- // '==': 'eq',
- // '===': 'seq',
- // '!==': 'sne'
- // PENDING: Whether support some common alias "ge", "le", "neq"?
- // ge: 'gte',
- // le: 'lte',
- // neq: 'ne',
- }; // type RelationalExpressionOpEvaluate = (tarVal: unknown, condVal: unknown) => boolean;
- var RegExpEvaluator =
- /** @class */
- function () {
- function RegExpEvaluator(rVal) {
- // Support condVal: RegExp | string
- var condValue = this._condVal = isString(rVal) ? new RegExp(rVal) : isRegExp(rVal) ? rVal : null;
- if (condValue == null) {
- var errMsg = '';
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('Illegal regexp', rVal, 'in');
- }
- throwError(errMsg);
- }
- }
- RegExpEvaluator.prototype.evaluate = function (lVal) {
- var type = typeof lVal;
- return isString(type) ? this._condVal.test(lVal) : isNumber(type) ? this._condVal.test(lVal + '') : false;
- };
- return RegExpEvaluator;
- }();
- var ConstConditionInternal =
- /** @class */
- function () {
- function ConstConditionInternal() {}
- ConstConditionInternal.prototype.evaluate = function () {
- return this.value;
- };
- return ConstConditionInternal;
- }();
- var AndConditionInternal =
- /** @class */
- function () {
- function AndConditionInternal() {}
- AndConditionInternal.prototype.evaluate = function () {
- var children = this.children;
- for (var i = 0; i < children.length; i++) {
- if (!children[i].evaluate()) {
- return false;
- }
- }
- return true;
- };
- return AndConditionInternal;
- }();
- var OrConditionInternal =
- /** @class */
- function () {
- function OrConditionInternal() {}
- OrConditionInternal.prototype.evaluate = function () {
- var children = this.children;
- for (var i = 0; i < children.length; i++) {
- if (children[i].evaluate()) {
- return true;
- }
- }
- return false;
- };
- return OrConditionInternal;
- }();
- var NotConditionInternal =
- /** @class */
- function () {
- function NotConditionInternal() {}
- NotConditionInternal.prototype.evaluate = function () {
- return !this.child.evaluate();
- };
- return NotConditionInternal;
- }();
- var RelationalConditionInternal =
- /** @class */
- function () {
- function RelationalConditionInternal() {}
- RelationalConditionInternal.prototype.evaluate = function () {
- var needParse = !!this.valueParser; // Call getValue with no `this`.
- var getValue = this.getValue;
- var tarValRaw = getValue(this.valueGetterParam);
- var tarValParsed = needParse ? this.valueParser(tarValRaw) : null; // Relational cond follow "and" logic internally.
- for (var i = 0; i < this.subCondList.length; i++) {
- if (!this.subCondList[i].evaluate(needParse ? tarValParsed : tarValRaw)) {
- return false;
- }
- }
- return true;
- };
- return RelationalConditionInternal;
- }();
- function parseOption(exprOption, getters) {
- if (exprOption === true || exprOption === false) {
- var cond = new ConstConditionInternal();
- cond.value = exprOption;
- return cond;
- }
- var errMsg = '';
- if (!isObjectNotArray(exprOption)) {
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('Illegal config. Expect a plain object but actually', exprOption);
- }
- throwError(errMsg);
- }
- if (exprOption.and) {
- return parseAndOrOption('and', exprOption, getters);
- } else if (exprOption.or) {
- return parseAndOrOption('or', exprOption, getters);
- } else if (exprOption.not) {
- return parseNotOption(exprOption, getters);
- }
- return parseRelationalOption(exprOption, getters);
- }
- function parseAndOrOption(op, exprOption, getters) {
- var subOptionArr = exprOption[op];
- var errMsg = '';
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('"and"/"or" condition should only be `' + op + ': [...]` and must not be empty array.', 'Illegal condition:', exprOption);
- }
- if (!isArray(subOptionArr)) {
- throwError(errMsg);
- }
- if (!subOptionArr.length) {
- throwError(errMsg);
- }
- var cond = op === 'and' ? new AndConditionInternal() : new OrConditionInternal();
- cond.children = map(subOptionArr, function (subOption) {
- return parseOption(subOption, getters);
- });
- if (!cond.children.length) {
- throwError(errMsg);
- }
- return cond;
- }
- function parseNotOption(exprOption, getters) {
- var subOption = exprOption.not;
- var errMsg = '';
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('"not" condition should only be `not: {}`.', 'Illegal condition:', exprOption);
- }
- if (!isObjectNotArray(subOption)) {
- throwError(errMsg);
- }
- var cond = new NotConditionInternal();
- cond.child = parseOption(subOption, getters);
- if (!cond.child) {
- throwError(errMsg);
- }
- return cond;
- }
- function parseRelationalOption(exprOption, getters) {
- var errMsg = '';
- var valueGetterParam = getters.prepareGetValue(exprOption);
- var subCondList = [];
- var exprKeys = keys(exprOption);
- var parserName = exprOption.parser;
- var valueParser = parserName ? getRawValueParser(parserName) : null;
- for (var i = 0; i < exprKeys.length; i++) {
- var keyRaw = exprKeys[i];
- if (keyRaw === 'parser' || getters.valueGetterAttrMap.get(keyRaw)) {
- continue;
- }
- var op = hasOwn(RELATIONAL_EXPRESSION_OP_ALIAS_MAP, keyRaw) ? RELATIONAL_EXPRESSION_OP_ALIAS_MAP[keyRaw] : keyRaw;
- var condValueRaw = exprOption[keyRaw];
- var condValueParsed = valueParser ? valueParser(condValueRaw) : condValueRaw;
- var evaluator = createFilterComparator(op, condValueParsed) || op === 'reg' && new RegExpEvaluator(condValueParsed);
- if (!evaluator) {
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('Illegal relational operation: "' + keyRaw + '" in condition:', exprOption);
- }
- throwError(errMsg);
- }
- subCondList.push(evaluator);
- }
- if (!subCondList.length) {
- if (process.env.NODE_ENV !== 'production') {
- errMsg = makePrintable('Relational condition must have at least one operator.', 'Illegal condition:', exprOption);
- } // No relational operator always disabled in case of dangers result.
- throwError(errMsg);
- }
- var cond = new RelationalConditionInternal();
- cond.valueGetterParam = valueGetterParam;
- cond.valueParser = valueParser;
- cond.getValue = getters.getValue;
- cond.subCondList = subCondList;
- return cond;
- }
- function isObjectNotArray(val) {
- return isObject(val) && !isArrayLike(val);
- }
- var ConditionalExpressionParsed =
- /** @class */
- function () {
- function ConditionalExpressionParsed(exprOption, getters) {
- this._cond = parseOption(exprOption, getters);
- }
- ConditionalExpressionParsed.prototype.evaluate = function () {
- return this._cond.evaluate();
- };
- return ConditionalExpressionParsed;
- }();
- ;
- export function parseConditionalExpression(exprOption, getters) {
- return new ConditionalExpressionParsed(exprOption, getters);
- }
|