MCPcopy
hub / github.com/webpack/webpack / execRule

Method execRule

lib/rules/RuleSetCompiler.js:146–202  ·  view source on GitHub ↗
(data, rule, effects)

Source from the content-addressed store, hash-verified

144 * @returns {boolean} true, if the rule has matched
145 */
146 const execRule = (data, rule, effects) => {
147 for (const condition of rule.conditions) {
148 const p = condition.property;
149 if (Array.isArray(p)) {
150 /** @type {EXPECTED_ANY} */
151 let current = data;
152 for (const subProperty of p) {
153 if (
154 current &&
155 typeof current === "object" &&
156 Object.prototype.hasOwnProperty.call(current, subProperty)
157 ) {
158 current = current[/** @type {keyof EffectData} */ (subProperty)];
159 } else {
160 current = undefined;
161 break;
162 }
163 }
164 if (current !== undefined) {
165 if (!condition.fn(current)) return false;
166 continue;
167 }
168 } else if (p in data) {
169 const value = data[/** @type {keyof EffectData} */ (p)];
170 if (value !== undefined) {
171 if (!condition.fn(value)) return false;
172 continue;
173 }
174 }
175 if (!condition.matchWhenEmpty) {
176 return false;
177 }
178 }
179 for (const effect of rule.effects) {
180 if (typeof effect === "function") {
181 const returnedEffects = effect(data);
182 for (const effect of returnedEffects) {
183 effects.push(effect);
184 }
185 } else {
186 effects.push(effect);
187 }
188 }
189 if (rule.rules) {
190 for (const childRule of rule.rules) {
191 execRule(data, childRule, effects);
192 }
193 }
194 if (rule.oneOf) {
195 for (const childRule of rule.oneOf) {
196 if (execRule(data, childRule, effects)) {
197 break;
198 }
199 }
200 }
201 return true;
202 };
203

Callers

nothing calls this directly

Calls 4

isArrayMethod · 0.80
callMethod · 0.45
fnMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected