MCPcopy Create free account
hub / github.com/webpack/mini-css-extract-plugin / compileBooleanMatcherFromLists

Function compileBooleanMatcherFromLists

src/utils.js:435–460  ·  view source on GitHub ↗
(positiveItems, negativeItems)

Source from the content-addressed store, hash-verified

433 * @returns {(val: string) => string} a template function to determine the value at runtime
434 */
435const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
436 if (positiveItems.length === 0) {
437 return () => "false";
438 }
439
440 if (negativeItems.length === 0) {
441 return () => "true";
442 }
443
444 if (positiveItems.length === 1) {
445 return (value) => `${toSimpleString(positiveItems[0])} == ${value}`;
446 }
447
448 if (negativeItems.length === 1) {
449 return (value) => `${toSimpleString(negativeItems[0])} != ${value}`;
450 }
451
452 const positiveRegexp = itemsToRegexp(positiveItems);
453 const negativeRegexp = itemsToRegexp(negativeItems);
454
455 if (positiveRegexp.length <= negativeRegexp.length) {
456 return (value) => `/^${positiveRegexp}$/.test(${value})`;
457 }
458
459 return (value) => `!/^${negativeRegexp}$/.test(${value})`;
460};
461
462// TODO simplify in the next major release and use it from webpack
463/**

Callers 1

compileBooleanMatcherFunction · 0.85

Calls 2

toSimpleStringFunction · 0.85
itemsToRegexpFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…