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
//#endif

//#ifndef SOME_DEFINE
//#endifn

//#macro SOME_VALUE 5

//#inline MY_MULTILINE_MACRO
.. code
//#endline

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

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, qfox.nl
Remember; only a proof of concept :)