* Applies the plugin by registering its hooks on the compiler. * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler * @returns {void}
(ruleSetCompiler)
| 43 | * @returns {void} |
| 44 | */ |
| 45 | apply(ruleSetCompiler) { |
| 46 | ruleSetCompiler.hooks.rule.tap( |
| 47 | PLUGIN_NAME, |
| 48 | (path, rule, unhandledProperties, result) => { |
| 49 | if (unhandledProperties.has(this.ruleProperty)) { |
| 50 | unhandledProperties.delete(this.ruleProperty); |
| 51 | const value = rule[this.ruleProperty]; |
| 52 | const condition = ruleSetCompiler.compileCondition( |
| 53 | `${path}.${this.ruleProperty}`, |
| 54 | /** @type {RuleSetConditionOrConditions | RuleSetConditionOrConditionsAbsolute} */ |
| 55 | (value) |
| 56 | ); |
| 57 | const fn = condition.fn; |
| 58 | result.conditions.push({ |
| 59 | property: this.dataProperty, |
| 60 | matchWhenEmpty: this.invert |
| 61 | ? !condition.matchWhenEmpty |
| 62 | : condition.matchWhenEmpty, |
| 63 | fn: this.invert ? (v) => !fn(v) : fn |
| 64 | }); |
| 65 | } |
| 66 | } |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | module.exports = BasicMatcherRulePlugin; |