Package com.google.javascript.jscomp

# 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 Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_FILENAME_PREFIX`

## Method Summary

Modifier and Type
Method
Description
`void`
`process(Node externs, Node root)`
Process the JS with root node root.
`static String`
`toModuleName(String filename)`
Turns a filename into a JS identifier that is used for moduleNames in rewritten code.
`static String`
`toModuleName(String requiredFilename, 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 Details

### DEFAULT_FILENAME_PREFIX

public static final String DEFAULT_FILENAME_PREFIX

See Also:
  - Constant Field Values

## 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;