simple if statement does not behave as expected
spikyjt opened this issue · comments
If I set a variable to true
in the config, a simple evaluation does not appear to work.
e.g. in options:
{
DEBUG: true
}
in code:
let mode = 'production';
/// #if DEBUG
mode = 'debug';
/// #endif
console.log(mode);
In this scenario, mode
is 'production', not 'debug' as expected. I had to use:
/// #if DEBUG === true
to get this to work as expected. (Triple equals is probably not necessary). The documentation suggests that DEBUG
just needs to be a truthy value for this to work as expected, without an explicit evaluation.
A further test indicates that ===
is in fact required.
that's strange because the evaluating function is built to work with thruty values:
const code = `return (${condition}) ? true : false;`;
(see line 199)
which results in:
return (DEBUG) ? true : false;
Indeed it is strange. I did wonder if it had to do with caching, so deleted node_modules/.cache
in between builds, but no change.
I'm using Typescript in Vue.js from vue-cli 3.
The behaviour I get is that if I just use #if VAR
the code is never included, whatever the value of VAR
. If I use #if VAR == true
the code is always included, even if VAR is false or null. If I use #if VAR === true
the code is included when true and not when false.
Sorry, it was a problem with caching.