Override toString in case this function is printed (#10949)

* 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

https://github.com/babel/babel/pull/10949#discussion_r362302625

* prettier
This commit is contained in:
Jayen Ashar 2020-01-02 01:36:20 +11:00 committed by Nicolò Ribaudo
parent 26eb891870
commit daaa2063bb

View File

@ -227,6 +227,11 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper: ?Function) {
newFn = wrapper(state.key, key, newFn); 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; return newFn;
}); });