mirror of
https://github.com/google/blockly.git
synced 2026-01-04 07:30:08 +01:00
* chore: migrate generators/javascript/text.js to goog.module * chore: convert generators/javascript/text.js to named requires * refactor: convert generators/javascript/variables.js to goog.module * refactor: convert generators/javascript/variables_dynamic to goog.module
33 lines
877 B
JavaScript
33 lines
877 B
JavaScript
/**
|
|
* @license
|
|
* Copyright 2012 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Generating JavaScript for variable blocks.
|
|
*/
|
|
'use strict';
|
|
|
|
goog.module('Blockly.JavaScript.variables');
|
|
|
|
const JavaScript = goog.require('Blockly.JavaScript');
|
|
const {NameType} = goog.require('Blockly.Names');
|
|
|
|
|
|
JavaScript['variables_get'] = function(block) {
|
|
// Variable getter.
|
|
const code = JavaScript.nameDB_.getName(block.getFieldValue('VAR'),
|
|
NameType.VARIABLE);
|
|
return [code, JavaScript.ORDER_ATOMIC];
|
|
};
|
|
|
|
JavaScript['variables_set'] = function(block) {
|
|
// Variable setter.
|
|
const argument0 = JavaScript.valueToCode(
|
|
block, 'VALUE', JavaScript.ORDER_ASSIGNMENT) || '0';
|
|
const varName = JavaScript.nameDB_.getName(
|
|
block.getFieldValue('VAR'), NameType.VARIABLE);
|
|
return varName + ' = ' + argument0 + ';\n';
|
|
};
|