massimiliano-mantione/metascript — pull request #39 by drslump (2014-06-15 12:36:09+00:00)
Title: generate verbatim javascript code

Some times it might be needed (or just helpful) to generate arbitrary javascript code. Right now we can use `eval` which gets the job done but it's too powerful and must be used with caution. This change enables verbatim output on escodegen and applies it only to calls for now, so that it's possible to annotate a call expression with some javascript code to be used at codegen.

There is also a simple macro `js` that serves as a safer replacement for `eval` (which is no longer a default external declaration). If the argument is a literal it will be used verbatim at codegen, otherwise it wraps the argument in a call to `eval` so that it can be resolved at runtime.

```js
var foo = () =>
assert this != js'this'
```

Note that when using `js` the developer is responsible for using it appropriately when including javascript statements, otherwise bad things can happen:

```js
var foo = js'10; 20' // `var foo = (10; 20)` which produces a javascript error
var foo = (#external eval) '10; 20' // `var foo = eval('10; 20')` hence foo === 20
```

The principal use for this is to be able to optimize tight loops in an application if for whatever reason the metascript codegen introduces some unneeded overhead for that specific use case. Another important use case I'm playing with is how to handle runtime helper functions in macros, where this will provide an easy way to *embed* supporting javascript code in the generated file.