From e7ebdce60fadb4349318f14a4409d1a077a63ebf Mon Sep 17 00:00:00 2001 From: Michal Srb Date: Tue, 23 Apr 2013 05:42:37 +0200 Subject: [PATCH] Fix #2953. Method calls on splice endpoints --- lib/coffee-script/nodes.js | 2 +- src/nodes.coffee | 3 ++- test/slicing_and_splicing.coffee | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 9f1c17ee..c128fc84 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -1746,7 +1746,7 @@ fromDecl = fromRef = '0'; } if (to) { - if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) { + if (from && from instanceof Value && (from != null ? from.isSimpleNumber() : void 0) && to instanceof Value && to.isSimpleNumber()) { to = +to.compile(o) - +fromRef; if (!exclusive) { to += 1; diff --git a/src/nodes.coffee b/src/nodes.coffee index fd8bb006..bc6c1098 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1261,7 +1261,8 @@ exports.Assign = class Assign extends Base else fromDecl = fromRef = '0' if to - if from?.isSimpleNumber() and to.isSimpleNumber() + if from and from instanceof Value and from?.isSimpleNumber() and + to instanceof Value and to.isSimpleNumber() to = +to.compile(o) - +fromRef to += 1 unless exclusive else diff --git a/test/slicing_and_splicing.coffee b/test/slicing_and_splicing.coffee index 5d37d840..a126ec00 100644 --- a/test/slicing_and_splicing.coffee +++ b/test/slicing_and_splicing.coffee @@ -144,3 +144,12 @@ test "#1723: operator precedence in unbounded splice compilation", -> list = [0..9] list[..if n then n else 0] = n arrayEq [n..9], list + +test "#2953: methods on endpoints in assignment from array splice literal", -> + list = [0..9] + + Number.prototype.same = -> this + list[1.same()...9.same()] = 5 + delete Number.prototype.same + + arrayEq [0, 5, 9], list