Skip to content

Commit

Permalink
fix: NodePath.get is always non nullish
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 23, 2020
1 parent 47b51c4 commit dc257bf
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/babel-plugin-proposal-optional-chaining/src/index.js
Expand Up @@ -35,9 +35,10 @@ export default declare((api, options) => {
optionalPath.isOptionalCallExpression()
) {
const { node } = optionalPath;
const childPath = skipTransparentExprWrappers(
optionalPath.get("object") ?? optionalPath.get("callee"),
);
const childKey = optionalPath.isOptionalMemberExpression()
? "object"
: "callee";
const childPath = skipTransparentExprWrappers(optionalPath.get(childKey));
if (node.optional) {
return !scope.isStatic(childPath.node);
}
Expand Down
@@ -0,0 +1,9 @@
function f(a = x?.y) {}

function g({ a, b = a?.c }) {}

function h(a, { b = a.b?.c?.d.e }) {}

function i(a, { b = (a.b?.c?.d).e }) {}

function j(a, { b = a?.b?.c().d.e }) {}
@@ -0,0 +1,3 @@
{
"plugins": [["proposal-optional-chaining", { "loose": true }]]
}
@@ -0,0 +1,34 @@
function f(a = (() => {
var _x;

return (_x = x) == null ? void 0 : _x.y;
})()) {}

function g({
a,
b = a == null ? void 0 : a.c
}) {}

function h(a, {
b = (() => {
var _a$b, _a$b$c;

return (_a$b = a.b) == null ? void 0 : (_a$b$c = _a$b.c) == null ? void 0 : _a$b$c.d.e;
})()
}) {}

function i(a, {
b = (() => {
var _a$b2, _a$b2$c;

return (_a$b2 = a.b) == null ? void 0 : (_a$b2$c = _a$b2.c) == null ? void 0 : _a$b2$c.d;
})().e
}) {}

function j(a, {
b = (() => {
var _a$b3;

return a == null ? void 0 : (_a$b3 = a.b) == null ? void 0 : _a$b3.c().d.e;
})()
}) {}
Expand Up @@ -5,3 +5,5 @@ function g({ a, b = a?.c }) {}
function h(a, { b = a.b?.c?.d.e }) {}

function i(a, { b = (a.b?.c?.d).e }) {}

function j(a, { b = a?.b?.c().d.e }) {}
Expand Up @@ -24,3 +24,11 @@ function i(a, {
return (_a$b2 = a.b) === null || _a$b2 === void 0 ? void 0 : (_a$b2$c = _a$b2.c) === null || _a$b2$c === void 0 ? void 0 : _a$b2$c.d;
})().e
}) {}

function j(a, {
b = (() => {
var _a$b3;

return a === null || a === void 0 ? void 0 : (_a$b3 = a.b) === null || _a$b3 === void 0 ? void 0 : _a$b3.c().d.e;
})()
}) {}

0 comments on commit dc257bf

Please sign in to comment.