UNPKG

metascript

Version:

Sophisticated meta programming in JavaScript, e.g. to build different versions of a library from a single source tree.

864 lines (270 loc) 10.9 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Class: MetaScript</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: MetaScript</h1> <section> <header> <h2> MetaScript </h2> </header> <article> <div class="container-overview"> <dt> <h4 class="name" id="MetaScript"><span class="type-signature"></span>new MetaScript<span class="signature">(sourceOrProgram, <span class="optional">filename</span>)</span><span class="type-signature"></span></h4> </dt> <dd> <div class="description"> <p>Constructs a new MetaScript instance.</p> </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>sourceOrProgram</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last"><p>Source to compile or meta program to run</p></td> </tr> <tr> <td class="name"><code>filename</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>Source file name if known, defaults to <code>&quot;main&quot;</code>.</p></td> </tr> </tbody> </table> <dl class="details"> </dl> </dd> </div> <h3 class="subsection-title">Members</h3> <dl> <dt> <h4 class="name" id="VERSION"><span class="type-signature">&lt;static, constant> </span>VERSION<span class="type-signature"> :string</span></h4> </dt> <dd> <div class="description"> <p>MetaScript version.</p> </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="filename"><span class="type-signature"></span>filename<span class="type-signature"> :string</span></h4> </dt> <dd> <div class="description"> <p>Original source file name.</p> </div> <dl class="details"> </dl> </dd> <dt> <h4 class="name" id="program"><span class="type-signature"></span>program<span class="type-signature"> :string</span></h4> </dt> <dd> <div class="description"> <p>The compiled meta program&#39;s source.</p> </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"> <p>Original source.</p> </div> <dl class="details"> </dl> </dd> </dl> <h3 class="subsection-title">Methods</h3> <dl> <dt> <h4 class="name" id="compile"><span class="type-signature">&lt;static> </span>compile<span class="signature">(source)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> <p>Compiles the specified source to a meta program and returns its source.</p> </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>source</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Source</p></td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Meta program</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="transform"><span class="type-signature">&lt;static> </span>transform<span class="signature">(source, <span class="optional">filename</span>, scope)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> <p>Compiles the source to a meta program and transforms it using the specified scope in a new VM context.</p> </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"><p>Source</p></td> </tr> <tr> <td class="name"><code>filename</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>Source file name</p></td> </tr> <tr> <td class="name"><code>scope</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> </td> <td class="description last"><p>Scope</p></td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Transformed source</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </dd> <dt> <h4 class="name" id="transform"><span class="type-signature"></span>transform<span class="signature">(scope)</span><span class="type-signature"> &rarr; {string}</span></h4> </dt> <dd> <div class="description"> <p>Transforms the meta program.</p> </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>scope</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Scope</p></td> </tr> </tbody> </table> <dl class="details"> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Transformed source</p> </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="MetaScript.html">MetaScript</a></li></ul><h3>Global</h3><ul><li><a href="global.html#dirname">dirname</a></li><li><a href="global.html#escapestr">escapestr</a></li><li><a href="global.html#include">include</a></li><li><a href="global.html#indent">indent</a></li><li><a href="global.html#write">write</a></li><li><a href="global.html#writeln">writeln</a></li></ul> </nav-inner> </nav> <br clear="both"> <script> prettyPrint(); </script> </body> </html>