mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
implementing grayrest's suggested cleanup for object comprehensions
This commit is contained in:
@@ -38,11 +38,9 @@
|
||||
klass.prototype = new __a();
|
||||
klass.prototype.constructor = klass;
|
||||
__b = props;
|
||||
for (name in __b) {
|
||||
for (name in __b) if (__hasProp.call(__b, name)) {
|
||||
prop = __b[name];
|
||||
if (__hasProp.call(__b, name)) {
|
||||
((klass.prototype[name] = prop));
|
||||
}
|
||||
((klass.prototype[name] = prop));
|
||||
}
|
||||
return klass;
|
||||
};
|
||||
@@ -1060,7 +1058,7 @@
|
||||
return true;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var body, body_dent, call, 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, 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;
|
||||
@@ -1088,7 +1086,7 @@
|
||||
index_var = null;
|
||||
source_part = svar + ' = ' + this.source.compile(o) + ';\n' + this.idt();
|
||||
step_part = this.step ? ivar + ' += ' + this.step.compile(o) : ivar + '++';
|
||||
for_part = this.object ? ivar + ' in ' + svar : ivar + ' = 0; ' + ivar + ' < ' + svar + '.length; ' + step_part;
|
||||
for_part = ivar + ' = 0; ' + ivar + ' < ' + svar + '.length; ' + step_part;
|
||||
if (name) {
|
||||
var_part = body_dent + name + ' = ' + svar + '[' + ivar + '];\n';
|
||||
}
|
||||
@@ -1116,11 +1114,7 @@
|
||||
}
|
||||
if (this.object) {
|
||||
o.scope.assign('__hasProp', 'Object.prototype.hasOwnProperty', true);
|
||||
call = new CallNode(new ValueNode(new LiteralNode('__hasProp'), [new AccessorNode(new LiteralNode('call'))]), [new LiteralNode(svar), new LiteralNode(ivar)]);
|
||||
body = Expressions.wrap([new IfNode(call, Expressions.wrap([body]), null, {
|
||||
statement: true
|
||||
})
|
||||
]);
|
||||
for_part = ivar + ' in ' + svar + ') if (__hasProp.call(' + svar + ', ' + ivar + ')';
|
||||
}
|
||||
if (!(top_level)) {
|
||||
return_result = '\n' + this.idt() + return_result + ';';
|
||||
|
||||
Reference in New Issue
Block a user