MithrilJS / mithril-codemods

jscodeshift-powered mithril@0.2.x to mithril@1.x transformations
MIT License
19 stars 4 forks source link

Functions within the view that accept the controller and state get transformed oddly with unsafe transforms. #19

Closed AGoblinKing closed 7 years ago

AGoblinKing commented 7 years ago

Original Source

function foo(ctrl, options) {

}

const comp = {
   view(ctrl, options) {
      return foo(ctrl, options);
   }
};

Tool Output

function foo(vnode) {

}

const comp = {
   view(vnode) {
       return foo(vnode.state, vnode.attrs);
   }
};

Expected Output

function foo(state) {

}

const comp = {
   view(vnode) {
      return foo(vnode.state);
   }
};
AGoblinKing commented 7 years ago

This could have been from one of my state properties being named focus.

tivac commented 7 years ago

The change to foo in your expected output confuses me. As far as I can tell function foo(ctrl, options) should've been left alone and the rest of the transform is correct.

It probably got swept up in the view-detecting code since I try to be aggressive about finding functions that accept ctrl, options as params and rewriting them. View functions live all over the place, sadly.

tivac commented 7 years ago

Not much I can do about this.