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>;
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[null,null,["Last updated 2024-09-18 UTC."],[[["`CodeGenerator.forBlock` is a dictionary that stores functions for generating code from Blockly blocks, organized by block type."],["Each function within `CodeGenerator.forBlock` takes a Block and a CodeGenerator instance as input, using them to produce the corresponding code."],["These functions return a code-precedence tuple for expressions, a string for statements, or null if no code generation is needed."]]],[]]