chore: Convert == to === and != to !== where possible. (#5599)

This commit is contained in:
Neil Fraser
2021-10-15 09:17:04 -07:00
committed by GitHub
parent 7ac1e27cd6
commit c929b3015b
183 changed files with 1409 additions and 1409 deletions

View File

@@ -52,18 +52,18 @@ Blockly.JavaScript['math_single'] = function(block) {
var operator = block.getFieldValue('OP');
var code;
var arg;
if (operator == 'NEG') {
if (operator === 'NEG') {
// Negation is a special case given its different operator precedence.
arg = Blockly.JavaScript.valueToCode(block, 'NUM',
Blockly.JavaScript.ORDER_UNARY_NEGATION) || '0';
if (arg[0] == '-') {
if (arg[0] === '-') {
// --3 is not legal in JS.
arg = ' ' + arg;
}
code = '-' + arg;
return [code, Blockly.JavaScript.ORDER_UNARY_NEGATION];
}
if (operator == 'SIN' || operator == 'COS' || operator == 'TAN') {
if (operator === 'SIN' || operator === 'COS' || operator === 'TAN') {
arg = Blockly.JavaScript.valueToCode(block, 'NUM',
Blockly.JavaScript.ORDER_DIVISION) || '0';
} else {
@@ -152,24 +152,24 @@ Blockly.JavaScript['math_number_property'] = function(block) {
Blockly.JavaScript.ORDER_MODULUS) || '0';
var dropdown_property = block.getFieldValue('PROPERTY');
var code;
if (dropdown_property == 'PRIME') {
if (dropdown_property === 'PRIME') {
// Prime is a special case as it is not a one-liner test.
var functionName = Blockly.JavaScript.provideFunction_(
'mathIsPrime',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(n) {',
' // https://en.wikipedia.org/wiki/Primality_test#Naive_methods',
' if (n == 2 || n == 3) {',
' if (n === 2 || n === 3) {',
' return true;',
' }',
' // False if n is NaN, negative, is 1, or not whole.',
' // And false if n is divisible by 2 or 3.',
' if (isNaN(n) || n <= 1 || n % 1 != 0 || n % 2 == 0 ||' +
' n % 3 == 0) {',
' if (isNaN(n) || n <= 1 || n % 1 !== 0 || n % 2 === 0 ||' +
' n % 3 === 0) {',
' return false;',
' }',
' // Check all the numbers of form 6k +/- 1, up to sqrt(n).',
' for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {',
' if (n % (x - 1) == 0 || n % (x + 1) == 0) {',
' if (n % (x - 1) === 0 || n % (x + 1) === 0) {',
' return false;',
' }',
' }',
@@ -180,13 +180,13 @@ Blockly.JavaScript['math_number_property'] = function(block) {
}
switch (dropdown_property) {
case 'EVEN':
code = number_to_check + ' % 2 == 0';
code = number_to_check + ' % 2 === 0';
break;
case 'ODD':
code = number_to_check + ' % 2 == 1';
code = number_to_check + ' % 2 === 1';
break;
case 'WHOLE':
code = number_to_check + ' % 1 == 0';
code = number_to_check + ' % 1 === 0';
break;
case 'POSITIVE':
code = number_to_check + ' > 0';
@@ -197,7 +197,7 @@ Blockly.JavaScript['math_number_property'] = function(block) {
case 'DIVISIBLE_BY':
var divisor = Blockly.JavaScript.valueToCode(block, 'DIVISOR',
Blockly.JavaScript.ORDER_MODULUS) || '0';
code = number_to_check + ' % ' + divisor + ' == 0';
code = number_to_check + ' % ' + divisor + ' === 0';
break;
}
return [code, Blockly.JavaScript.ORDER_EQUALITY];
@@ -209,7 +209,7 @@ Blockly.JavaScript['math_change'] = function(block) {
Blockly.JavaScript.ORDER_ADDITION) || '0';
var varName = Blockly.JavaScript.nameDB_.getName(
block.getFieldValue('VAR'), Blockly.VARIABLE_CATEGORY_NAME);
return varName + ' = (typeof ' + varName + ' == \'number\' ? ' + varName +
return varName + ' = (typeof ' + varName + ' === \'number\' ? ' + varName +
' : 0) + ' + argument0 + ';\n';
};
@@ -239,7 +239,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
code = 'Math.max.apply(null, ' + list + ')';
break;
case 'AVERAGE':
// mathMean([null,null,1,3]) == 2.0.
// mathMean([null,null,1,3]) === 2.0.
var functionName = Blockly.JavaScript.provideFunction_(
'mathMean',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
@@ -252,16 +252,16 @@ Blockly.JavaScript['math_on_list'] = function(block) {
code = functionName + '(' + list + ')';
break;
case 'MEDIAN':
// mathMedian([null,null,1,3]) == 2.0.
// mathMedian([null,null,1,3]) === 2.0.
var functionName = Blockly.JavaScript.provideFunction_(
'mathMedian',
['function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
'(myList) {',
' var localList = myList.filter(function (x) ' +
'{return typeof x == \'number\';});',
'{return typeof x === \'number\';});',
' if (!localList.length) return null;',
' localList.sort(function(a, b) {return b - a;});',
' if (localList.length % 2 == 0) {',
' if (localList.length % 2 === 0) {',
' return (localList[localList.length / 2 - 1] + ' +
'localList[localList.length / 2]) / 2;',
' } else {',
@@ -301,7 +301,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
' maxCount = Math.max(thisCount, maxCount);',
' }',
' for (var j = 0; j < counts.length; j++) {',
' if (counts[j][1] == maxCount) {',
' if (counts[j][1] === maxCount) {',
' modes.push(counts[j][0]);',
' }',
' }',