Add support for the optional chaining operator (babel/babel-eslint#630)

This commit is contained in:
Rubén Norte 2018-06-15 15:31:43 +01:00
parent 735abb06b4
commit 3477626973
2 changed files with 16 additions and 0 deletions

View File

@ -233,6 +233,10 @@ function monkeypatch(modules) {
// visit ClassPrivateProperty as a Property. // visit ClassPrivateProperty as a Property.
referencer.prototype.ClassPrivateProperty = visitClassProperty; referencer.prototype.ClassPrivateProperty = visitClassProperty;
// visit OptionalMemberExpression as a MemberExpression.
referencer.prototype.OptionalMemberExpression =
referencer.prototype.MemberExpression;
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression // visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
var visitFunction = referencer.prototype.visitFunction; var visitFunction = referencer.prototype.visitFunction;
referencer.prototype.visitFunction = function(node) { referencer.prototype.visitFunction = function(node) {

View File

@ -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", () => { it("flow types on class method should be visited correctly", () => {
verifyAndAssertMessages( verifyAndAssertMessages(
` `