From 58bf969b68006385e44b385f5c075738efbb8d10 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Fri, 20 Jan 2017 18:02:43 -0500 Subject: [PATCH 1/3] Escape " { `); expect(transform(source)).toBe(source); }); + + it("should handle script escape", () => { + const source = unpad(` + " { } } + // https://github.com/babel/babili/issues/382 + if (typeof res.value === 'string' && + res.value.indexOf(' -1) { + res.value = res.value.replace(/<\/script/g, '<\\/script'); + } + const node = t.valueToNode(res.value); node[seen] = true; path.replaceWith(node); From 570daa7e38a5186ac133150029bbf53b4de67352 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Fri, 20 Jan 2017 18:28:04 -0500 Subject: [PATCH 2/3] Fix lint --- packages/babel-plugin-minify-constant-folding/src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/babel-plugin-minify-constant-folding/src/index.js b/packages/babel-plugin-minify-constant-folding/src/index.js index 8344fdca6..1102b3814 100644 --- a/packages/babel-plugin-minify-constant-folding/src/index.js +++ b/packages/babel-plugin-minify-constant-folding/src/index.js @@ -113,9 +113,9 @@ module.exports = ({ types: t, traverse }) => { } // https://github.com/babel/babili/issues/382 - if (typeof res.value === 'string' && - res.value.indexOf(' -1) { - res.value = res.value.replace(/<\/script/g, '<\\/script'); + if (typeof res.value === "string" && + res.value.indexOf(" -1) { + res.value = res.value.replace(/<\/script/g, "<\\/script"); } const node = t.valueToNode(res.value); From e927380e5ebe53108cf98a26e2cfd568dab17c41 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Tue, 24 Jan 2017 12:26:47 -0500 Subject: [PATCH 3/3] Use jsesc --- .../__tests__/constant-folding-test.js | 22 +++++++++++++++++++ .../src/index.js | 8 ++++--- 2 files changed, 27 insertions(+), 3 deletions(-) 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 607123534..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 @@ -71,4 +71,26 @@ describe("constant-folding-plugin", () => { `); expect(transform(source)).toBe(expected); }); + + it("should handle style escape", () => { + const source = unpad(` + " { + const source = unpad(` + " { const seen = Symbol("seen"); @@ -113,9 +114,10 @@ module.exports = ({ types: t, traverse }) => { } // https://github.com/babel/babili/issues/382 - if (typeof res.value === "string" && - res.value.indexOf(" -1) { - res.value = res.value.replace(/<\/script/g, "<\\/script"); + if (typeof res.value === "string") { + res.value = jsesc(res.value, { + isScriptContext: true + }); } const node = t.valueToNode(res.value);