Refining syntax, reducing jslint warnings

This commit is contained in:
Tom MacWright 2011-08-22 17:19:11 -04:00
parent cbc34d3fbb
commit 19e77cd8ab
4 changed files with 32 additions and 14 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env node #!/usr/bin/env node
var path = require('path'); var path = require('path'),
var fs = require('fs'); fs = require('fs'),
var sys = require('sys'); sys = require('sys'),
carto = require('carto');
var carto = require('carto');
var args = process.argv.slice(1); var args = process.argv.slice(1);
var options = {}; var options = {};
@ -102,6 +102,10 @@ function compile(err, data) {
} }
}); });
} catch (e) { } catch (e) {
if (e.stack) {
sys.error(e.stack);
} else {
sys.error(e); sys.error(e);
} }
}
}; };

View File

@ -123,7 +123,8 @@ carto.Parser = function Parser(env) {
} else { } else {
sync(); sync();
if (match = tok.exec(chunks[j])) { match = tok.exec(chunks[j]);
if (match) {
length = match[0].length; length = match[0].length;
} else { } else {
return null; return null;
@ -187,7 +188,7 @@ carto.Parser = function Parser(env) {
err.line = (input.slice(0, err.index).match(/\n/g) || '').length + 1; err.line = (input.slice(0, err.index).match(/\n/g) || '').length + 1;
for (var n = err.index; n >= 0 && input.charAt(n) !== '\n'; n--) { for (var n = err.index; n >= 0 && input.charAt(n) !== '\n'; n--) {
err.column++; err.column++;
}; }
return new Error(_('<%=filename%>:<%=line%>:<%=column%> <%=message%>').template(err)); return new Error(_('<%=filename%>:<%=line%>:<%=column%> <%=message%>').template(err));
} }

View File

@ -3,7 +3,7 @@
*/ */
module.exports.find = function (obj, fun) { module.exports.find = function (obj, fun) {
for (var i = 0, r; i < obj.length; i++) { for (var i = 0, r; i < obj.length; i++) {
if (r = fun.call(obj, obj[i])) { return r } if (r = fun.call(obj, obj[i])) { return r; }
} }
return null; return null;
}; };

View File

@ -13,13 +13,26 @@ tree.Zoom = function(op, value, index) {
}; };
} }
var start = 0, end = Infinity, zoom = 0; var start = 0,
end = Infinity,
zoom = 0;
switch (op) { switch (op) {
case '=': return 1 << value; break; case '=':
case '>': start = value + 1; break; return 1 << value;
case '>=': start = value; break; break;
case '<': end = value - 1; break; case '>':
case '<=': end = value; break; start = value + 1;
break;
case '>=':
start = value;
break;
case '<':
end = value - 1;
break;
case '<=':
end = value;
break;
} }
for (var i = 0; i <= tree.Zoom.maxZoom; i++) { for (var i = 0; i <= tree.Zoom.maxZoom; i++) {
if (i >= start && i <= end) { if (i >= start && i <= end) {