Skip to content

Commit e802577

Browse files
rubennorteexistentialism
authored andcommitted
Add support for the optional chaining operator (babel#630)
1 parent ebc46e1 commit e802577

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/patch-eslint-scope.js

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ function monkeypatch(modules) {
233233
// visit ClassPrivateProperty as a Property.
234234
referencer.prototype.ClassPrivateProperty = visitClassProperty;
235235

236+
// visit OptionalMemberExpression as a MemberExpression.
237+
referencer.prototype.OptionalMemberExpression =
238+
referencer.prototype.MemberExpression;
239+
236240
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
237241
var visitFunction = referencer.prototype.visitFunction;
238242
referencer.prototype.visitFunction = function(node) {

test/non-regression.js

+12
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,18 @@ describe("verify", () => {
16511651
});
16521652
});
16531653

1654+
describe("optional chaining operator", () => {
1655+
it("should not be undefined #595", () => {
1656+
verifyAndAssertMessages(
1657+
`
1658+
const foo = {};
1659+
foo?.bar;
1660+
`,
1661+
{ "no-undef": 1 }
1662+
);
1663+
});
1664+
});
1665+
16541666
it("flow types on class method should be visited correctly", () => {
16551667
verifyAndAssertMessages(
16561668
`

0 commit comments

Comments
 (0)