changed from map to imperative
MODIFY
packages/@romejs/js-compiler/lint/rules/emptyMatches.ts
packages/@romejs/js-compiler/lint/rules/emptyMatches.ts
* LICENSE file in the root directory of this source tree.
*/
-import {AnyRegExpExpression, AnyRegExpBodyItem} from '@romejs/js-ast';
+import {AnyRegExpBodyItem, AnyRegExpExpression} from '@romejs/js-ast';
import {Path, TransformExitResult} from '@romejs/js-compiler';
import {descriptions} from '@romejs/diagnostics';
@@ -15,15 +15,21 @@ function isQuantifiedMinZero(el: AnyRegExpBodyItem): boolean {
function lintEmptyMatches(expr: AnyRegExpExpression): boolean {
if (expr.type === 'RegExpSubExpression') {
- return expr.body
- .map((item) => {
- if (item.type === 'RegExpGroupNonCapture' || item.type === 'RegExpGroupCapture') {
- return lintEmptyMatches(item.expression);
+ for (const item of expr.body) {
+ let matches = false;
+ if (
+ item.type === 'RegExpGroupNonCapture' ||
+ item.type === 'RegExpGroupCapture'
+ ) {
+ matches = lintEmptyMatches(item.expression);
} else {
- return isQuantifiedMinZero(item);
+ matches = isQuantifiedMinZero(item);
}
- })
- .every(el => el === true);
+ if (!matches) {
+ return false;
+ }
+ }
+ return true;
} else {
return lintEmptyMatches(expr.left) || lintEmptyMatches(expr.right);
}

changed from map to imperative