From 824d8ee998ce757ffce1cdeab956ac1298fada3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 12 Jun 2018 12:52:42 +0100 Subject: [PATCH 1/2] Added failing test for optional chaining operator --- test/non-regression.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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( ` From ece86610f7cd1e6d7754b5d371f9a5d7b6662f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Tue, 12 Jun 2018 12:55:46 +0100 Subject: [PATCH 2/2] Patched scope to visit OptionalMemberExpression as a MemberExpression --- lib/patch-eslint-scope.js | 4 ++++ 1 file changed, 4 insertions(+) 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) {