Skip to content
amarcruz edited this page Sep 7, 2016 · 8 revisions

#set <varname> [=] <expression>

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.

#unset <varname>

Undefines a jscc variable.

#if <expression>

Includes the block that follows if <expression> is not falsy.

You can nest multiple #if.. blocks.

#elif <expression>

It will be evaluated if the previous #if was falsy.

You can have multiple #elif blocks.

#else

Includes the block that follows, if the previous #if/#elif expressions were falsy.

#endif

Closes the #if... block.

#ifset <varname>

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.

#ifnset

Test the nonexistence of a jscc variable.

Variable names

Use '__' followed by one or more digits or uppercase letters.

Variable substitution

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

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.

Clone this wiki locally