mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #2709 from epidemian/minor-embellishments
Minor embellishments
This commit is contained in:
@@ -594,8 +594,8 @@
|
||||
this.base = base;
|
||||
this.properties = properties;
|
||||
this.properties || (this.properties = []);
|
||||
if (tag) {
|
||||
this[tag] = true;
|
||||
if (tag === 'this') {
|
||||
this["this"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -1330,16 +1326,12 @@
|
||||
};
|
||||
|
||||
Class.prototype.addBoundFunctions = function(o) {
|
||||
var bvar, lhs, _i, _len, _ref2, _results;
|
||||
if (this.boundFuncs.length) {
|
||||
_ref2 = this.boundFuncs;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
bvar = _ref2[_i];
|
||||
lhs = (Value.wrap(new Literal("this"), [new Access(bvar)])).compile(o);
|
||||
_results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
|
||||
}
|
||||
return _results;
|
||||
var bvar, lhs, _i, _len, _ref2;
|
||||
_ref2 = this.boundFuncs;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
bvar = _ref2[_i];
|
||||
lhs = (Value.wrap(new Literal("this"), [new Access(bvar)])).compile(o);
|
||||
this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)"));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@ exports.Value = class Value extends Base
|
||||
|
||||
constructor: (@base, @properties, tag) ->
|
||||
@properties or= []
|
||||
@[tag] = true if tag
|
||||
@this = true if tag is 'this'
|
||||
|
||||
children: ['base', 'properties']
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -895,10 +893,10 @@ exports.Class = class Class extends Base
|
||||
# Ensure that all functions bound to the instance are proxied in the
|
||||
# constructor.
|
||||
addBoundFunctions: (o) ->
|
||||
if @boundFuncs.length
|
||||
for bvar in @boundFuncs
|
||||
lhs = (Value.wrap (new Literal "this"), [new Access bvar]).compile o
|
||||
@ctor.body.unshift new Literal "#{lhs} = #{utility 'bind'}(#{lhs}, this)"
|
||||
for bvar in @boundFuncs
|
||||
lhs = (Value.wrap (new Literal "this"), [new Access bvar]).compile o
|
||||
@ctor.body.unshift new Literal "#{lhs} = #{utility 'bind'}(#{lhs}, this)"
|
||||
return
|
||||
|
||||
# Merge the properties from a top-level object as prototypal properties
|
||||
# on the class.
|
||||
|
||||
Reference in New Issue
Block a user