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

babel-plugin-minify-dead-code-elimination: produces wrong code #469

Closed
jacott opened this issue Mar 8, 2017 · 4 comments
Closed

babel-plugin-minify-dead-code-elimination: produces wrong code #469

jacott opened this issue Mar 8, 2017 · 4 comments
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Milestone

Comments

@jacott
Copy link

jacott commented Mar 8, 2017

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.

@hzoo
Copy link
Member

hzoo commented Mar 8, 2017

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.

@jacott
Copy link
Author

jacott commented Mar 8, 2017

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);

@boopathi boopathi added the bug Confirmed bug label Mar 18, 2017
@boopathi
Copy link
Member

bug in guarded expressions

@vigneshshanmugam
Copy link
Member

Fixed by #831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants