mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
feat!: Throw errors on missing inputs (#7969)
Previously generators could generate code from inputs that didn't exist and get back the empty string. This silent failure was causing problems for diagnosing issues. This PR changes the behaviour so that an error is thrown. This will break generators which rely on the previous behaviour. Several of our demo blocks needed editing to accomodate this change. Resolves #7665
This commit is contained in:
@@ -313,6 +313,9 @@ export class CodeGenerator {
|
||||
throw TypeError('Expecting valid order from block: ' + block.type);
|
||||
}
|
||||
const targetBlock = block.getInputTargetBlock(name);
|
||||
if (!targetBlock && !block.getInput(name)) {
|
||||
throw ReferenceError(`Input "${name}" doesn't exist on "${block.type}"`);
|
||||
}
|
||||
if (!targetBlock) {
|
||||
return '';
|
||||
}
|
||||
@@ -391,6 +394,9 @@ export class CodeGenerator {
|
||||
*/
|
||||
statementToCode(block: Block, name: string): string {
|
||||
const targetBlock = block.getInputTargetBlock(name);
|
||||
if (!targetBlock && !block.getInput(name)) {
|
||||
throw ReferenceError(`Input "${name}" doesn't exist on "${block.type}"`);
|
||||
}
|
||||
let code = this.blockToCode(targetBlock);
|
||||
// Value blocks must return code and order of operations info.
|
||||
// Statement blocks must only return code.
|
||||
|
||||
Reference in New Issue
Block a user