question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support conditional compilation

See original GitHub issue

On codeplex this was a popular feature request:

https://typescript.codeplex.com/workitem/111 https://typescript.codeplex.com/workitem/1926

Personally I think preprocessor directives like #if, #elif, #else #endif with possibility to specify symbol to compiler would be very useful. And a way to mark function (or ambient function declaration) as Conditional (something like ConditionalAattribute in C#) would be great improvement too. I have lot’s of console.log like function calls that decrease performance of my application and ability to easily remove all calls to this function would be great.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:89
  • Comments:82 (25 by maintainers)

github_iconTop GitHub Comments

28reactions
NoelAbrahamscommented, Aug 24, 2014

Some use-cases:

  • Variable defintion
// Production sources and keys        
   var foo = {
        root: "https://yyy.blob.core.foobar.net/",
        googlePlusKey: { id: "888888", key: "GIzdfBy" },
        facebookKey: { id: "444444444" }
     };

// Development sources and keys        
#if(DEBUG)
   var foo = {
        root: "https://xxx.blob.core.foobar.net/",
        googlePlusKey: { id: "458588", key: "BIzdfGy" },
        facebookKey: { id: "123219585123132" }
     };
#endif
  • Import statement
#if(DEBUG)
       import foo = require('debug');
#else
       import foo = require('release');
#endif

function doFoo(){
    foo.someMethod();
}
  • Class definition
#if(DEBUG)
       class Foo { doFoo(){ console.log('debug'); }  }
#else
       class Foo { doFoo(){ console.log('release'); }  }
#endif

var foo = new Foo();
10reactions
oliverjanikcommented, Mar 19, 2018

Here’s our use case. This feature would greatly simplify our lives.

We have a common code-base targeting the browsers and Cordova hybrid apps. Parts of our code base only deal with one or the other.

We would love if we could leave certain parts out for different builds. They also pull in different dependencies. So when building for the web we have to pull in Cordova dependencies otherwise TS complains about missing types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding conditional compilation (VBA) - Microsoft Learn
Use conditional compilation to run blocks of code selectively, for example, debugging statements comparing the speed of different approaches ...
Read more >
Conditional compilation - Wikipedia
In computer programming, conditional compilation is a compilation technique which results in ... Many programming languages support conditional compilation.
Read more >
3.3.4 Conditional Compilation
The third useful facility provided by the preprocessor is conditional compilation; i.e. the selection of lines of source code to be compiled and...
Read more >
Conditional inclusion - cppreference.com
The preprocessor supports conditional compilation of parts of source file. This behavior is controlled by #if , #else , #elif , #ifdef ...
Read more >
Conditional compilation (Delphi) - RAD Studio
Category Symbol DCC32 DCC64 Since XE2 DCCOSX Since XE2 DCCOSX64 Sin... Compiler DCC DEFINED DEFINED DEFINED DEFINED Platform CONSOLE DEFINED DEFINED DEFINED DEFINED Platform IOS not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found