Fix compiler errors

This commit is contained in:
Rachel Fenichel
2020-07-16 11:36:48 -06:00
parent 7288c66294
commit 809148b435
8 changed files with 109 additions and 14 deletions

View File

@@ -75,6 +75,7 @@ goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connectio
goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.Events', 'Blockly.blockAnimations'], {'lang': 'es5'});
goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IBlocklyActionable'], [], {});
goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {});
goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {});
goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {});
goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {});
goog.addDependency('../../core/interfaces/i_deletearea.js', ['Blockly.IDeleteArea'], [], {});

View File

@@ -16,7 +16,7 @@ goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Xml');
goog.requireType('Blockly.ConnectionChecker');
goog.requireType('Blockly.IConnectionChecker');
goog.requireType('Blockly.IASTNodeLocationWithBlock');
@@ -253,7 +253,7 @@ Blockly.Connection.prototype.isConnected = function() {
Blockly.Connection.prototype.canConnectWithReason = function(target) {
// TODO: deprecation warning with date, plus tests.
return this.getConnectionChecker().canConnectWithReason(
this, target);
this, target, false);
};
/**
@@ -268,15 +268,15 @@ Blockly.Connection.prototype.checkConnection = function(target) {
// TODO: Add deprecation warning notices *and* add tests to make sure these
// still work (for any blocks that use them).
var checker = this.getConnectionChecker();
var reason = !checker.canConnectWithReason(this, target, false);
var reason = checker.canConnectWithReason(this, target, false);
if (reason != Blockly.Connection.CAN_CONNECT) {
throw new Error(checker.getErrorMessage(this, target, reason));
throw new Error(checker.getErrorMessage(reason, this, target));
}
};
/**
* Get the workspace's connection type checker object.
* @return {!Blockly.ConnectionChecker} The connection type checker for the
* @return {!Blockly.IConnectionChecker} The connection type checker for the
* source block's workspace.
* @package
*/

View File

@@ -13,10 +13,12 @@
goog.provide('Blockly.ConnectionChecker');
goog.requireType('Blockly.IConnectionChecker');
goog.requireType('Blockly.Connection');
/**
* Class for connection type checking logic.
* @implements {Blockly.IConnectionChecker}
* @constructor
*/
Blockly.ConnectionChecker = function() {
@@ -62,8 +64,8 @@ Blockly.ConnectionChecker.prototype.canConnectWithReason = function(
return Blockly.Connection.REASON_CHECKS_FAILED;
}
if (isDragging && this.doDragChecks(connOne, connTwo, false)) {
return Blockly.REASON_DRAG_CHECKS_FAILED;
if (isDragging && this.doDragChecks(connOne, connTwo)) {
return Blockly.Connection.REASON_DRAG_CHECKS_FAILED;
}
return Blockly.Connection.CAN_CONNECT;

View File

@@ -16,14 +16,14 @@ goog.provide('Blockly.ConnectionDB');
goog.require('Blockly.RenderedConnection');
goog.requireType('Blockly.ConnectionChecker');
goog.requireType('Blockly.IConnectionChecker');
/**
* Database of connections.
* Connections are stored in order of their vertical component. This way
* connections in an area may be looked up quickly using a binary search.
* @param {!Blockly.ConnectionChecker} checker The workspace's
* @param {!Blockly.IConnectionChecker} checker The workspace's
* connection type checker, used to decide if connections are valid during a
* drag.
* @constructor
@@ -35,6 +35,12 @@ Blockly.ConnectionDB = function(checker) {
* @private
*/
this.connections_ = [];
/**
* The workspace's connection type checker, used to decide if connections are
* valid during a drag.
* @type {!Blockly.IConnectionChecker}
* @private
*/
this.connectionChecker_ = checker;
};
@@ -279,7 +285,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
/**
* Initialize a set of connection DBs for a workspace.
* @param {!Blockly.ConnectionChecker} checker The workspace's
* @param {!Blockly.IConnectionChecker} checker The workspace's
* connection checker, used to decide if connections are valid during a drag.
* @return {!Array.<!Blockly.ConnectionDB>} Array of databases.
*/

View File

@@ -0,0 +1,87 @@
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview The interface for an object that encapsulates logic for
* checking whether a potential connection is safe and valid.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.IConnectionChecker');
goog.requireType('Blockly.Connection');
/**
* Class for connection type checking logic.
* @interface
*/
Blockly.IConnectionChecker = function() {};
/**
* Check whether the current connection can connect with the target
* connection.
* @param {Blockly.Connection} one Connection to check compatibility with.
* @param {Blockly.Connection} two Connection to check compatibility with.
* @param {boolean} isDragging True if the connection is being made by dragging
* a block.
* @return {boolean} Whether the connection is legal.
* @public
*/
Blockly.IConnectionChecker.prototype.canConnect;
/**
* Checks whether the current connection can connect with the target
* connection, and return an error code if there are problems.
* @param {Blockly.Connection} one Connection to check compatibility with.
* @param {Blockly.Connection} two Connection to check compatibility with.
* @param {boolean} isDragging [description]
* @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal,
* an error code otherwise.
* @public
*/
Blockly.IConnectionChecker.prototype.canConnectWithReason;
/**
* Helper method that translates a connection error code into a string.
* @param {number} errorCode The error code.
* @param {Blockly.Connection} one One of the two connections being checked.
* @param {Blockly.Connection} two The second of the two connections being
* checked.
* @return {string} A developer-readable error string.
* @public
*/
Blockly.IConnectionChecker.prototype.getErrorMessage;
/**
* Check that connecting the given connections is safe, meaning that it would
* not break any of Blockly's basic assumptions (e.g. no self connections).
* @param {Blockly.Connection} one The first of the connections to check.
* @param {Blockly.Connection} two The second of the connections to check.
* @return {number} An enum with the reason this connection is safe or unsafe.
* @public
*/
Blockly.IConnectionChecker.prototype.doSafetyChecks;
/**
* Check whether this connection is compatible with another connection with
* respect to the value type system. E.g. square_root("Hello") is not
* compatible.
* @param {!Blockly.Connection} one Connection to compare.
* @param {!Blockly.Connection} two Connection to compare against.
* @return {boolean} True if the connections share a type.
* @public
*/
Blockly.IConnectionChecker.prototype.doTypeChecks;
/**
* Check whether this connection can be made by dragging.
* @param {!Blockly.Connection} one Connection to compare.
* @param {!Blockly.Connection} two Connection to compare against.
* @return {boolean} True if the connections share a type.
* @public
*/
Blockly.IConnectionChecker.prototype.doDragChecks;

View File

@@ -504,7 +504,7 @@ Blockly.navigation.connect_ = function(movingConnection, destConnection) {
var reason = checker.canConnectWithReason(
movingConnection, destConnection, false);
Blockly.navigation.warn_('Connection failed with error: ' +
checker.getErrorMessage(movingConnection, destConnection, reason));
checker.getErrorMessage(reason, movingConnection, destConnection));
return false;
}
};

View File

@@ -19,8 +19,6 @@ goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.object');
goog.requireType('Blockly.ConnectionChecker');
/**
* Class for a connection between blocks that may be rendered on screen.

View File

@@ -20,6 +20,7 @@ goog.require('Blockly.utils.math');
goog.require('Blockly.VariableMap');
goog.requireType('Blockly.IASTNodeLocation');
goog.requireType('Blockly.IConnectionChecker');
/**
@@ -45,7 +46,7 @@ Blockly.Workspace = function(opt_options) {
/**
* An object that encapsulates logic for safety, type, and dragging checks.
* @type {Blockly}
* @type {!Blockly.IConnectionChecker}
*/
this.connectionChecker = new Blockly.ConnectionChecker();