I know this is an old question, anyway here is some attempt of mine:
https://www.mathworks.com/matlabcentral/fileexchange/182709-mstyleminify
Tested for @RodyOldenhuis cases (transpose, tricky strings) ... not heavily tested otherwise but seems to work fine so far:
PS: I'm replacing with whitespaces because in my case I'm trying to automate modifying mfiles by adding call to some extrafunction in all main-function / constructor (even if weirdly formatted) of many mfiles ... if you have some idea on that ... mtree/getcallinfo are of help but not to automatically insert code in mfiles.