Test Update and Unary expressions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
17
packages/babel-plugin-transform-optional-chaining/test/fixtures/execute/unary.js
vendored
Normal file
17
packages/babel-plugin-transform-optional-chaining/test/fixtures/execute/unary.js
vendored
Normal 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);
|
||||
14
packages/babel-plugin-transform-optional-chaining/test/fixtures/execute/update.js
vendored
Normal file
14
packages/babel-plugin-transform-optional-chaining/test/fixtures/execute/update.js
vendored
Normal 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);
|
||||
Reference in New Issue
Block a user