mirror of
https://github.com/google/blockly.git
synced 2026-01-12 03:17:09 +01:00
Clean up get/set accessor definitions (#5488)
* Use Object.defineProperties instead of .defineProperty when installing get and set accessors for previously-mutable exports. * Add entries to renamings.js where feasible (i.e., for static rather than instance properties). (Don't do blockly.js yet, to avoid merge conflicts.)
This commit is contained in:
committed by
GitHub
parent
28fadf8c15
commit
dbf10cf167
@@ -29,6 +29,7 @@ const WidgetDiv = goog.require('Blockly.WidgetDiv');
|
||||
const Xml = goog.require('Blockly.Xml');
|
||||
const aria = goog.require('Blockly.utils.aria');
|
||||
const browserEvents = goog.require('Blockly.browserEvents');
|
||||
const deprecation = goog.require('Blockly.utils.deprecation');
|
||||
const dom = goog.require('Blockly.utils.dom');
|
||||
const internalConstants = goog.require('Blockly.internalConstants');
|
||||
const userAgent = goog.require('Blockly.utils.userAgent');
|
||||
@@ -64,9 +65,21 @@ const setCurrentBlock = function(block) {
|
||||
exports.setCurrentBlock = setCurrentBlock;
|
||||
|
||||
// Ad JS accessors for backwards compatibility.
|
||||
Object.defineProperty(exports, 'currentBlock', {
|
||||
get: getCurrentBlock,
|
||||
set: setCurrentBlock,
|
||||
Object.defineProperties(exports, {
|
||||
currentBlock: {
|
||||
get: function() {
|
||||
deprecation.warn(
|
||||
'Blockly.ContextMenu.currentBlock', 'September 2021', 'September 2022',
|
||||
'Blockly.Tooltip.getCurrentBlock()');
|
||||
return getCurrentBlock();
|
||||
},
|
||||
set: function(block) {
|
||||
deprecation.warn(
|
||||
'Blockly.ContextMenu.currentBlock', 'September 2021', 'September 2022',
|
||||
'Blockly.Tooltip.setCurrentBlock(block)');
|
||||
setCurrentBlock(block);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -411,27 +411,29 @@ Generator.prototype.functionNames_;
|
||||
*/
|
||||
Generator.prototype.nameDB_;
|
||||
|
||||
Object.defineProperty(Generator.prototype, 'variableDB_', {
|
||||
/**
|
||||
* Getter.
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @this {Generator}
|
||||
* @return {!Names|undefined} Name database.
|
||||
*/
|
||||
get: function() {
|
||||
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
|
||||
return this.nameDB_;
|
||||
Object.defineProperties(Generator.prototype, {
|
||||
variableDB_: {
|
||||
/**
|
||||
* Getter.
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @this {Generator}
|
||||
* @return {!Names|undefined} Name database.
|
||||
*/
|
||||
get: function() {
|
||||
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
|
||||
return this.nameDB_;
|
||||
},
|
||||
/**
|
||||
* Setter.
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @this {Generator}
|
||||
* @param {!Names|undefined} nameDb New name database.
|
||||
*/
|
||||
set: function(nameDb) {
|
||||
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
|
||||
this.nameDB_ = nameDb;
|
||||
},
|
||||
},
|
||||
/**
|
||||
* Setter.
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @this {Generator}
|
||||
* @param {!Names|undefined} nameDb New name database.
|
||||
*/
|
||||
set: function(nameDb) {
|
||||
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
|
||||
this.nameDB_ = nameDb;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,6 +86,27 @@ const renamings = {
|
||||
// Blockly.common.getMainWorkspace().hideChaff(). See PR #5460.
|
||||
},
|
||||
},
|
||||
'Blockly.ContextMenu': {
|
||||
exports: {
|
||||
currentBlock: {get: 'getCurrentBlock', set: 'setCurrentBlock'},
|
||||
},
|
||||
},
|
||||
'Blockly.Events': {
|
||||
exports: {
|
||||
recordUndo: {get: 'getRecordUndo', set: 'setRecordUndo'},
|
||||
},
|
||||
},
|
||||
'Blockly.Tooltip': {
|
||||
exports: {
|
||||
DIV: {get: 'getDiv', set: 'setDiv'},
|
||||
visible: {get: 'isVisible'},
|
||||
},
|
||||
},
|
||||
'Blockly.WidgetDiv': {
|
||||
exports: {
|
||||
DIV: {get: 'getDiv'},
|
||||
},
|
||||
},
|
||||
'Blockly.utils': {
|
||||
exports: {
|
||||
genUid: {module: 'Blockly.utils.idGenerator'},
|
||||
|
||||
@@ -28,7 +28,7 @@ goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionCheck
|
||||
goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Msg', 'Blockly.clipboard', 'Blockly.dialog', 'Blockly.inputTypes', 'Blockly.utils.idGenerator', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
@@ -28,7 +28,7 @@ goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionCheck
|
||||
goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Msg', 'Blockly.clipboard', 'Blockly.dialog', 'Blockly.inputTypes', 'Blockly.utils.idGenerator', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
Reference in New Issue
Block a user