diff --git a/packages/babel-plugin-minify-constant-folding/__tests__/constant-folding-test.js b/packages/babel-plugin-minify-constant-folding/__tests__/constant-folding-test.js index 30fe72afc..64998bdf0 100644 --- a/packages/babel-plugin-minify-constant-folding/__tests__/constant-folding-test.js +++ b/packages/babel-plugin-minify-constant-folding/__tests__/constant-folding-test.js @@ -60,4 +60,37 @@ describe("constant-folding-plugin", () => { `); expect(transform(source)).toBe(source); }); + + it("should handle script escape", () => { + const source = unpad(` + " { + const source = unpad(` + " { + const source = unpad(` + " { const seen = Symbol("seen"); @@ -112,6 +113,13 @@ module.exports = ({ types: t, traverse }) => { } } + // https://github.com/babel/babili/issues/382 + if (typeof res.value === "string") { + res.value = jsesc(res.value, { + isScriptContext: true + }); + } + const node = t.valueToNode(res.value); node[seen] = true; path.replaceWith(node);