From ca4ea7649d94c4185666b06fa5b5b3928834f1db Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 25 Apr 2010 11:22:15 -0400 Subject: [PATCH] Throwing an error when pattern matching has a non-identifier on the left-hand side. --- lib/nodes.js | 3 +++ src/nodes.coffee | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/nodes.js b/lib/nodes.js index 4400601f..e7ff45df 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -943,6 +943,9 @@ obj = _c[0]; idx = _c[1]; } + if (!(obj instanceof ValueNode || obj instanceof SplatNode)) { + throw new Error('pattern matching must use only identifiers on the left-hand side.'); + } is_string = idx.value && idx.value.match(IS_STRING); access_class = is_string || this.variable.is_array() ? IndexNode : AccessorNode; if (obj instanceof SplatNode && !splat) { diff --git a/src/nodes.coffee b/src/nodes.coffee index f8c938a2..500c6ec4 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -692,6 +692,8 @@ exports.AssignNode: class AssignNode extends BaseNode for obj, i in @variable.base.objects idx: i [obj, idx]: [obj.value, obj.variable.base] if @variable.is_object() + if not (obj instanceof ValueNode or obj instanceof SplatNode) + throw new Error 'pattern matching must use only identifiers on the left-hand side.' is_string: idx.value and idx.value.match IS_STRING access_class: if is_string or @variable.is_array() then IndexNode else AccessorNode if obj instanceof SplatNode and not splat