mirror of
https://github.com/google/blockly.git
synced 2026-01-04 07:30:08 +01:00
* refactor(generators): Introduce class JavascriptGenerator Also fix an import ordering error. * refactor(generators): Use Order.* instead of .ORDER_* * refactor(generators): Don't rename javascriptGenerator
33 lines
967 B
JavaScript
33 lines
967 B
JavaScript
/**
|
|
* @license
|
|
* Copyright 2012 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Generating JavaScript for variable blocks.
|
|
*/
|
|
|
|
import * as goog from '../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.JavaScript.variables');
|
|
|
|
import {NameType} from '../../core/names.js';
|
|
import {Order, javascriptGenerator} from '../javascript.js';
|
|
|
|
|
|
javascriptGenerator.forBlock['variables_get'] = function(block) {
|
|
// Variable getter.
|
|
const code = javascriptGenerator.nameDB_.getName(block.getFieldValue('VAR'),
|
|
NameType.VARIABLE);
|
|
return [code, Order.ATOMIC];
|
|
};
|
|
|
|
javascriptGenerator.forBlock['variables_set'] = function(block) {
|
|
// Variable setter.
|
|
const argument0 = javascriptGenerator.valueToCode(
|
|
block, 'VALUE', Order.ASSIGNMENT) || '0';
|
|
const varName = javascriptGenerator.nameDB_.getName(
|
|
block.getFieldValue('VAR'), NameType.VARIABLE);
|
|
return varName + ' = ' + argument0 + ';\n';
|
|
};
|