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

run DCE on program exit (fix #289) #292

Merged
merged 1 commit into from Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
`);
expect(transform(source)).toBe(expected);
Expand Down