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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user