From a1e39734997a18fa15cb4c0c70ab02fea81b1b07 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 19 Sep 2019 14:53:28 -0700 Subject: [PATCH] Make block comments an optional module. (#3053) Measured as a 5 KB *increase* in code size, but that's because some other commit just landed between my tests. It's like running down an up escalator. --- blocks/procedures.js | 1 + build.py | 1 + core/block.js | 1 - core/block_svg.js | 3 +++ core/requires.js | 51 ++++++++++++++++++++++++++++---------------- gulpfile.js | 1 + 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index ca829a000..c200528a2 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -28,6 +28,7 @@ goog.provide('Blockly.Blocks.procedures'); goog.require('Blockly'); goog.require('Blockly.Blocks'); +goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); diff --git a/build.py b/build.py index 71ced9293..244e7db4b 100755 --- a/build.py +++ b/build.py @@ -248,6 +248,7 @@ class Gen_compressed(threading.Thread): params.append(("js_code", """ goog.provide('Blockly'); goog.provide('Blockly.Blocks'); +goog.provide('Blockly.Comment'); goog.provide('Blockly.FieldCheckbox'); goog.provide('Blockly.FieldColour'); goog.provide('Blockly.FieldDropdown'); diff --git a/core/block.js b/core/block.js index 7f6a915f4..e7c38e27e 100644 --- a/core/block.js +++ b/core/block.js @@ -27,7 +27,6 @@ goog.provide('Blockly.Block'); goog.require('Blockly.Blocks'); -goog.require('Blockly.Comment'); goog.require('Blockly.Connection'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockChange'); diff --git a/core/block_svg.js b/core/block_svg.js index 64f40c93a..5e705302a 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1092,6 +1092,9 @@ Blockly.BlockSvg.prototype.setCommentText = function(text) { var changedState = false; if (typeof text == 'string') { if (!this.comment) { + if (!Blockly.Comment) { + throw Error('Missing require for Blockly.Comment'); + } this.comment = new Blockly.Comment(this); changedState = true; } diff --git a/core/requires.js b/core/requires.js index b8acc0c4c..4ce356a33 100644 --- a/core/requires.js +++ b/core/requires.js @@ -27,26 +27,41 @@ goog.provide('Blockly.requires'); -// Blockly Core. +// Blockly Core (absolutely mandatory). goog.require('Blockly'); -goog.require('Blockly.Mutator'); + + +// If block comments aren't required, then Blockly.inject's "comments" +// configuration must be false, and no blocks may be loaded from XML which +// define comments. +goog.require('Blockly.Comment'); +// If a trashcan on the workspace isn't required, then Blockly.inject's +// "trashcan" configuration must be false. goog.require('Blockly.Trashcan'); +// If zoom controls aren't required, then Blockly.inject's +// "zoom"/"controls" configuration must be false. goog.require('Blockly.ZoomControls'); -// Blockly Fields. -goog.require('Blockly.FieldAngle'); -goog.require('Blockly.FieldCheckbox'); -goog.require('Blockly.FieldColour'); -// Date picker commented out since it increases footprint by 60%. -// Add it only if you need it. -// goog.require('Blockly.FieldDate'); -goog.require('Blockly.FieldDropdown'); -goog.require('Blockly.FieldLabelSerializable'); -goog.require('Blockly.FieldImage'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.FieldMultilineInput'); -goog.require('Blockly.FieldNumber'); -goog.require('Blockly.FieldVariable'); + + +// Block dependencies. +// None of these should be required since individual block files should +// include the requirements they depend on. +// goog.require('Blockly.Mutator'); +// goog.require('Blockly.FieldAngle'); +// goog.require('Blockly.FieldCheckbox'); +// goog.require('Blockly.FieldColour'); +// goog.require('Blockly.FieldDropdown'); +// goog.require('Blockly.FieldLabelSerializable'); +// goog.require('Blockly.FieldImage'); +// goog.require('Blockly.FieldTextInput'); +// goog.require('Blockly.FieldMultilineInput'); +// goog.require('Blockly.FieldNumber'); +// goog.require('Blockly.FieldVariable'); + + // Blockly Renderers. +// At least one renderer is mandatory. Geras is the default one. +// Others may be chosen using Blockly.inject's "renderer" configuration. goog.require('Blockly.geras.Renderer'); -goog.require('Blockly.thrasos.Renderer'); -goog.require('Blockly.zelos.Renderer'); +// goog.require('Blockly.thrasos.Renderer'); +// goog.require('Blockly.zelos.Renderer'); diff --git a/gulpfile.js b/gulpfile.js index 8ee20a372..41732bb02 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -141,6 +141,7 @@ gulp.task('build-blocks', function () { const provides = ` goog.provide('Blockly'); goog.provide('Blockly.Blocks'); +goog.provide('Blockly.Comment'); goog.provide('Blockly.FieldCheckbox'); goog.provide('Blockly.FieldColour'); goog.provide('Blockly.FieldDropdown');