From 5cf52c566a4ce6fe31b66fc1bbb355bc1d92e99f Mon Sep 17 00:00:00 2001
From: Neil Fraser
Date: Fri, 17 May 2019 16:23:18 -0700
Subject: [PATCH] Fix a dozen compiler warnings.
---
core/block_svg.js | 2 +-
core/events.js | 3 ++-
core/flyout_base.js | 4 ++--
core/generator.js | 2 +-
core/gesture.js | 2 +-
core/workspace_svg.js | 26 ++++++++++++++++----------
core/xml.js | 8 ++++++--
core/xml_utils.js | 2 +-
externs/browser-externs.js | 32 ++++++++++++++++++++++++++++++++
tests/compile/compile.sh | 1 +
tests/compile/index.html | 2 +-
11 files changed, 64 insertions(+), 20 deletions(-)
create mode 100644 externs/browser-externs.js
diff --git a/core/block_svg.js b/core/block_svg.js
index 505da905a..47cee2673 100644
--- a/core/block_svg.js
+++ b/core/block_svg.js
@@ -629,7 +629,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
Blockly.BlockSvg.prototype.showHelp_ = function() {
var url = (typeof this.helpUrl == 'function') ? this.helpUrl() : this.helpUrl;
if (url) {
- open(url);
+ window.open(url);
}
};
diff --git a/core/events.js b/core/events.js
index 41f247f2f..285c9d45c 100644
--- a/core/events.js
+++ b/core/events.js
@@ -411,7 +411,8 @@ Blockly.Events.disableOrphans = function(event) {
var workspace = Blockly.Workspace.getById(event.workspaceId);
var block = workspace.getBlockById(event.blockId);
if (block) {
- if (block.getParent() && !block.getParent().disabled) {
+ var parent = block.getParent()
+ if (parent && parent.isEnabled()) {
var children = block.getDescendants(false);
for (var i = 0, child; child = children[i]; i++) {
child.setEnabled(true);
diff --git a/core/flyout_base.js b/core/flyout_base.js
index b651f7255..c8fcc79d2 100644
--- a/core/flyout_base.js
+++ b/core/flyout_base.js
@@ -455,7 +455,7 @@ Blockly.Flyout.prototype.show = function(xmlList) {
switch (xml.tagName.toUpperCase()) {
case 'BLOCK':
var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_);
- if (curBlock.disabled) {
+ if (!curBlock.isEnabled()) {
// Record blocks that were initially disabled.
// Do not enable these blocks as a result of capacity filtering.
this.permanentlyDisabled_.push(curBlock);
@@ -612,7 +612,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) {
* @package
*/
Blockly.Flyout.prototype.isBlockCreatable_ = function(block) {
- return !block.disabled;
+ return block.isEnabled();
};
/**
diff --git a/core/generator.js b/core/generator.js
index fc59214c1..4241e2440 100644
--- a/core/generator.js
+++ b/core/generator.js
@@ -182,7 +182,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) {
if (!block) {
return '';
}
- if (block.disabled) {
+ if (!block.isEnabled()) {
// Skip past this block if it is disabled.
return opt_thisOnly ? '' : this.blockToCode(block.getNextBlock());
}
diff --git a/core/gesture.js b/core/gesture.js
index 9023b272f..4e18a1204 100644
--- a/core/gesture.js
+++ b/core/gesture.js
@@ -734,7 +734,7 @@ Blockly.Gesture.prototype.doFieldClick_ = function() {
Blockly.Gesture.prototype.doBlockClick_ = function() {
// Block click in an autoclosing flyout.
if (this.flyout_ && this.flyout_.autoClose) {
- if (!this.targetBlock_.disabled) {
+ if (this.targetBlock_.isEnabled()) {
if (!Blockly.Events.getGroup()) {
Blockly.Events.setGroup(true);
}
diff --git a/core/workspace_svg.js b/core/workspace_svg.js
index 7f20dca13..f07cdc5f2 100644
--- a/core/workspace_svg.js
+++ b/core/workspace_svg.js
@@ -272,6 +272,21 @@ Blockly.WorkspaceSvg.prototype.trashcan = null;
*/
Blockly.WorkspaceSvg.prototype.scrollbar = null;
+/**
+ * Fixed flyout providing blocks which may be dragged into this workspace.
+ * @type {Blockly.Flyout}
+ * @private
+ */
+Blockly.WorkspaceSvg.prototype.flyout_ = null;
+
+/**
+ * Category-based toolbox providing blocks which may be dragged into this
+ * workspace.
+ * @type {Blockly.Toolbox}
+ * @private
+ */
+Blockly.WorkspaceSvg.prototype.toolbox_ = null;
+
/**
* The current gesture in progress on this workspace, if any.
* @type {Blockly.TouchGesture}
@@ -533,10 +548,6 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
// Determine if there needs to be a category tree, or a simple list of
// blocks. This cannot be changed later, since the UI is very different.
if (this.options.hasCategories) {
- /**
- * @type {Blockly.Toolbox}
- * @private
- */
this.toolbox_ = new Blockly.Toolbox(this);
}
if (this.grid_) {
@@ -660,11 +671,6 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) {
horizontalLayout: this.horizontalLayout,
toolboxPosition: this.options.toolboxPosition
};
- /**
- * @type {!Blockly.Flyout}
- * @private
- */
- this.flyout_ = null;
if (this.horizontalLayout) {
this.flyout_ = new Blockly.HorizontalFlyout(workspaceOptions);
} else {
@@ -672,7 +678,7 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) {
}
this.flyout_.autoClose = false;
- // Return the element so that callers can place it in their desired
+ // Return the element so that callers can place it in their desired
// spot in the DOM. For example, mutator flyouts do not go in the same place
// as main workspace flyouts.
return this.flyout_.createDom(tagName);
diff --git a/core/xml.js b/core/xml.js
index 3c03c0c64..eb736afaf 100644
--- a/core/xml.js
+++ b/core/xml.js
@@ -206,7 +206,7 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
if (block.isCollapsed()) {
element.setAttribute('collapsed', true);
}
- if (block.disabled) {
+ if (!block.isEnabled()) {
element.setAttribute('disabled', true);
}
if (!block.isDeletable() && !block.isShadow()) {
@@ -350,11 +350,13 @@ Blockly.Xml.clearWorkspaceAndLoadFromXml = function(xml, workspace) {
* Decode an XML DOM and create blocks on the workspace.
* @param {!Element} xml XML DOM.
* @param {!Blockly.Workspace} workspace The workspace.
- * @return {Array.} An array containing new block IDs.
+ * @return {!Array.} An array containing new block IDs.
*/
Blockly.Xml.domToWorkspace = function(xml, workspace) {
if (xml instanceof Blockly.Workspace) {
var swap = xml;
+ // Closure Compiler complains here because the arguments are reversed.
+ /** @suppress {checkTypes} */
xml = workspace;
workspace = swap;
console.warn('Deprecated call to Blockly.Xml.domToWorkspace, ' +
@@ -498,6 +500,8 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) {
Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
if (xmlBlock instanceof Blockly.Workspace) {
var swap = xmlBlock;
+ // Closure Compiler complains here because the arguments are reversed.
+ /** @suppress {checkTypes} */
xmlBlock = workspace;
workspace = swap;
console.warn('Deprecated call to Blockly.Xml.domToBlock, ' +
diff --git a/core/xml_utils.js b/core/xml_utils.js
index 0e1a3d4a1..1395923dc 100644
--- a/core/xml_utils.js
+++ b/core/xml_utils.js
@@ -58,7 +58,7 @@ Blockly.Xml.utils.createTextNode = function(text) {
* Converts an XML string into a DOM tree. This method will be overridden in
* the Node.js build of Blockly. See gulpfile.js, blockly_javascript_en task.
* @param {string} text XML string.
- * @return {!Element} The DOM document.
+ * @return {Document} The DOM document.
* @throws if XML doesn't parse.
* @package
*/
diff --git a/externs/browser-externs.js b/externs/browser-externs.js
new file mode 100644
index 000000000..38a84fdd9
--- /dev/null
+++ b/externs/browser-externs.js
@@ -0,0 +1,32 @@
+/**
+ * @license
+ * Visual Blocks Editor
+ *
+ * Copyright 2019 Google Inc.
+ * https://developers.google.com/blockly/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @fileoverview Property definitions in browsers that Closure Compiler is
+ * unaware of.
+ * @author fraser@google.com (Neil Fraser)
+ *
+ * @externs
+ */
+'use strict';
+
+
+Element.ELEMENT_NODE = 1;
+Element.TEXT_NODE = 3;
diff --git a/tests/compile/compile.sh b/tests/compile/compile.sh
index f60c37cb1..6352746a3 100755
--- a/tests/compile/compile.sh
+++ b/tests/compile/compile.sh
@@ -82,6 +82,7 @@ COMPILATION_COMMAND="java -jar $COMPILER --js='$BLOCKLY_ROOT/tests/compile/main.
--js='$CLOSURE_LIB_ROOT/closure/goog/**.js' \
--js='$CLOSURE_LIB_ROOT/third_party/closure/goog/**.js' \
--generate_exports \
+ --externs $BLOCKLY_ROOT/externs/browser-externs.js \
--externs $BLOCKLY_ROOT/externs/svg-externs.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--dependency_mode=STRICT --entry_point=Main \
diff --git a/tests/compile/index.html b/tests/compile/index.html
index 93444421d..95e2af9d3 100644
--- a/tests/compile/index.html
+++ b/tests/compile/index.html
@@ -20,7 +20,7 @@
To run this test manually, download
closure-compiler-vxxxxxxxx.jar,
- place it in this directory, then run compile.js from the command line.
+ place it in this directory, then run compile.sh from the command line.
Measure the size of main_compressed.js (295kb as of October 2017), then reload
this page and see if Blockly works.