fix the bug in empty match checking; switched to top level regexliteral instead of sub expression
MODIFY
packages/@romejs/js-compiler/lint/rules/emptyMatches.test.ts
packages/@romejs/js-compiler/lint/rules/emptyMatches.test.ts
@@ -17,7 +17,6 @@ test(
// infinite match possible
'let a = /a*/',
'let b = /a*(abc)?[1,2,3]*/',
-
// valid regexes
'let a = /a*(abc)+[1,2,3]?/',
'let b = /a+(abc)*/',

MODIFY
packages/@romejs/js-compiler/lint/rules/emptyMatches.ts
packages/@romejs/js-compiler/lint/rules/emptyMatches.ts
@@ -10,15 +10,16 @@ import {Path, TransformExitResult} from '@romejs/js-compiler';
import {descriptions} from '@romejs/diagnostics';
function isQuantifiedMinZero(el: AnyRegExpBodyItem): boolean {
- return el.type === 'RegExpQuantified' && el.min == 0;
+ return el.type === 'RegExpQuantified' && el.min === 0;
}
export default {
name: 'noEmptyCharacterClass',
enter(path: Path): TransformExitResult {
const {context, node} = path;
- if (node.type === 'RegExpSubExpression') {
- if (node.body.every(isQuantifiedMinZero)) {
+ if (node.type === 'RegExpLiteral') {
+ const {body} = node.expression;
+ if (body && body.every(isQuantifiedMinZero)) {
context.addNodeDiagnostic(node, descriptions.LINT.EMPTY_MATCHES);
}
}

fix the bug in empty match checking; switched to top level regexliteral instead of sub expression