How feasible would a code-within-a-module re-orderer be?

Just throwing this idea out here for discussion, it’s something i myself would love, and i think maybe other people would appreciate it too if they had it but i’ve never seen anyone suggest it. It’s kind of a tooling issue (but it would probably have to be a tool that’s built on the compiler).

TL;DR - i’d like to be able to press a button and have all the declarations in a module ordered by dependency, ie in the reverse order that they appear in the generated JS code.

Why i would like this: i feel like this is self-evident but maybe not, maybe it’s just a personal preference. I want to open a module and see the exported functions / declarations first and then the functions / declarations that these exported functions use and so on. Down to orphan functions or declarations that are neither used nor exported. But when i write code, and above all when i refactor code, this ideal quickly falls away for a variety of boring contingent reasons.

I can’t help but notice that for language reasons the JavaScript has to be emitted in the form of a reverse dependency graph, ie, the exact opposite order from what i want the PureScript to be. And knowing that the graph exists at compile time makes me wonder whether there’s a path to re-ordering the source automatically.

Does this spark any interest or thoughts? I’d love to discuss further if so.

(ps it’s obviously not a trivial task because [ comments, data-definitions, coding conventions, FFI, …] )