Skip to content

Commit

Permalink
Override toString in case this function is printed (#10949)
Browse files Browse the repository at this point in the history
* Override toString in case this function is printed

Related to https://stackoverflow.com/questions/59543968/unexpected-return-value-from-visitor-method

* Don't override `toString` if `wrapper` is true

Override `toString` immediately before returning a newFn, otherwise it will be overridden if wrapper is true

#10949 (comment)

* prettier
  • Loading branch information
jayenashar authored and nicolo-ribaudo committed Jan 1, 2020
1 parent 26eb891 commit daaa206
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-traverse/src/visitors.js
Expand Up @@ -227,6 +227,11 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper: ?Function) {
newFn = wrapper(state.key, key, newFn);
}

// Override toString in case this function is printed, we want to print the wrapped function, same as we do in `wrapCheck`
if (newFn !== fn) {
newFn.toString = () => fn.toString();
}

return newFn;
});

Expand Down

0 comments on commit daaa206

Please sign in to comment.