From 94bdd1850582ef4332c76f3f9c486fba9c48367b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:23:17 -0700 Subject: [PATCH] Migrate core/field_number.js to ES6 const/let --- core/field_number.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 369a161f8..d45c790cd 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -225,14 +225,14 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { */ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; - var precisionString = String(this.precision_); + let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { // String() is fast. But it turns .0000001 into '1e-7'. // Use the much slower toLocaleString to access all the digits. precisionString = this.precision_.toLocaleString('en-US', {maximumFractionDigits: 20}); } - var decimalIndex = precisionString.indexOf('.'); + const decimalIndex = precisionString.indexOf('.'); if (decimalIndex == -1) { // If the precision is 0 (float) allow any number of decimals, // otherwise allow none. @@ -265,7 +265,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Clean up text. - var newValue = String(opt_newValue); + let newValue = String(opt_newValue); // TODO: Handle cases like 'ten', '1.203,14', etc. // 'O' is sometimes mistaken for '0' by inexperienced users. newValue = newValue.replace(/O/ig, '0'); @@ -275,7 +275,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { newValue = newValue.replace(/infinity/i, 'Infinity'); // Clean up number. - var n = Number(newValue || 0); + let n = Number(newValue || 0); if (isNaN(n)) { // Invalid number. return null; @@ -300,7 +300,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @override */ Blockly.FieldNumber.prototype.widgetCreate_ = function() { - var htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); + const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..5485014dd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']);