fix: use undefined instead of null

This commit is contained in:
Sven SAULEAU 2017-04-29 18:53:19 +02:00 committed by Justin Ridgewell
parent 64ff5a080d
commit ed15443dba
3 changed files with 11 additions and 6 deletions

View File

@ -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);
},
},
};

View File

@ -1,3 +1,3 @@
var _temp;
(_temp = foo) != null ? _temp.bar : null;
(_temp = foo) != null ? _temp.bar : undefined;

View File

@ -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;