diff --git a/lib/nodes.js b/lib/nodes.js index 51076035..a6715ea2 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -435,17 +435,8 @@ } return null; }; - Value.unfoldSoak = function(o, parent, name) { - var ifn; - if (!(ifn = parent[name].unfoldSoak(o))) { - return; - } - parent[name] = ifn.body; - ifn.body = new Value(parent); - return ifn; - }; return Value; - }).call(this); + })(); exports.Comment = (function() { Comment = (function() { function Comment(_arg) { @@ -546,7 +537,7 @@ call.variable.base = ifn; } } - ifn = Value.unfoldSoak(o, call, 'variable'); + ifn = If.unfoldSoak(o, call, 'variable'); } return ifn; }; @@ -1001,7 +992,7 @@ if (this.variable.isSplice()) { return this.compileSplice(o); } - if (ifn = Value.unfoldSoak(o, this, 'variable')) { + if (ifn = If.unfoldSoak(o, this, 'variable')) { delete o.top; return ifn.compile(o); } @@ -1899,8 +1890,17 @@ If.prototype.unfoldSoak = function() { return this.soakNode && this; }; + If.unfoldSoak = function(o, parent, name) { + var ifn; + if (!(ifn = parent[name].unfoldSoak(o))) { + return; + } + parent[name] = ifn.body; + ifn.body = new Value(parent); + return ifn; + }; return If; - })(); + }).call(this); Push = { wrap: function(name, expressions) { if (expressions.empty() || expressions.containsPureStatement()) { diff --git a/src/nodes.coffee b/src/nodes.coffee index 61114f01..a4d632ed 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -402,13 +402,6 @@ exports.Value = class Value extends Base return ifn null - # Unfold a node's child if soak, then tuck the node under created `If` - @unfoldSoak: (o, parent, name) -> - return unless ifn = parent[name].unfoldSoak o - parent[name] = ifn.body - ifn.body = new Value parent - ifn - #### Comment # CoffeeScript passes through block comments as JavaScript block comments @@ -492,7 +485,7 @@ exports.Call = class Call extends Base call.variable = ifn else call.variable.base = ifn - ifn = Value.unfoldSoak o, call, 'variable' + ifn = If.unfoldSoak o, call, 'variable' ifn # Compile a vanilla function call. @@ -863,7 +856,7 @@ exports.Assign = class Assign extends Base if isValue = @isValue() return @compilePatternMatch(o) if @variable.isArray() or @variable.isObject() return @compileSplice(o) if @variable.isSplice() - if ifn = Value.unfoldSoak o, this, 'variable' + if ifn = If.unfoldSoak o, this, 'variable' delete o.top return ifn.compile o top = del o, 'top' @@ -1592,6 +1585,13 @@ exports.If = class If extends Base unfoldSoak: -> @soakNode and this + # Unfold a node's child if soak, then tuck the node under created `If` + @unfoldSoak: (o, parent, name) -> + return unless ifn = parent[name].unfoldSoak o + parent[name] = ifn.body + ifn.body = new Value parent + ifn + # Faux-Nodes # ---------- # Faux-nodes are never created by the grammar, but are used during code