Rewrite resolveMapping algorithm.

Now it is a top-down traversal instead of bottom-up.
It traverses all the dependencies from the output filename. All those
modules might be in that output file. The final decision is decided by
the count the module should be in that file.
Make sure some modules will be in the main.js file.

even though a module really belongs to another file, but is required by
the main file, it should be in the main file.  This solves immediate
loading of a second file in the browser