diff --git a/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js b/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js index 55d69ca49..b4461a584 100644 --- a/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js +++ b/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js @@ -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/;"; diff --git a/packages/babel-plugin-transform-regexp-constructors/src/index.js b/packages/babel-plugin-transform-regexp-constructors/src/index.js index d4c4a09d6..c68bdefe8 100644 --- a/packages/babel-plugin-transform-regexp-constructors/src/index.js +++ b/packages/babel-plugin-transform-regexp-constructors/src/index.js @@ -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")