Skip to content

Commit

Permalink
Merge pull request #304 from SimonSelg/master
Browse files Browse the repository at this point in the history
Escape unicode newline in regex optimization
  • Loading branch information
kangax committed Nov 26, 2016
2 parents 1249def + 5aaef24 commit f2178c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Expand Up @@ -22,6 +22,12 @@ describe("transform-regexp-constructors-plugin", () => {
expect(transform(source)).toBe(expected);
});

it("should transform unicode newlines fine", () => {
const source = String.raw`var x = new RegExp('\u2028\u2029');`;
const expected = String.raw`var x = /\u2028\u2029/;`;
expect(transform(source)).toBe(expected);
});

it("should transform RegExp constructors with string literals", () => {
const source = "var x = new RegExp('ab+c');";
const expected = "var x = /ab+c/;";
Expand Down
Expand Up @@ -17,6 +17,8 @@ function createRegExpLiteral(args, prettify, t) {
pattern = new RegExp(pattern).source;
if (prettify) {
pattern = pattern.replace(/\n/g, "\\n")
.replace(/\u2028/g, "\\u2028")
.replace(/\u2029/g, "\\u2029")
.replace(/[\b]/g, "[\\b]")
.replace(/\v/g, "\\v")
.replace(/\f/g, "\\f")
Expand Down

0 comments on commit f2178c8

Please sign in to comment.