Skip to content

Commit

Permalink
Change === to == and !== to !=
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 10, 2016
1 parent a217024 commit 55cf834
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html
Expand Up @@ -98,11 +98,11 @@
});

addStyle('Show Subsections', {
show : "${id} === 1 || ${id} > 250 && ${id} < 300"
show : "${id} == 1 || ${id} > 250 && ${id} < 300"
});

addStyle('Mod', {
show : "${id} % 2 === 0"
show : "${id} % 2 == 0"
});

addStyle('Secondary Color', {
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles.html
Expand Up @@ -485,7 +485,7 @@

var leftOperand = 0;
var rightOperand = 0;
var op = '===';
var op = '==';

// Left operand (properties and literals)

Expand All @@ -499,7 +499,7 @@

// Operator

var ops = ['<', '<=', '>', '>=', '===', '!=='];
var ops = ['<', '<=', '>', '>=', '==', '!='];
var operators = [{
text : 'Operator',
onselect : function() {
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ConditionsExpression.js
Expand Up @@ -33,8 +33,8 @@ define([
* var expression = new Cesium.Expression({
* expression : 'regExp("^1(\\d)").exec(${id})',
* conditions : [
* ['${expression} === "1"', 'color("#FF0000")'],
* ['${expression} === "2"', 'color("#00FF00")'],
* ['${expression} == "1"', 'color("#FF0000")'],
* ['${expression} == "2"', 'color("#00FF00")'],
* ['true', 'color("#FFFFFF")']
* ]
* });
Expand Down
29 changes: 13 additions & 16 deletions Source/Scene/Expression.js
Expand Up @@ -18,7 +18,7 @@ define([
"use strict";

var unaryOperators = ['!', '-', '+'];
var binaryOperators = ['+', '-', '*', '/', '%', '===', '!==', '>', '>=', '<', '<=', '&&', '||', '!~', '=~'];
var binaryOperators = ['+', '-', '*', '/', '%', '==', '!=', '>', '>=', '<', '<=', '&&', '||', '!~', '=~'];

var variableRegex = /\${(.*?)}/g;
var backslashRegex = /\\/g;
Expand Down Expand Up @@ -531,9 +531,9 @@ define([
node.evaluate = node._evaluateDivide;
} else if (node._value === '%') {
node.evaluate = node._evaluateMod;
} else if (node._value === '===') {
} else if (node._value === '==') {
node.evaluate = node._evaluateEquals;
} else if (node._value === '!==') {
} else if (node._value === '!=') {
node.evaluate = node._evaluateNotEquals;
} else if (node._value === '<') {
node.evaluate = node._evaluateLessThan;
Expand Down Expand Up @@ -840,7 +840,10 @@ define([
if ((right instanceof Color) && (left instanceof Color)) {
return Color.equals(left, right);
}
return left === right;

// Specifically want to do an abstract equality comparison (==) instead of a strict equality comparison (===)
// so that cases like "5 === '5'" return true. Tell jsHint to ignore this line.
return left == right; // jshint ignore:line
};

Node.prototype._evaluateNotEquals = function(feature) {
Expand Down Expand Up @@ -1029,14 +1032,12 @@ define([
var value = this._value;

// Right may be a string if it's a member variable: e.g. "${property.name}"
var stringMember = typeof(this._right) === 'string';
//>>includeStart('debug', pragmas.debug);
if (stringMember) {
if (typeof(this._right) === 'string') {
//>>includeStart('debug', pragmas.debug);
throw new DeveloperError('Error generating style shader: string members are not supported.');
}
//>>includeEnd('debug');
if (stringMember) {
return undefined;
//>>includeEnd('debug');
// Return undefined when not in debug. Tell jsHint to ignore this line.
return; // jshint ignore:line
}

if (defined(this._left)) {
Expand Down Expand Up @@ -1094,13 +1095,9 @@ define([
//>>includeEnd('debug');
return value + left;
case ExpressionNodeType.BINARY:
// Supported types: ||, &&, ===, !==, <, >, <=, >=, +, -, *, /, %
// Supported types: ||, &&, ==, !=, <, >, <=, >=, +, -, *, /, %
if (value === '%') {
return 'mod(' + left + ', ' + right + ')';
} else if (value === '===') {
return '(' + left + ' == ' + right + ')';
} else if (value === '!==') {
return '(' + left + ' != ' + right + ')';
}
return '(' + left + ' ' + value + ' ' + right + ')';
case ExpressionNodeType.CONDITIONAL:
Expand Down
6 changes: 3 additions & 3 deletions Specs/Scene/Cesium3DTileStyleSpec.js
Expand Up @@ -328,7 +328,7 @@ defineSuite([

it ('applies show style with variable', function() {
var style = new Cesium3DTileStyle({
"show" : "${ZipCode} === '19341'"
"show" : "${ZipCode} == '19341'"
});

expect(style.show.evaluate(feature1)).toEqual(true);
Expand Down Expand Up @@ -404,8 +404,8 @@ defineSuite([
"color" : {
"expression" : "regExp('^1(\\d)').exec(${id})",
"conditions" : [
["${expression} === '1'", "color('#FF0000')"],
["${expression} === '2'", "color('#00FF00')"],
["${expression} == '1'", "color('#FF0000')"],
["${expression} == '2'", "color('#00FF00')"],
["true", "color('#FFFFFF')"]
]
}
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/ConditionsExpressionSpec.js
Expand Up @@ -46,7 +46,7 @@ defineSuite([

var jsonExpWithUndefinedExpression = {
conditions : [
['${expression} === undefined', 'color("blue")'],
['${expression} == undefined', 'color("blue")'],
['true', 'color("lime")']
]
};
Expand Down
30 changes: 15 additions & 15 deletions Specs/Scene/ExpressionSpec.js
Expand Up @@ -161,11 +161,11 @@ defineSuite([
}).toThrowDeveloperError();

expect(function() {
return new Expression('2 == 3');
return new Expression('2 === 3');
}).toThrowDeveloperError();

expect(function() {
return new Expression('2 != 3');
return new Expression('2 !== 3');
}).toThrowDeveloperError();

expect(function() {
Expand Down Expand Up @@ -544,24 +544,24 @@ defineSuite([
});

it('evaluates binary equals', function() {
var expression = new Expression('\'hello\' === \'hello\'');
var expression = new Expression('\'hello\' == \'hello\'');
expect(expression.evaluate(undefined)).toEqual(true);

expression = new Expression('1 === 2');
expression = new Expression('1 == 2');
expect(expression.evaluate(undefined)).toEqual(false);

expression = new Expression('false === true === false');
expression = new Expression('false == true == false');
expect(expression.evaluate(undefined)).toEqual(true);
});

it('evaluates binary not equals', function() {
var expression = new Expression('\'hello\' !== \'hello\'');
var expression = new Expression('\'hello\' != \'hello\'');
expect(expression.evaluate(undefined)).toEqual(false);

expression = new Expression('1 !== 2');
expression = new Expression('1 != 2');
expect(expression.evaluate(undefined)).toEqual(true);

expression = new Expression('false !== true !== false');
expression = new Expression('false != true != false');
expect(expression.evaluate(undefined)).toEqual(true);
});

Expand Down Expand Up @@ -709,16 +709,16 @@ defineSuite([
expression = new Expression('rgba(255, 255, 255, 1.0) % rgba(255, 255, 255, 1.0)');
expect(expression.evaluate(undefined)).toEqual(new Color(0, 0, 0, 0));

expression = new Expression('color(\'green\') === color(\'green\')');
expression = new Expression('color(\'green\') == color(\'green\')');
expect(expression.evaluate(undefined)).toEqual(true);

expression = new Expression('color() === color()');
expression = new Expression('color() == color()');
expect(expression.evaluate(undefined)).toEqual(true);

expression = new Expression('!!color() === true');
expression = new Expression('!!color() == true');
expect(expression.evaluate(undefined)).toEqual(true);

expression = new Expression('color(\'green\') !== color(\'green\')');
expression = new Expression('color(\'green\') != color(\'green\')');
expect(expression.evaluate(undefined)).toEqual(false);
});

Expand Down Expand Up @@ -951,7 +951,7 @@ defineSuite([
color : Color.BLUE
});

expression = new Expression('${feature} === ${feature.feature}');
expression = new Expression('${feature} == ${feature.feature}');
expect(expression.evaluate(feature)).toEqual(true);
});

Expand Down Expand Up @@ -1293,14 +1293,14 @@ defineSuite([
});

it('gets shader expression for binary equals', function() {
var expression = new Expression('1.0 === 2.0');
var expression = new Expression('1.0 == 2.0');
var shaderExpression = expression.getShaderExpression('', {});
var expected = '(1.0 == 2.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for binary not equals', function() {
var expression = new Expression('1.0 !== 2.0');
var expression = new Expression('1.0 != 2.0');
var shaderExpression = expression.getShaderExpression('', {});
var expected = '(1.0 != 2.0)';
expect(shaderExpression).toEqual(expected);
Expand Down

0 comments on commit 55cf834

Please sign in to comment.