nippur72 / ifdef-loader

Webpack loader for JavaScript/TypeScript conditional compilation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Add support for #elif

GWigWam opened this issue · comments

Add support for an #elif operator (similar to C's #elif preprocessor)

Currently one might write:

/// #if Version == 1
console.log('v1');
/// #endif
/// #if Version == 2
console.log('v2');
/// #endif
/* This cannot be replaced with #else because it would also trigger if Version == 1: */
/// #if Version != 1 && Version != 2
console.log('other version');
/// #endif

Or:

/// #if Version == 1
console.log('v1');
/// #else
///   #if Version == 2
console.log('v2');
///   #else
console.log('other version');
///   #endif
/// #endif

This would become:

/// #if Version == 1
console.log('v1');
/// #elif Version == 2
console.log('v2');
/// #else 
console.log('other version');
/// #endif

It's a bit shorter, and in my opinion much more readable.

Change would be non-breaking.

If you are interested in this feature and are still maintaining this package and repo please let me know. I can probably implement this feature and create a pull request within the coming 1 or 2 weeks.

I don't think much about it these days, but sure, if you implement it I'll merge the PR :-)

Be warned that the source is not easy to extend because it was written in hurry, not thinking it would get published oneday. It's rather brutal the way it parses lines.

I've merged it and published in the npm registry. Thank you!

Happy to help, was a fun little project to work on.

Thank you for the quick responses!