Generated JS helper functions should be camelCase.

Complying with Google style guide.
This commit is contained in:
Neil Fraser
2016-06-01 17:18:02 -07:00
parent 0e29021b31
commit 32192850ad
5 changed files with 23 additions and 23 deletions

View File

@@ -196,9 +196,9 @@ Blockly.JavaScript.scrub_ = function(block, code) {
}
// Collect comments for all value arguments.
// Don't collect comments for nested statements.
for (var x = 0; x < block.inputList.length; x++) {
if (block.inputList[x].type == Blockly.INPUT_VALUE) {
var childBlock = block.inputList[x].connection.targetBlock();
for (var i = 0; i < block.inputList.length; i++) {
if (block.inputList[i].type == Blockly.INPUT_VALUE) {
var childBlock = block.inputList[i].connection.targetBlock();
if (childBlock) {
var comment = Blockly.JavaScript.allNestedComments(childBlock);
if (comment) {

View File

@@ -38,7 +38,7 @@ Blockly.JavaScript['colour_picker'] = function(block) {
Blockly.JavaScript['colour_random'] = function(block) {
// Generate a random colour.
var functionName = Blockly.JavaScript.provideFunction_(
'colour_random',
'colourRandom',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {',
' var num = Math.floor(Math.random() * Math.pow(2, 24));',
' return \'#\' + (\'00000\' + num.toString(16)).substr(-6);',
@@ -56,7 +56,7 @@ Blockly.JavaScript['colour_rgb'] = function(block) {
var blue = Blockly.JavaScript.valueToCode(block, 'BLUE',
Blockly.JavaScript.ORDER_COMMA) || 0;
var functionName = Blockly.JavaScript.provideFunction_(
'colour_rgb',
'colourRgb',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(r, g, b) {',
' r = Math.max(Math.min(Number(r), 100), 0) * 2.55;',
@@ -80,7 +80,7 @@ Blockly.JavaScript['colour_blend'] = function(block) {
var ratio = Blockly.JavaScript.valueToCode(block, 'RATIO',
Blockly.JavaScript.ORDER_COMMA) || 0.5;
var functionName = Blockly.JavaScript.provideFunction_(
'colour_blend',
'colourBlend',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(c1, c2, ratio) {',
' ratio = Math.max(Math.min(Number(ratio), 1), 0);',

View File

@@ -48,7 +48,7 @@ Blockly.JavaScript['lists_create_with'] = function(block) {
Blockly.JavaScript['lists_repeat'] = function(block) {
// Create a list with one element repeated.
var functionName = Blockly.JavaScript.provideFunction_(
'lists_repeat',
'listsRepeat',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(value, n) {',
' var array = [];',
@@ -145,7 +145,7 @@ Blockly.JavaScript['lists_getIndex'] = function(block) {
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
} else if (mode == 'GET_REMOVE' || mode == 'REMOVE') {
var functionName = Blockly.JavaScript.provideFunction_(
'lists_remove_from_end',
'listsRemoveFromEnd',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(list, x) {',
' x = list.length - x;',
@@ -160,7 +160,7 @@ Blockly.JavaScript['lists_getIndex'] = function(block) {
}
} else if (where == 'RANDOM') {
var functionName = Blockly.JavaScript.provideFunction_(
'lists_get_random_item',
'listsGetRandomItem',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(list, remove) {',
' var x = Math.floor(Math.random() * list.length);',
@@ -272,7 +272,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) {
var code = list + '.concat()';
} else {
var functionName = Blockly.JavaScript.provideFunction_(
'lists_get_sublist',
'listsGetSublist',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(list, where1, at1, where2, at2) {',
' function getAt(where, at) {',
@@ -307,7 +307,7 @@ Blockly.JavaScript['lists_sort'] = function(block) {
var direction = block.getFieldValue('DIRECTION') === '1' ? 1 : -1;
var type = block.getFieldValue('TYPE');
var getCompareFunctionName = Blockly.JavaScript.provideFunction_(
'lists_get_sort_compare',
'listsGetSortCompare',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(type, direction) {',
' var compareFuncs = {',
@@ -322,8 +322,8 @@ Blockly.JavaScript['lists_sort'] = function(block) {
' var compare = compareFuncs[type];',
' return function(a, b) { return compare(a, b) * direction; }',
'}']);
return ['(' + listCode + ').slice().sort(' +
getCompareFunctionName + '("' + type + '", ' + direction + '))',
return ['(' + listCode + ').slice().sort(' +
getCompareFunctionName + '("' + type + '", ' + direction + '))',
Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

View File

@@ -167,7 +167,7 @@ Blockly.JavaScript['math_number_property'] = function(block) {
if (dropdown_property == 'PRIME') {
// Prime is a special case as it is not a one-liner test.
var functionName = Blockly.JavaScript.provideFunction_(
'math_isPrime',
'mathIsPrime',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(n) {',
' // https://en.wikipedia.org/wiki/Primality_test#Naive_methods',
' if (n == 2 || n == 3) {',
@@ -253,7 +253,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
case 'AVERAGE':
// math_median([null,null,1,3]) == 2.0.
var functionName = Blockly.JavaScript.provideFunction_(
'math_mean',
'mathMean',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(myList) {',
' return myList.reduce(function(x, y) {return x + y;}) / ' +
@@ -266,7 +266,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
case 'MEDIAN':
// math_median([null,null,1,3]) == 2.0.
var functionName = Blockly.JavaScript.provideFunction_(
'math_median',
'mathMedian',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(myList) {',
' var localList = myList.filter(function (x) ' +
@@ -289,7 +289,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
// the returned result is provided as an array.
// Mode of [3, 'x', 'x', 1, 1, 2, '3'] -> ['x', 1].
var functionName = Blockly.JavaScript.provideFunction_(
'math_modes',
'mathModes',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(values) {',
' var modes = [];',
@@ -325,7 +325,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
break;
case 'STD_DEV':
var functionName = Blockly.JavaScript.provideFunction_(
'math_standard_deviation',
'mathStandardDeviation',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(numbers) {',
' var n = numbers.length;',
@@ -344,7 +344,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
break;
case 'RANDOM':
var functionName = Blockly.JavaScript.provideFunction_(
'math_random_list',
'mathRandomList',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(list) {',
' var x = Math.floor(Math.random() * list.length);',
@@ -390,7 +390,7 @@ Blockly.JavaScript['math_random_int'] = function(block) {
var argument1 = Blockly.JavaScript.valueToCode(block, 'TO',
Blockly.JavaScript.ORDER_COMMA) || '0';
var functionName = Blockly.JavaScript.provideFunction_(
'math_random_int',
'mathRandomInt',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(a, b) {',
' if (a > b) {',

View File

@@ -129,7 +129,7 @@ Blockly.JavaScript['text_charAt'] = function(block) {
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
case 'RANDOM':
var functionName = Blockly.JavaScript.provideFunction_(
'text_random_letter',
'textRandomLetter',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(text) {',
' var x = Math.floor(Math.random() * text.length);',
@@ -155,7 +155,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
var code = text;
} else {
var functionName = Blockly.JavaScript.provideFunction_(
'text_get_substring',
'textGetSubstring',
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(text, where1, at1, where2, at2) {',
' function getAt(where, at) {',
@@ -199,7 +199,7 @@ Blockly.JavaScript['text_changeCase'] = function(block) {
} else {
// Title case is not a native JavaScript function. Define one.
var functionName = Blockly.JavaScript.provideFunction_(
'text_toTitleCase',
'textToTitleCase',
[ 'function ' +
Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(str) {',
' return str.replace(/\\S+/g,',