dcodeIO / Preprocessor.js

A JavaScript source file preprocessor in pure JavaScript, e.g. to build different versions of a library.
http://dcode.io
Apache License 2.0
72 stars 19 forks source link

Allow noop without preprocess #17

Closed barneycarroll closed 10 years ago

barneycarroll commented 10 years ago

The idea behind preprocess is very similar to conditional compilation, a JScript feature Microsoft shipped with IE. However, one of its core features was to:

always place conditional compilation code in comments. Consequently, hosts that do not support conditional compilation can ignore it.

Preprocessor doesn't allow this silent failure – if Preprocessor doesn't compile the code, the code intended exclusively for execution based on Preprocessor directives hidden in comments is exposed Javascript and will get executed regardless. This is especially crap for forked conditional logic, where contradictory outcomes will execute one after the other.

The way I'd like to use Preprocessor is to modify a couple of lines in my Javascript app's config if and when I compile it from the command line with certain arguments passed in. I'm wondering if my use case – call it 'noop-by-default' or 'safe-mode' – has any legs on it, or if it's just not intended usage.

Here's an example syntax for the sake of argument:

/* 
#pp
#ifdef FULL
console.log("Including extension");
#include "path/to/extension.js"
#else
console.log("Not including extension");
#endif
#endpp
*/

In the implementation above, #pp signals to capture all code up until #endpp and treat it as a separate execution context where non-pp statements are considered uncommented (where a non-pp statement is simply what's left after all #{token}{statement}'s have been matched). Of course getting this to work is another matter ;)

barneycarroll commented 10 years ago

Sorry @dcodeIO – that's really bad form of me. Right there at the top of the README! – thanks for pointing me the right way!

barneycarroll commented 10 years ago

BTW turn off issues if Preprocessor is effectively obsolete?

dcodeIO commented 10 years ago

Sorry, I unintentionally deleted my comment. Here it is again:


I am completely aware of the downsides of this library, thus decided to stop working on it in favor of MetaScript, like stated in the README:

Deprecation notice: Preprocessor.js has been deprecated in favor of MetaScript, a much more JavaScripty way for build time meta programming using JavaScript itself as the meta language. Check out the migration guide to get a quick impression of its merits.


Yeah, that's probably a good idea. Is it possible to just disable new issues instead of removing it entirely - just in case someone stumbles upon something that might be useful to him?

barneycarroll commented 10 years ago

No, I just tried it on one of my repos and it makes the whole issues interface inaccessible (and redirects /issues/ to /pulls/ for some reason, while 404ing on /issues/:issueNumber). It doesn't delete them, mind – but I suppose that's small comfort if the only way you can get back at them is by re-enabling.