what about a more complex "if" ?
yairEO opened this issue · 3 comments
I have many of the lines below:
//#if _JSCC__BUNDLE_FOO || _JSCC__BUNDLE_ALL
import foo from './controllers/foo';
//#endif
//#if _JSCC__BUNDLE_BAR || _JSCC__BUNDLE_ALL
import bar from './controllers/bar';
//#endif
//#if _JSCC__BUNDLE_BAZ || _JSCC__BUNDLE_ALL
import baz from './controllers/baz';
//#endif
I use Rollup and I want the user to control if each component should or should be loaded individually or simply allow all of them to be bundled. I saw no mention of this in the WIKI.
Also, why is the //#endif
needed? can you make so if it is omitted then only the code line directly below the if
is taken into account?
Thanks!
@yairEO , currently jscc is not binded to JavaScript (has no a JS parser) and does not to know about "single-line" constructions of the source being processed, this is a forward-only tool that can be used with any text file (.md, .jsx, .txt, css, ...)
Think about this frament of a .pug file:
//#if _PUG_SAY_HI
p
= 'Hi'
the //#endif
is required and it is neccesary to keep a simple but restrictive syntax.
Regarding complexity of #if
I'm not sure if I understand, this is similar to how it is written in other languages. With this ES6 equivalent of your sample:
if (_JSCC__BUNDLE_FOO || _JSCC__BUNDLE_ALL) {
import foo from './controllers/foo';
}
if (_JSCC__BUNDLE_BAR || _JSCC__BUNDLE_ALL) {
import bar from './controllers/bar';
}
if (_JSCC__BUNDLE_BAZ || _JSCC__BUNDLE_ALL) {
import baz from './controllers/baz';
}
...I do not see another way to simplify the conditionals by JSCC, although in this particular case _JSCC__BUNDLE_ALL
could not be necessary if you use:
//#set _JSCC_BUNDLE_ALL = 0
//#set _JSCC__BUNDLE_FOO = _JSCC_BUNDLE_ALL || 1
//#set _JSCC__BUNDLE_BAR = _JSCC_BUNDLE_ALL || 0
//#set _JSCC__BUNDLE_BAZ = _JSCC_BUNDLE_ALL || 0
I hope the answer help.
yes thank you