Skip to content

Commit 4500f2a

Browse files
committed
chore: improve code cov
1 parent 7d34c9f commit 4500f2a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/__tests__/compiler.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ test('regex constructor', () => {
2828
expect(buildRegex('a').test('a')).toBeTruthy();
2929
expect(buildRegex('a').test('b')).toBeFalsy();
3030
});
31+
32+
test('buildRegex throws error on unknown element', () => {
33+
expect(() =>
34+
// @ts-expect-error intentionally passing incorrect object
35+
buildRegex({ type: 'unknown' })
36+
).toThrowErrorMatchingInlineSnapshot(`"Unknown elements type unknown"`);
37+
});

src/compiler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ function compileSingle(element: RegexElement): string {
3838
return compileCharacterClass(element);
3939
}
4040

41-
const compiledChildren = compileList(element.children);
42-
4341
if (element.type === 'repeat') {
42+
const compiledChildren = compileList(element.children);
4443
return compileRepeat(element.config, compiledChildren);
4544
}
4645

4746
if (isBaseQuantifier(element)) {
47+
const compiledChildren = compileList(element.children);
4848
const compiler = baseQuantifiers[element.type];
4949
return compiler(compiledChildren);
5050
}

0 commit comments

Comments
 (0)