From dc4a719e2f507468b303ed228381dc7d033cdd57 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:50:42 -0700 Subject: [PATCH 1/3] Migrate core/variable_model.js to goog.module --- core/variable_model.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index bc097da8a..ce4c37c66 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VariableModel'); +goog.module('Blockly.VariableModel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Workspace'); * @see {Blockly.FieldVariable} * @constructor */ -Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { +const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. * @type {!Blockly.Workspace} @@ -73,18 +74,20 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { /** * @return {string} The ID for the variable. */ -Blockly.VariableModel.prototype.getId = function() { +VariableModel.prototype.getId = function() { return this.id_; }; /** * A custom compare function for the VariableModel objects. - * @param {Blockly.VariableModel} var1 First variable to compare. - * @param {Blockly.VariableModel} var2 Second variable to compare. + * @param {VariableModel} var1 First variable to compare. + * @param {VariableModel} var2 Second variable to compare. * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, * and 1 if greater. * @package */ -Blockly.VariableModel.compareByName = function(var1, var2) { +VariableModel.compareByName = function(var1, var2) { return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'}); }; + +exports = VariableModel; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..0e0a7f034 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -196,7 +196,7 @@ goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['B goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); -goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); +goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 0a6893706f2c2a64b6865ab68c4bc62ce625a2ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:26 -0700 Subject: [PATCH 2/3] Migrate core/variable_model.js to named requires --- core/variable_model.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index ce4c37c66..74bc2b578 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -13,18 +13,18 @@ goog.module('Blockly.VariableModel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.utils'); - -goog.requireType('Blockly.Workspace'); /** * Class for a variable model. * Holds information for the variable including name, ID, and type. - * @param {!Blockly.Workspace} workspace The variable's workspace. + * @param {!Workspace} workspace The variable's workspace. * @param {string} name The name of the variable. This is the user-visible name * (e.g. 'my var' or '私の変数'), not the generated name. * @param {string=} opt_type The type of the variable like 'int' or 'string'. @@ -38,7 +38,7 @@ goog.requireType('Blockly.Workspace'); const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; @@ -65,9 +65,9 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { * @type {string} * @private */ - this.id_ = opt_id || Blockly.utils.genUid(); + this.id_ = opt_id || utils.genUid(); - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_CREATE))( + Events.fire(new (Events.get(Events.VAR_CREATE))( this)); }; From 6eb8667c3ccb5c9a4d613a881f0711a845cec533 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:46 -0700 Subject: [PATCH 3/3] clang-format core/variable_model.js --- core/variable_model.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index 74bc2b578..2f5936f4e 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -67,8 +67,7 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { */ this.id_ = opt_id || utils.genUid(); - Events.fire(new (Events.get(Events.VAR_CREATE))( - this)); + Events.fire(new (Events.get(Events.VAR_CREATE))(this)); }; /**