chore: replace more uses of var with const and let (#5628)

* chore: fix uses of var in core/block_dragger

* chore: fix uses of var in core/extensions.js

* chore: fix uses of var in core/field_multilineinput.js

* chore: fix uses of var in assorted core files

* chore: fix uses of var in node test runner and playground screenshot code

* fix: undefined return from measureFontMetrics

* fix: violations of no-const-assign

* chore: only one variable declaration per line
This commit is contained in:
Rachel Fenichel
2021-10-25 09:28:31 -07:00
committed by GitHub
parent 5cdc5f587f
commit f70032aaa6
11 changed files with 61 additions and 54 deletions

View File

@@ -275,12 +275,16 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) {
const preventMove = !!this.dragTarget_ &&
this.dragTarget_.shouldPreventMove(this.draggingBlock_);
/** @type {Coordinate} */
let newLoc;
/** @type {Coordinate} */
let delta;
if (preventMove) {
var newLoc = this.startXY_;
newLoc = this.startXY_;
} else {
const newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY);
var delta = newValues.delta;
var newLoc = newValues.newLocation;
delta = newValues.delta;
newLoc = newValues.newLocation;
}
this.draggingBlock_.moveOffDragSurface(newLoc);

View File

@@ -95,7 +95,7 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) {
const errorPrefix = 'Error when registering mutator "' + name + '": ';
checkHasMutatorProperties(errorPrefix, mixinObj);
var hasMutatorDialog = checkMutatorDialog(mixinObj, errorPrefix);
const hasMutatorDialog = checkMutatorDialog(mixinObj, errorPrefix);
if (opt_helperFn && (typeof opt_helperFn !== 'function')) {
throw Error(errorPrefix + 'Extension "' + name + '" is not a function');
@@ -261,8 +261,8 @@ const checkMutatorDialog = function(object, errorPrefix) {
* not actually a function.
*/
const checkHasFunctionPair = function(object, name1, name2, errorPrefix) {
var has1 = object[name1] !== undefined;
var has2 = object[name2] !== undefined;
const has1 = object[name1] !== undefined;
const has2 = object[name2] !== undefined;
if (has1 && has2) {
if (typeof object[name1] !== 'function') {
@@ -285,8 +285,8 @@ const checkHasFunctionPair = function(object, name1, name2, errorPrefix) {
* @param {!Object} object The object to inspect.
*/
const checkHasMutatorProperties = function(errorPrefix, object) {
var hasXmlHooks = checkXmlHooks(object, errorPrefix);
var hasJsonHooks = checkJsonHooks(object, errorPrefix);
const hasXmlHooks = checkXmlHooks(object, errorPrefix);
const hasJsonHooks = checkJsonHooks(object, errorPrefix);
if (!hasXmlHooks && !hasJsonHooks) {
throw Error(
errorPrefix +

View File

@@ -246,7 +246,7 @@ FieldMultilineInput.prototype.render_ = function() {
}
if (this.isBeingEdited_) {
var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_);
const htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_);
if (this.isOverflowedY_) {
dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY');
} else {
@@ -265,7 +265,7 @@ FieldMultilineInput.prototype.render_ = function() {
} else {
this.resizeEditor_();
}
var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_);
const htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_);
if (!this.isTextValid_) {
dom.addClass(htmlInput, 'blocklyInvalidInput');
aria.setState(htmlInput, aria.State.INVALID, true);
@@ -284,7 +284,7 @@ FieldMultilineInput.prototype.updateSize_ = function() {
const nodes = this.textGroup_.childNodes;
let totalWidth = 0;
let totalHeight = 0;
for (var i = 0; i < nodes.length; i++) {
for (let i = 0; i < nodes.length; i++) {
const tspan = /** @type {!Element} */ (nodes[i]);
const textWidth = dom.getTextWidth(tspan);
if (textWidth > totalWidth) {
@@ -306,7 +306,7 @@ FieldMultilineInput.prototype.updateSize_ = function() {
const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT;
const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY;
for (var i = 0; i < actualEditorLines.length; i++) {
for (let i = 0; i < actualEditorLines.length; i++) {
if (actualEditorLines[i].length > this.maxDisplayLength) {
actualEditorLines[i] =
actualEditorLines[i].substring(0, this.maxDisplayLength);

View File

@@ -432,7 +432,7 @@ ASTNode.prototype.findPrevForField_ = function() {
* @private
*/
ASTNode.prototype.navigateBetweenStacks_ = function(forward) {
var curLocation = this.getLocation();
let curLocation = this.getLocation();
if (curLocation.getSourceBlock) {
curLocation = /** @type {!IASTNodeLocationWithBlock} */ (curLocation)
.getSourceBlock();

View File

@@ -45,7 +45,7 @@ const {inputTypes} = goog.require('Blockly.inputTypes');
* }}
* @alias Blockly.serialization.blocks.ConnectionState
*/
var ConnectionState;
let ConnectionState;
exports.ConnectionState = ConnectionState;
/**
@@ -67,7 +67,7 @@ exports.ConnectionState = ConnectionState;
* }}
* @alias Blockly.serialization.blocks.State
*/
var State;
let State;
exports.State = State;
/**

View File

@@ -35,7 +35,7 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
* }}
* @alias Blockly.serialization.variables.State
*/
var State;
let State;
exports.State = State;
/**

View File

@@ -722,7 +722,7 @@ Trashcan.prototype.cleanBlockJson_ = function(json) {
}
const inputs = json['inputs'];
for (var name in inputs) {
for (const name in inputs) {
const input = inputs[name];
cleanRec(input['block']);
cleanRec(input['shadow']);

View File

@@ -413,8 +413,11 @@ const measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) {
div.appendChild(block);
document.body.appendChild(div);
const result = {
height: 0,
baseline: 0,
};
try {
var result = {};
div.style.alignItems = 'baseline';
result.baseline = block.offsetTop - span.offsetTop;
div.style.alignItems = 'flex-end';

View File

@@ -2688,8 +2688,8 @@ WorkspaceSvg.prototype.hideChaff = function(opt_onlyClosePopups) {
WidgetDiv.hide();
DropDownDiv.hideWithoutAnimation();
var onlyClosePopups = !!opt_onlyClosePopups;
var autoHideables = this.getComponentManager().getComponents(
const onlyClosePopups = !!opt_onlyClosePopups;
const autoHideables = this.getComponentManager().getComponents(
ComponentManager.Capability.AUTOHIDEABLE, true);
autoHideables.forEach(
(autoHideable) => autoHideable.autoHide(onlyClosePopups));