From 769870b493ef0bbb0b79ac4a84a2e6040429f330 Mon Sep 17 00:00:00 2001 From: satyr Date: Sat, 2 Oct 2010 21:49:21 +0900 Subject: [PATCH] `[x] = [y] = [1]` works again --- lib/nodes.js | 2 +- src/nodes.coffee | 2 +- test/test_pattern_matching.coffee | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 081f6b8c..795db29b 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -991,7 +991,7 @@ return value.compile(o); } isObject = this.variable.isObject(); - if (olength === 1 && !((obj = objects[0]) instanceof SplatNode)) { + if (o.top && olength === 1 && !((obj = objects[0]) instanceof SplatNode)) { if (obj instanceof AssignNode) { _ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value; } else { diff --git a/src/nodes.coffee b/src/nodes.coffee index f5769942..6bf2819c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -877,7 +877,7 @@ exports.AssignNode = class AssignNode extends BaseNode {objects} = @variable.base return value.compile o unless olength = objects.length isObject = @variable.isObject() - if olength is 1 and (obj = objects[0]) not instanceof SplatNode + if o.top and olength is 1 and (obj = objects[0]) not instanceof SplatNode # Unroll simplest cases: `{v} = x` -> `v = x.v` if obj instanceof AssignNode {variable: {base: idx}, value: obj} = obj diff --git a/test/test_pattern_matching.coffee b/test/test_pattern_matching.coffee index af37a20c..15721b9f 100644 --- a/test/test_pattern_matching.coffee +++ b/test/test_pattern_matching.coffee @@ -139,3 +139,6 @@ if func func {a} = obj ok a is 101 + +[x] = {0: y} = {'0': z} = [Math.random()] +ok x is y is z, 'destructuring in multiple'