Test Update and Unary expressions

This commit is contained in:
Justin Ridgewell
2017-06-05 23:48:20 -04:00
parent d92309f0db
commit 54d9732d0b
3 changed files with 35 additions and 1 deletions

View File

@@ -92,7 +92,10 @@ export default function ({ types: t }) {
if (path.key == "callee" && (parentPath.isCallExpression() || parentPath.isNewExpression())) {
return false;
}
if (path.key == "argument" && parentPath.isUnaryExpression()) {
if (path.key == "argument" && parentPath.isUpdateExpression()) {
return false;
}
if (path.key == "argument" && parentPath.isUnaryExpression({ operator: "delete" })) {
return false;
}

View File

@@ -0,0 +1,17 @@
const obj = {
a: {
b: 0,
},
};
let test = +obj?.a?.b;
assert.equal(test, 0);
test = +obj?.a.b;
assert.equal(test, 0);
test = +obj?.b?.b;
assert.isNaN(test);
test = +obj?.b?.b;
assert.isNaN(test);

View File

@@ -0,0 +1,14 @@
const obj = {
a: {
b: 0,
},
};
obj?.a.b++;
assert.equal(obj.a.b, 1);
obj?.a?.b++;
assert.equal(obj.a.b, 2);
obj?.b?.b++;
assert.equal(obj.b, undefined);