Skip to content

Commit

Permalink
Remove Empty Functions in block (close #247) (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi authored and kangax committed Nov 3, 2016
1 parent 55ddb2b commit e8dbc90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("dce-plugin", () => {
const source = unpad(`
function foo(p) {
return 1;
};
}
function bar(q) {
return q + 1;
}
Expand Down Expand Up @@ -2193,4 +2193,20 @@ describe("dce-plugin", () => {
}
})).toBe(expected);
});
it("should remove empty statements when children of block", () => {
const source = unpad(`
(function () {
function foo() {};
function bar() {};
function baz() {};
function ban() {};
function quux() {};
function cake() {};
})();
`);
const expected = unpad(`
(function () {})();
`);
expect(transform(source)).toBe(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ module.exports = ({ types: t, traverse }) => {
return {
name: "minify-dead-code-elimination",
visitor: {
EmptyStatement(path) {
if (path.parentPath.isBlockStatement() || path.parentPath.isProgram()) {
path.remove();
}
},
Program(path, {
opts: {
// set defaults
Expand Down

0 comments on commit e8dbc90

Please sign in to comment.