(
ce: ComputeEngine,
rs: Rule | ReadonlyArray<Rule | BoxedRule> | BoxedRuleSet | undefined | null,
options?: { canonical?: boolean; purpose?: RulePurpose }
)
| 899 | * This also crucially prevents wildcards from being given definitions where captured & bound. |
| 900 | * |
| 901 | * @param ce |
| 902 | */ |
| 903 | function pushSafeScope(ce: ComputeEngine) { |
| 904 | const systemScope = ce.contextStack[0]?.lexicalScope; |
| 905 | if (systemScope) { |
| 906 | ce.pushScope({ parent: systemScope, bindings: new Map() }); |
| 907 | } else { |
| 908 | ce.pushScope(); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Create a boxed rule set from a collection of non-boxed rules |
| 914 | */ |
| 915 | export function boxRules( |
| 916 | ce: ComputeEngine, |
| 917 | rs: Rule | ReadonlyArray<Rule | BoxedRule> | BoxedRuleSet | undefined | null, |
| 918 | options?: { canonical?: boolean; purpose?: RulePurpose } |
| 919 | ): BoxedRuleSet { |
| 920 | if (!rs) return { rules: [] }; |
| 921 | |
| 922 | if (typeof rs === 'object' && 'rules' in rs) return rs as BoxedRuleSet; |
| 923 | |
| 924 | if (!Array.isArray(rs)) rs = [rs as Rule | BoxedRule]; |
| 925 | |
| 926 | const rules: BoxedRule[] = []; |
| 927 | for (const rule of rs) { |
| 928 | try { |
| 929 | rules.push(boxRule(ce, rule, options)); |
| 930 | } catch (e) { |
| 931 | // There was a problem with a rule: log it, skip that one rule, and |
| 932 | // continue boxing the rest. A single malformed rule must not take down |
| 933 | // the entire ruleset (e.g. one bad entry in the default simplify set, or |
| 934 | // an unsupported shortcut in a user ruleset). This matches the "Skipping |
| 935 | // rule" wording that was already printed here — previously the error was |
| 936 | // re-thrown despite the message, aborting the whole set. |
no test coverage detected