Partial fix for 653.

This commit is contained in:
Jeremy Ashkenas 2010-09-12 11:08:05 -04:00
parent e5837b4ee9
commit 3a20d7dacb
3 changed files with 31 additions and 9 deletions

View File

@ -357,20 +357,25 @@
return this.base instanceof LiteralNode && this.base.value.match(NUMBER);
};
ValueNode.prototype.cacheIndexes = function(o) {
var _b, _c, _d, copy, i;
var _b, _c, _d, _e, copy, i;
copy = new ValueNode(this.base, this.properties.slice(0));
_c = copy.properties;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
if (this.base instanceof CallNode) {
_b = this.base.compileReference(o);
this.base = _b[0];
copy.base = _b[1];
}
_d = copy.properties;
for (_c = 0, _e = _d.length; _c < _e; _c++) {
(function() {
var _e, index, indexVar;
var i = _b;
var prop = _c[_b];
var _f, index, indexVar;
var i = _c;
var prop = _d[_c];
if (prop instanceof IndexNode && prop.contains(function(n) {
return n instanceof CallNode;
})) {
_e = prop.index.compileReference(o);
index = _e[0];
indexVar = _e[1];
_f = prop.index.compileReference(o);
index = _f[0];
indexVar = _f[1];
this.properties[i] = new IndexNode(index);
return (copy.properties[i] = new IndexNode(indexVar));
}

View File

@ -339,6 +339,8 @@ exports.ValueNode = class ValueNode extends BaseNode
# the value of the indexes.
cacheIndexes: (o) ->
copy = new ValueNode @base, @properties[0..]
if @base instanceof CallNode
[@base, copy.base] = @base.compileReference o
for prop, i in copy.properties
if prop instanceof IndexNode and prop.contains((n) -> n instanceof CallNode)
[index, indexVar] = prop.index.compileReference o

View File

@ -95,6 +95,21 @@ count = 0
list[key()] ?= 100
ok list.join(' ') is '0 100 5 10'
count = 0
key = ->
count += 1
key
key().val or= 100
ok key.val is 100
ok count is 1
key().val ?= 200
ok key.val is 100
ok count is 2
# Ensure that RHS is treated as a group.
a = b = false