Fix some jsdoc types (#2701)

* Fix JSDoc regarding type inconsistencies. Make image field src required and update image field tests.
This commit is contained in:
Sam El-Husseini
2019-07-25 12:24:36 -07:00
committed by GitHub
parent 94bc23ff7e
commit c1b49a1da7
10 changed files with 57 additions and 35 deletions

View File

@@ -262,6 +262,7 @@ Blockly.BlockSvg.prototype.getIcons = function() {
/**
* Set parent of this block to be a new block or null.
* @param {Blockly.BlockSvg} newParent New parent block.
* @override
*/
Blockly.BlockSvg.prototype.setParent = function(newParent) {
var oldParent = this.parentBlock_;
@@ -894,10 +895,10 @@ Blockly.BlockSvg.prototype.getSvgRoot = function() {
/**
* Dispose of this block.
* @param {boolean} healStack If true, then try to heal any gap by connecting
* @param {boolean=} healStack If true, then try to heal any gap by connecting
* the next statement with the previous statement. Otherwise, dispose of
* all children of this block.
* @param {boolean} animate If true, show a disposal animation and sound.
* @param {boolean=} animate If true, show a disposal animation and sound.
*/
Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
if (!this.workspace) {

View File

@@ -199,7 +199,7 @@ Blockly.DropDownDiv.setCategory = function(category) {
* @param {!Blockly.Block} block Block to position the drop-down around.
* @param {Function=} opt_onHide Optional callback for when the drop-down is
* hidden.
* @param {number} opt_secondaryYOffset Optional Y offset for above-block
* @param {number=} opt_secondaryYOffset Optional Y offset for above-block
* positioning.
* @return {boolean} True if the menu rendered below block; false if above.
*/

View File

@@ -887,7 +887,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) {
/**
* Change the tooltip text for this field.
* @param {string|function|!Element} newTip Text for tooltip or a parent
* @param {string|Function|!Element} newTip Text for tooltip or a parent
* element to link to for its tooltip.
*/
Blockly.Field.prototype.setTooltip = function(newTip) {

View File

@@ -337,6 +337,7 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() {
* @param {string|number=} newValue The input value.
* @return {?number} A valid angle, or null if invalid.
* @protected
* @override
*/
Blockly.FieldAngle.prototype.doClassValidation_ = function(newValue) {
if (isNaN(newValue)) {

View File

@@ -36,7 +36,7 @@ goog.require('goog.math.Size');
/**
* Class for an image on a block.
* @param {string=} src The URL of the image. Defaults to an empty string.
* @param {string} src The URL of the image. Defaults to an empty string.
* @param {!(string|number)} width Width of the image.
* @param {!(string|number)} height Height of the image.
* @param {string=} opt_alt Optional alt text for when block is collapsed.
@@ -50,6 +50,9 @@ Blockly.FieldImage = function(src, width, height,
opt_alt, opt_onClick, opt_flipRtl) {
this.sourceBlock_ = null;
if (!src) {
throw Error('Src value of an image field is required');
}
if (isNaN(height) || isNaN(width)) {
throw Error('Height and width values of an image field must cast to' +

View File

@@ -39,6 +39,7 @@ goog.require('Blockly.FieldTextInput');
* @param {Function=} opt_validator A function that is called to validate
* changes to the field's value. Takes in a number & returns a validated
* number, or null to abort the change.
* @extends {Blockly.FieldTextInput}
* @constructor
*/
Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision,
@@ -105,6 +106,7 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) {
* @param {string|number=} newValue The input value.
* @return {?number} A valid number, or null if invalid.
* @protected
* @override
*/
Blockly.FieldNumber.prototype.doClassValidation_ = function(newValue) {
if (newValue === null || newValue === undefined) {

View File

@@ -320,7 +320,7 @@ Blockly.RenderedConnection.prototype.hideAll = function() {
/**
* Check if the two connections can be dragged to connect to each other.
* @param {!Blockly.Connection} candidate A nearby connection to check.
* @param {number} maxRadius The maximum radius allowed for connections, in
* @param {number=} maxRadius The maximum radius allowed for connections, in
* workspace units.
* @return {boolean} True if the connection is allowed, false otherwise.
*/

View File

@@ -27,16 +27,29 @@ goog.provide('Blockly.Theme');
/**
* A block style or a category style.
* @typedef {!Object.<string, string>}
*/
Blockly.Theme.Style;
* A block style.
* @typedef {{
* colourPrimary:string,
* colourSecondary:string,
* colourTertiary:string,
* hat:string
* }}
*/
Blockly.Theme.BlockStyle;
/**
* A category style.
* @typedef {{
* colour:string
* }}
*/
Blockly.Theme.CategoryStyle;
/**
* Class for a theme.
* @param {!Object.<string, Blockly.Theme.Style>} blockStyles A map from style
* @param {!Object.<string, Blockly.Theme.BlockStyle>} blockStyles A map from style
* names (strings) to objects with style attributes relating to blocks.
* @param {!Object.<string, Blockly.Theme.Style>} categoryStyles A map from
* @param {!Object.<string, Blockly.Theme.CategoryStyle>} categoryStyles A map from
* style names (strings) to objects with style attributes relating to
* categories.
* @constructor
@@ -48,7 +61,7 @@ Blockly.Theme = function(blockStyles, categoryStyles) {
/**
* Overrides or adds all values from blockStyles to blockStyles_
* @param {Object.<string, Blockly.Theme.Style>} blockStyles Map of
* @param {Object.<string, Blockly.Theme.BlockStyle>} blockStyles Map of
* block styles.
*/
Blockly.Theme.prototype.setAllBlockStyles = function(blockStyles) {
@@ -59,7 +72,7 @@ Blockly.Theme.prototype.setAllBlockStyles = function(blockStyles) {
/**
* Gets a map of all the block style names.
* @return {!Object.<string, Blockly.Theme.Style>} Map of block styles.
* @return {!Object.<string, Blockly.Theme.BlockStyle>} Map of block styles.
*/
Blockly.Theme.prototype.getAllBlockStyles = function() {
return this.blockStyles_;
@@ -68,7 +81,7 @@ Blockly.Theme.prototype.getAllBlockStyles = function() {
/**
* Gets the BlockStyle for the given block style name.
* @param {string} blockStyleName The name of the block style.
* @return {Blockly.Theme.Style|undefined} The named block style.
* @return {Blockly.Theme.BlockStyle|undefined} The named block style.
*/
Blockly.Theme.prototype.getBlockStyle = function(blockStyleName) {
return this.blockStyles_[blockStyleName];
@@ -77,7 +90,7 @@ Blockly.Theme.prototype.getBlockStyle = function(blockStyleName) {
/**
* Overrides or adds a style to the blockStyles map.
* @param {string} blockStyleName The name of the block style.
* @param {Blockly.Theme.Style} blockStyle The block style.
* @param {Blockly.Theme.BlockStyle} blockStyle The block style.
*/
Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) {
this.blockStyles_[blockStyleName] = blockStyle;
@@ -86,7 +99,7 @@ Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) {
/**
* Gets the CategoryStyle for the given category style name.
* @param {string} categoryStyleName The name of the category style.
* @return {Blockly.Theme.Style|undefined} The named category style.
* @return {Blockly.Theme.CategoryStyle|undefined} The named category style.
*/
Blockly.Theme.prototype.getCategoryStyle = function(categoryStyleName) {
return this.categoryStyles_[categoryStyleName];
@@ -95,7 +108,7 @@ Blockly.Theme.prototype.getCategoryStyle = function(categoryStyleName) {
/**
* Overrides or adds a style to the categoryStyles map.
* @param {string} categoryStyleName The name of the category style.
* @param {Blockly.Theme.Style} categoryStyle The category style.
* @param {Blockly.Theme.CategoryStyle} categoryStyle The category style.
*/
Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName,
categoryStyle) {

View File

@@ -671,6 +671,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new ID.
* @return {!Blockly.BlockSvg} The created block.
* @override
*/
Blockly.WorkspaceSvg.prototype.newBlock = function(prototypeName, opt_id) {
return new Blockly.BlockSvg(this, prototypeName, opt_id);

View File

@@ -25,9 +25,6 @@ suite ('Image Fields', function() {
assertEquals(actualValue, expectedValue);
assertEquals(actualText, expectedText);
}
function assertValueDefault(imageField) {
assertValue(imageField, '', '');
}
suite('Constructor', function() {
test('Empty', function() {
chai.assert.throws(function() {
@@ -35,12 +32,14 @@ suite ('Image Fields', function() {
});
});
test('Null Src', function() {
var imageField = new Blockly.FieldImage(null, 1, 1);
assertValueDefault(imageField);
chai.assert.throws(function() {
new Blockly.FieldImage(null, 1, 1);
});
});
test('Undefined Src', function() {
var imageField = new Blockly.FieldImage(undefined, 1, 1);
assertValueDefault(imageField);
chai.assert.throws(function() {
new Blockly.FieldImage(undefined, 1, 1);
});
});
test('Null Size', function() {
chai.assert.throws(function() {
@@ -81,20 +80,22 @@ suite ('Image Fields', function() {
});
});
test('Null Src', function() {
var imageField = Blockly.FieldImage.fromJson({
src: null,
width: 1,
height: 1
chai.assert.throws(function() {
Blockly.FieldImage.fromJson({
src: null,
width: 1,
height: 1
});
});
assertValueDefault(imageField);
});
test('Undefined Src', function() {
var imageField = Blockly.FieldImage.fromJson({
src: undefined,
width: 1,
height: 1
chai.assert.throws(function() {
Blockly.FieldImage.fromJson({
src: undefined,
width: 1,
height: 1
});
});
assertValueDefault(imageField);
});
test('Null Size', function() {
chai.assert.throws(function() {