This commit is contained in:
Justin Ridgewell 2017-06-05 13:56:28 -04:00
parent 6cc2f5dc78
commit faa6c9f708

View File

@ -4,6 +4,7 @@ export default function ({ types: t }) {
function optional(path, key, replacementPath, needsContext = false, loose = false) { function optional(path, key, replacementPath, needsContext = false, loose = false) {
const { scope } = path; const { scope } = path;
const optionals = [path.node]; const optionals = [path.node];
const nil = scope.buildUndefinedNode();
let objectPath = path.get(key); let objectPath = path.get(key);
while (objectPath.isMemberExpression()) { while (objectPath.isMemberExpression()) {
@ -65,7 +66,7 @@ export default function ({ types: t }) {
replacementPath.replaceWith(t.conditionalExpression( replacementPath.replaceWith(t.conditionalExpression(
t.binaryExpression("==", check, t.nullLiteral()), t.binaryExpression("==", check, t.nullLiteral()),
scope.buildUndefinedNode(), nil,
replacementPath.node replacementPath.node
)); ));