Skip to content

Commit

Permalink
Chore: follow up #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 16, 2018
1 parent c59845a commit 4bcab0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 4bcab0b

Please sign in to comment.