UNPKG

preprocessor

Version:

Preprocessor.js: A JavaScript source file preprocessor, e.g. to build different versions of a library.

1,872 lines (560 loc) 22.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Class: Preprocessor</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="scripts/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-esoccer.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: Preprocessor</h1> <section> <header> <h2> Preprocessor </h2> <div class="class-description">Provides pre-processing of JavaScript source files, e.g. to build different versions of a library.</div> </header> <article> <div class="container-overview"> <dt> <h4 class="name" id="Preprocessor"><span class="type-signature"></span>new Preprocessor<span class="signature">(source, <span class="optional">baseDirOrIncludes</span>, preserveLineNumbers)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> Constructs a new Preprocessor. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>source</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">Source to process</td> </tr> <tr> <td class="name"><code>baseDirOrIncludes</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">Object.&lt;string,string></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Source base directory used for includes (node.js only) or an object containing all the included sources by filename. Defaults to the current working directory.</td> </tr> <tr> <td class="name"><code>preserveLineNumbers</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> </td> <td class="description last">When removing blocks of code, replace the block with blank lines so that line numbers are preserved, as long as #include is not used</td> </tr> </tbody> </table> <dl class="details"> </dl> </dd> </div> <h3 class="subsection-title">Members</h3> <dl> <dt> <h4 class="name" id="DEFINE"><span class="type-signature">&lt;static> </span>DEFINE<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> #define EXPRESSION </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="ENDIF"><span class="type-signature">&lt;static> </span>ENDIF<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> #endif/#else, #elif EXPRESSION </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="EXPR"><span class="type-signature">&lt;static> </span>EXPR<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> Definition expression </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="IF"><span class="type-signature">&lt;static> </span>IF<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> #ifdef/#ifndef SOMEDEFINE, #if EXPRESSION </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="INCLUDE"><span class="type-signature">&lt;static> </span>INCLUDE<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> #include "path/to/file". Requires node.js' "fs" module. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="PUT"><span class="type-signature">&lt;static> </span>PUT<span class="type-signature"> :RegExp</span></h4> </dt> <dd> <div class="description"> #put EXPRESSION </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="baseDir"><span class="type-signature"></span>baseDir<span class="type-signature"> :string</span></h4> </dt> <dd> <div class="description"> Source base directory. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="defines"><span class="type-signature"></span>defines<span class="type-signature"> :Array.&lt;string></span></h4> </dt> <dd> <div class="description"> Runtime defines. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="errorSourceAhead"><span class="type-signature"></span>errorSourceAhead<span class="type-signature"> :number</span></h4> </dt> <dd> <div class="description"> Error reporting source ahead length. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="includes"><span class="type-signature"></span>includes<span class="type-signature"> :Object.&lt;string, string></span></h4> </dt> <dd> <div class="description"> Included sources by filename. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="isNode"><span class="type-signature"></span>isNode<span class="type-signature"> :boolean</span></h4> </dt> <dd> <div class="description"> Whether running inside of node.js or not. </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="preserveLineNumbers"><span class="type-signature"></span>preserveLineNumbers<span class="type-signature"> :boolean</span></h4> </dt> <dd> <div class="description"> Preserve line numbers when removing blocks of code </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="source"><span class="type-signature"></span>source<span class="type-signature"> :string</span></h4> </dt> <dd> <div class="description"> Source code to pre-process. </div> <dl class="details"> </dl> </dd> </dl> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="addSlashes"><span class="type-signature">&lt;static> </span>addSlashes<span class="signature">(str)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Adds slashes to an unescaped string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>str</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Unescaped string</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> Escaped string </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="evaluate"><span class="type-signature">&lt;static> </span>evaluate<span class="signature">(runtimeDefines, inlineDefines, <span class="optional">expr</span>)</span><span class="type-signature"> &rarr; {*}</span></h4> </dt> <dd> <div class="description"> Evaluates an expression. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>runtimeDefines</code></td> <td class="type"> <span class="param-type">object.&lt;string,string></span> </td> <td class="attributes"> </td> <td class="description last">Runtime defines</td> </tr> <tr> <td class="name"><code>inlineDefines</code></td> <td class="type"> <span class="param-type">Array.&lt;string></span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">Inline defines (optional for backward compatibility)</td> </tr> <tr> <td class="name"><code>expr</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Expression to evaluate</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Throws:</h5> <div class="param-desc"> If the expression cannot be evaluated </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Error</span> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Expression result </div> <dl> <dt> Type </dt> <dd> <span class="param-type">*</span> </dd> </dl> </dd> <dt> <h4 class="name" id="indent"><span class="type-signature">&lt;static> </span>indent<span class="signature">(str, indent)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Indents a multi-line string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>str</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Multi-line string to indent</td> </tr> <tr> <td class="name"><code>indent</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Indent to use</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> Indented string </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="nlToStr"><span class="type-signature">&lt;static> </span>nlToStr<span class="signature">(str)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Transforms a string for display in error messages. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>str</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">String to transform</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="stripSlashes"><span class="type-signature">&lt;static> </span>stripSlashes<span class="signature">(str)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Strips slashes from an escaped string. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>str</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Escaped string</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> Unescaped string </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="process"><span class="type-signature"></span>process<span class="signature">(defines, <span class="optional">verbose</span>)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Preprocesses. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Argument</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>defines</code></td> <td class="type"> <span class="param-type">object.&lt;string,string></span> </td> <td class="attributes"> </td> <td class="description last">Defines</td> </tr> <tr> <td class="name"><code>verbose</code></td> <td class="type"> <span class="param-type">function(string)</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Print verbose processing information to the specified function as the first parameter. Defaults to not print debug information.</td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Throws:</h5> <div class="param-desc"> If the source cannot be pre-processed </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Error</span> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Processed source </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="toString"><span class="type-signature"></span>toString<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> Returns a string representation of this object. </div> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> String representation as of "Preprocessor" </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> </dl> </article> </section> </div> <nav> <nav-inner> <h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="Preprocessor.html">Preprocessor</a></li></ul> </nav-inner> </nav> <br clear="both"> <script> prettyPrint(); </script> </body> </html>