JS Pragma compiler directives

Allows you to refactor your code beyond the usual level for js. It's specific usages are for testing and benchmarking. You can take snippets of scripts out of their usual context and put them in their own function. For the production code, you compile the directives out and you're left with a regular script.

The ifdef also allows you to create multiple versions of the same code, using constants and macros.

As the compile script demonstrates, the original script with directives can be used perfectly fine.

Supported directives: (Click here to expand...)

//#define SOME_DEFINE

//#ifdef SOME_DEFINE

//#ifndef SOME_DEFINE

//#macro SOME_VALUE 5

.. code

var f = function(){ // (this line is discarded)
  ... function body
return s; }; // (this line is discarded)

Give it a spin. The compiler itself actually uses these directives.

inline function inline macro define ifdef ifndef

Output with syntax highlighting

© Peter van der Zee, December 2010, pvdz.ee
Remember; only a proof of concept :)