From 74bcd898e77fd69ee99dbc6ab36789d454b0d89c Mon Sep 17 00:00:00 2001 From: matehat Date: Mon, 22 Mar 2010 02:02:04 -0400 Subject: [PATCH] improving readability a bit --- lib/nodes.js | 12 +++++++----- src/nodes.coffee | 15 ++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 88ffa512..9b42d820 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -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)); diff --git a/src/nodes.coffee b/src/nodes.coffee index dbb33640..55e3be43 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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")