mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
fix: Rename Generator to CodeGenerator (#6585)
Stops collisions with ES6's Generator. The old Blockly.Generator still exists as a name, but is now deprecated.
This commit is contained in:
@@ -160,7 +160,6 @@
|
||||
"jsdoc/check-param-names": ["off", {"checkDestructured": false}],
|
||||
// Allow any text in the license tag. Other checks are not relevant.
|
||||
"jsdoc/check-values": ["off"]
|
||||
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ import {FlyoutButton} from './flyout_button.js';
|
||||
import {HorizontalFlyout} from './flyout_horizontal.js';
|
||||
import {FlyoutMetricsManager} from './flyout_metrics_manager.js';
|
||||
import {VerticalFlyout} from './flyout_vertical.js';
|
||||
import {Generator} from './generator.js';
|
||||
import {CodeGenerator} from './generator.js';
|
||||
import {Gesture} from './gesture.js';
|
||||
import {Grid} from './grid.js';
|
||||
import {Icon} from './icon.js';
|
||||
@@ -663,7 +663,8 @@ export {FieldVariable};
|
||||
export {Flyout};
|
||||
export {FlyoutButton};
|
||||
export {FlyoutMetricsManager};
|
||||
export {Generator};
|
||||
export {CodeGenerator};
|
||||
export {CodeGenerator as Generator}; // Deprecated name, October 2022.
|
||||
export {Gesture};
|
||||
export {Grid};
|
||||
export {HorizontalFlyout};
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* @class
|
||||
*/
|
||||
import * as goog from '../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Generator');
|
||||
goog.declareModuleId('Blockly.CodeGenerator');
|
||||
|
||||
import type {Block} from './block.js';
|
||||
import * as common from './common.js';
|
||||
@@ -24,14 +24,14 @@ import type {Workspace} from './workspace.js';
|
||||
* Class for a code generator that translates the blocks into a language.
|
||||
*
|
||||
* @unrestricted
|
||||
* @alias Blockly.Generator
|
||||
* @alias Blockly.CodeGenerator
|
||||
*/
|
||||
export class Generator {
|
||||
export class CodeGenerator {
|
||||
name_: string;
|
||||
|
||||
/**
|
||||
* This is used as a placeholder in functions defined using
|
||||
* Generator.provideFunction_. It must not be legal code that could
|
||||
* CodeGenerator.provideFunction_. It must not be legal code that could
|
||||
* legitimately appear in a function definition (or comment), and it must
|
||||
* not confuse the regular expression parser.
|
||||
*/
|
||||
@@ -205,7 +205,7 @@ export class Generator {
|
||||
|[string, number] {
|
||||
if (this.isInitialized === false) {
|
||||
console.warn(
|
||||
'Generator init was not called before blockToCode was called.');
|
||||
'CodeGenerator init was not called before blockToCode was called.');
|
||||
}
|
||||
if (!block) {
|
||||
return '';
|
||||
@@ -414,7 +414,7 @@ export class Generator {
|
||||
* "listRandom", not "random"). There is no danger of colliding with reserved
|
||||
* words, or user-defined variable or procedure names.
|
||||
*
|
||||
* The code gets output when Generator.finish() is called.
|
||||
* The code gets output when CodeGenerator.finish() is called.
|
||||
*
|
||||
* @param desiredName The desired name of the function (e.g. mathIsPrime).
|
||||
* @param code A list of statements or one multi-line code string. Use ' '
|
||||
@@ -514,23 +514,23 @@ export class Generator {
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperties(Generator.prototype, {
|
||||
Object.defineProperties(CodeGenerator.prototype, {
|
||||
/**
|
||||
* A database of variable names.
|
||||
*
|
||||
* @name Blockly.Generator.prototype.variableDB_
|
||||
* @name Blockly.CodeGenerator.prototype.variableDB_
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
variableDB_: ({
|
||||
/** @returns Name database. */
|
||||
get(this: Generator): Names |
|
||||
get(this: CodeGenerator): Names |
|
||||
undefined {
|
||||
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
|
||||
return this.nameDB_;
|
||||
},
|
||||
/** @param nameDb New name database. */
|
||||
set(this: Generator, nameDb: Names|undefined) {
|
||||
set(this: CodeGenerator, nameDb: Names|undefined) {
|
||||
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
|
||||
this.nameDB_ = nameDb;
|
||||
},
|
||||
|
||||
@@ -194,4 +194,3 @@ BlocklyDevTools.Analytics.sendQueued = function() {
|
||||
// stub
|
||||
this.LOG_TO_CONSOLE_ && console.log('Analytics.sendQueued');
|
||||
};
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ Code.renderContent = function() {
|
||||
|
||||
/**
|
||||
* Attempt to generate the code and display it in the UI, pretty printed.
|
||||
* @param generator {!Blockly.Generator} The generator to use.
|
||||
* @param generator {!Blockly.CodeGenerator} The generator to use.
|
||||
*/
|
||||
Code.attemptCodeGeneration = function(generator) {
|
||||
var content = document.getElementById('content_' + Code.selected);
|
||||
@@ -388,7 +388,7 @@ Code.attemptCodeGeneration = function(generator) {
|
||||
|
||||
/**
|
||||
* Check whether all blocks in use have generator functions.
|
||||
* @param generator {!Blockly.Generator} The generator to use.
|
||||
* @param generator {!Blockly.CodeGenerator} The generator to use.
|
||||
*/
|
||||
Code.checkAllGeneratorFunctionsDefined = function(generator) {
|
||||
var blocks = Code.workspace.getAllBlocks(false);
|
||||
|
||||
@@ -108,4 +108,3 @@ class ViewController: UIViewController, WKUIDelegate {
|
||||
present(alert, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ goog.module('Blockly.Dart');
|
||||
const Variables = goog.require('Blockly.Variables');
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Generator} = goog.require('Blockly.Generator');
|
||||
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
|
||||
const {Names, NameType} = goog.require('Blockly.Names');
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
@@ -23,9 +23,9 @@ const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
|
||||
/**
|
||||
* Dart code generator.
|
||||
* @type {!Generator}
|
||||
* @type {!CodeGenerator}
|
||||
*/
|
||||
const Dart = new Generator('Dart');
|
||||
const Dart = new CodeGenerator('Dart');
|
||||
|
||||
/**
|
||||
* List of illegal variable names.
|
||||
@@ -86,7 +86,7 @@ Dart.isInitialized = false;
|
||||
* @param {!Workspace} workspace Workspace to generate code from.
|
||||
*/
|
||||
Dart.init = function(workspace) {
|
||||
// Call Blockly.Generator's init.
|
||||
// Call Blockly.CodeGenerator's init.
|
||||
Object.getPrototypeOf(this).init.call(this);
|
||||
|
||||
if (!this.nameDB_) {
|
||||
@@ -145,7 +145,7 @@ Dart.finish = function(code) {
|
||||
definitions.push(def);
|
||||
}
|
||||
}
|
||||
// Call Blockly.Generator's finish.
|
||||
// Call Blockly.CodeGenerator's finish.
|
||||
code = Object.getPrototypeOf(this).finish.call(this, code);
|
||||
this.isInitialized = false;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ goog.module('Blockly.JavaScript');
|
||||
const Variables = goog.require('Blockly.Variables');
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Generator} = goog.require('Blockly.Generator');
|
||||
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
|
||||
const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
const {Names, NameType} = goog.require('Blockly.Names');
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
@@ -23,9 +23,9 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
|
||||
/**
|
||||
* JavaScript code generator.
|
||||
* @type {!Generator}
|
||||
* @type {!CodeGenerator}
|
||||
*/
|
||||
const JavaScript = new Generator('JavaScript');
|
||||
const JavaScript = new CodeGenerator('JavaScript');
|
||||
|
||||
/**
|
||||
* List of illegal variable names.
|
||||
@@ -127,7 +127,7 @@ JavaScript.isInitialized = false;
|
||||
* @param {!Workspace} workspace Workspace to generate code from.
|
||||
*/
|
||||
JavaScript.init = function(workspace) {
|
||||
// Call Blockly.Generator's init.
|
||||
// Call Blockly.CodeGenerator's init.
|
||||
Object.getPrototypeOf(this).init.call(this);
|
||||
|
||||
if (!this.nameDB_) {
|
||||
@@ -169,7 +169,7 @@ JavaScript.init = function(workspace) {
|
||||
JavaScript.finish = function(code) {
|
||||
// Convert the definitions dictionary into a list.
|
||||
const definitions = Object.values(this.definitions_);
|
||||
// Call Blockly.Generator's finish.
|
||||
// Call Blockly.CodeGenerator's finish.
|
||||
code = Object.getPrototypeOf(this).finish.call(this, code);
|
||||
this.isInitialized = false;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ goog.module('Blockly.Lua');
|
||||
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Generator} = goog.require('Blockly.Generator');
|
||||
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
|
||||
const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
const {Names} = goog.require('Blockly.Names');
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
@@ -23,9 +23,9 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
|
||||
/**
|
||||
* Lua code generator.
|
||||
* @type {!Generator}
|
||||
* @type {!CodeGenerator}
|
||||
*/
|
||||
const Lua = new Generator('Lua');
|
||||
const Lua = new CodeGenerator('Lua');
|
||||
|
||||
/**
|
||||
* List of illegal variable names.
|
||||
@@ -92,7 +92,7 @@ Lua.isInitialized = false;
|
||||
* @param {!Workspace} workspace Workspace to generate code from.
|
||||
*/
|
||||
Lua.init = function(workspace) {
|
||||
// Call Blockly.Generator's init.
|
||||
// Call Blockly.CodeGenerator's init.
|
||||
Object.getPrototypeOf(this).init.call(this);
|
||||
|
||||
if (!this.nameDB_) {
|
||||
@@ -115,7 +115,7 @@ Lua.init = function(workspace) {
|
||||
Lua.finish = function(code) {
|
||||
// Convert the definitions dictionary into a list.
|
||||
const definitions = Object.values(this.definitions_);
|
||||
// Call Blockly.Generator's finish.
|
||||
// Call Blockly.CodeGenerator's finish.
|
||||
code = Object.getPrototypeOf(this).finish.call(this, code);
|
||||
this.isInitialized = false;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ goog.module('Blockly.PHP');
|
||||
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Generator} = goog.require('Blockly.Generator');
|
||||
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
|
||||
const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
const {Names} = goog.require('Blockly.Names');
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
@@ -22,9 +22,9 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
|
||||
/**
|
||||
* PHP code generator.
|
||||
* @type {!Generator}
|
||||
* @type {!CodeGenerator}
|
||||
*/
|
||||
const PHP = new Generator('PHP');
|
||||
const PHP = new CodeGenerator('PHP');
|
||||
|
||||
/**
|
||||
* List of illegal variable names.
|
||||
@@ -130,7 +130,7 @@ PHP.isInitialized = false;
|
||||
* @param {!Workspace} workspace Workspace to generate code from.
|
||||
*/
|
||||
PHP.init = function(workspace) {
|
||||
// Call Blockly.Generator's init.
|
||||
// Call Blockly.CodeGenerator's init.
|
||||
Object.getPrototypeOf(this).init.call(this);
|
||||
|
||||
if (!this.nameDB_) {
|
||||
@@ -154,7 +154,7 @@ PHP.init = function(workspace) {
|
||||
PHP.finish = function(code) {
|
||||
// Convert the definitions dictionary into a list.
|
||||
const definitions = Object.values(this.definitions_);
|
||||
// Call Blockly.Generator's finish.
|
||||
// Call Blockly.CodeGenerator's finish.
|
||||
code = Object.getPrototypeOf(this).finish.call(this, code);
|
||||
this.isInitialized = false;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ goog.module('Blockly.Python');
|
||||
const stringUtils = goog.require('Blockly.utils.string');
|
||||
const Variables = goog.require('Blockly.Variables');
|
||||
const {Block} = goog.requireType('Blockly.Block');
|
||||
const {Generator} = goog.require('Blockly.Generator');
|
||||
const {CodeGenerator} = goog.require('Blockly.CodeGenerator');
|
||||
const {inputTypes} = goog.require('Blockly.inputTypes');
|
||||
const {Names, NameType} = goog.require('Blockly.Names');
|
||||
const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
@@ -23,9 +23,9 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
|
||||
|
||||
/**
|
||||
* Python code generator.
|
||||
* @type {!Generator}
|
||||
* @type {!CodeGenerator}
|
||||
*/
|
||||
const Python = new Generator('Python');
|
||||
const Python = new CodeGenerator('Python');
|
||||
|
||||
/**
|
||||
* List of illegal variable names.
|
||||
@@ -137,10 +137,10 @@ Python.isInitialized = false;
|
||||
/**
|
||||
* Initialise the database of variable names.
|
||||
* @param {!Workspace} workspace Workspace to generate code from.
|
||||
* @this {Generator}
|
||||
* @this {CodeGenerator}
|
||||
*/
|
||||
Python.init = function(workspace) {
|
||||
// Call Blockly.Generator's init.
|
||||
// Call Blockly.CodeGenerator's init.
|
||||
Object.getPrototypeOf(this).init.call(this);
|
||||
|
||||
/**
|
||||
@@ -196,7 +196,7 @@ Python.finish = function(code) {
|
||||
definitions.push(def);
|
||||
}
|
||||
}
|
||||
// Call Blockly.Generator's finish.
|
||||
// Call Blockly.CodeGenerator's finish.
|
||||
code = Object.getPrototypeOf(this).finish.call(this, code);
|
||||
this.isInitialized = false;
|
||||
|
||||
|
||||
@@ -166,7 +166,6 @@ suite('Dropdown Fields', function() {
|
||||
this.workspace = new Blockly.Workspace();
|
||||
defineRowBlock();
|
||||
|
||||
|
||||
this.assertValue = (value, field) => {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
field.setValue(value);
|
||||
|
||||
@@ -27,7 +27,7 @@ suite('Generator', function() {
|
||||
|
||||
suite('prefix', function() {
|
||||
setup(function() {
|
||||
this.generator = new Blockly.Generator('INTERCAL');
|
||||
this.generator = new Blockly.CodeGenerator('INTERCAL');
|
||||
});
|
||||
|
||||
test('Nothing', function() {
|
||||
|
||||
@@ -55,7 +55,7 @@ export class CodeGenerationTestSuite {
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* @type {!Blockly.Generator} The generator to use for running test cases.
|
||||
* @type {!Blockly.CodeGenerator} The generator to use for running test cases.
|
||||
*/
|
||||
this.generator;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export class CodeGenerationTestSuite {
|
||||
/**
|
||||
* Returns mocha test callback for code generation based on provided
|
||||
* generator.
|
||||
* @param {!Blockly.Generator} generator The generator to use in test.
|
||||
* @param {!Blockly.CodeGenerator} generator The generator to use in test.
|
||||
* @return {function(!CodeGenerationTestCase):!Function} Function that
|
||||
* returns mocha test callback based on test case.
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user