Skip to content

Instantly share code, notes, and snippets.

@ralt
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralt/d1e07c3c77813383734b to your computer and use it in GitHub Desktop.
Save ralt/d1e07c3c77813383734b to your computer and use it in GitHub Desktop.
cpp preprocessor for JS source
/*
$ cpp -P -nostdinc test.js bundle.js
# OR
$ cpp -P -nostdinc test.js
# To give parameters, use -D, like this:
$ cpp -P -nostdinc -D DEV test.js
# For source code like this:
*/
#if defined DEV
#define ASSERT(x) console.assert(x)
#else
#define ASSERT(x)
#endif
#define SOME_CONST 5
var Promise = require('bluebird');
ASSERT(1 === 1);
Promise.cast([1, 2, 3, SOME_CONST]).reduce(function(_, i) {
console.log('Launching ' + i);
return Promise.delay(Math.floor(Math.random() * 1000)).then(function() {
console.log('Executing ' + i);
});
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment