Use nil
This commit is contained in:
parent
6cc2f5dc78
commit
faa6c9f708
@ -4,6 +4,7 @@ export default function ({ types: t }) {
|
|||||||
function optional(path, key, replacementPath, needsContext = false, loose = false) {
|
function optional(path, key, replacementPath, needsContext = false, loose = false) {
|
||||||
const { scope } = path;
|
const { scope } = path;
|
||||||
const optionals = [path.node];
|
const optionals = [path.node];
|
||||||
|
const nil = scope.buildUndefinedNode();
|
||||||
|
|
||||||
let objectPath = path.get(key);
|
let objectPath = path.get(key);
|
||||||
while (objectPath.isMemberExpression()) {
|
while (objectPath.isMemberExpression()) {
|
||||||
@ -65,7 +66,7 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
replacementPath.replaceWith(t.conditionalExpression(
|
replacementPath.replaceWith(t.conditionalExpression(
|
||||||
t.binaryExpression("==", check, t.nullLiteral()),
|
t.binaryExpression("==", check, t.nullLiteral()),
|
||||||
scope.buildUndefinedNode(),
|
nil,
|
||||||
replacementPath.node
|
replacementPath.node
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user