Closed petrosmm closed 5 years ago
It doesn't appear it has the support for removing dead code from if statements like:
if (false) { ... }
But it does support removing unused functions.
Here is the test I ran with the latest release (v5.14): Test JavaScript:
function foo() {
if (false) {
console.log("I'll never be true.");
}
console.log("I'll always be used.");
function unused() {
console.log("I'm unused.");
}
}
AjaxMinifer Command:
AjaxMinifier.exe deadCodeTest.js -out deadCodeTest.min.js
Output:
function foo(){!1&&console.log("I'll never be true.");console.log("I'll always be used.")}
I think what you are looking for is called "Tree Shaking": https://webpack.js.org/guides/tree-shaking/
I have not tested to verify.
I tested with roolup.js which supports Tree Shaking.
Test Code:
(function foo() {
if (false) {
console.log("I'll never be true.");
}
console.log("I'll always be used.");
function unused() {
console.log("I'm unused.");
}
})();
rollup command
rollup deadCodeTest.js --file deadCodeTest.min2.js --format iife
Output:
(function () {
'use strict';
(function foo() {
console.log("I'll always be used.");
})();
}());
Hmm interesting... I have never heard that term before and I will look into it. Thank you!
In various projects I have worked on, developers leave a lot of dead code in the comments mostly for debugging purposes, however that code get's transported and it does not get removed... Before writing here, I came across this issue with @Taritsyn of the WebMarkUpMin project as well as NUglify JS minifer project. Does ajaxmin support removing dead code -- the 'if (false' statements)?