Created
October 5, 2018 22:27
-
-
Save trueadm/fef1ee3cbc465cb326f62ce3e8233fbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_getPropertyAssignmentStatement( | |
location: BabelNodeLVal, | |
value: Value, | |
mightHaveBeenDeleted: boolean, | |
deleteIfMightHaveBeenDeleted: boolean = false | |
): BabelNodeStatement { | |
if (mightHaveBeenDeleted) { | |
// We always need to serialize this value in order to keep the invariants happy. | |
let serializedValue = this.serializeValue(value); | |
let condition; | |
if (value instanceof AbstractValue && value.kind === "conditional") { | |
let cf = this.conditionalFeasibility.get(value); | |
invariant(cf !== undefined); | |
let conditionalSerializedValue; | |
if (cf.t && !cf.f) { | |
conditionalSerializedValue = this.serializeValue(value.args[1]); | |
} else if (!cf.t && cf.f) { | |
conditionalSerializedValue = this.serializeValue(value.args[2]); | |
} else { | |
invariant(cf.t && cf.f); | |
} | |
if (conditionalSerializedValue !== undefined) { | |
return t.expressionStatement(t.assignmentExpression("=", location, conditionalSerializedValue)); | |
} | |
let [c, x, y] = value.args; | |
if (x instanceof EmptyValue) { | |
if (c instanceof AbstractValue && c.kind === "!") condition = this.serializeValue(c.args[0]); | |
else condition = t.unaryExpression("!", this.serializeValue(c)); | |
serializedValue = this.serializeValue(y); | |
} else if (y instanceof EmptyValue) { | |
condition = this.serializeValue(c); | |
serializedValue = this.serializeValue(x); | |
} | |
} | |
if (condition === undefined) { | |
condition = t.binaryExpression("!==", this.serializeValue(value), this._serializeEmptyValue()); | |
} | |
let assignment = t.expressionStatement(t.assignmentExpression("=", location, serializedValue)); | |
let deletion = null; | |
if (deleteIfMightHaveBeenDeleted) { | |
invariant(location.type === "MemberExpression"); | |
deletion = t.expressionStatement( | |
t.unaryExpression("delete", ((location: any): BabelNodeMemberExpression), true) | |
); | |
} | |
return t.ifStatement(condition, assignment, deletion); | |
} else { | |
return t.expressionStatement(t.assignmentExpression("=", location, this.serializeValue(value))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment