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

evaluate incorrectly evaluates variables to undefined #897

Open
mvanderlee opened this issue Aug 28, 2018 · 1 comment
Open

evaluate incorrectly evaluates variables to undefined #897

mvanderlee opened this issue Aug 28, 2018 · 1 comment
Labels
bug Confirmed bug

Comments

@mvanderlee
Copy link

Describe the bug
When minifying angularjs I ran into an issue where valid variables were defined to undefined, and then void 0

To Reproduce

 function ngOptionsPostLink(scope, selectElement, attr, ctrls)
 {
     // if ngModel is not defined, we don't need to do anything
     var ngModelCtrl = ctrls[1];
     if (!ngModelCtrl) return;

     var selectCtrl = ctrls[0];
     var multiple = attr.multiple;

     // The emptyOption allows the application developer to provide their own custom "empty"
     // option when the viewValue does not match any of the option values.
     var emptyOption;
     for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++)
     {
         if (children[i].value === '')
         {
             emptyOption = children.eq(i);
             break;
         }
     }
    return emptyOption;
 }

Actual Output

function ngOptionsPostLink(scope, selectElement, attr, ctrls)
{
    var ngModelCtrl = ctrls[1];
    if (ngModelCtrl)
        for (var selectCtrl = ctrls[0], multiple = attr.multiple, i = 0, children = selectElement.children(), ii = (void 0).length; void 0 > i; i++)
            if ('' === (void 0)[i].value)
            {
                (void 0).eq(i);
                break
            }
        return emptyOption
}

Expected Output

function ngOptionsPostLink(scope, selectElement, attr, ctrls)
{
    var ngModelCtrl = ctrls[1];
    if (ngModelCtrl)
    {
        for (var emptyOption, selectCtrl = ctrls[0], multiple = attr.multiple, i = 0, children = selectElement.children(), ii = children.length; i < ii; i++)
            if ('' === children[i].value)
            {
                emptyOption = children.eq(i);
                break
            }
        return emptyOption
    }
}

Configuration
7.0.0 (@babel/core 7.0.0)
Babel cli and via grunt.

{
  "presets": [
    ["minify", {
      "builtIns": false,
      "mangle": false,
      "removeConsole": true,
      "removeDebugger": true,
      "evaluate": true
    }]  
  ]
}
@vigneshshanmugam vigneshshanmugam added the bug Confirmed bug label Sep 25, 2018
@attatrol
Copy link

attatrol commented Nov 8, 2018

I figured out that the error occures only when both plugins transform-merge-sibling-variables and minify-constant-folding are enabled.

Currently i use workaround that forces minify-constant-folding to run before transform-merge-sibling-variables:

{
  "presets": [
    ["minify", {
      "evaluate": false
    }]  
  ],
  "plugins": [
    ["minify-constant-folding"]
  ]
}

However i'm not sure if the plugins used in minify preset could be rearranged in arbitrary order. In general case plugin order matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants