Skip to content

Commit

Permalink
refactor: Name default export of Blockly.blocks
Browse files Browse the repository at this point in the history
Use named exports in Blockly.blocks by giving the former default
export the name 'definitions'.

Part of #5153.
  • Loading branch information
cpcallen committed Sep 21, 2021
1 parent 8aa44f3 commit e33b736
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 76 deletions.
18 changes: 9 additions & 9 deletions blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
}
]); // END JSON EXTRACT (Do not delete this comment.)

Blockly.blocks['lists_create_with'] = {
Blockly.blocks.definitions['lists_create_with'] = {
/**
* Block for creating a list with any number of elements of any type.
* @this {Blockly.Block}
Expand Down Expand Up @@ -259,7 +259,7 @@ Blockly.blocks['lists_create_with'] = {
}
};

Blockly.blocks['lists_create_with_container'] = {
Blockly.blocks.definitions['lists_create_with_container'] = {
/**
* Mutator block for list container.
* @this {Blockly.Block}
Expand All @@ -274,7 +274,7 @@ Blockly.blocks['lists_create_with_container'] = {
}
};

Blockly.blocks['lists_create_with_item'] = {
Blockly.blocks.definitions['lists_create_with_item'] = {
/**
* Mutator block for adding items.
* @this {Blockly.Block}
Expand All @@ -290,7 +290,7 @@ Blockly.blocks['lists_create_with_item'] = {
}
};

Blockly.blocks['lists_indexOf'] = {
Blockly.blocks.definitions['lists_indexOf'] = {
/**
* Block for finding an item in the list.
* @this {Blockly.Block}
Expand Down Expand Up @@ -319,7 +319,7 @@ Blockly.blocks['lists_indexOf'] = {
}
};

Blockly.blocks['lists_getIndex'] = {
Blockly.blocks.definitions['lists_getIndex'] = {
/**
* Block for getting element at index.
* @this {Blockly.Block}
Expand Down Expand Up @@ -510,7 +510,7 @@ Blockly.blocks['lists_getIndex'] = {
}
};

Blockly.blocks['lists_setIndex'] = {
Blockly.blocks.definitions['lists_setIndex'] = {
/**
* Block for setting the element at index.
* @this {Blockly.Block}
Expand Down Expand Up @@ -656,7 +656,7 @@ Blockly.blocks['lists_setIndex'] = {
}
};

Blockly.blocks['lists_getSublist'] = {
Blockly.blocks.definitions['lists_getSublist'] = {
/**
* Block for getting sublist.
* @this {Blockly.Block}
Expand Down Expand Up @@ -772,7 +772,7 @@ Blockly.blocks['lists_getSublist'] = {
}
};

Blockly.blocks['lists_sort'] = {
Blockly.blocks.definitions['lists_sort'] = {
/**
* Block for sorting a list.
* @this {Blockly.Block}
Expand Down Expand Up @@ -812,7 +812,7 @@ Blockly.blocks['lists_sort'] = {
}
};

Blockly.blocks['lists_split'] = {
Blockly.blocks.definitions['lists_split'] = {
/**
* Block for splitting text into a list, or joining a list into text.
* @this {Blockly.Block}
Expand Down
84 changes: 52 additions & 32 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ goog.require('Blockly.Mutator');
goog.require('Blockly.Warning');


Blockly.blocks['procedures_defnoreturn'] = {
Blockly.blocks.definitions['procedures_defnoreturn'] = {
/**
* Block for defining a procedure with no return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -450,7 +450,7 @@ Blockly.blocks['procedures_defnoreturn'] = {
callType_: 'procedures_callnoreturn'
};

Blockly.blocks['procedures_defreturn'] = {
Blockly.blocks.definitions['procedures_defreturn'] = {
/**
* Block for defining a procedure with a return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -482,12 +482,16 @@ Blockly.blocks['procedures_defreturn'] = {
this.setStatements_(true);
this.statementConnection_ = null;
},
setStatements_: Blockly.blocks['procedures_defnoreturn'].setStatements_,
updateParams_: Blockly.blocks['procedures_defnoreturn'].updateParams_,
mutationToDom: Blockly.blocks['procedures_defnoreturn'].mutationToDom,
domToMutation: Blockly.blocks['procedures_defnoreturn'].domToMutation,
decompose: Blockly.blocks['procedures_defnoreturn'].decompose,
compose: Blockly.blocks['procedures_defnoreturn'].compose,
setStatements_:
Blockly.blocks.definitions['procedures_defnoreturn'].setStatements_,
updateParams_:
Blockly.blocks.definitions['procedures_defnoreturn'].updateParams_,
mutationToDom:
Blockly.blocks.definitions['procedures_defnoreturn'].mutationToDom,
domToMutation:
Blockly.blocks.definitions['procedures_defnoreturn'].domToMutation,
decompose: Blockly.blocks.definitions['procedures_defnoreturn'].decompose,
compose: Blockly.blocks.definitions['procedures_defnoreturn'].compose,
/**
* Return the signature of this procedure definition.
* @return {!Array} Tuple containing three elements:
Expand All @@ -499,16 +503,21 @@ Blockly.blocks['procedures_defreturn'] = {
getProcedureDef: function() {
return [this.getFieldValue('NAME'), this.arguments_, true];
},
getVars: Blockly.blocks['procedures_defnoreturn'].getVars,
getVarModels: Blockly.blocks['procedures_defnoreturn'].getVarModels,
renameVarById: Blockly.blocks['procedures_defnoreturn'].renameVarById,
updateVarName: Blockly.blocks['procedures_defnoreturn'].updateVarName,
displayRenamedVar_: Blockly.blocks['procedures_defnoreturn'].displayRenamedVar_,
customContextMenu: Blockly.blocks['procedures_defnoreturn'].customContextMenu,
getVars: Blockly.blocks.definitions['procedures_defnoreturn'].getVars,
getVarModels:
Blockly.blocks.definitions['procedures_defnoreturn'].getVarModels,
renameVarById:
Blockly.blocks.definitions['procedures_defnoreturn'].renameVarById,
updateVarName:
Blockly.blocks.definitions['procedures_defnoreturn'].updateVarName,
displayRenamedVar_:
Blockly.blocks.definitions['procedures_defnoreturn'].displayRenamedVar_,
customContextMenu:
Blockly.blocks.definitions['procedures_defnoreturn'].customContextMenu,
callType_: 'procedures_callreturn'
};

Blockly.blocks['procedures_mutatorcontainer'] = {
Blockly.blocks.definitions['procedures_mutatorcontainer'] = {
/**
* Mutator block for procedure container.
* @this {Blockly.Block}
Expand All @@ -526,7 +535,7 @@ Blockly.blocks['procedures_mutatorcontainer'] = {
},
};

Blockly.blocks['procedures_mutatorarg'] = {
Blockly.blocks.definitions['procedures_mutatorarg'] = {
/**
* Mutator block for procedure argument.
* @this {Blockly.Block}
Expand Down Expand Up @@ -637,7 +646,7 @@ Blockly.blocks['procedures_mutatorarg'] = {
}
};

Blockly.blocks['procedures_callnoreturn'] = {
Blockly.blocks.definitions['procedures_callnoreturn'] = {
/**
* Block for calling a procedure with no return value.
* @this {Blockly.Block}
Expand Down Expand Up @@ -1029,7 +1038,7 @@ Blockly.blocks['procedures_callnoreturn'] = {
defType_: 'procedures_defnoreturn'
};

Blockly.blocks['procedures_callreturn'] = {
Blockly.blocks.definitions['procedures_callreturn'] = {
/**
* Block for calling a procedure with a return value.
* @this {Blockly.Block}
Expand All @@ -1048,24 +1057,33 @@ Blockly.blocks['procedures_callreturn'] = {
this.previousEnabledState_ = true;
},

getProcedureCall: Blockly.blocks['procedures_callnoreturn'].getProcedureCall,
renameProcedure: Blockly.blocks['procedures_callnoreturn'].renameProcedure,
getProcedureCall:
Blockly.blocks.definitions['procedures_callnoreturn'].getProcedureCall,
renameProcedure:
Blockly.blocks.definitions['procedures_callnoreturn'].renameProcedure,
setProcedureParameters_:
Blockly.blocks['procedures_callnoreturn'].setProcedureParameters_,
updateShape_: Blockly.blocks['procedures_callnoreturn'].updateShape_,
mutationToDom: Blockly.blocks['procedures_callnoreturn'].mutationToDom,
domToMutation: Blockly.blocks['procedures_callnoreturn'].domToMutation,
saveExtraState: Blockly.blocks['procedures_callnoreturn'].saveExtraState,
loadExtraState: Blockly.blocks['procedures_callnoreturn'].loadExtraState,
getVars: Blockly.blocks['procedures_callnoreturn'].getVars,
getVarModels: Blockly.blocks['procedures_callnoreturn'].getVarModels,
onchange: Blockly.blocks['procedures_callnoreturn'].onchange,
Blockly.blocks.definitions['procedures_callnoreturn']
.setProcedureParameters_,
updateShape_:
Blockly.blocks.definitions['procedures_callnoreturn'].updateShape_,
mutationToDom:
Blockly.blocks.definitions['procedures_callnoreturn'].mutationToDom,
domToMutation:
Blockly.blocks.definitions['procedures_callnoreturn'].domToMutation,
saveExtraState:
Blockly.blocks.definitions['procedures_callnoreturn'].saveExtraState,
loadExtraState:
Blockly.blocks.definitions['procedures_callnoreturn'].loadExtraState,
getVars: Blockly.blocks.definitions['procedures_callnoreturn'].getVars,
getVarModels:
Blockly.blocks.definitions['procedures_callnoreturn'].getVarModels,
onchange: Blockly.blocks.definitions['procedures_callnoreturn'].onchange,
customContextMenu:
Blockly.blocks['procedures_callnoreturn'].customContextMenu,
Blockly.blocks.definitions['procedures_callnoreturn'].customContextMenu,
defType_: 'procedures_defreturn'
};

Blockly.blocks['procedures_ifreturn'] = {
Blockly.blocks.definitions['procedures_ifreturn'] = {
/**
* Block for conditionally returning a value from a procedure.
* @this {Blockly.Block}
Expand Down Expand Up @@ -1162,7 +1180,9 @@ Blockly.blocks['procedures_ifreturn'] = {
/**
* List of block types that are functions and thus do not need warnings.
* To add a new function type add this to your code:
* Blockly.blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
*
* Blockly.blocks.definitions['procedures_ifreturn']
* .FUNCTION_TYPES.push('custom_func');
*/
FUNCTION_TYPES: ['procedures_defnoreturn', 'procedures_defreturn']
};
24 changes: 12 additions & 12 deletions blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
}
]); // END JSON EXTRACT (Do not delete this comment.)

Blockly.blocks['text_getSubstring'] = {
Blockly.blocks.definitions['text_getSubstring'] = {
/**
* Block for getting substring.
* @this {Blockly.Block}
Expand Down Expand Up @@ -347,7 +347,7 @@ Blockly.blocks['text_getSubstring'] = {
}
};

Blockly.blocks['text_changeCase'] = {
Blockly.blocks.definitions['text_changeCase'] = {
/**
* Block for changing capitalization.
* @this {Blockly.Block}
Expand All @@ -368,7 +368,7 @@ Blockly.blocks['text_changeCase'] = {
}
};

Blockly.blocks['text_trim'] = {
Blockly.blocks.definitions['text_trim'] = {
/**
* Block for trimming spaces.
* @this {Blockly.Block}
Expand All @@ -389,7 +389,7 @@ Blockly.blocks['text_trim'] = {
}
};

Blockly.blocks['text_print'] = {
Blockly.blocks.definitions['text_print'] = {
/**
* Block for print statement.
* @this {Blockly.Block}
Expand All @@ -412,7 +412,7 @@ Blockly.blocks['text_print'] = {
}
};

Blockly.blocks['text_prompt_ext'] = {
Blockly.blocks.definitions['text_prompt_ext'] = {
/**
* Block for prompt function (external message).
* @this {Blockly.Block}
Expand Down Expand Up @@ -474,7 +474,7 @@ Blockly.blocks['text_prompt_ext'] = {
// XML hooks are kept for backwards compatibility.
};

Blockly.blocks['text_prompt'] = {
Blockly.blocks.definitions['text_prompt'] = {
/**
* Block for prompt function (internal message).
* The 'text_prompt_ext' block is preferred as it is more flexible.
Expand Down Expand Up @@ -506,12 +506,12 @@ Blockly.blocks['text_prompt'] = {
Blockly.Msg['TEXT_PROMPT_TOOLTIP_NUMBER'];
});
},
updateType_: Blockly.blocks['text_prompt_ext'].updateType_,
mutationToDom: Blockly.blocks['text_prompt_ext'].mutationToDom,
domToMutation: Blockly.blocks['text_prompt_ext'].domToMutation
updateType_: Blockly.blocks.definitions['text_prompt_ext'].updateType_,
mutationToDom: Blockly.blocks.definitions['text_prompt_ext'].mutationToDom,
domToMutation: Blockly.blocks.definitions['text_prompt_ext'].domToMutation
};

Blockly.blocks['text_count'] = {
Blockly.blocks.definitions['text_count'] = {
/**
* Block for counting how many times one string appears within another string.
* @this {Blockly.Block}
Expand Down Expand Up @@ -540,7 +540,7 @@ Blockly.blocks['text_count'] = {
}
};

Blockly.blocks['text_replace'] = {
Blockly.blocks.definitions['text_replace'] = {
/**
* Block for replacing one string with another in the text.
* @this {Blockly.Block}
Expand Down Expand Up @@ -574,7 +574,7 @@ Blockly.blocks['text_replace'] = {
}
};

Blockly.blocks['text_reverse'] = {
Blockly.blocks.definitions['text_reverse'] = {
/**
* Block for reversing a string.
* @this {Blockly.Block}
Expand Down
2 changes: 1 addition & 1 deletion core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Block = function(workspace, prototypeName, opt_id) {
if (prototypeName) {
/** @type {string} */
this.type = prototypeName;
const prototype = blocks[prototypeName];
const prototype = blocks.definitions[prototypeName];
if (!prototype || typeof prototype != 'object') {
throw TypeError('Unknown block type: ' + prototypeName);
}
Expand Down
8 changes: 4 additions & 4 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ goog.require('Blockly.Xml');


// Reexports.
/** @deprecated Use Blockly.blocks instead. */
exports.Blocks = blocks;
/** @deprecated Use Blockly.blocks.definitions instead. */
exports.Blocks = blocks.definitions;

/**
* Blockly core version.
Expand Down Expand Up @@ -246,12 +246,12 @@ const defineBlocksWithJsonArray = function(jsonArray) {
'Block definition #' + i +
' in JSON array is missing a type attribute. Skipping.');
} else {
if (blocks[typename]) {
if (blocks.definitions[typename]) {
console.warn(
'Block definition #' + i + ' in JSON array' +
' overwrites prior definition of "' + typename + '".');
}
blocks[typename] = {init: jsonInitFactory(elem)};
blocks.definitions[typename] = {init: jsonInitFactory(elem)};
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ goog.module.declareLegacyNamespace();
* A mapping of block type names to block prototype objects.
* @type {!Object<string,!Object>}
*/
const blocks = Object.create(null);
const definitions = Object.create(null);

exports = blocks;
exports.definitions = definitions;
6 changes: 3 additions & 3 deletions core/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ exports.rename = rename;
*/
const flyoutCategory = function(workspace) {
const xmlList = [];
if (blocks['procedures_defnoreturn']) {
if (blocks.definitions['procedures_defnoreturn']) {
// <block type="procedures_defnoreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
Expand All @@ -207,7 +207,7 @@ const flyoutCategory = function(workspace) {
block.appendChild(nameField);
xmlList.push(block);
}
if (blocks['procedures_defreturn']) {
if (blocks.definitions['procedures_defreturn']) {
// <block type="procedures_defreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
Expand All @@ -221,7 +221,7 @@ const flyoutCategory = function(workspace) {
block.appendChild(nameField);
xmlList.push(block);
}
if (blocks['procedures_ifreturn']) {
if (blocks.definitions['procedures_ifreturn']) {
// <block type="procedures_ifreturn" gap="16"></block>
const block = utilsXml.createElement('block');
block.setAttribute('type', 'procedures_ifreturn');
Expand Down
Loading

0 comments on commit e33b736

Please sign in to comment.