Minify: babel-plugin-minify-dead-code-elimination: produces wrong code

Created on 9 Mar 2017  路  4Comments  路  Source: babel/minify

version 0.1.4

from Babel REPL:

 function subList(list=[], template) {

      var olElm = template.element;

      if (olElm.tagName !== 'OL') {
        olElm = document.createElement('ol');
      } else {
        var reinsert = foo => list.push(olElm);
        var hash = {};
      }

      if (hash) {
        reinsert();
      }

      return olElm;
    }

produces:

function subList(a=[],b){
var c=b.element;
if('OL'!==c.tagName)
  c=document.createElement('ol');
else
  var d=()=>a.push(c);
return d(),c
}

hash is eliminated when it shouldn't be. This is a cut down version of the code that had the problem which is why it doesn't make much sense.

bug has PR

All 4 comments

Hey @jacott! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

May not be just a bug in dead-code; this also produces wrong code with dead-code turned off:

 if (foo) {
   var hash = {};
   for (var i = 1; i < 10; )
   ++i;
 }

 var elm = hash && hash[li.id];
        if (elm) {
          hash[li.id] = null;
        }

produces:

if(foo) for(var hash={},i=1;10>i;)
  ++i;
var elm=hash[li.id];
elm&&(hash[li.id]=null);

bug in guarded expressions

Fixed by #831

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Reinmar picture Reinmar  路  4Comments

zamb3zi picture zamb3zi  路  3Comments

boopathi picture boopathi  路  3Comments

jamesloewen picture jamesloewen  路  3Comments

sourabhv picture sourabhv  路  3Comments