Skip to content

Commit 4872cf6

Browse files
fix: walker was visiting states multiple times
1 parent c42d678 commit 4872cf6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

assembly/__tests__/capture-group.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ it("should not return captured values for non-matching alternations", () => {
3333
expect(match.matches[1]).toBe("");
3434
expect(match.matches[2]).toBe("b");
3535
});
36+
37+
it("repeated capture groups should return the last match", () => {
38+
const match = exec("([a-c])+", "ac");
39+
expect(match.matches[0]).toBe("ac");
40+
expect(match.matches[1]).toBe("c");
41+
});

assembly/nfa/walker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export function walker(
55
visitor: (state: State) => void,
66
visited: State[] = []
77
): void {
8-
visitor(state);
98
if (visited.includes(state)) return;
9+
visitor(state);
1010
visited.push(state);
1111
const nextStates = state.transitions;
1212
for (let i = 0, len = nextStates.length; i < len; i++) {

0 commit comments

Comments
 (0)