mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
* feat(generators): Pass this CodeGenerator to generator functions This implements option 1A of proposal 1 of #7086. This commit is not by itself a breaking change, except in the unlikely event that developers' custom generator functions take an (optional) second argument of a dfferent type. * feat(generators): Accept generator argument in block functions Accept a CodeGenerator instance as parameter two of every per-block-type generator function. * fix(generators): Pass generator when calling other generator functions Make sure to pass generator to any other block functions that are called recursively. * refactor(generators)!: Use generator argument in generator functions Refactor per-block-type generator functions to use the provided generator argument to make recursive calls, rather than depending on the closed-over <lang>Generator instance. This allows generator functions to be moved between CodeGenerator instances (of the same language, at least). This commit was created by search-and-replace and addresses most but not all recursive references; remaining uses will require manual attention and will be dealt with in a following commit. BREAKING CHANGE: This commit makes the generator functions we provide dependent on the new generator parameter. Although CodeGenerator.prototype.blockToCode has been modified to supply this, so this change will not affect most developers, this change will be a breaking change where developers make direct calls to these generator functions without supplying the generator parameter. See previous commit for an example of the update required. * refactor(generators): Manual fix for remaining uses of langGenerator Manually replace remaining uses of <lang>Generator in block generator functions. * fix(generators): Delete duplicate procedures_callnoreturn generator For some reason the generator function for procedures_callnoreturn appears twice in generators/javascript/procedures.js. Delete the first copy (since the second one overwrote it anyway). * chore(generators): Format
35 lines
921 B
JavaScript
35 lines
921 B
JavaScript
/**
|
|
* @license
|
|
* Copyright 2014 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Generating Dart for variable blocks.
|
|
*/
|
|
|
|
import * as goog from '../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.Dart.variables');
|
|
|
|
import {NameType} from '../../core/names.js';
|
|
import {dartGenerator, Order} from '../dart.js';
|
|
|
|
|
|
dartGenerator.forBlock['variables_get'] = function(block, generator) {
|
|
// Variable getter.
|
|
const code =
|
|
generator.nameDB_.getName(
|
|
block.getFieldValue('VAR'), NameType.VARIABLE);
|
|
return [code, Order.ATOMIC];
|
|
};
|
|
|
|
dartGenerator.forBlock['variables_set'] = function(block, generator) {
|
|
// Variable setter.
|
|
const argument0 =
|
|
generator.valueToCode(block, 'VALUE', Order.ASSIGNMENT) || '0';
|
|
const varName =
|
|
generator.nameDB_.getName(
|
|
block.getFieldValue('VAR'), NameType.VARIABLE);
|
|
return varName + ' = ' + argument0 + ';\n';
|
|
};
|