Skip to content

Commit 4bcab0b

Browse files
committed
Chore: follow up #2
1 parent c59845a commit 4bcab0b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Parse a given regular expression literal then make AST object.
3535
This is equivalent to `new RegExpParser(options).parseLiteral(source)`.
3636

3737
- **Parameters:**
38-
- `source` (`string`) The source code to parse.
38+
- `source` (`string | RegExp`) The source code to parse.
3939
- `options?` ([`RegExpParser.Options`]) The options to parse.
4040
- **Return:**
4141
- The AST of the regular expression.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function parseRegExpLiteral(
1515
source: string | RegExp,
1616
options?: RegExpParser.Options,
1717
): AST.RegExpLiteral {
18-
return new RegExpParser(options).parseLiteral(source instanceof RegExp ? String(source) : source)
18+
return new RegExpParser(options).parseLiteral(String(source))
1919
}
2020

2121
/**

test/parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ describe("parseRegExpLiteral function:", () => {
5050
}
5151
})
5252
}
53+
54+
it("should parse RegExp object", () => {
55+
const actual = cloneWithoutCircular(parseRegExpLiteral(/[A-Z]+/))
56+
const expected = cloneWithoutCircular(parseRegExpLiteral("/[A-Z]+/"))
57+
58+
assert.deepStrictEqual(actual, expected)
59+
})
5360
})
5461

5562
for (const filename of Object.keys(Fixtures)) {

0 commit comments

Comments
 (0)