JSPP
JSPP is a pre-compiler with Javascript syntax, similar in function to C's CPP. You could use JSPP for many languages but it's naturally suitable for Javascript.
When used with Javascript, JSPP adds the following functionality:
If you're writing serious Javascript and don't intend to use m4, then I suggest you take a look at these examples.
$ jspp File1.js > output.js
#include File2.js helloworld();
function helloworld() { alert("Hello world!") }
function helloworld() { alert("Hello world!") } helloworld();
$ jspp File1.js > output.js
#var debug=1; #if (debug) { function stderr(a) { alert(a) } #} else { function stderr(a) { } #} stderr('My program has started');
function stderr(a) { alert(a) } stderr('My program has started');
$ jspp File1.js > output.js
#function strlen(a) { emit(a+'.length()') } var mystr='hello'; #emit("print('mystr has length: '+"); #strlen('mystr'); ); #emit('alert("Hi world");\n'); alert("The end");
var mystr='hello'; print('mystr has length: '+mystr.length()); alert("Hi world"); alert("The end");
$ jspp File1.js > output.js
#var uses={strlen:1,atoi:1}; #include File2.js alert(atoi('4')+' = '+strlen('abcd'));
#if (uses['strlen']) { function strlen(a) { return (''+a).length } #} #if (uses['atoi']) { function atoi(a) { return parseInt(a) } #} #if (uses['atof']) { function atof(a) { return parseFloat(a) } #}
function strlen(a) { return (''+a).length } function atoi(a) { return parseInt(a) } alert(atoi('4')+' = '+strlen('abcd'));
This is not ideal for production servers but it works well enough for development.
$ chmod +x program.sh
#!/bin/sh echo "Content-type: text/javascript" echo jspp program.js
$ make
#include project//*.js
function one() {}
function two() {}
AJS=$(shell ls project/*.js) JS=project.js ${AJS} xproject.js: ${JS} jspp project.js > xproject.js
function one() {} function two() {}
Notes
JSPP is released under the GPL It is written in C It should compile on any unixy system, e.g. Linux It has not yet been ported to Windows It wants a Javascript shell installed, such as Mozilla's Spidermonkey ($ apt-get install spidermonkey-bin) Processing foreign code can't exec arbitary code (when used with Spidermonkey) You can run "$ jspp -p project.js | less" to see the Javascript it passes to the shell You can run "$ jspp -p project.js | js - | less" to see what the shell passes back
To Do: Write full documentation
You can email me at <support@[thisdomain]>
Download source code (version 0.02, 17k)