source: trip-planner-front/node_modules/webpack/lib/rules/ObjectMatcherRulePlugin.js@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 1.3 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 ObjectMatcherRulePlugin {
12 constructor(ruleProperty, dataProperty) {
13 this.ruleProperty = ruleProperty;
14 this.dataProperty = dataProperty || ruleProperty;
15 }
16
17 /**
18 * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
19 * @returns {void}
20 */
21 apply(ruleSetCompiler) {
22 const { ruleProperty, dataProperty } = this;
23 ruleSetCompiler.hooks.rule.tap(
24 "ObjectMatcherRulePlugin",
25 (path, rule, unhandledProperties, result) => {
26 if (unhandledProperties.has(ruleProperty)) {
27 unhandledProperties.delete(ruleProperty);
28 const value = rule[ruleProperty];
29 for (const property of Object.keys(value)) {
30 const nestedDataProperties = property.split(".");
31 const condition = ruleSetCompiler.compileCondition(
32 `${path}.${ruleProperty}.${property}`,
33 value[property]
34 );
35 result.conditions.push({
36 property: [dataProperty, ...nestedDataProperties],
37 matchWhenEmpty: condition.matchWhenEmpty,
38 fn: condition.fn
39 });
40 }
41 }
42 }
43 );
44 }
45}
46
47module.exports = ObjectMatcherRulePlugin;
Note: See TracBrowser for help on using the repository browser.