Closed tech-meppem closed 2 years ago
Nested if
s is indeed a basic feature in the preprocessor from other languages. Since the need of the whole preprocessor thing is pretty rare in vanilla javascript, the preprocessor loader is intended to be as simple as possible. That is why it lacks such features.
@tech-meppem Just curious, under what tricky circumstances you need such a complex nested condition?
Anyway, I am planing to implement the feature.
@afterwind-io We build some of our frontend files differently for different units / devices. For example, lets say I have devices A, B and C. I was trying to do something like:
#!if A || C
// large block of code that's the same for A & C
#!if A
//specific to A
#!elseif C
//specific to C
#!endif
// large block of code that's the same for A & C
#!endif
And we were getting the problem that the second "large block of code" also appeared for B, because both if
s end at the first endif
Implemented in v1.2.0
Implemented in v1.2.0
Thanks! We'll try it out soon.
Nesting #!if statements in other #!if statements doesn't resolve how you would expect it to.
Having a param such as
debug
set totrue
, and then doing the following:You would expect it to output
console.log("world")
, however,console.log("hello")
is produced. Changing the first line to// #!if !debug
doesn't change the output either, even though you would then expect neither line to exist.Also, having something like this:
debug
is true, so the expected output would be for the whole block to excluded. However, both#!if
statements terminate at the first#!endif
, and so regardless of the value ofdebug
,console.log("world")
is always outputted.Tested on
webpack-preprocessor-loader@1.1.4
&webpack@5.68.0