Skip to content

Commit

Permalink
Fixed Unparse of assignment patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer committed Mar 15, 2019
1 parent 3688fca commit c678d7a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,9 @@ export class ObjectPattern {
function isFunctionExpression(e: any): e is AnyFunctionExpression {
return e.type === Syntax.FunctionExpression;
}
function isAssignmentPattern(e: any): e is AssignmentPattern {
return e.type === Syntax.AssignmentPattern;
}
export class Property {
readonly type: string;
readonly key: PropertyKey;
Expand All @@ -1458,15 +1461,16 @@ export class Property {
readonly wsBeforeColon: string;
wsAfter: string = "";
unparse(parent?: Unparsable): string {
var ap = this.value && isAssignmentPattern(this.value)
return this.wsBefore + (this.method && this.value ?
isFunctionExpression(this.value) ?
(this.value.async ? this.value.wsBeforeAsync + "async" : "") +
(this.value.generator ? this.value.wsBeforeStar + "*" : "") : ""
: "") +
(this.kind == "get" || this.kind == "set" ? this.wsBeforeGetSet + this.kind : "") +
unparseChild(this)(this.key) +
(ap ? "" : unparseChild(this)(this.key)) +
(this.method || this.shorthand || this.kind == "get" || this.kind == "set" ? "": this.wsBeforeColon + ":") +
(this.shorthand ? "" : unparseChild(this)(this.value)) + this.wsAfter;
(this.shorthand && !ap ? "" : unparseChild(this)(this.value)) + this.wsAfter;
}
constructor(kind: "init" | "get" | "set", key: PropertyKey, wsBeforeGetSet: string, wsBeforeColon: string, computed: boolean, value: PropertyValue | null, method: boolean, shorthand: boolean) {
this.type = Syntax.Property;
Expand Down

0 comments on commit c678d7a

Please sign in to comment.