Class ProcessCommonJSModules

java.lang.Object
com.google.javascript.jscomp.ProcessCommonJSModules
All Implemented Interfaces:
CompilerPass

public class ProcessCommonJSModules extends Object implements CompilerPass
Rewrites a CommonJS module http://wiki.commonjs.org/wiki/Modules/1.1.1 into a form that can be safely concatenated. Does not add a function around the module body but instead adds suffixes to global variables to avoid conflicts. Calls to require are changed to reference the required module directly. goog.provide and goog.require are emitted for closure compiler automatic ordering.
  • Field Details

  • Method Details

    • process

      public void process(Node externs, Node root)
      Description copied from interface: CompilerPass
      Process the JS with root node root. Can modify the contents of each Node tree
      Specified by:
      process in interface CompilerPass
      Parameters:
      externs - Top of external JS tree
      root - Top of JS tree
    • toModuleName

      public static String toModuleName(String filename)
      Turns a filename into a JS identifier that is used for moduleNames in rewritten code. Removes leading ./, replaces / with $, removes trailing .js and replaces - with _. All moduleNames get a "module$" prefix.
    • toModuleName

      public static String toModuleName(String requiredFilename, String currentFilename)
      Turn a filename into a moduleName with support for relative addressing with ./ and ../ based on currentFilename;