From 22c1eba546666fd4d65d8d4478b4306457abb401 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 31 Oct 2019 22:26:27 -0700 Subject: [PATCH] Make warnings an optional module. --- blocks/loops.js | 1 + blocks/procedures.js | 1 + build.py | 1 + core/block_svg.js | 6 ++-- core/renderers/measurables/types.js | 44 ++++++++++++++--------------- core/requires.js | 1 + gulpfile.js | 3 +- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/blocks/loops.js b/blocks/loops.js index 3e95ed685..6ec71900b 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -35,6 +35,7 @@ goog.require('Blockly.FieldDropdown'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldNumber'); goog.require('Blockly.FieldVariable'); +goog.require('Blockly.Warning'); /** diff --git a/blocks/procedures.js b/blocks/procedures.js index 7487a0c92..d9111057d 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -30,6 +30,7 @@ goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); goog.require('Blockly.Mutator'); +goog.require('Blockly.Warning'); Blockly.Blocks['procedures_defnoreturn'] = { diff --git a/build.py b/build.py index 6dcfd4593..906d96e08 100755 --- a/build.py +++ b/build.py @@ -237,6 +237,7 @@ goog.provide('Blockly.FieldNumber'); goog.provide('Blockly.FieldTextInput'); goog.provide('Blockly.FieldVariable'); goog.provide('Blockly.Mutator'); +goog.provide('Blockly.Warning'); """)) # Read in all the source files. filenames = glob.glob(os.path.join("blocks", "*.js")) diff --git a/core/block_svg.js b/core/block_svg.js index d568207fd..c8ac13956 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -40,7 +40,6 @@ goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); goog.require('Blockly.utils.Rect'); -goog.require('Blockly.Warning'); /** @@ -1107,7 +1106,7 @@ Blockly.BlockSvg.prototype.setCommentText = function(text) { } if (shouldHaveComment) { this.commentIcon_ = new Blockly.Comment(this); - this.comment = this.commentIcon_; // For backwards compatibility. + this.comment = this.commentIcon_; // For backwards compatibility. } else { this.commentIcon_.dispose(); this.commentIcon_ = null; @@ -1127,6 +1126,9 @@ Blockly.BlockSvg.prototype.setCommentText = function(text) { * maintain multiple warnings. */ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) { + if (!Blockly.Warning) { + throw Error('Missing require for Blockly.Warning'); + } if (!this.warningTextDb_) { // Create a database of warning PIDs. // Only runs once per block (and only those with warnings). diff --git a/core/renderers/measurables/types.js b/core/renderers/measurables/types.js index d31ea79ba..c15f7d4fb 100644 --- a/core/renderers/measurables/types.js +++ b/core/renderers/measurables/types.js @@ -30,31 +30,31 @@ goog.provide('Blockly.blockRendering.Types'); * @enum {number} */ Blockly.blockRendering.Types = { - NONE: 0, // None - FIELD: 1 << 0, // Field. - HAT: 1 << 1, // Hat. - ICON: 1 << 2, // Icon. - SPACER: 1 << 3, // Spacer. - BETWEEN_ROW_SPACER: 1 << 4, // Between Row Spacer. - IN_ROW_SPACER: 1 << 5, // In Row Spacer. + NONE: 0, // None + FIELD: 1 << 0, // Field. + HAT: 1 << 1, // Hat. + ICON: 1 << 2, // Icon. + SPACER: 1 << 3, // Spacer. + BETWEEN_ROW_SPACER: 1 << 4, // Between Row Spacer. + IN_ROW_SPACER: 1 << 5, // In Row Spacer. EXTERNAL_VALUE_INPUT: 1 << 6, // External Value Input. - INPUT: 1 << 7, // Input - INLINE_INPUT: 1 << 8, // Inline Input. - STATEMENT_INPUT: 1 << 9, // Statement Input. - CONNECTION: 1 << 10, // Connection. + INPUT: 1 << 7, // Input. + INLINE_INPUT: 1 << 8, // Inline Input. + STATEMENT_INPUT: 1 << 9, // Statement Input. + CONNECTION: 1 << 10, // Connection. PREVIOUS_CONNECTION: 1 << 11, // Previous Connection. - NEXT_CONNECTION: 1 << 12, // Next Connection. - OUTPUT_CONNECTION: 1 << 13, // Output Connection. - CORNER: 1 << 14, // Corner. - LEFT_SQUARE_CORNER: 1 << 15, // Square Corner. - LEFT_ROUND_CORNER: 1 << 16, // Round Corner. + NEXT_CONNECTION: 1 << 12, // Next Connection. + OUTPUT_CONNECTION: 1 << 13, // Output Connection. + CORNER: 1 << 14, // Corner. + LEFT_SQUARE_CORNER: 1 << 15, // Square Corner. + LEFT_ROUND_CORNER: 1 << 16, // Round Corner. RIGHT_SQUARE_CORNER: 1 << 17, // Right Square Corner. - RIGHT_ROUND_CORNER: 1 << 18, // Right Round Corner. - JAGGED_EDGE: 1 << 19, // Jagged Edge. - ROW: 1 << 20, // Row - TOP_ROW: 1 << 21, // Top Row. - BOTTOM_ROW: 1 << 22, // Bototm Row. - INPUT_ROW: 1 << 23, // Input Row. + RIGHT_ROUND_CORNER: 1 << 18, // Right Round Corner. + JAGGED_EDGE: 1 << 19, // Jagged Edge. + ROW: 1 << 20, // Row. + TOP_ROW: 1 << 21, // Top Row. + BOTTOM_ROW: 1 << 22, // Bottom Row. + INPUT_ROW: 1 << 23 // Input Row. }; /** diff --git a/core/requires.js b/core/requires.js index 77f80d7c2..d80533c8f 100644 --- a/core/requires.js +++ b/core/requires.js @@ -62,6 +62,7 @@ goog.require('Blockly.ZoomControls'); // None of these should be required when using advanced compilation since // individual block files should include the requirements they depend on. goog.require('Blockly.Mutator'); +goog.require('Blockly.Warning'); goog.require('Blockly.FieldAngle'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldColour'); diff --git a/gulpfile.js b/gulpfile.js index 645efb57f..1b1ffad39 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -208,7 +208,8 @@ goog.provide('Blockly.FieldMultilineInput'); goog.provide('Blockly.FieldNumber'); goog.provide('Blockly.FieldTextInput'); goog.provide('Blockly.FieldVariable'); -goog.provide('Blockly.Mutator');`; +goog.provide('Blockly.Mutator'); +goog.provide('Blockly.Warning');`; return gulp.src('blocks/*.js', {base: './'}) // Add Blockly.Blocks to be compatible with the compiler. .pipe(gulp.replace(`goog.provide('Blockly.Constants.Colour');`,