fix: use undefined instead of null
This commit is contained in:
parent
64ff5a080d
commit
ed15443dba
@ -1,6 +1,6 @@
|
|||||||
export default function ({ types: t }) {
|
export default function ({ types: t }) {
|
||||||
|
|
||||||
function createCondition(ref, access, nextProperty) {
|
function createCondition(ref, access, nextProperty, bailout) {
|
||||||
|
|
||||||
return t.conditionalExpression(
|
return t.conditionalExpression(
|
||||||
createCheckAgainstNull(
|
createCheckAgainstNull(
|
||||||
@ -8,7 +8,7 @@ export default function ({ types: t }) {
|
|||||||
),
|
),
|
||||||
|
|
||||||
t.memberExpression(ref, nextProperty),
|
t.memberExpression(ref, nextProperty),
|
||||||
t.NullLiteral()
|
bailout,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,9 +36,14 @@ export default function ({ types: t }) {
|
|||||||
path.scope.push({ id });
|
path.scope.push({ id });
|
||||||
}
|
}
|
||||||
|
|
||||||
path.replaceWith(
|
const remplacement = createCondition(
|
||||||
createCondition(state.optionalTemp, object, property)
|
state.optionalTemp,
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
t.identifier("undefined")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
path.replaceWith(remplacement);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
var _temp;
|
var _temp;
|
||||||
|
|
||||||
(_temp = foo) != null ? _temp.bar : null;
|
(_temp = foo) != null ? _temp.bar : undefined;
|
||||||
@ -1,3 +1,3 @@
|
|||||||
var _temp;
|
var _temp;
|
||||||
|
|
||||||
((_temp = ((_temp = a) != null ? _temp.b : null).c) != null ? _temp.d : null).e;
|
((_temp = ((_temp = a) != null ? _temp.b : undefined).c) != null ? _temp.d : undefined).e;
|
||||||
Loading…
x
Reference in New Issue
Block a user