1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* 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);
}