(positiveItems, negativeItems)
| 433 | * @returns {(val: string) => string} a template function to determine the value at runtime |
| 434 | */ |
| 435 | const 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 | /** |
no test coverage detected
searching dependent graphs…