From e802577d57de1a5f1a4b65dba4f513ece9dfc480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 15 Jun 2018 15:31:43 +0100 Subject: [PATCH] Add support for the optional chaining operator (#630) --- lib/patch-eslint-scope.js | 4 ++++ test/non-regression.js | 12 ++++++++++++ 2 files changed, 16 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) { 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( `