* @param {import("../lib/javascript/BasicEvaluatedExpression")} evalExpr eval expr * @returns {string} result
(evalExpr)
| 663 | * @returns {string} result |
| 664 | */ |
| 665 | function evalExprToString(evalExpr) { |
| 666 | if (!evalExpr) { |
| 667 | return "null"; |
| 668 | } |
| 669 | const result = []; |
| 670 | if (evalExpr.isString()) result.push(`string=${evalExpr.string}`); |
| 671 | if (evalExpr.isNumber()) result.push(`number=${evalExpr.number}`); |
| 672 | if (evalExpr.isBigInt()) result.push(`bigint=${evalExpr.bigint}`); |
| 673 | if (evalExpr.isBoolean()) result.push(`bool=${evalExpr.bool}`); |
| 674 | if (evalExpr.isRegExp()) result.push(`regExp=${evalExpr.regExp}`); |
| 675 | if (evalExpr.isConditional()) { |
| 676 | result.push( |
| 677 | `options=[${/** @type {import("../lib/javascript/BasicEvaluatedExpression")[]} */ (evalExpr.options).map(evalExprToString).join("],[")}]` |
| 678 | ); |
| 679 | } |
| 680 | if (evalExpr.isArray()) { |
| 681 | result.push( |
| 682 | `items=[${/** @type {import("../lib/javascript/BasicEvaluatedExpression")[]} */ (evalExpr.items).map(evalExprToString).join("],[")}]` |
| 683 | ); |
| 684 | } |
| 685 | if (evalExpr.isConstArray()) { |
| 686 | result.push( |
| 687 | `array=[${/** @type {(string | number | boolean | null | RegExp | bigint)[]} */ (evalExpr.array).join("],[")}]` |
| 688 | ); |
| 689 | } |
| 690 | if (evalExpr.isTemplateString()) { |
| 691 | result.push( |
| 692 | `template=[${/** @type {import("../lib/javascript/BasicEvaluatedExpression")[]} */ (evalExpr.quasis).map(evalExprToString).join("],[")}]` |
| 693 | ); |
| 694 | } |
| 695 | if (evalExpr.isWrapped()) { |
| 696 | result.push( |
| 697 | `wrapped=[${evalExprToString(/** @type {import("../lib/javascript/BasicEvaluatedExpression")} */ (evalExpr.prefix))}]+[${evalExprToString( |
| 698 | /** @type {import("../lib/javascript/BasicEvaluatedExpression")} */ ( |
| 699 | evalExpr.postfix |
| 700 | ) |
| 701 | )}]` |
| 702 | ); |
| 703 | } |
| 704 | if (evalExpr.range) { |
| 705 | const start = evalExpr.range[0] - 5; |
| 706 | const end = evalExpr.range[1] - 5; |
| 707 | return ( |
| 708 | key.slice(start, end) + |
| 709 | (result.length > 0 ? ` ${result.join(" ")}` : "") |
| 710 | ); |
| 711 | } |
| 712 | return result.join(" "); |
| 713 | } |
| 714 | |
| 715 | it(`should eval ${key}`, () => { |
| 716 | const evalExpr = evaluateInParser(key); |
no test coverage detected