using @containsType.

This commit is contained in:
Jeremy Ashkenas
2010-09-12 14:44:03 -04:00
parent 3a20d7dacb
commit ea3aa6803a
2 changed files with 20 additions and 28 deletions

View File

@@ -50,9 +50,7 @@
var compiled, pair, reference; var compiled, pair, reference;
options || (options = {}); options || (options = {});
pair = (function() { pair = (function() {
if (!((this instanceof CallNode || this.contains(function(n) { if (!(this.containsType(CallNode) || (this instanceof ValueNode && (!(this.base instanceof LiteralNode) || this.hasProperties())))) {
return n instanceof CallNode;
})) || (this instanceof ValueNode && (!(this.base instanceof LiteralNode) || this.hasProperties())))) {
return [this, this]; return [this, this];
} else if (this instanceof ValueNode && options.assignment) { } else if (this instanceof ValueNode && options.assignment) {
return this.cacheIndexes(o); return this.cacheIndexes(o);
@@ -387,7 +385,7 @@
return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o); return !o.top || this.properties.length ? ValueNode.__super__.compile.call(this, o) : this.base.compile(o);
}; };
ValueNode.prototype.compileNode = function(o) { ValueNode.prototype.compileNode = function(o) {
var _b, _c, _d, baseline, complete, i, only, op, props; var _b, _c, baseline, complete, i, only, op, part, prop, props, temp;
only = del(o, 'onlyFirst'); only = del(o, 'onlyFirst');
op = this.tags.operation; op = this.tags.operation;
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties; props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
@@ -400,29 +398,23 @@
baseline = ("(" + (baseline) + ")"); baseline = ("(" + (baseline) + ")");
} }
complete = (this.last = baseline); complete = (this.last = baseline);
_c = props; _b = props;
for (_b = 0, _d = _c.length; _b < _d; _b++) { for (i = 0, _c = _b.length; i < _c; i++) {
(function() { prop = _b[i];
var part, temp; this.source = baseline;
var i = _b; if (prop.soakNode) {
var prop = _c[_b]; if (this.base.containsType(CallNode) && i === 0) {
this.source = baseline; temp = o.scope.freeVariable();
if (prop.soakNode) { complete = ("(" + (baseline = temp) + " = (" + (complete) + "))");
if (this.base instanceof CallNode || this.base.contains(function(n) {
return n instanceof CallNode;
}) && i === 0) {
temp = o.scope.freeVariable();
complete = ("(" + (baseline = temp) + " = (" + (complete) + "))");
}
complete = i === 0 ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null) ? undefined : ") : ("" + (complete) + " == null ? undefined : ");
return complete += (baseline += prop.compile(o));
} else {
part = prop.compile(o);
baseline += part;
complete += part;
return (this.last = part);
} }
}).call(this); complete = i === 0 ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null) ? undefined : ") : ("" + (complete) + " == null ? undefined : ");
complete += (baseline += prop.compile(o));
} else {
part = prop.compile(o);
baseline += part;
complete += part;
this.last = part;
}
} }
return op && this.wrapped ? ("(" + (complete) + ")") : complete; return op && this.wrapped ? ("(" + (complete) + ")") : complete;
}; };

View File

@@ -64,7 +64,7 @@ exports.BaseNode = class BaseNode
# by assigning it to a temporary variable. # by assigning it to a temporary variable.
compileReference: (o, options) -> compileReference: (o, options) ->
options or= {} options or= {}
pair = if not ((this instanceof CallNode or @contains((n) -> n instanceof CallNode)) or pair = if not (@containsType(CallNode) or
(this instanceof ValueNode and (not (@base instanceof LiteralNode) or @hasProperties()))) (this instanceof ValueNode and (not (@base instanceof LiteralNode) or @hasProperties())))
[this, this] [this, this]
else if this instanceof ValueNode and options.assignment else if this instanceof ValueNode and options.assignment
@@ -369,7 +369,7 @@ exports.ValueNode = class ValueNode extends BaseNode
for prop, i in props for prop, i in props
@source = baseline @source = baseline
if prop.soakNode if prop.soakNode
if @base instanceof CallNode or @base.contains((n) -> n instanceof CallNode) and i is 0 if @base.containsType(CallNode) and i is 0
temp = o.scope.freeVariable() temp = o.scope.freeVariable()
complete = "(#{ baseline = temp } = (#{complete}))" complete = "(#{ baseline = temp } = (#{complete}))"
complete = if i is 0 complete = if i is 0