Skip to content

Commit

Permalink
[[FIX]] Allow invoking result of optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Jul 12, 2021
1 parent 7bae44b commit 71ec395
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/jshint.js
Expand Up @@ -3081,6 +3081,21 @@ var JSHINT = (function() {
return that;
}, 160, true);


/**
* Determine if a CallExpression's "base" is a type of expression commonly
* used in this position.
*
* @param {token} token - token describing the "base" of the CallExpression
* @returns {boolean}
*/
function isTypicalCallExpression(token) {
return token.identifier || token.id === "." || token.id === "[" ||
token.id === "=>" || token.id === "(" || token.id === "&&" ||
token.id === "||" || token.id === "?" || token.id === "async" ||
token.id === "?." || (state.inES6() && token["(name)"]);
}

infix("(", function(context, left, that) {
if (state.option.immed && left && !left.immed && left.id === "function") {
warning("W062");
Expand Down Expand Up @@ -3171,9 +3186,7 @@ var JSHINT = (function() {
addEvalCode(left, p[0]);
}
}
if (!left.identifier && left.id !== "." && left.id !== "[" && left.id !== "=>" &&
left.id !== "(" && left.id !== "&&" && left.id !== "||" && left.id !== "?" &&
left.id !== "async" && !(state.inES6() && left["(name)"])) {
if (!isTypicalCallExpression(left)) {
warning("W067", that);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -10590,5 +10590,11 @@ exports.optionalChaining = function (test) {
{ esversion: 11 }
);

TestRun(test, "CallExpression")
.test(
"true?.false();",
{ esversion: 11 }
);

test.done();
};

0 comments on commit 71ec395

Please sign in to comment.