From 4ed3295ad9e8f50f10c4c65c1599c0949e20f8c9 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 27 Sep 2019 10:47:10 -0700 Subject: [PATCH] Make generator an optional module (#3105) --- core/block.js | 5 +++-- core/blockly.js | 1 - core/css.js | 2 +- core/extensions.js | 4 ++-- core/requires.js | 4 ++++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/block.js b/core/block.js index 0aee781d4..139ff002a 100644 --- a/core/block.js +++ b/core/block.js @@ -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; } } diff --git a/core/blockly.js b/core/blockly.js index d71e97f01..03f84cd6c 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -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'); diff --git a/core/css.js b/core/css.js index 7c638d679..ebb6cc2fb 100644 --- a/core/css.js +++ b/core/css.js @@ -362,7 +362,7 @@ Blockly.Css.CONTENT = [ '}', '.blocklyMultilineText {', - ' font-family: monospace;', + 'font-family: monospace;', '}', '.blocklyNonEditableText>text {', diff --git a/core/extensions.js b/core/extensions.js index 1f19a087d..6c0d93b9e 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -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; diff --git a/core/requires.js b/core/requires.js index b4a131399..b3030e2d9 100644 --- a/core/requires.js +++ b/core/requires.js @@ -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');