1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

improving readability a bit

This commit is contained in:
matehat 2010-03-22 02:02:04 -04:00
parent 296808d4d3
commit 74bcd898e7
2 changed files with 13 additions and 14 deletions

View file

@ -934,13 +934,13 @@
// See the [ECMAScript Harmony Wiki](http://wiki.ecmascript.org/doku.php?id=harmony:destructuring)
// for details.
AssignNode.prototype.compile_pattern_match = function compile_pattern_match(o) {
var _a, _b, _c, access_class, assigns, code, i, idx, obj, oindex, olength, splatted, val, val_var, value;
var _a, _b, _c, access_class, assigns, code, i, idx, obj, oindex, olength, splat, val, val_var, value;
val_var = o.scope.free_variable();
value = this.value.is_statement() ? ClosureNode.wrap(this.value) : this.value;
assigns = ['' + this.tab + val_var + " = " + (value.compile(o)) + ";"];
o.top = true;
o.as_statement = true;
splatted = false;
splat = false;
_a = this.variable.base.objects;
for (i = 0, _b = _a.length; i < _b; i++) {
obj = _a[i];
@ -951,11 +951,13 @@
idx = _c[1];
}
access_class = this.variable.is_array() ? IndexNode : AccessorNode;
if (obj instanceof SplatNode && !splatted) {
if (obj instanceof SplatNode && !splat) {
val = literal(obj.compile_value(o, val_var, ((oindex = this.variable.base.objects.indexOf(obj))), ((olength = this.variable.base.objects.length)) - oindex - 1));
splatted = true;
splat = true;
} else {
typeof idx !== 'object' ? splatted ? (idx = literal('' + (val_var) + ".length - " + (olength - idx))) : (idx = literal(idx)) : null;
if (typeof idx !== 'object') {
idx = literal(splat ? '' + (val_var) + ".length - " + (olength - idx) : idx);
}
val = new ValueNode(literal(val_var), [new access_class(idx)]);
}
assigns.push(new AssignNode(obj, val).compile(o));

View file

@ -708,21 +708,18 @@ exports.AssignNode: class AssignNode extends BaseNode
assigns: ["$@tab$val_var = ${ value.compile(o) };"]
o.top: true
o.as_statement: true
splatted: false
splat: false
for obj, i in @variable.base.objects
idx: i
[obj, idx]: [obj.value, obj.variable.base] if @variable.is_object()
access_class: if @variable.is_array() then IndexNode else AccessorNode
if obj instanceof SplatNode and not splatted
val: literal(obj.compile_value(o, val_var, (oindex: @variable.base.objects.indexOf(obj)),
if obj instanceof SplatNode and not splat
val: literal(obj.compile_value(o, val_var,
(oindex: @variable.base.objects.indexOf(obj)),
(olength: @variable.base.objects.length) - oindex - 1))
splatted: true
splat: true
else
if typeof idx isnt 'object'
if splatted
idx: literal("${val_var}.length - ${olength - idx}")
else
idx: literal(idx)
idx: literal(if splat then "${val_var}.length - ${olength - idx}" else idx) if typeof idx isnt 'object'
val: new ValueNode(literal(val_var), [new access_class(idx)])
assigns.push(new AssignNode(obj, val).compile(o))
code: assigns.join("\n")