fix: use undefined instead of null
This commit is contained in:
parent
64ff5a080d
commit
ed15443dba
@ -1,6 +1,6 @@
|
||||
export default function ({ types: t }) {
|
||||
|
||||
function createCondition(ref, access, nextProperty) {
|
||||
function createCondition(ref, access, nextProperty, bailout) {
|
||||
|
||||
return t.conditionalExpression(
|
||||
createCheckAgainstNull(
|
||||
@ -8,7 +8,7 @@ export default function ({ types: t }) {
|
||||
),
|
||||
|
||||
t.memberExpression(ref, nextProperty),
|
||||
t.NullLiteral()
|
||||
bailout,
|
||||
);
|
||||
}
|
||||
|
||||
@ -36,9 +36,14 @@ export default function ({ types: t }) {
|
||||
path.scope.push({ id });
|
||||
}
|
||||
|
||||
path.replaceWith(
|
||||
createCondition(state.optionalTemp, object, property)
|
||||
const remplacement = createCondition(
|
||||
state.optionalTemp,
|
||||
object,
|
||||
property,
|
||||
t.identifier("undefined")
|
||||
);
|
||||
|
||||
path.replaceWith(remplacement);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
var _temp;
|
||||
|
||||
(_temp = foo) != null ? _temp.bar : null;
|
||||
(_temp = foo) != null ? _temp.bar : undefined;
|
||||
@ -1,3 +1,3 @@
|
||||
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