Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional compilation #1503

Closed
gissehel opened this issue Jul 11, 2011 · 6 comments
Closed

Conditional compilation #1503

gissehel opened this issue Jul 11, 2011 · 6 comments

Comments

@gissehel
Copy link

This is an enhancement I would like to see on coffee-script.

I have two profiles Development/Production (or call them Debug/Release). In Development/Debug profile, I'm including directly the coffee script into the html page (as well as less css code). In Production/Release, I'm including javascript and css generated once.

What I would like is a way to include some javascript code lines only in development/debug profile, and not even use a "if" at run time. something like :

firstcall()
[DEBUG]console.log "firstcall has been called"
secondcall()

that would compile to :

firstcall();
console.log("firstcall has been called");
secondcall();

in "DEBUG" profile (with "DEBUG" beeing "defined" at compile time)
and compile to :

firstcall();
secondcall();

"DEBUG" could then be passed as option in the script tag as well as a parameter on the command line.

the syntax [DEBUG] is just an example and could be @@debug@@ or %DEBUG% I don't really care.

Of course, writing :

firstcall()
if DEBUG
    console.log "firstcall has been called"
secondcall()

could achieve the same goal, except I don't want the "if" to be executed at run time.

@jashkenas
Copy link
Owner

Thanks for the ticket, but I'm afraid we won't be adding conditional compilation to CoffeeScript. Feel free to strip stuff out of your codebase before compiling, if you like.

@davispuh
Copy link

why not? I think it would be really great feature, besides it wouldn't matter to those who wouldn't use it...

I think easiest way making it would be exactly like it is in C (adding preprocessor support #1466)

#ifndef release
#define debug true
#endif

#ifdef debug
console.log "Debug info..."
#endif

(where #define variable could be given with compiler flag eg. coffee -d release=true -c -o lib/ src/)

using C style preprocessor wouldn't make any incompatibilities with older compilers as # is comment and it would be ignored (obvious blocks inside #ifdef's would always be included...)

preprocessor/macro is really MUST HAVE feature which could be used in really a lot of ways. Also it doesn't really matter if other syntax is used, but there need one. And always can rework/rewrite if something was done incorrectly.

@ajrouvoet
Copy link

+1

@loveencounterflow
Copy link

@davispuh i sincerely hope you do not mean to suggest introducing C-style preprocessor macros into CS. they're full of edge cases and pitfalls. if what you mean to say is "i want to have syntactic macros in CS" then +1.

@vendethiel
Copy link
Collaborator

@loveencounterflow Seen BlackCoffee ?

@loveencounterflow
Copy link

yes, and sadly, i can't extend the syntax of CS with BC...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants