From 4bcab0b82c2a384d2c45f46e804a46912eb17ad5 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 16 Jun 2018 11:38:45 +0900 Subject: [PATCH] Chore: follow up #2 --- README.md | 2 +- src/index.ts | 2 +- test/parser.ts | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc78ed2..b6eeefc 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Parse a given regular expression literal then make AST object. This is equivalent to `new RegExpParser(options).parseLiteral(source)`. - **Parameters:** - - `source` (`string`) The source code to parse. + - `source` (`string | RegExp`) The source code to parse. - `options?` ([`RegExpParser.Options`]) The options to parse. - **Return:** - The AST of the regular expression. diff --git a/src/index.ts b/src/index.ts index a96784f..0b6bac5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ export function parseRegExpLiteral( source: string | RegExp, options?: RegExpParser.Options, ): AST.RegExpLiteral { - return new RegExpParser(options).parseLiteral(source instanceof RegExp ? String(source) : source) + return new RegExpParser(options).parseLiteral(String(source)) } /** diff --git a/test/parser.ts b/test/parser.ts index 2bffecf..3e6e1a0 100644 --- a/test/parser.ts +++ b/test/parser.ts @@ -50,6 +50,13 @@ describe("parseRegExpLiteral function:", () => { } }) } + + it("should parse RegExp object", () => { + const actual = cloneWithoutCircular(parseRegExpLiteral(/[A-Z]+/)) + const expected = cloneWithoutCircular(parseRegExpLiteral("/[A-Z]+/")) + + assert.deepStrictEqual(actual, expected) + }) }) for (const filename of Object.keys(Fixtures)) {