escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Incorrect generation of destructuring assignment with rename and default

Open apaleslimghost opened this issue 7 years ago • 1 comments

const {generate} = require('escodegen');
const {parse} = require('esprima');

generate(parse('const {foo: bar = baz} = quux')) === `const {
  bar = baz: bar = baz
} = quux;`

apaleslimghost avatar Jan 12 '17 13:01 apaleslimghost

This change will fix the issue.

diff --git a/escodegen.js b/escodegen.js
index 42c05ae..b3b3dbd 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -987,7 +987,7 @@
             result.push('[');
         }
 
-        if (value.type === 'AssignmentPattern') {
+        if (value.type === 'AssignmentPattern' && expr.name === value.left.name) {
             result.push(this.AssignmentPattern(value, Precedence.Sequence, E_TTT));
         } else {
             result.push(this.generateExpression(expr, Precedence.Sequence, E_TTT));

t2ym avatar Jan 26 '17 04:01 t2ym