Both Closure Compiler and UglifyJS has something called defines which allow you to override the value of a variable using a command line parameter. Combining this with their dead code removal and you have a preprocessor tool similar to #ifdefs.
https://github.com/mishoo/UglifyJS2#conditional-compilation https://developers.google.com/closure/compiler/docs/js-for-compiler (search for @define) On Nov 28, 2013 5:25 AM, "David Bruant" <[email protected]> wrote: > > Le 28/11/2013 09:59, Brandon Andrews a écrit : >> >> Lately I've been writing very processor heavy Javascript. I feel like it >> could benefit a lot from having a syntax feature for removing debug >> statements. Obviously JS is interpreted and not compiled, so I'm not sure if >> this sounds completely unrealistic, but it has some very useful scenarios. >> >> I like to write verbose type checking for functions to check ranges and >> throw exceptions if invalid input is detected. The issue is in a production >> environment (especially with games) the code executes too slowly with all >> the extra branches. It would be nice if there was a simple syntax to treat >> code as if it's commented out when a flag is set. > > Does this need to be part of JavaScript (and be implemented in web browsers)? > From what I understand, what you're describing is purely a development time > concern and not a (production) runtime concern, so I feel the solution should > be found in better development tooling. > > Good news! Olov Lassus already worked on something like this! > http://blog.lassus.se/2011/03/c-style-assertions-in-javascript-via.html > https://www.youtube.com/watch?v=yk6t4kRN53w > > I haven't looked at it too much, but it might be possible to do assertions > (that run in dev, but not in prod) with Sweet.js [1] macros. Potentially > that's something that could be part of TypeScript too (I haven't seen an > issue on this topic or in the roadmap, but maybe that's an addition they'd be > open to do?). > > JavaScript isn't compiled, but we can build tools that do compile to JS > without requiring support from the browser. > > David > > [1] http://sweetjs.org/ > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

