blockly > CodeGenerator > forBlock

CodeGenerator.forBlock property

A dictionary of block generator functions, keyed by block type. Each block generator function takes two parameters:

  • the Block to generate code for, and - the calling CodeGenerator (or subclass) instance, so the function can call methods defined below (e.g. blockToCode) or on the relevant subclass (e.g. JavascripGenerator),

and returns:

  • a [code, precedence] tuple (for value/expression blocks), or - a string containing the generated code (for statement blocks), or - null if no code should be emitted for block.

Signature:

forBlock: Record<string, (block: Block, generator: this) => [string, number] | string | null>;