Skip to content

Commit

Permalink
[[FIX]] Correct parsing of arrow function
Browse files Browse the repository at this point in the history
Ensure that the "token" object is consistently returned by the "prefix"
`(` operator's null denotation function. This alleviates calling code
from having to account for "functor" objects and instead consistently
interpret operands as token objects.
  • Loading branch information
jugglinmike committed Dec 23, 2018
1 parent 35e1b17 commit 8fa6e39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,8 @@ var JSHINT = (function() {
// current token marks the beginning of a "fat arrow" function and parsing
// should proceed accordingly.
if (pn.value === "=>") {
return doFunction({ type: "arrow", parsedOpening: true });
pn.funct = doFunction({ type: "arrow", parsedOpening: true });
return pn;
}

var exprs = [];
Expand Down Expand Up @@ -2576,7 +2577,7 @@ var JSHINT = (function() {
isNecessary =
// Used to distinguish from an ExpressionStatement which may not
// begin with the `{` and `function` tokens
(opening.beginsStmt && (ret.id === "{" || triggerFnExpr || isFunctor(ret))) ||
(opening.beginsStmt && (ret.id === "{" || triggerFnExpr)) ||
// Used to signal that a function expression is being supplied to
// some other operator.
(triggerFnExpr &&
Expand All @@ -2587,7 +2588,7 @@ var JSHINT = (function() {
(!isEndOfExpr() || state.tokens.prev.id !== "}")) ||
// Used to demarcate an arrow function as the left-hand side of some
// operator.
(isFunctor(ret) && !isEndOfExpr()) ||
(ret.id === "=>" && !isEndOfExpr()) ||
// Used as the return value of a single-statement arrow function
(ret.id === "{" && preceeding.id === "=>") ||
// Used to cover a unary expression as the left-hand side of the
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5854,19 +5854,15 @@ exports["fat arrows support"] = function (test) {
.addError(16, 16, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(17, 1, "'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(17, 22, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(17, 32, "Bad invocation.")
.addError(18, 1, "'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(18, 20, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(19, 1, "'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(19, 26, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(19, 46, "Bad invocation.")
.addError(20, 1, "'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(21, 13, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(22, 19, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(22, 29, "Bad invocation.")
.addError(23, 17, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(24, 23, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').")
.addError(24, 43, "Bad invocation.")
.addError(26, 1, "'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(26, 29, "'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').");

Expand Down

0 comments on commit 8fa6e39

Please sign in to comment.