MCPcopy
hub / github.com/webpack/webpack / compileBooleanMatcherFromLists

Function compileBooleanMatcherFromLists

lib/util/compileBooleanMatcher.js:120–135  ·  view source on GitHub ↗
(positiveItems, negativeItems)

Source from the content-addressed store, hash-verified

118 * @returns {(value: string) => string} a template function to determine the value at runtime
119 */
120const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
121 if (positiveItems.length === 0) return () => "false";
122 if (negativeItems.length === 0) return () => "true";
123 if (positiveItems.length === 1) {
124 return (value) => `${toSimpleString(positiveItems[0])} == ${value}`;
125 }
126 if (negativeItems.length === 1) {
127 return (value) => `${toSimpleString(negativeItems[0])} != ${value}`;
128 }
129 const positiveRegexp = itemsToRegexp(positiveItems);
130 const negativeRegexp = itemsToRegexp(negativeItems);
131 if (positiveRegexp.length <= negativeRegexp.length) {
132 return (value) => `/^${positiveRegexp}$/.test(${value})`;
133 }
134 return (value) => `!/^${negativeRegexp}$/.test(${value})`;
135};
136
137/** @typedef {string[][]} ListOfCommonItems */
138

Callers 1

compileBooleanMatcherFunction · 0.85

Calls 2

toSimpleStringFunction · 0.85
itemsToRegexpFunction · 0.85

Tested by

no test coverage detected