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

Rename wrongly in switch/case statement #194

Open
tmhao2005 opened this issue Apr 15, 2020 · 0 comments
Open

Rename wrongly in switch/case statement #194

tmhao2005 opened this issue Apr 15, 2020 · 0 comments

Comments

@tmhao2005
Copy link

tmhao2005 commented Apr 15, 2020

I just found out an issue regarding the option "removeImport": true like I got a following snippet function:

function foo(arg, list) {
    switch (arg) {
      case 0: {
        const item = arg.payload;
        return list.some(_item => _item.id === item.id);
      };
      case 1: {
        const item = arg.payload;
        return list.some(_item => _item.id === item.id);
      }
    }    
  }

the results after compile with es5 mode:

function foo(arg, list) {
            switch (arg) {
              case 0:
                {
                  var item = arg.payload;
                  return list.some(function (_item) {
                    return _item.id === item.id;
                  });
                }
                ;
      
              case 1:
                {
                  var _item = arg.payload;
                  return list.some(function (_item) {
                   /* BUG HERE: it renamed wrongly here 2 vars with same name  */
                   return _item.id === _item.id;
                  });
                }
            }
          }

The issue is at the case 1 where it renames 2 vars with the name name _item in 2 scopes that creating bug.

Seems reprocess the scope causes the issue here:

programPath.scope.crawl()

https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types/blob/master/src/index.js#L364

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

No branches or pull requests

1 participant