Node.js has its own require system. It's called CommonJS. I was thinking that it could also be based on imported classes. It can be a little tricky, though. A module is pretty flexible with what it exports. Most simply, a module could export a single class. In this case, the translation is pretty simple:
//as import SomeClass; //js var SomeClass = require("SomeClass"); However, a module could export multiple classes or even functions too, more like an ActionScript package. It might work something like this: //as import fs.readFileSync; //function import fs.ReadStream; //class //js var readFileSync = require("fs").readFileSync; var ReadStream = require("fs").ReadStream; That's for the core modules. You can also require() modules using a relative path. If we were to allow the ability to emit classes as CommonJS modules, we might use the following syntax. In a class in the top-level package, it might look like this: //as import com.example.RelativeClass; //js var RelativeClass = require("./com/example/RelativeClass"); But for something in com/example, it would look like this: //as import com.example.RelativeClass; //js var RelativeClass = require("./RelativeClass"); - Josh On Wed, Dec 2, 2015 at 10:14 AM, Alex Harui <aha...@adobe.com> wrote: > > > On 12/2/15, 9:59 AM, "Josh Tynjala" <joshtynj...@gmail.com> wrote: > > >The require() call for a Node.js module should probably be generated in > >the > >PackageHeaderEmitter, where the goog.require() calls are generated. > > OK, but based on what kind of source code lines? The goog.requires are > generated from import statements, although we might change that to being > generated by explicit instantiation of a class someday. > > I think you are saying you want to replace the goog.require subsystem with > some other require subsystem in order to get node.js to work. Is node.js > using RequireJS or their own require system? The work item may be to > finally getting around to supporting alternative require subsystems. > > -Alex > >