Repository: estools/escodegen (JavaScript)

Issue:
Property issue in ObjectPattern
Hello I've stumbled in this code example:
```
let { test:myvar = "default" }= { test: "aValue" };
```
Escodegen outputs the following code from Esprima AST:
```
let {
    myvar = 'default': myvar = 'default'
} = { test: 'aValue' };
```
Which is obviously wrong.
Sample code to reproduce:
```
var es_parse = require('esprima').parse;
var esgenerate = require('escodegen').generate
var code = 'let { test:myvar = "default" }= { test: "aValue" };';
var ast = es_parse(code);
console.log(esgenerate(ast));
```

Thanks!


Discussion:
Any feedback?

I've hit this bug with fuse-box bundler which uses acorn parser.  

```
function a({b:c="d"}) { console.log(c) }
```
produced 
```
function a({
    c = 'd': c = 'd'
}) {
    console.log(c);
}
```
Your patch fixes it well, thanks!  Hope it will be merged and released soon.
@michaelficarra @Constellation any feedback would be welcome.
Asking this in a bit of a rush because we hope the PR to be approved and get it to mainstream.

Thanks



Patch:
diff --git a/escodegen.js b/escodegen.js
index e2bad862..ffbf3857 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -980,18 +980,14 @@
         return result;
     };
 
-    CodeGenerator.prototype.generatePropertyKey = function (expr, computed, value) {
+    CodeGenerator.prototype.generatePropertyKey = function (expr, computed) {
         var result = [];
 
         if (computed) {
             result.push('[');
         }
 
-        if (value.type === 'AssignmentPattern') {
-            result.push(this.AssignmentPattern(value, Precedence.Sequence, E_TTT));
-        } else {
-            result.push(this.generateExpression(expr, Precedence.Sequence, E_TTT));
-        }
+        result.push(this.generateExpression(expr, Precedence.Sequence, E_TTT));
 
         if (computed) {
             result.push(']');
@@ -2118,13 +2114,13 @@
             }
             if (expr.kind === 'get' || expr.kind === 'set') {
                 fragment = [
-                    join(expr.kind, this.generatePropertyKey(expr.key, expr.computed, expr.value)),
+                    join(expr.kind, this.generatePropertyKey(expr.key, expr.computed)),
                     this.generateFunctionBody(expr.value)
                 ];
             } else {
                 fragment = [
                     generateMethodPrefix(expr),
-                    this.generatePropertyKey(expr.key, expr.computed, expr.value),
+                    this.generatePropertyKey(expr.key, expr.computed),
                     this.generateFunctionBody(expr.value)
                 ];
             }
@@ -2135,25 +2131,28 @@
             if (expr.kind === 'get' || expr.kind === 'set') {
                 return [
                     expr.kind, noEmptySpace(),
-                    this.generatePropertyKey(expr.key, expr.computed, expr.value),
+                    this.generatePropertyKey(expr.key, expr.computed),
                     this.generateFunctionBody(expr.value)
                 ];
             }
 
             if (expr.shorthand) {
-                return this.generatePropertyKey(expr.key, expr.computed, expr.value);
+                if (expr.value.type === "AssignmentPattern") {
+                    return this.AssignmentPattern(expr.value, Precedence.Sequence, E_TTT);
+                }
+                return this.generatePropertyKey(expr.key, expr.computed);
             }
 
             if (expr.method) {
                 return [
                     generateMethodPrefix(expr),
-                    this.generatePropertyKey(expr.key, expr.computed, expr.value),
+                    this.generatePropertyKey(expr.key, expr.computed),
                     this.generateFunctionBody(expr.value)
                 ];
             }
 
             return [
-                this.generatePropertyKey(expr.key, expr.computed, expr.value),
+                this.generatePropertyKey(expr.key, expr.computed),
                 ':' + space,
                 this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
             ];


Test patch:
diff --git a/test/harmony.js b/test/harmony.js
index 9941f18d..fe836b8f 100644
--- a/test/harmony.js
+++ b/test/harmony.js
@@ -510,6 +510,203 @@ data = {
     },
 
     'Object destructuring (and aliasing)':  {
+        "let {\n    test: myvar = 'a'\n} = { test: 'b' };": {
+            generateFrom: {
+                loc: {
+                    start: {
+                        line: 1,
+                        column: 0
+                    },
+                    end: {
+                        line: 3,
+                        column: 23
+                    }
+                },
+                type: "Program",
+                body: [
+                    {
+                    loc: {
+                        start: {
+                            line: 1,
+                            column: 0
+                        },
+                        end: {
+                            line: 3,
+                            column: 23
+                        }
+                    },
+                    type: "VariableDeclaration",
+                    declarations: [
+                        {
+                        loc: {
+                            start: {
+                                line: 1,
+                                column: 4
+                            },
+                            end: {
+                                line: 3,
+                                column: 22
+                            }
+                        },
+                        type: "VariableDeclarator",
+                        id: {
+                            loc: {
+                                start: {
+                                    line: 1,
+                                    column: 4
+                                },
+                                end: {
+                                    line: 3,
+                                    column: 1
+                                }
+                            },
+                            type: "ObjectPattern",
+                            properties: [
+                                {
+                                loc: {
+                                    start: {
+                                        line: 2,
+                                        column: 4
+                                    },
+                                    end: {
+                                        line: 2,
+                                        column: 27
+                                    }
+                                },
+                                type: "Property",
+                                key: {
+                                    loc: {
+                                        start: {
+                                            line: 2,
+                                            column: 4
+                                        },
+                                        end: {
+                                            line: 2,
+                                            column: 8
+                                        }
+                                    },
+                                    type: "Identifier",
+                                    name: "test"
+                                },
+                                computed: false,
+                                value: {
+                                    loc: {
+                                        start: {
+                                            line: 2,
+                                            column: 10
+                                        },
+                                        end: {
+                                            line: 2,
+                                            column: 27
+                                        }
+                                    },
+                                    type: "AssignmentPattern",
+                                    left: {
+                                        loc: {
+                                            start: {
+                                                line: 2,
+                                                column: 10
+                                            },
+                                            end: {
+                                                line: 2,
+                                                column: 15
+                                            }
+                                        },
+                                        type: "Identifier",
+                                        name: "myvar"
+                                    },
+                                    right: {
+                                        loc: {
+                                            start: {
+                                                line: 2,
+                                                column: 18
+                                            },
+                                            end: {
+                                                line: 2,
+                                                column: 27
+                                            }
+                                        },
+                                        type: "Literal",
+                                        value: "a",
+                                        raw: "'a'"
+                                    }
+                                },
+                                kind: "init",
+                                method: false,
+                                shorthand: false
+                            }
+                            ]
+                        },
+                        init: {
+                            loc: {
+                                start: {
+                                    line: 3,
+                                    column: 4
+                                },
+                                end: {
+                                    line: 3,
+                                    column: 22
+                                }
+                            },
+                            type: "ObjectExpression",
+                            properties: [
+                                {
+                                loc: {
+                                    start: {
+                                        line: 3,
+                                        column: 6
+                                    },
+                                    end: {
+                                        line: 3,
+                                        column: 20
+                                    }
+                                },
+                                type: "Property",
+                                key: {
+                                    loc: {
+                                        start: {
+                                            line: 3,
+                                            column: 6
+                                        },
+                                        end: {
+                                            line: 3,
+                                            column: 10
+                                        }
+                                    },
+                                    type: "Identifier",
+                                    name: "test"
+                                },
+                                computed: false,
+                                value: {
+                                    loc: {
+                                        start: {
+                                            line: 3,
+                                            column: 12
+                                        },
+                                        end: {
+                                            line: 3,
+                                            column: 20
+                                        }
+                                    },
+                                    type: "Literal",
+                                    value: "b",
+                                    raw: "'b'"
+                                },
+                                kind: "init",
+                                method: false,
+                                shorthand: false
+                            }
+                            ]
+                        }
+                    }
+                    ],
+                    kind: "let"
+                }
+                ],
+                sourceType: "script"
+            }
+        },
+
         '({a = "b", b = {\n        c: "d",\n        e: "f"\n    }} = {}) => {\n};': {
             generateFrom: {
                 type: "ExpressionStatement",