(
exprOption: RelationalExpressionOption,
getters: ConditionalGetters
)
| 382 | } |
| 383 | |
| 384 | function parseRelationalOption( |
| 385 | exprOption: RelationalExpressionOption, |
| 386 | getters: ConditionalGetters |
| 387 | ): ParsedConditionInternal { |
| 388 | let errMsg = ''; |
| 389 | |
| 390 | const valueGetterParam = getters.prepareGetValue(exprOption); |
| 391 | |
| 392 | const subCondList = [] as RelationalConditionInternal['subCondList']; |
| 393 | const exprKeys = keys(exprOption); |
| 394 | |
| 395 | const parserName = exprOption.parser; |
| 396 | const valueParser = parserName ? getRawValueParser(parserName) : null; |
| 397 | |
| 398 | for (let i = 0; i < exprKeys.length; i++) { |
| 399 | const keyRaw = exprKeys[i]; |
| 400 | if (keyRaw === 'parser' || getters.valueGetterAttrMap.get(keyRaw)) { |
| 401 | continue; |
| 402 | } |
| 403 | |
| 404 | const op: keyof RelationalExpressionOptionByOp = hasOwn(RELATIONAL_EXPRESSION_OP_ALIAS_MAP, keyRaw) |
| 405 | ? RELATIONAL_EXPRESSION_OP_ALIAS_MAP[keyRaw as keyof RelationalExpressionOptionByOpAlias] |
| 406 | : (keyRaw as keyof RelationalExpressionOptionByOp); |
| 407 | const condValueRaw = exprOption[keyRaw]; |
| 408 | const condValueParsed = valueParser ? valueParser(condValueRaw) : condValueRaw; |
| 409 | const evaluator = createFilterComparator(op, condValueParsed) |
| 410 | || (op === 'reg' && new RegExpEvaluator(condValueParsed)); |
| 411 | |
| 412 | if (!evaluator) { |
| 413 | if (__DEV__) { |
| 414 | errMsg = makePrintable( |
| 415 | 'Illegal relational operation: "' + keyRaw + '" in condition:', exprOption |
| 416 | ); |
| 417 | } |
| 418 | throwError(errMsg); |
| 419 | } |
| 420 | |
| 421 | subCondList.push(evaluator); |
| 422 | } |
| 423 | |
| 424 | if (!subCondList.length) { |
| 425 | if (__DEV__) { |
| 426 | errMsg = makePrintable( |
| 427 | 'Relational condition must have at least one operator.', |
| 428 | 'Illegal condition:', exprOption |
| 429 | ); |
| 430 | } |
| 431 | // No relational operator always disabled in case of dangers result. |
| 432 | throwError(errMsg); |
| 433 | } |
| 434 | |
| 435 | const cond = new RelationalConditionInternal(); |
| 436 | cond.valueGetterParam = valueGetterParam; |
| 437 | cond.valueParser = valueParser; |
| 438 | cond.getValue = getters.getValue; |
| 439 | cond.subCondList = subCondList; |
| 440 | |
| 441 | return cond; |
no test coverage detected
searching dependent graphs…