Use a better nested syntax

This way, it quickly returns from the conditions. The first nil will
now exit, instead of checking every nil.

This also allows conditionalChaining inside a container to still
operate the container.
This commit is contained in:
Justin Ridgewell
2017-06-03 02:07:40 -04:00
parent 3fae121460
commit 2a496890ff
7 changed files with 22 additions and 8 deletions

View File

@@ -47,11 +47,11 @@ export default function ({ types: t }) {
node.object = ref;
let parent = path;
let expression;
do {
let expression = path;
while (parent.listKey === undefined) {
expression = parent;
parent = parent.parentPath;
} while (!parent.container);
}
const replace = parent.isExpression() ? parent : expression;
replace.replaceWith(t.conditionalExpression(