Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Add support for the optional chaining operator #630

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/patch-eslint-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down