diff --git a/lib/patch-eslint-scope.js b/lib/patch-eslint-scope.js index aec71fc6..2bf2b350 100644 --- a/lib/patch-eslint-scope.js +++ b/lib/patch-eslint-scope.js @@ -233,6 +233,10 @@ function monkeypatch(modules) { // visit ClassPrivateProperty as a Property. referencer.prototype.ClassPrivateProperty = visitClassProperty; + // visit OptionalMemberExpression as a MemberExpression. + referencer.prototype.OptionalMemberExpression = + referencer.prototype.MemberExpression; + // visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression var visitFunction = referencer.prototype.visitFunction; referencer.prototype.visitFunction = function(node) { diff --git a/test/non-regression.js b/test/non-regression.js index 2a23ee58..687af37c 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -1651,6 +1651,18 @@ describe("verify", () => { }); }); + describe("optional chaining operator", () => { + it("should not be undefined #595", () => { + verifyAndAssertMessages( + ` + const foo = {}; + foo?.bar; + `, + { "no-undef": 1 } + ); + }); + }); + it("flow types on class method should be visited correctly", () => { verifyAndAssertMessages( `