Permalink
Browse files

Rename eval to ev to fix many jshint problems and future safari problems

  • Loading branch information...
1 parent 29b641c commit 87d4f9627b03902c91352c597d8b6c756ab76b3f @tmcw tmcw committed Jan 3, 2013
View
@@ -63,4 +63,4 @@ fs.readFile(process.argv[2], 'utf-8', function(err, data) {
}, 4));
});
parser.parseString(data);
-});
+});
@@ -251,7 +251,7 @@ function inheritRules(definitions, env) {
var current, previous, attachment;
definitions.forEach(function(d) {
- d.filters.eval(env);
+ d.filters.ev(env);
});
for (var i = 0; i < definitions.length; i++) {
@@ -336,7 +336,7 @@ function getMapProperties(m, rulesets, env) {
index: r.rules[i].index
});
}
- rules[key] = r.rules[i].eval(env).toXML(env);
+ rules[key] = r.rules[i].ev(env).toXML(env);
}
});
return rules;
@@ -8,16 +8,16 @@ tree.Call = function Call(name, args, index) {
tree.Call.prototype = {
is: 'call',
- // When evaluating a function call,
+ // When evuating a function call,
@gravitystorm
gravitystorm Jan 6, 2013 Collaborator

I think a find+replace on "eval" has also hit the comments in this file.

@springmeyer
springmeyer Jan 6, 2013 Member

nice catch, fixed in 0d686bb

// we either find the function in `tree.functions` [1],
- // in which case we call it, passing the evaluated arguments,
+ // in which case we call it, passing the evuated arguments,
// or we simply print it out as it appeared originally [2].
// The *functions.js* file contains the built-in functions.
- // The reason why we evaluate the arguments, is in the case where
+ // The reason why we evuate the arguments, is in the case where
// we try to pass a variable to a function, like: `saturate(@color)`.
// The function should receive the value, not the variable.
- 'eval': function(env) {
- var args = this.args.map(function(a) { return a.eval(env); });
+ 'ev': function(env) {
+ var args = this.args.map(function(a) { return a.ev(env); });
for (var i = 0; i < args.length; i++) {
if (args[i].is === 'undefined') {
@@ -90,7 +90,7 @@ tree.Call.prototype = {
value: 'undefined'
};
} else {
- // Save the evaluated versions of arguments
+ // Save the evuated versions of arguments
this.args = args;
return this;
}
@@ -23,7 +23,7 @@ tree.Color = function Color(rgb, a) {
tree.Color.prototype = {
is: 'color',
- 'eval': function() { return this; },
+ 'ev': function() { return this; },
// If we have some transparency, the only way to represent it
// is via `rgba`. Otherwise, we use the hex representation,
@@ -9,7 +9,7 @@ tree.Comment.prototype = {
toString: function(env) {
return '<!--' + this.value + '-->';
},
- 'eval': function() { return this; }
+ 'ev': function() { return this; }
};
})(require('../tree'));
@@ -129,9 +129,9 @@ tree.Definition.prototype.symbolizersToXML = function(env, symbolizers, zoom) {
var x = tree.Reference.selector(attributes[j].name);
if (x && x.serialization && x.serialization === 'content') {
selfclosing = false;
- tagcontent = attributes[j].eval(env).toXML(env, true);
+ tagcontent = attributes[j].ev(env).toXML(env, true);
} else {
- xml += attributes[j].eval(env).toXML(env) + ' ';
+ xml += attributes[j].ev(env).toXML(env) + ' ';
}
}
if (selfclosing) {
@@ -11,7 +11,7 @@ tree.Dimension = function Dimension(value, unit, index) {
tree.Dimension.prototype = {
is: 'float',
- 'eval': function (env) {
+ 'ev': function (env) {
if (this.unit && (this.unit !== 'px' && this.unit !== '%')) {
env.error({
message: "Invalid unit: '" + this.unit + "'",
@@ -6,13 +6,13 @@ tree.Expression = function Expression(value) {
tree.Expression.prototype = {
is: 'expression',
- eval: function(env) {
+ ev: function(env) {
if (this.value.length > 1) {
return new tree.Expression(this.value.map(function(e) {
- return e.eval(env);
+ return e.ev(env);
}));
} else {
- return this.value[0].eval(env);
+ return this.value[0].ev(env);
}
},
@@ -9,7 +9,7 @@ tree.Field.prototype = {
toString: function() {
return '[' + this.value + ']';
},
- 'eval': function() {
+ 'ev': function() {
return this;
}
};
@@ -21,9 +21,9 @@ var ops = {
'=~': ['.match(', 'string', ')']
};
-tree.Filter.prototype['eval'] = function(env) {
- this.key = this.key['eval'](env);
- this.val = this.val['eval'](env);
+tree.Filter.prototype['ev'] = function(env) {
+ this.key = this.key['ev'](env);
+ this.val = this.val['ev'](env);
return this;
};
@@ -22,9 +22,9 @@ tree.Filterset.prototype.toString = function() {
return arr.sort().join('\t');
};
-tree.Filterset.prototype.eval = function(env) {
+tree.Filterset.prototype.ev = function(env) {
for (var i in this.filters) {
- this.filters[i].eval(env);
+ this.filters[i].ev(env);
}
return this;
};
@@ -7,7 +7,7 @@ tree.ImageFilter = function ImageFilter(filter, args) {
tree.ImageFilter.prototype = {
is: 'imagefilter',
- eval: function() { return this; },
+ ev: function() { return this; },
toString: function() {
if (this.args) {
@@ -8,7 +8,7 @@ tree.Invalid = function Invalid(chunk, index, message) {
tree.Invalid.prototype.is = 'invalid';
-tree.Invalid.prototype.eval = function(env) {
+tree.Invalid.prototype.ev = function(env) {
env.error({
chunk: this.chunk,
index: this.index,
@@ -10,7 +10,7 @@ tree.Keyword = function Keyword(value) {
this.is = special[value] ? special[value] : 'keyword';
};
tree.Keyword.prototype = {
- eval: function() { return this; },
+ ev: function() { return this; },
toString: function() { return this.value; }
};
@@ -12,7 +12,7 @@ tree.Literal.prototype = {
toString: function() {
return this.value;
},
- 'eval': function() {
+ 'ev': function() {
return this;
}
};
@@ -10,9 +10,9 @@ tree.Operation = function Operation(op, operands, index) {
tree.Operation.prototype.is = 'operation';
-tree.Operation.prototype.eval = function(env) {
- var a = this.operands[0].eval(env),
- b = this.operands[1].eval(env),
+tree.Operation.prototype.ev = function(env) {
+ var a = this.operands[0].ev(env),
+ b = this.operands[1].ev(env),
temp;
if (a.is === 'undefined' || b.is === 'undefined') {
@@ -64,7 +64,7 @@ tree.Operation.prototype.eval = function(env) {
value: 'undefined'
};
} else {
- return new tree.Literal(a.eval(env).toString(true) + this.op + b.eval(env).toString(true));
+ return new tree.Literal(a.ev(env).toString(true) + this.op + b.ev(env).toString(true));
}
}
@@ -12,7 +12,7 @@ tree.Quoted.prototype = {
return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
},
- 'eval': function() {
+ 'ev': function() {
return this;
},
@@ -109,10 +109,10 @@ tree.Rule.prototype.toXML = function(env, content, sep, format) {
}
};
-// TODO: Rule eval chain should add fontsets to env.frames
-tree.Rule.prototype['eval'] = function(context) {
+// TODO: Rule ev chain should add fontsets to env.frames
+tree.Rule.prototype['ev'] = function(context) {
return new tree.Rule(this.name,
- this.value['eval'](context),
+ this.value['ev'](context),
this.index,
this.filename);
};
@@ -8,7 +8,7 @@ tree.Ruleset = function Ruleset(selectors, rules) {
};
tree.Ruleset.prototype = {
is: 'ruleset',
- 'eval': function(env) {
+ 'ev': function(env) {
var i,
ruleset = new tree.Ruleset(this.selectors, this.rules.slice(0));
ruleset.root = this.root;
@@ -19,7 +19,7 @@ tree.Ruleset.prototype = {
// Evaluate everything else
for (i = 0, rule; i < ruleset.rules.length; i++) {
rule = ruleset.rules[i];
- ruleset.rules[i] = rule.eval ? rule.eval(env) : rule;
+ ruleset.rules[i] = rule.ev ? rule.ev(env) : rule;
}
// Pop the stack
@@ -79,11 +79,11 @@ tree.Ruleset.prototype = {
},
// Zooms can use variables. This replaces tree.Zoom objects on selectors
// with simple bit-arrays that we can compare easily.
- evalZooms: function(env) {
+ evZooms: function(env) {
for (var i = 0; i < this.selectors.length; i++) {
var zval = tree.Zoom.all;
for (var z = 0; z < this.selectors[i].zoom.length; z++) {
- zval = zval & this.selectors[i].zoom[z].eval(env).zoom;
+ zval = zval & this.selectors[i].zoom[z].ev(env).zoom;
}
this.selectors[i].zoom = zval;
}
@@ -93,7 +93,7 @@ tree.Ruleset.prototype = {
if (this.selectors.length === 0) {
env.frames = env.frames.concat(this.rules);
}
- this.evalZooms(env);
+ this.evZooms(env);
for (i = 0; i < this.selectors.length; i++) {
var child = this.selectors[i];
@@ -27,16 +27,16 @@ tree.StyleXML = function(name, attachment, definitions, env) {
if (image_filters.length) {
attrs_xml += ' image-filters="' + image_filters.map(function(f) {
- return f.eval(env).toXML(env, true, ',', 'image-filter');
+ return f.ev(env).toXML(env, true, ',', 'image-filter');
}).join(',') + '" ';
}
if (comp_op.length) {
- attrs_xml += ' comp-op="' + comp_op[0].value.eval(env).toString() + '" ';
+ attrs_xml += ' comp-op="' + comp_op[0].value.ev(env).toString() + '" ';
}
if (opacity.length) {
- attrs_xml += ' opacity="' + opacity[0].value.eval(env).toString() + '" ';
+ attrs_xml += ' opacity="' + opacity[0].value.ev(env).toString() + '" ';
}
var rule_string = rules.join('');
if (!attrs_xml && !rule_string) return '';
@@ -10,8 +10,8 @@ tree.URL.prototype = {
toString: function() {
return this.value.toString();
},
- eval: function(ctx) {
- return new tree.URL(this.value.eval(ctx), this.paths);
+ ev: function(ctx) {
+ return new tree.URL(this.value.ev(ctx), this.paths);
}
};
@@ -6,12 +6,12 @@ tree.Value = function Value(value) {
tree.Value.prototype = {
is: 'value',
- eval: function(env) {
+ ev: function(env) {
if (this.value.length === 1) {
- return this.value[0].eval(env);
+ return this.value[0].ev(env);
} else {
return new tree.Value(this.value.map(function(v) {
- return v.eval(env);
+ return v.ev(env);
}));
}
},
@@ -11,7 +11,7 @@ tree.Variable.prototype = {
toString: function() {
return this.name;
},
- eval: function(env) {
+ ev: function(env) {
var variable,
v,
name = this.name;
@@ -22,7 +22,7 @@ tree.Variable.prototype = {
return f.name == this.name;
}.bind(this));
if (thisframe.length) {
- return thisframe[0].value.eval(env);
+ return thisframe[0].value.ev(env);
} else {
env.error({
message: 'variable ' + this.name + ' is undefined',
@@ -14,10 +14,10 @@ tree.Zoom.prototype.setZoom = function(zoom) {
return this;
};
-tree.Zoom.prototype.eval = function(env) {
+tree.Zoom.prototype.ev = function(env) {
var start = 0,
end = Infinity,
- value = parseInt(this.value.eval(env).toString(), 10),
+ value = parseInt(this.value.ev(env).toString(), 10),
zoom = 0;
if (value > tree.Zoom.maxZoom || value < 0) {
View
@@ -10,14 +10,14 @@ describe('Field', function() {
var f = new tree.Filter(new tree.Field('foo'), '=', new tree.Dimension(1));
assert.ok(f);
});
- it('can be evaluated', function() {
+ it('can be evuated', function() {
var f = new tree.Filter(new tree.Field('foo'), '=', new tree.Dimension(1));
- f.eval({});
+ f.ev({});
assert.ok(f);
});
it('yields xml', function() {
var f = new tree.Filter(new tree.Field('foo'), '=', new tree.Dimension(1));
- f.eval({});
+ f.ev({});
assert.equal(f.toXML({}), '[foo] = 1');
});
});

0 comments on commit 87d4f96

Please sign in to comment.