nodes: Value.unfoldSoak -> If.unfoldSoak
This commit is contained in:
parent
55794d9534
commit
8d0a0e8ab1
26
lib/nodes.js
26
lib/nodes.js
|
@ -435,17 +435,8 @@
|
||||||
}
|
}
|
||||||
return null;
|
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;
|
return Value;
|
||||||
}).call(this);
|
})();
|
||||||
exports.Comment = (function() {
|
exports.Comment = (function() {
|
||||||
Comment = (function() {
|
Comment = (function() {
|
||||||
function Comment(_arg) {
|
function Comment(_arg) {
|
||||||
|
@ -546,7 +537,7 @@
|
||||||
call.variable.base = ifn;
|
call.variable.base = ifn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ifn = Value.unfoldSoak(o, call, 'variable');
|
ifn = If.unfoldSoak(o, call, 'variable');
|
||||||
}
|
}
|
||||||
return ifn;
|
return ifn;
|
||||||
};
|
};
|
||||||
|
@ -1001,7 +992,7 @@
|
||||||
if (this.variable.isSplice()) {
|
if (this.variable.isSplice()) {
|
||||||
return this.compileSplice(o);
|
return this.compileSplice(o);
|
||||||
}
|
}
|
||||||
if (ifn = Value.unfoldSoak(o, this, 'variable')) {
|
if (ifn = If.unfoldSoak(o, this, 'variable')) {
|
||||||
delete o.top;
|
delete o.top;
|
||||||
return ifn.compile(o);
|
return ifn.compile(o);
|
||||||
}
|
}
|
||||||
|
@ -1899,8 +1890,17 @@
|
||||||
If.prototype.unfoldSoak = function() {
|
If.prototype.unfoldSoak = function() {
|
||||||
return this.soakNode && this;
|
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;
|
return If;
|
||||||
})();
|
}).call(this);
|
||||||
Push = {
|
Push = {
|
||||||
wrap: function(name, expressions) {
|
wrap: function(name, expressions) {
|
||||||
if (expressions.empty() || expressions.containsPureStatement()) {
|
if (expressions.empty() || expressions.containsPureStatement()) {
|
||||||
|
|
|
@ -402,13 +402,6 @@ exports.Value = class Value extends Base
|
||||||
return ifn
|
return ifn
|
||||||
null
|
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
|
#### Comment
|
||||||
|
|
||||||
# CoffeeScript passes through block comments as JavaScript block comments
|
# CoffeeScript passes through block comments as JavaScript block comments
|
||||||
|
@ -492,7 +485,7 @@ exports.Call = class Call extends Base
|
||||||
call.variable = ifn
|
call.variable = ifn
|
||||||
else
|
else
|
||||||
call.variable.base = ifn
|
call.variable.base = ifn
|
||||||
ifn = Value.unfoldSoak o, call, 'variable'
|
ifn = If.unfoldSoak o, call, 'variable'
|
||||||
ifn
|
ifn
|
||||||
|
|
||||||
# Compile a vanilla function call.
|
# Compile a vanilla function call.
|
||||||
|
@ -863,7 +856,7 @@ exports.Assign = class Assign extends Base
|
||||||
if isValue = @isValue()
|
if isValue = @isValue()
|
||||||
return @compilePatternMatch(o) if @variable.isArray() or @variable.isObject()
|
return @compilePatternMatch(o) if @variable.isArray() or @variable.isObject()
|
||||||
return @compileSplice(o) if @variable.isSplice()
|
return @compileSplice(o) if @variable.isSplice()
|
||||||
if ifn = Value.unfoldSoak o, this, 'variable'
|
if ifn = If.unfoldSoak o, this, 'variable'
|
||||||
delete o.top
|
delete o.top
|
||||||
return ifn.compile o
|
return ifn.compile o
|
||||||
top = del o, 'top'
|
top = del o, 'top'
|
||||||
|
@ -1592,6 +1585,13 @@ exports.If = class If extends Base
|
||||||
|
|
||||||
unfoldSoak: -> @soakNode and this
|
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
|
||||||
# ----------
|
# ----------
|
||||||
# Faux-nodes are never created by the grammar, but are used during code
|
# Faux-nodes are never created by the grammar, but are used during code
|
||||||
|
|
Loading…
Reference in New Issue