source: trip-planner-front/node_modules/webpack/lib/rules/BasicMatcherRulePlugin.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
9/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
10
11class BasicMatcherRulePlugin {
12 constructor(ruleProperty, dataProperty, invert) {
13 this.ruleProperty = ruleProperty;
14 this.dataProperty = dataProperty || ruleProperty;
15 this.invert = invert || false;
16 }
17
18 /**
19 * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
20 * @returns {void}
21 */
22 apply(ruleSetCompiler) {
23 ruleSetCompiler.hooks.rule.tap(
24 "BasicMatcherRulePlugin",
25 (path, rule, unhandledProperties, result) => {
26 if (unhandledProperties.has(this.ruleProperty)) {
27 unhandledProperties.delete(this.ruleProperty);
28 const value = rule[this.ruleProperty];
29 const condition = ruleSetCompiler.compileCondition(
30 `${path}.${this.ruleProperty}`,
31 value
32 );
33 const fn = condition.fn;
34 result.conditions.push({
35 property: this.dataProperty,
36 matchWhenEmpty: this.invert
37 ? !condition.matchWhenEmpty
38 : condition.matchWhenEmpty,
39 fn: this.invert ? v => !fn(v) : fn
40 });
41 }
42 }
43 );
44 }
45}
46
47module.exports = BasicMatcherRulePlugin;
Note: See TracBrowser for help on using the repository browser.