Make generator an optional module (#3105)

This commit is contained in:
Neil Fraser
2019-09-27 10:47:10 -07:00
committed by GitHub
parent 6a771a8636
commit 4ed3295ad9
5 changed files with 10 additions and 6 deletions

View File

@@ -56,7 +56,8 @@ goog.require('Blockly.Workspace');
* @throws When block is not valid or block name is not allowed.
*/
Blockly.Block = function(workspace, prototypeName, opt_id) {
if (typeof Blockly.Generator.prototype[prototypeName] !== 'undefined') {
if (Blockly.Generator &&
typeof Blockly.Generator.prototype[prototypeName] != 'undefined') {
// Occluding Generator class members is not allowed.
throw Error('Block prototypeName "' + prototypeName +
'" conflicts with Blockly.Generator members.');
@@ -1052,7 +1053,7 @@ Blockly.Block.prototype.setOnChange = function(onchangeFn) {
Blockly.Block.prototype.getField = function(name) {
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field.name === name) {
if (field.name == name) {
return field;
}
}

View File

@@ -33,7 +33,6 @@ goog.provide('Blockly');
goog.require('Blockly.BlockSvg.render');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Ui');
goog.require('Blockly.Generator');
goog.require('Blockly.navigation');
goog.require('Blockly.Procedures');
goog.require('Blockly.Tooltip');

View File

@@ -362,7 +362,7 @@ Blockly.Css.CONTENT = [
'}',
'.blocklyMultilineText {',
' font-family: monospace;',
'font-family: monospace;',
'}',
'.blocklyNonEditableText>text {',

View File

@@ -355,7 +355,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName,
* @this {Blockly.Block}
*/
var extensionFn = function() {
if (this.type && blockTypesChecked.indexOf(this.type) === -1) {
if (this.type && blockTypesChecked.indexOf(this.type) == -1) {
Blockly.Extensions.checkDropdownOptionsInTable_(
this, dropdownName, lookupTable);
blockTypesChecked.push(this.type);
@@ -365,7 +365,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName,
var value = this.getFieldValue(dropdownName);
var tooltip = lookupTable[value];
if (tooltip == null) {
if (blockTypesChecked.indexOf(this.type) === -1) {
if (blockTypesChecked.indexOf(this.type) == -1) {
// Warn for missing values on generated tooltips.
var warning = 'No tooltip mapping for value ' + value +
' of field ' + dropdownName;

View File

@@ -41,6 +41,10 @@ goog.require('Blockly.VerticalFlyout');
// Flyout buttons are needed by the variable category,
// and by any custom toolbox that has a button or a label.
goog.require('Blockly.FlyoutButton');
// If there is code generation into any language, then the generator is needed.
// Should not be required when using advanced compilation since
// individual generator files should already have this require.
goog.require('Blockly.Generator');
// If the toolbox does not have categories and only has a simple flyout, then
// 'Blockly.Toolbox' is not needed.
goog.require('Blockly.Toolbox');