From e69b30fa6c9e36deca916c1bbb22cc0d6bad607c Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 23 Oct 2016 14:12:28 -0400 Subject: [PATCH] add more tests for DCE'ing conditional expressions --- .../__tests__/dead-code-elimination-test.js | 24 +++++++++++++++++++ 1 file changed, 24 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 d66b1e939..dd8904a7c 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 @@ -791,6 +791,30 @@ describe("dce-plugin", () => { expect(transform(source).trim()).toBe(expected); }); + it("should evaluate conditional expressions 3", () => { + const source = "'foo' ? a() : b();"; + const expected = "a();"; + expect(transform(source).trim()).toBe(expected); + }); + + it("should evaluate conditional expressions 4", () => { + const source = "null ? a() : b();"; + const expected = "b();"; + expect(transform(source).trim()).toBe(expected); + }); + + it("should evaluate conditional expressions 5", () => { + const source = "'foo' === 'foo' ? a() : b();"; + const expected = "a();"; + expect(transform(source).trim()).toBe(expected); + }); + + it("should evaluate conditional expressions 6", () => { + const source = "'foo' !== 'bar' ? a() : b();"; + const expected = "a();"; + expect(transform(source).trim()).toBe(expected); + }); + it("should not remove needed expressions", () => { const source = unpad(` var n = 1;