Class ProcessCommonJSModules

  • All Implemented Interfaces:
    CompilerPass

    public class ProcessCommonJSModules
    extends java.lang.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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void process​(Node externs, Node root)
      Process the JS with root node root.
      static java.lang.String toModuleName​(java.lang.String filename)
      Turns a filename into a JS identifier that is used for moduleNames in rewritten code.
      static java.lang.String toModuleName​(java.lang.String requiredFilename, java.lang.String currentFilename)
      Turn a filename into a moduleName with support for relative addressing with ./ and ../ based on currentFilename;
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_FILENAME_PREFIX

        public static final java.lang.String DEFAULT_FILENAME_PREFIX
        See Also:
        Constant Field Values
    • Method Detail

      • 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 java.lang.String toModuleName​(java.lang.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 java.lang.String toModuleName​(java.lang.String requiredFilename,
                                                    java.lang.String currentFilename)
        Turn a filename into a moduleName with support for relative addressing with ./ and ../ based on currentFilename;