From 661c6f0111580583363d2fef27b88c06dc27dd23 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Wed, 25 Jan 2017 14:19:14 +0100 Subject: [PATCH] Add tests --- .../__tests__/dead-code-elimination-test.js | 9 +++++++++ .../babel-preset-babili/__tests__/preset-tests.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/babel-plugin-minify-dead-code-elimination/__tests__/dead-code-elimination-test.js b/packages/babel-plugin-minify-dead-code-elimination/__tests__/dead-code-elimination-test.js index 372da8dcf..34952c60f 100644 --- a/packages/babel-plugin-minify-dead-code-elimination/__tests__/dead-code-elimination-test.js +++ b/packages/babel-plugin-minify-dead-code-elimination/__tests__/dead-code-elimination-test.js @@ -2421,4 +2421,13 @@ describe("dce-plugin", () => { expect(transform(source)).toBe(expected); }); + + it("should deopt impure expressions in if statements", () => { + const source = unpad(` + if (a.b(), true) { + foo(); + } + `); + expect(transform(source)).toBe(source); + }); }); diff --git a/packages/babel-preset-babili/__tests__/preset-tests.js b/packages/babel-preset-babili/__tests__/preset-tests.js index 2a23f6700..a98a51e4d 100644 --- a/packages/babel-preset-babili/__tests__/preset-tests.js +++ b/packages/babel-preset-babili/__tests__/preset-tests.js @@ -61,4 +61,18 @@ describe("preset", () => { `); expect(transform(source)).toBe(expected); }); + + it("should fix issue#385 - impure if statements with Sequence and DCE", () => { + const source = unpad(` + a = b; + c = d; + if (false) { + const x = y + } + `); + const expected = unpad(` + a = b, c = d; + `); + expect(transform(source)).toBe(expected); + }); });