Implementing sethaurus' suggestion for better temp variable names -- getting rid of the numbers.

This commit is contained in:
Jeremy Ashkenas
2010-02-16 18:00:40 -05:00
parent e4bb6c91e7
commit db6bc0ba02
8 changed files with 256 additions and 256 deletions

View File

@@ -30,16 +30,16 @@
};
// Quickie inheritance convenience wrapper to reduce typing.
inherit = function inherit(parent, props) {
var _1, _2, klass, name, prop;
var _a, _b, klass, name, prop;
klass = del(props, 'constructor');
_1 = function(){};
_1.prototype = parent.prototype;
_a = function(){};
_a.prototype = parent.prototype;
klass.__superClass__ = parent.prototype;
klass.prototype = new _1();
klass.prototype = new _a();
klass.prototype.constructor = klass;
_2 = props;
for (name in _2) if (__hasProp.call(_2, name)) {
prop = _2[name];
_b = props;
for (name in _b) if (__hasProp.call(_b, name)) {
prop = _b[name];
((klass.prototype[name] = prop));
}
return klass;
@@ -86,20 +86,20 @@
};
// Quick short method for the current indentation level, plus tabbing in.
Node.prototype.idt = function idt(tabs) {
var _1, _2, _3, _4, i, idt;
var _a, _b, _c, _d, i, idt;
idt = (this.indent || '');
_3 = 0; _4 = (tabs || 0);
for (_2=0, i=_3; (_3 <= _4 ? i < _4 : i > _4); (_3 <= _4 ? i += 1 : i -= 1), _2++) {
_c = 0; _d = (tabs || 0);
for (_b=0, i=_c; (_c <= _d ? i < _d : i > _d); (_c <= _d ? i += 1 : i -= 1), _b++) {
idt += TAB;
}
return idt;
};
// Does this node, or any of its children, contain a node of a certain kind?
Node.prototype.contains = function contains(block) {
var _1, _2, node;
_1 = this.children;
for (_2 = 0; _2 < _1.length; _2++) {
node = _1[_2];
var _a, _b, node;
_a = this.children;
for (_b = 0; _b < _a.length; _b++) {
node = _a[_b];
if (block(node)) {
return true;
}
@@ -168,14 +168,14 @@
},
// Compile each expression in the Expressions body.
compile_node: function compile_node(o) {
var _1, _2, _3, node;
var _a, _b, _c, node;
return ((function() {
_1 = []; _2 = this.expressions;
for (_3 = 0; _3 < _2.length; _3++) {
node = _2[_3];
_1.push(this.compile_expression(node, _.clone(o)));
_a = []; _b = this.expressions;
for (_c = 0; _c < _b.length; _c++) {
node = _b[_c];
_a.push(this.compile_expression(node, _.clone(o)));
}
return _1;
return _a;
}).call(this)).join("\n");
},
// If this is the top-level Expressions, wrap everything in a safety closure.
@@ -315,7 +315,7 @@
return this.base.is_statement && this.base.is_statement() && !this.has_properties();
},
compile_node: function compile_node(o) {
var _1, _2, baseline, code, only, part, parts, prop, props, soaked, temp;
var _a, _b, baseline, code, only, part, parts, prop, props, soaked, temp;
soaked = false;
only = del(o, 'only_first');
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
@@ -324,9 +324,9 @@
baseline = '(' + baseline + ')';
}
parts = [baseline];
_1 = props;
for (_2 = 0; _2 < _1.length; _2++) {
prop = _1[_2];
_a = props;
for (_b = 0; _b < _a.length; _b++) {
prop = _a[_b];
if (prop instanceof AccessorNode && prop.soak) {
soaked = true;
if (this.base instanceof CallNode && prop === props[0]) {
@@ -383,19 +383,19 @@
},
// Compile a vanilla function call.
compile_node: function compile_node(o) {
var _1, _2, _3, arg, args;
var _a, _b, _c, arg, args;
if (_.any(this.args, function(a) {
return a instanceof SplatNode;
})) {
return this.compile_splat(o);
}
args = ((function() {
_1 = []; _2 = this.args;
for (_3 = 0; _3 < _2.length; _3++) {
arg = _2[_3];
_1.push(arg.compile(o));
_a = []; _b = this.args;
for (_c = 0; _c < _b.length; _c++) {
arg = _b[_c];
_a.push(arg.compile(o));
}
return _1;
return _a;
}).call(this)).join(', ');
if (this.variable === 'super') {
return this.compile_super(args, o);
@@ -412,20 +412,20 @@
},
// Compile a function call being passed variable arguments.
compile_splat: function compile_splat(o) {
var _1, _2, arg, args, code, i, meth, obj;
var _a, _b, arg, args, code, i, meth, obj;
meth = this.variable.compile(o);
obj = this.variable.source || 'this';
args = (function() {
_1 = []; _2 = this.args;
for (i = 0; i < _2.length; i++) {
arg = _2[i];
_1.push((function() {
_a = []; _b = this.args;
for (i = 0; i < _b.length; i++) {
arg = _b[i];
_a.push((function() {
code = arg.compile(o);
code = arg instanceof SplatNode ? code : '[' + code + ']';
return i === 0 ? code : '.concat(' + code + ')';
}).call(this));
}
return _1;
return _a;
}).call(this);
return this.prefix + meth + '.apply(' + obj + ', ' + args.join('') + ')';
},
@@ -564,24 +564,24 @@
// AssignNodes get interleaved correctly, with no trailing commas or
// commas affixed to comments. TODO: Extract this and add it to ArrayNode.
compile_node: function compile_node(o) {
var _1, _2, _3, _4, _5, i, indent, inner, join, last_noncom, non_comments, prop, props;
var _a, _b, _c, _d, _e, i, indent, inner, join, last_noncom, non_comments, prop, props;
o.indent = this.idt(1);
non_comments = (function() {
_1 = []; _2 = this.properties;
for (_3 = 0; _3 < _2.length; _3++) {
prop = _2[_3];
_a = []; _b = this.properties;
for (_c = 0; _c < _b.length; _c++) {
prop = _b[_c];
if (!(prop instanceof CommentNode)) {
_1.push(prop);
_a.push(prop);
}
}
return _1;
return _a;
}).call(this);
last_noncom = non_comments[non_comments.length - 1];
props = (function() {
_4 = []; _5 = this.properties;
for (i = 0; i < _5.length; i++) {
prop = _5[i];
_4.push((function() {
_d = []; _e = this.properties;
for (i = 0; i < _e.length; i++) {
prop = _e[i];
_d.push((function() {
join = ",\n";
if ((prop === last_noncom) || (prop instanceof CommentNode)) {
join = "\n";
@@ -593,7 +593,7 @@
return indent + prop.compile(o) + join;
}).call(this));
}
return _4;
return _d;
}).call(this);
props = props.join('');
inner = props ? '\n' + props + '\n' + this.idt() : '';
@@ -608,13 +608,13 @@
return this;
},
compile_node: function compile_node(o) {
var _1, _2, code, ending, i, obj, objects;
var _a, _b, code, ending, i, obj, objects;
o.indent = this.idt(1);
objects = (function() {
_1 = []; _2 = this.objects;
for (i = 0; i < _2.length; i++) {
obj = _2[i];
_1.push((function() {
_a = []; _b = this.objects;
for (i = 0; i < _b.length; i++) {
obj = _b[i];
_a.push((function() {
code = obj.compile(o);
if (obj instanceof CommentNode) {
return '\n' + code + '\n' + o.indent;
@@ -625,7 +625,7 @@
}
}).call(this));
}
return _1;
return _a;
}).call(this);
objects = objects.join('');
ending = objects.indexOf('\n') >= 0 ? "\n" + this.idt() + ']' : ']';
@@ -718,19 +718,19 @@
// object literals to a value. Peeks at their properties to assign inner names.
// See: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
compile_pattern_match: function compile_pattern_match(o) {
var _1, _2, access_class, assigns, i, idx, obj, val, val_var;
var _a, _b, access_class, assigns, i, idx, obj, val, val_var;
val_var = o.scope.free_variable();
assigns = [this.idt() + val_var + ' = ' + this.value.compile(o) + ';'];
o.top = true;
o.as_statement = true;
_1 = this.variable.base.objects;
for (i = 0; i < _1.length; i++) {
obj = _1[i];
_a = this.variable.base.objects;
for (i = 0; i < _a.length; i++) {
obj = _a[i];
idx = i;
if (this.variable.is_object()) {
_2 = [obj.value, obj.variable.base];
obj = _2[0];
idx = _2[1];
_b = [obj.value, obj.variable.base];
obj = _b[0];
idx = _b[1];
}
access_class = this.variable.is_array() ? IndexNode : AccessorNode;
if (obj instanceof SplatNode) {
@@ -769,7 +769,7 @@
return this;
},
compile_node: function compile_node(o) {
var _1, _2, _3, _4, _5, code, func, inner, name_part, param, params, shared_scope, splat, top;
var _a, _b, _c, _d, _e, code, func, inner, name_part, param, params, shared_scope, splat, top;
shared_scope = del(o, 'shared_scope');
top = del(o, 'top');
o.scope = shared_scope || new Scope(o.scope, this.body, this);
@@ -784,16 +784,16 @@
this.body.unshift(splat);
}
params = ((function() {
_1 = []; _2 = this.params;
for (_3 = 0; _3 < _2.length; _3++) {
param = _2[_3];
_1.push(param.compile(o));
_a = []; _b = this.params;
for (_c = 0; _c < _b.length; _c++) {
param = _b[_c];
_a.push(param.compile(o));
}
return _1;
return _a;
}).call(this));
_4 = params;
for (_5 = 0; _5 < _4.length; _5++) {
param = _4[_5];
_d = params;
for (_e = 0; _e < _d.length; _e++) {
param = _d[_e];
(o.scope.parameter(param));
}
code = this.body.expressions.length ? '\n' + this.body.compile_with_declarations(o) + '\n' : '';
@@ -923,20 +923,20 @@
// Mimic Python's chained comparisons. See:
// http://docs.python.org/reference/expressions.html#notin
compile_chain: function compile_chain(o) {
var _1, shared;
var _a, shared;
shared = this.first.unwrap().second;
if (shared instanceof CallNode) {
_1 = shared.compile_reference(o);
this.first.second = _1[0];
shared = _1[1];
_a = shared.compile_reference(o);
this.first.second = _a[0];
shared = _a[1];
}
return '(' + this.first.compile(o) + ') && (' + shared.compile(o) + ' ' + this.operator + ' ' + this.second.compile(o) + ')';
},
compile_assignment: function compile_assignment(o) {
var _1, first, second;
_1 = [this.first.compile(o), this.second.compile(o)];
first = _1[0];
second = _1[1];
var _a, first, second;
_a = [this.first.compile(o), this.second.compile(o)];
first = _a[0];
second = _a[1];
if (first.match(IDENTIFIER)) {
o.scope.find(first);
}
@@ -946,10 +946,10 @@
return first + ' = ' + first + ' ' + this.operator.substr(0, 2) + ' ' + second;
},
compile_existence: function compile_existence(o) {
var _1, first, second;
_1 = [this.first.compile(o), this.second.compile(o)];
first = _1[0];
second = _1[1];
var _a, first, second;
_a = [this.first.compile(o), this.second.compile(o)];
first = _a[0];
second = _a[1];
return ExistenceNode.compile_test(o, this.first) + ' ? ' + first + ' : ' + second;
},
compile_unary: function compile_unary(o) {
@@ -1007,14 +1007,14 @@
}
}));
ExistenceNode.compile_test = function compile_test(o, variable) {
var _1, _2, first, second;
_1 = [variable, variable];
first = _1[0];
second = _1[1];
var _a, _b, first, second;
_a = [variable, variable];
first = _a[0];
second = _a[1];
if (variable instanceof CallNode) {
_2 = variable.compile_reference(o);
first = _2[0];
second = _2[1];
_b = variable.compile_reference(o);
first = _b[0];
second = _b[1];
}
return '(typeof ' + first.compile(o) + ' !== "undefined" && ' + second.compile(o) + ' !== null)';
};
@@ -1042,7 +1042,7 @@
ForNode = (exports.ForNode = inherit(Node, {
type: 'For',
constructor: function constructor(body, source, name, index) {
var _1;
var _a;
this.body = body;
this.name = name;
this.index = index || null;
@@ -1051,9 +1051,9 @@
this.step = source.step;
this.object = !!source.object;
if (this.object) {
_1 = [this.index, this.name];
this.name = _1[0];
this.index = _1[1];
_a = [this.index, this.name];
this.name = _a[0];
this.index = _a[1];
}
this.children = _.compact([this.body, this.source, this.filter]);
return this;
@@ -1164,15 +1164,15 @@
},
// Rewrite a chain of IfNodes with their switch condition for equality.
rewrite_condition: function rewrite_condition(expression) {
var _1, _2, _3, cond;
var _a, _b, _c, cond;
this.condition = (function() {
if (this.multiple) {
_1 = []; _2 = this.condition;
for (_3 = 0; _3 < _2.length; _3++) {
cond = _2[_3];
_1.push(new OpNode('is', expression, cond));
_a = []; _b = this.condition;
for (_c = 0; _c < _b.length; _c++) {
cond = _b[_c];
_a.push(new OpNode('is', expression, cond));
}
return _1;
return _a;
} else {
return new OpNode('is', expression, this.condition);
}
@@ -1198,14 +1198,14 @@
return this.statement = this.statement || !!(this.comment || this.tags.statement || this.body.is_statement() || (this.else_body && this.else_body.is_statement()));
},
compile_condition: function compile_condition(o) {
var _1, _2, _3, cond;
var _a, _b, _c, cond;
return ((function() {
_1 = []; _2 = _.flatten([this.condition]);
for (_3 = 0; _3 < _2.length; _3++) {
cond = _2[_3];
_1.push(cond.compile(o));
_a = []; _b = _.flatten([this.condition]);
for (_c = 0; _c < _b.length; _c++) {
cond = _b[_c];
_a.push(cond.compile(o));
}
return _1;
return _a;
}).call(this)).join(' || ');
},
compile_node: function compile_node(o) {