speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
843 stars 90 forks source link

Property left of ForInStatement expected node to be of a type ["VariableDeclaration","LVal"] but instead got "CallExpression" #184

Closed mikesherov closed 7 years ago

mikesherov commented 7 years ago

Got the following error during transpilation:

Property left of ForInStatement expected node to be of a type ["VariableDeclaration","LVal"] but instead got "CallExpression"

for the following code:

'use strict';

var eventmap = [];
var eventname = '';
var ron = /^on/;

for (eventname in global) {
  if (ron.test(eventname)) {
    eventmap.push(eventname.slice(2));
  }
}

module.exports = eventmap;

changing to:

'use strict';

var eventmap = [];
var ron = /^on/;

for (var eventname in global) {
  if (ron.test(eventname)) {
    eventmap.push(eventname.slice(2));
  }
}

module.exports = eventmap;

produces no errors.

Might be related to #173

I'll have a PR with tests shortly, but wanted to report the issue here first. Thanks again for your work on this excellent plugin!

speedskater commented 7 years ago

@mikesherov Thank you for providing the fix. It is incorporated into babel-plugin-rewire 1.1.0. I also added you to the list of contributors on the github page.