feat: cleanup
This commit is contained in:
committed by
Justin Ridgewell
parent
00f58b9bfa
commit
72259ca5d3
@@ -7,8 +7,8 @@ const nullOrUndefinedCheck = createTemplate(`
|
||||
: null
|
||||
`);
|
||||
|
||||
function isOptional(path) {
|
||||
return path.node.optional === true;
|
||||
function isNodeOptional(node) {
|
||||
return node.optional === true;
|
||||
}
|
||||
|
||||
const nullOrUndefinedCheckVisitor = {
|
||||
@@ -39,18 +39,16 @@ export default function ({ types: t }) {
|
||||
visitor: {
|
||||
MemberExpression(path) {
|
||||
|
||||
if (isOptional(path)) {
|
||||
if (isNodeOptional(path.node)) {
|
||||
let { object } = path.node;
|
||||
|
||||
while (
|
||||
t.isMemberExpression(object)
|
||||
&& isOptional({ node: object })
|
||||
) {
|
||||
do {
|
||||
object = createCheck(
|
||||
object,
|
||||
object.object
|
||||
);
|
||||
}
|
||||
|
||||
} while (t.isMemberExpression(object) && isNodeOptional(object));
|
||||
|
||||
path.replaceWith(
|
||||
createCheck(path.node, object)
|
||||
|
||||
Reference in New Issue
Block a user