nodes: Value.unfoldSoak -> If.unfoldSoak

This commit is contained in:
satyr 2010-10-17 13:53:02 +09:00
parent 55794d9534
commit 8d0a0e8ab1
2 changed files with 22 additions and 22 deletions

View File

@ -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()) {

View File

@ -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