Skip to content

Commit

Permalink
run DCE on program exit (fix babel#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Nov 22, 2016
1 parent eb7b3c8 commit 67611fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions packages/babel-plugin-minify-dead-code-elimination/src/index.js
Expand Up @@ -690,21 +690,23 @@ module.exports = ({ types: t, traverse }) => {
path.remove();
}
},
Program(path, {
opts: {
// set defaults
optimizeRawSize = false,
keepFnName = false,
keepFnArgs = false,
} = {}
} = {}) {
// We need to run this plugin in isolation.
path.traverse(main, {
functionToBindings: new Map(),
optimizeRawSize,
keepFnName,
keepFnArgs,
});
Program: {
exit(path, {
opts: {
// set defaults
optimizeRawSize = false,
keepFnName = false,
keepFnArgs = false,
} = {}
} = {}) {
// We need to run this plugin in isolation.
path.traverse(main, {
functionToBindings: new Map(),
optimizeRawSize,
keepFnName,
keepFnArgs,
});
}
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-babili/__tests__/preset-tests.js
Expand Up @@ -34,7 +34,7 @@ describe("preset", () => {
const expected = unpad(`
function foo() {
var d, e, f;
d ? e && f : !b && f;
d ? e && f : e || f;

This comment has been minimized.

Copy link
@kangax

kangax Nov 23, 2016

Was this a bug or?

}
`);
expect(transform(source)).toBe(expected);
Expand Down

0 comments on commit 67611fd

Please sign in to comment.