Resolve 13 warnings

Reduce count from 632 to 619.
Eliminate copy-paste code duplication in Field.prototype.setValue
This commit is contained in:
Neil Fraser
2019-06-11 21:12:29 -07:00
committed by Neil Fraser
parent bf6d621c63
commit b8cbd9e7df
12 changed files with 59 additions and 50 deletions

View File

@@ -468,7 +468,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = {
i++;
}
// Rebuild block.
for (var i = 1; i <= this.elseifCount_; i++) {
for (i = 1; i <= this.elseifCount_; i++) {
this.appendValueInput('IF' + i)
.setCheck('Boolean')
.appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF']);

View File

@@ -372,17 +372,18 @@ Blockly.Blocks['procedures_defnoreturn'] = {
// Add options to create getters for each parameter.
if (!this.isCollapsed()) {
for (var i = 0; i < this.argumentVarModels_.length; i++) {
var option = {enabled: true};
var argOption = {enabled: true};
var argVar = this.argumentVarModels_[i];
var name = argVar.name;
option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', name);
argOption.text = Blockly.Msg['VARIABLES_SET_CREATE_GET']
.replace('%1', argVar.name);
var xmlField = Blockly.Variables.generateVariableFieldDom(argVar);
var xmlBlock = document.createElement('block');
xmlBlock.setAttribute('type', 'variables_get');
xmlBlock.appendChild(xmlField);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
options.push(option);
var argXmlField = Blockly.Variables.generateVariableFieldDom(argVar);
var argXmlBlock = document.createElement('block');
argXmlBlock.setAttribute('type', 'variables_get');
argXmlBlock.appendChild(argXmlField);
argOption.callback =
Blockly.ContextMenu.callbackFactory(this, argXmlBlock);
options.push(argOption);
}
}
},

View File

@@ -700,8 +700,8 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
if (this.workspace.options.disable && this.isEditable()) {
// Option to disable/enable block.
var disableOption = {
text: this.disabled ?
Blockly.Msg['ENABLE_BLOCK'] : Blockly.Msg['DISABLE_BLOCK'],
text: this.isEnabled() ?
Blockly.Msg['DISABLE_BLOCK'] : Blockly.Msg['ENABLE_BLOCK'],
enabled: !this.getInheritedDisabled(),
callback: function() {
var group = Blockly.Events.getGroup();
@@ -936,7 +936,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
* Change the colour of a block.
*/
Blockly.BlockSvg.prototype.updateColour = function() {
if (this.disabled) {
if (!this.isEnabled()) {
// Disabled blocks don't have colour.
return;
}
@@ -999,7 +999,7 @@ Blockly.BlockSvg.prototype.setShadowColour_ = function() {
* Enable or disable a block.
*/
Blockly.BlockSvg.prototype.updateDisabled = function() {
if (this.disabled || this.getInheritedDisabled()) {
if (!this.isEnabled() || this.getInheritedDisabled()) {
var added = Blockly.utils.dom.addClass(
/** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled');
if (added) {

View File

@@ -107,7 +107,7 @@ Blockly.clipboardTypeCounts_ = null;
/**
* Cached value for whether 3D is supported.
* @type {!boolean}
* @type {?boolean}
* @private
*/
Blockly.cache3dSupported_ = null;
@@ -181,9 +181,9 @@ Blockly.svgResize = function(workspace) {
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there
// are multiple workspaces and non-main workspaces are able to accept input.
Blockly.onKeyDown_ = function(e) {
var workspace = Blockly.mainWorkspace;
if (workspace.options.readOnly || Blockly.utils.isTargetInput(e) ||
(workspace.rendered && !workspace.isVisible())) {
var mainWorkspace = Blockly.mainWorkspace;
if (mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) ||
(mainWorkspace.rendered && !mainWorkspace.isVisible())) {
// No key actions on readonly workspaces.
// When focused on an HTML text input widget, don't trap any keys.
// Ignore keypresses on rendered workspaces that have been explicitly
@@ -247,7 +247,7 @@ Blockly.onKeyDown_ = function(e) {
} else if (e.keyCode == 90) {
// 'z' for undo 'Z' is for redo.
Blockly.hideChaff();
workspace.undo(e.shiftKey);
mainWorkspace.undo(e.shiftKey);
}
}
// Common code for delete and cut.

View File

@@ -374,7 +374,7 @@ Blockly.Bubble.prototype.registerResizeEvent = function(callback) {
/**
* Move this bubble to the top of the stack.
* @return {!boolean} Whether or not the bubble has been moved.
* @return {boolean} Whether or not the bubble has been moved.
* @private
*/
Blockly.Bubble.prototype.promote_ = function() {

View File

@@ -736,31 +736,19 @@ Blockly.Field.prototype.setValue = function(newValue) {
var validatedValue = this.doClassValidation_(newValue);
// Class validators might accidentally forget to return, we'll ignore that.
if (validatedValue !== undefined) {
newValue = validatedValue;
}
if (newValue === null) {
doLogging && console.log('invalid, return');
this.doValueInvalid_();
if (this.isDirty_) {
this.forceRerender();
}
newValue = this.validate_(newValue, validatedValue);
if (newValue instanceof Error) {
doLogging && console.log('invalid class validation, return');
return;
}
var localValidator = this.getValidator();
if (localValidator) {
var validatedValue = localValidator.call(this, newValue);
validatedValue = localValidator.call(this, newValue);
// Local validators might accidentally forget to return, we'll ignore that.
if (validatedValue !== undefined) {
newValue = validatedValue;
}
if (newValue === null) {
doLogging && console.log('invalid, return');
this.doValueInvalid_();
if (this.isDirty_) {
this.forceRerender();
}
newValue = this.validate_(newValue, validatedValue);
if (newValue instanceof Error) {
doLogging && console.log('invalid local validation, return');
return;
}
}
@@ -782,6 +770,27 @@ Blockly.Field.prototype.setValue = function(newValue) {
doLogging && console.log(this.value_);
};
/**
* Process the result of validation.
* @param {*} newValue New value.
* @param {*} validatedValue Validated value.
* @return {*} New value, or an Error object.
* @private
*/
Blockly.Field.prototype.validate_ = function(newValue, validatedValue) {
if (validatedValue !== undefined) {
newValue = validatedValue;
}
if (newValue === null) {
this.doValueInvalid_();
if (this.isDirty_) {
this.forceRerender();
}
return Error();
}
return newValue;
};
/**
* Get the current value of the field.
* @return {*} Current value.

View File

@@ -36,7 +36,6 @@ goog.require('goog.date.DateTime');
goog.require('goog.events');
goog.require('goog.i18n.DateTimeSymbols');
goog.require('goog.i18n.DateTimeSymbols_he');
goog.require('goog.style');
goog.require('goog.ui.DatePicker');

View File

@@ -134,7 +134,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function() {
* Called by setValue if the text input is valid. Updates the value of the
* field, and updates the text of the field if it is not currently being
* edited (i.e. handled by the htmlInput_).
* @param {!string} newValue The new validated value of the field.
* @param {string} newValue The new validated value of the field.
* @protected
*/
Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) {

View File

@@ -608,7 +608,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) {
* Does this flyout allow you to create a new instance of the given block?
* Used for deciding if a block can be "dragged out of" the flyout.
* @param {!Blockly.BlockSvg} block The block to copy from the flyout.
* @return {!boolean} True if you can create a new instance of the block, false
* @return {boolean} True if you can create a new instance of the block, false
* otherwise.
* @package
*/

View File

@@ -164,7 +164,7 @@ Blockly.Options.prototype.getMetrics = null;
* Parse the user-specified move options, using reasonable defaults where
* behaviour is unspecified.
* @param {!Object} options Dictionary of options.
* @param {!boolean} hasCategories Whether the workspace has categories or not.
* @param {boolean} hasCategories Whether the workspace has categories or not.
* @return {!Object} A dictionary of normalized options.
* @private
*/

View File

@@ -94,8 +94,8 @@ Blockly.utils.Coordinate.magnitude = function(a) {
/**
* Returns the difference between two coordinates as a new
* Blockly.utils.Coordinate.
* @param {!Blockly.utils.Coordinate} a A Coordinate.
* @param {!Blockly.utils.Coordinate} b A Coordinate.
* @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate.
* @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate.
* @return {!Blockly.utils.Coordinate} A Coordinate representing the difference
* between `a` and `b`.
*/
@@ -105,10 +105,10 @@ Blockly.utils.Coordinate.difference = function(a, b) {
/**
* Returns the sum of two coordinates as a new Blockly.utils.Coordinate.
* @param {!Blockly.utils.Coordinate} a A Coordinate.
* @param {!Blockly.utils.Coordinate} b A Coordinate.
* @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of the two
* coordinates.
* @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate.
* @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate.
* @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of
* the two coordinates.
*/
Blockly.utils.Coordinate.sum = function(a, b) {
return new Blockly.utils.Coordinate(a.x + b.x, a.y + b.y);

View File

@@ -1676,7 +1676,7 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, amount) {
// Find the new scrollX/scrollY so that the center remains in the same
// position (relative to the center) after we zoom.
// newScale and matrix.a should be identical (within a rounding error).
var matrix = matrix.translate(x * (1 - scaleChange), y * (1 - scaleChange))
matrix = matrix.translate(x * (1 - scaleChange), y * (1 - scaleChange))
.scale(scaleChange);
// scrollX and scrollY are in pixels.
// The scrollX and scrollY still need to have absoluteLeft and absoluteTop