Note that there are some explanatory texts on larger screens.

plurals
  1. POlightweight javascript to javascript parser
    text
    copied!<p>How would I go about writing a lightweight javascript to javascript parser. Something simple that can convert some snippets of code.</p> <p>I would like to basically make the internal scope objects in functions public.</p> <p>So something like this</p> <pre><code>var outer = 42; window.addEventListener('load', function() { var inner = 42; function magic() { var in_magic = inner + outer; console.log(in_magic); } magic(); }, false); </code></pre> <p>Would compile to</p> <pre><code>__Scope__.set('outer', 42); __Scope__.set('console', console); window.addEventListener('load', constructScopeWrapper(__Scope__, function(__Scope__) { __Scope__.set('inner', 42); __Scope__.set('magic',constructScopeWrapper(__Scope__, function _magic(__Scope__) { __Scope__.set('in_magic', __Scope__.get('inner') + __Scope__.get('outer')); __Scope__.get('console').log(__Scope__.get('in_magic')); })); __Scope__.get('magic')(); }), false); </code></pre> <p><a href="http://jsfiddle.net/pPnLf/11/" rel="nofollow">Demonstation Example</a></p> <p>Motivation behind this is to serialize the state of functions and closures and keep them synchronized across different machines (client, server, multiple servers). For this I would need a representation of <code>[[Scope]]</code></p> <p><strong>Questions:</strong></p> <ol> <li>Can I do this kind of compiler without writing a full JavaScript -> (slightly different) JavaScript compiler?</li> <li>How would I go about writing such a compiler?</li> <li>Can I re-use existing js -> js compilers?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload