mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Simplify Value::unfoldSoak momoization code (only a bit...)
This commit is contained in:
parent
03cfe23493
commit
9ed804d9b1
2 changed files with 11 additions and 17 deletions
|
@ -711,20 +711,17 @@
|
|||
};
|
||||
|
||||
Value.prototype.unfoldSoak = function(o) {
|
||||
var result,
|
||||
var _ref2,
|
||||
_this = this;
|
||||
if (this.unfoldedSoak != null) {
|
||||
return this.unfoldedSoak;
|
||||
}
|
||||
result = (function() {
|
||||
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
|
||||
return (_ref2 = this.unfoldedSoak) != null ? _ref2 : this.unfoldedSoak = (function() {
|
||||
var fst, i, ifn, prop, ref, snd, _i, _len, _ref3, _ref4;
|
||||
if (ifn = _this.base.unfoldSoak(o)) {
|
||||
Array.prototype.push.apply(ifn.body.properties, _this.properties);
|
||||
(_ref3 = ifn.body.properties).push.apply(_ref3, _this.properties);
|
||||
return ifn;
|
||||
}
|
||||
_ref2 = _this.properties;
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
prop = _ref2[i];
|
||||
_ref4 = _this.properties;
|
||||
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
||||
prop = _ref4[i];
|
||||
if (!prop.soak) {
|
||||
continue;
|
||||
}
|
||||
|
@ -740,9 +737,8 @@
|
|||
soak: true
|
||||
});
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
})();
|
||||
return this.unfoldedSoak = result || false;
|
||||
};
|
||||
|
||||
return Value;
|
||||
|
|
|
@ -457,10 +457,9 @@ exports.Value = class Value extends Base
|
|||
|
||||
# Unfold a soak into an `If`: `a?.b` -> `a.b if a?`
|
||||
unfoldSoak: (o) ->
|
||||
return @unfoldedSoak if @unfoldedSoak?
|
||||
result = do =>
|
||||
@unfoldedSoak ?= do =>
|
||||
if ifn = @base.unfoldSoak o
|
||||
Array::push.apply ifn.body.properties, @properties
|
||||
ifn.body.properties.push @properties...
|
||||
return ifn
|
||||
for prop, i in @properties when prop.soak
|
||||
prop.soak = off
|
||||
|
@ -471,8 +470,7 @@ exports.Value = class Value extends Base
|
|||
fst = new Parens new Assign ref, fst
|
||||
snd.base = ref
|
||||
return new If new Existence(fst), snd, soak: on
|
||||
null
|
||||
@unfoldedSoak = result or no
|
||||
no
|
||||
|
||||
#### Comment
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue