common-shakeify icon indicating copy to clipboard operation
common-shakeify copied to clipboard

does not remove imports that belongs to dead code which is removed by common-shake

Open nikhildpawar opened this issue 5 years ago • 1 comments

Thanks for the efforts. This plugin works great. I will try to explain the case i came across.

"index.es6" imports {Storage} from "abc" which intern import {Cookie} from "xyz". "abc" is using {Cookie} from "xyz". But Index.es6 is not using {Storage} from "abc". Now common-shake is removing {Storage} from the code but {Cookie} remains in the output file. If I remove reference to {Cookie} from abc then common-shake is removing {Cookie} as well.

Here is the file structure

index.es6

import {Storage} from "./abc";
console.log("this is an example");

abc.es6

import {Cookie} from "./xyz";

export var Storage = function(){
}
Storage.prototype = {
  getCookie: function(){
    let cookie = new Cookie(); // if i remove this line then common-shake removes Cookie from the output
  }
}

xyz.es6

export var Cookie= function(){
}

Cookie.prototype = {
  readCookie: function(){
     console.log("reading cookie");
  }
}

nikhildpawar avatar Oct 25 '18 07:10 nikhildpawar

Sorry I missed this. The reason for this is that common-shake doesn't know that the Storage.prototype assignment is related to the exports.Storage export. I don't think that'll be easy to solve, it would require much more sophisticated analysis than common-shake can do currently.

goto-bus-stop avatar Jun 29 '19 14:06 goto-bus-stop