-
Notifications
You must be signed in to change notification settings - Fork 9
Syntax
Defines, or redefines, a jscc (compile-time) variable. You can use raw values or expressions.
If you don't specify a value, the variable is set to the undefined
value.
Undefines a jscc variable.
Includes the block that follows if <expression>
is not falsy.
You can nest multiple #if..
blocks.
It will be evaluated if the previous #if
was falsy.
You can have multiple #elif
blocks.
Includes the block that follows, if the previous #if/#elif
expressions were falsy.
Closes the #if...
block.
Test the existence of a jscc variable, even if its value is undefined
.
The returned value is a boolean
, its behavior is the same as #if/#elif
.
Test the nonexistence of a jscc variable.
Use '__'
followed by one or more digits or uppercase letters.
Prefix the name of the variable to be replaced with '$'
.
Inexistent variables are not replaced, nor property identifiers.
Example:
//#set __FOO 'foo'
let bar = '$__FOO'.toUpperCase() // bar = 'FOO'
let baz = { $__FOO: 'bar' } // baz = { foo: 'bar' }
console.log('$__FOO') // print 'foo'
console.log(baz['$__FOO']) // print 'bar'
console.log(baz.$__FOO) // ERROR: property-like names are not replaced!
Expressions in jscc are simple JavaScript and has simple rules:
- Expressions are evaluated in the context of the jscc variables.
- Non-defined variables are replaced with
undefined
. - Varnames inside quotes or regexes are not evaluated.
- Expressions are not transpiled.
You don't need prefix the varnames with this
as jscc does it for you and if a variable is not in this
but exists in the global
object (at compile-time), that is used.
Example:
//#set __FOO = ('foo' + 'bar').toUpperCase()
//#set __BAR = __FOO === 'FOOBAR' ? 'Yes' : 'No'
//#set __BAZ = '__BAR'
console.log('$__BAR') // print `yes`
console.log('$__BAZ') // print `__BAR`
Please avoid comments in expressions.