metascript
Version:
Sophisticated meta programming in JavaScript, e.g. to build different versions of a library from a single source tree.
1,016 lines (330 loc) • 13.4 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: MetaScript</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.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, filename<span class="signature-attributes">opt</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>Attributes</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">
<optional><br>
</td>
<td class="description last"><p>Source file name if known, defaults to <code>"main"</code>.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
</dd>
</div>
<h3 class="subsection-title">Members</h3>
<dl>
<dt>
<h4 class="name" id="VERSION"><span class="type-signature">(static, constant) </span>VERSION<span class="type-signature"> :string</span></h4>
</dt>
<dd>
<div class="description">
<p>MetaScript version.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line72">line 72</a>
</li></ul></dd>
</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>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line58">line 58</a>
</li></ul></dd>
</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's source.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line64">line 64</a>
</li></ul></dd>
</dl>
</dd>
<dt>
<h4 class="name" id="source"><span class="type-signature">(nullable) </span>source<span class="type-signature"> :string</span></h4>
</dt>
<dd>
<div class="description">
<p>Original source.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line52">line 52</a>
</li></ul></dd>
</dl>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<dl>
<dt>
<h4 class="name" id="compile"><span class="type-signature">(static) </span>compile<span class="signature">(source)</span><span class="type-signature"> → {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">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line79">line 79</a>
</li></ul></dd>
</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">(static) </span>transform<span class="signature">(source, filename<span class="signature-attributes">opt</span>, scope<span class="signature-attributes">non-null</span>)</span><span class="type-signature"> → {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>Attributes</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">
<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">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line219">line 219</a>
</li></ul></dd>
</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"> → {string}</span></h4>
</dt>
<dd>
<div class="description">
<p>Runs the meta program with the specified scope in the current context and returns the final document. This method
should always be invoked in a fresh or otherwise safe context, so if you do not know exactly what you are doing,
use <a href="MetaScript.html#transform">MetaScript.transform</a> instead, which always creates a fresh VM context before calling this method.</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">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="MetaScript.js.html">MetaScript.js</a>, <a href="MetaScript.js.html#line242">line 242</a>
</li></ul></dd>
</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>
<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>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Sat Aug 23 2014 00:45:26 GMT+0200 (Mitteleuropäische Sommerzeit)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>