Skip to content
This repository was archived by the owner on Oct 11, 2021. It is now read-only.

Commit 033dffe

Browse files
Updated refa version
1 parent 9fc02d2 commit 033dffe

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/rules/disjoint-alternatives.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JS, NFA, ReadonlyNFA } from "refa";
1+
import { JS, NFA, ReadonlyNFA, TooManyNodesError } from "refa";
22
import { Alternative, CapturingGroup, Group, LookaroundAssertion, Node, Pattern } from "regexpp/ast";
33
import { mention, toRegExpString } from "../format";
44
import { CleanRegexRule, createRuleListener, getDocUrl } from "../rules-util";
@@ -22,10 +22,19 @@ export default {
2222
* Converts the given alternative to an NFA. The returned NFA does not accept the empty string.
2323
*/
2424
function toNfa(alt: Alternative): ReadonlyNFA {
25-
const result = parser.parseElement(alt, { lookarounds: "disable" });
26-
const nfa = NFA.fromRegex(result.expression, { maxCharacter: result.maxCharacter });
27-
nfa.withoutEmptyWord();
28-
return nfa;
25+
try {
26+
const result = parser.parseElement(alt, { backreferences: "disable", assertions: "disable" });
27+
const nfa = NFA.fromRegex(result.expression, { maxCharacter: result.maxCharacter });
28+
nfa.withoutEmptyWord();
29+
return nfa;
30+
} catch (e) {
31+
// the NFA construction might fail because the NFA is too big
32+
if (e instanceof TooManyNodesError) {
33+
return NFA.empty({ maxCharacter: flags.unicode ? 0x10ffff : 0xffff });
34+
}
35+
36+
throw e;
37+
}
2938
}
3039

3140
function findFirstSuperset(alternatives: Alternative[], subset: ReadonlyNFA): Alternative[] {

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test": "mocha -r ts-node/register 'tests/**/*.ts'"
2626
},
2727
"dependencies": {
28-
"refa": "^0.5.0",
28+
"refa": "^0.7.1",
2929
"regexpp": "^3.1.0"
3030
},
3131
"devDependencies": {

0 commit comments

Comments
 (0)