Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for DCE'ing conditional expressions #218

Merged
merged 1 commit into from
Oct 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if the assumption was that 'foo' === 'foo' would be reduced to true by constant folding, but I didn't see any tests for that in the constant folding plugin.

So if you prefer I can move these two to constant-folding-test.js

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;
Expand Down