Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update javascript block generators to const and let #5661

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions generators/javascript/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ goog.require('Blockly.JavaScript');

Blockly.JavaScript['colour_picker'] = function(block) {
// Colour picker.
var code = Blockly.JavaScript.quote_(block.getFieldValue('COLOUR'));
const code = Blockly.JavaScript.quote_(block.getFieldValue('COLOUR'));
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};

Blockly.JavaScript['colour_random'] = function(block) {
// Generate a random colour.
var functionName = Blockly.JavaScript.provideFunction_(
const functionName = Blockly.JavaScript.provideFunction_(
'colourRandom',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {',
' var num = Math.floor(Math.random() * Math.pow(2, 24));',
' return \'#\' + (\'00000\' + num.toString(16)).substr(-6);',
'}']);
var code = functionName + '()';
const code = functionName + '()';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

Blockly.JavaScript['colour_rgb'] = function(block) {
// Compose a colour from RGB components expressed as percentages.
var red = Blockly.JavaScript.valueToCode(block, 'RED',
const red = Blockly.JavaScript.valueToCode(block, 'RED',
Blockly.JavaScript.ORDER_NONE) || 0;
var green = Blockly.JavaScript.valueToCode(block, 'GREEN',
const green = Blockly.JavaScript.valueToCode(block, 'GREEN',
Blockly.JavaScript.ORDER_NONE) || 0;
var blue = Blockly.JavaScript.valueToCode(block, 'BLUE',
const blue = Blockly.JavaScript.valueToCode(block, 'BLUE',
Blockly.JavaScript.ORDER_NONE) || 0;
var functionName = Blockly.JavaScript.provideFunction_(
const functionName = Blockly.JavaScript.provideFunction_(
'colourRgb',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(r, g, b) {',
Expand All @@ -52,19 +52,19 @@ Blockly.JavaScript['colour_rgb'] = function(block) {
' b = (\'0\' + (Math.round(b) || 0).toString(16)).slice(-2);',
' return \'#\' + r + g + b;',
'}']);
var code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
const code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

Blockly.JavaScript['colour_blend'] = function(block) {
// Blend two colours together.
var c1 = Blockly.JavaScript.valueToCode(block, 'COLOUR1',
const c1 = Blockly.JavaScript.valueToCode(block, 'COLOUR1',
Blockly.JavaScript.ORDER_NONE) || '\'#000000\'';
var c2 = Blockly.JavaScript.valueToCode(block, 'COLOUR2',
const c2 = Blockly.JavaScript.valueToCode(block, 'COLOUR2',
Blockly.JavaScript.ORDER_NONE) || '\'#000000\'';
var ratio = Blockly.JavaScript.valueToCode(block, 'RATIO',
const ratio = Blockly.JavaScript.valueToCode(block, 'RATIO',
Blockly.JavaScript.ORDER_NONE) || 0.5;
var functionName = Blockly.JavaScript.provideFunction_(
const functionName = Blockly.JavaScript.provideFunction_(
'colourBlend',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(c1, c2, ratio) {',
Expand All @@ -83,6 +83,6 @@ Blockly.JavaScript['colour_blend'] = function(block) {
' b = (\'0\' + (b || 0).toString(16)).slice(-2);',
' return \'#\' + r + g + b;',
'}']);
var code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
const code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
Loading