SitePen / dojo-amd-converter

A legacy dojo to AMD conversion utility.
Other
11 stars 5 forks source link

Handle conversion of modules that were not required #32

Open rmaccracken opened 11 years ago

rmaccracken commented 11 years ago

I'm not sure if this is already handled or not, but we had many cases where modules that were used in a file were not required in that file. We knew they were already required by the main app, so we just left them out. It would be nice if this conversion tool could fix such cases.

Take the following example:

dojo.provide("A.B"); dojo.require("A.C"); dojo.declare("A.B", A.C, { foo: function() { return A.D.bar(); } });

So the question now is will A.D be converted properly? In our AMD conversion tool, we had a configuration file that included 3 columns:

  1. Old module - "A.D"
  2. Module ID - "A/D"
  3. Local variable name - "D"

This allowed the conversion tool to output the following:

require(["dojo/_base/declare","A/C","A/D"], function(declare,C,D) { return declare(C, { foo: function() { return D.bar(); } } });

neonstalwart commented 11 years ago

do you mean a module like https://github.com/SitePen/dojo-amd-converter/blob/master/tests/test4.js

rmaccracken commented 11 years ago

Yes - if that is already working, then great. I guess I should have studied the examples a bit closer.

Is the logic such that it will find any references to global objects in the file (A.D.bar) and then see if it can find a corresponding file? In this case, it would look for "A/D/bar", and if it couldn't find such a file, then it would look for "A/D", and finally "A"?