adding an extra pair of braces to the code produced by object comprehensions, so as to squeak by in JSLint's good graces

This commit is contained in:
Jeremy Ashkenas
2010-02-18 20:22:53 -05:00
parent d4a180c413
commit a278d8f018
6 changed files with 25 additions and 23 deletions

View File

@@ -32,7 +32,7 @@
print_tasks = function print_tasks() {
var _a, _b, _c, _d, _e, _f, _g, i, name, spaces, task;
_a = []; _b = tasks;
for (name in _b) if (__hasProp.call(_b, name)) {
for (name in _b) { if (__hasProp.call(_b, name)) {
task = _b[name];
_a.push((function() {
spaces = 20 - name.length;
@@ -45,7 +45,7 @@
}).call(this).join('') : '';
return puts("cake " + name + spaces + ' # ' + task.description);
}).call(this));
}
}}
return _a;
};
// Running `cake` runs the tasks you pass asynchronously (node-style), or

View File

@@ -524,7 +524,7 @@
bnf = {};
tokens = [];
_a = grammar;
for (name in _a) if (__hasProp.call(_a, name)) {
for (name in _a) { if (__hasProp.call(_a, name)) {
non_terminal = _a[name];
bnf[name] = (function() {
_b = []; _c = non_terminal;
@@ -542,7 +542,7 @@
}
return _b;
}).call(this);
}
}}
tokens = tokens.join(" ");
exports.parser = new Parser({
tokens: tokens,

View File

@@ -13,16 +13,16 @@
var _a, _b, fresh, key, val;
fresh = {};
_a = options;
for (key in _a) if (__hasProp.call(_a, key)) {
for (key in _a) { if (__hasProp.call(_a, key)) {
val = _a[key];
((fresh[key] = val));
}
}}
if (overrides) {
_b = overrides;
for (key in _b) if (__hasProp.call(_b, key)) {
for (key in _b) { if (__hasProp.call(_b, key)) {
val = _b[key];
((fresh[key] = val));
}
}}
}
return fresh;
};
@@ -66,10 +66,10 @@
klass.prototype = new _a();
klass.prototype.constructor = klass;
_b = props;
for (name in _b) if (__hasProp.call(_b, name)) {
for (name in _b) { if (__hasProp.call(_b, name)) {
prop = _b[name];
((klass.prototype[name] = prop));
}
}}
return klass;
};
// Mark a node as a statement, or a statement only.
@@ -1116,7 +1116,7 @@
return true;
},
compile_node: function compile_node(o) {
var body, body_dent, for_part, index, index_found, index_var, ivar, name, name_found, range, return_result, rvar, scope, set_result, source, source_part, step_part, svar, top_level, var_part, vars;
var body, body_dent, close, for_part, index, index_found, index_var, ivar, name, name_found, range, return_result, rvar, scope, set_result, source, source_part, step_part, svar, top_level, var_part, vars;
top_level = del(o, 'top') && !o.returns;
range = this.source instanceof ValueNode && this.source.base instanceof RangeNode && !this.source.properties.length;
source = range ? this.source.base : this.source;
@@ -1172,7 +1172,7 @@
}
if (this.object) {
o.scope.assign('__hasProp', 'Object.prototype.hasOwnProperty', true);
for_part = ivar + ' in ' + svar + ') if (__hasProp.call(' + svar + ', ' + ivar + ')';
for_part = ivar + ' in ' + svar + ') { if (__hasProp.call(' + svar + ', ' + ivar + ')';
}
if (!(top_level)) {
return_result = '\n' + this.idt() + return_result + ';';
@@ -1182,7 +1182,8 @@
top: true
}));
vars = range ? name : name + ', ' + ivar;
return set_result + source_part + 'for (' + for_part + ') {\n' + var_part + body + '\n' + this.idt() + '}\n' + this.idt() + return_result;
close = this.object ? '}}\n' : '}\n';
return set_result + source_part + 'for (' + for_part + ') {\n' + var_part + body + '\n' + this.idt() + close + this.idt() + return_result;
}
}));
statement(ForNode);

View File

@@ -306,12 +306,12 @@
})(this));
unclosed = (function() {
_i = []; _j = levels;
for (key in _j) if (__hasProp.call(_j, key)) {
for (key in _j) { if (__hasProp.call(_j, key)) {
value = _j[key];
if (value > 0) {
_i.push(key);
}
}
}}
return _i;
}).call(this);
if (unclosed.length) {
@@ -336,10 +336,10 @@
stack = [];
debt = {};
_i = INVERSES;
for (key in _i) if (__hasProp.call(_i, key)) {
for (key in _i) { if (__hasProp.call(_i, key)) {
val = _i[key];
((debt[key] = 0));
}
}}
return this.scan_tokens((function(__this) {
var __func = function(prev, token, post, i) {
var inv, match, mtag, tag;

View File

@@ -81,12 +81,12 @@
var _a, _b, key, val;
return (function() {
_a = []; _b = this.variables;
for (key in _b) if (__hasProp.call(_b, key)) {
for (key in _b) { if (__hasProp.call(_b, key)) {
val = _b[key];
if (val === 'var') {
_a.push(key);
}
}
}}
return _a;
}).call(this).sort();
};
@@ -95,12 +95,12 @@
Scope.prototype.assigned_variables = function assigned_variables() {
var _a, _b, key, val;
_a = []; _b = this.variables;
for (key in _b) if (__hasProp.call(_b, key)) {
for (key in _b) { if (__hasProp.call(_b, key)) {
val = _b[key];
if (val.assigned) {
_a.push(key + ' = ' + val.value);
}
}
}}
return _a;
};
// Compile the string representing all of the declared variables for this scope.

View File

@@ -934,11 +934,12 @@ ForNode: exports.ForNode: inherit Node, {
body: Expressions.wrap([new IfNode(@filter, body)])
if @object
o.scope.assign('__hasProp', 'Object.prototype.hasOwnProperty', true)
for_part: ivar + ' in ' + svar + ') if (__hasProp.call(' + svar + ', ' + ivar + ')'
for_part: ivar + ' in ' + svar + ') { if (__hasProp.call(' + svar + ', ' + ivar + ')'
return_result: '\n' + @idt() + return_result + ';' unless top_level
body: body.compile(merge(o, {indent: body_dent, top: true}))
vars: if range then name else name + ', ' + ivar
set_result + source_part + 'for (' + for_part + ') {\n' + var_part + body + '\n' + @idt() + '}\n' + @idt() + return_result
close: if @object then '}}\n' else '}\n'
set_result + source_part + 'for (' + for_part + ') {\n' + var_part + body + '\n' + @idt() + close + @idt() + return_result
}