Skip to content

Commit

Permalink
[[FIX]] Tolerate late definition of async function
Browse files Browse the repository at this point in the history
We used to mark `async function` as unreachable instead of treating it
as any other late function definition. This change makes jshint react to
`async` keyword in the same way as it reacted to `function` keyword.
  • Loading branch information
pirxpilot committed Jun 12, 2022
1 parent 61c868c commit 86d212d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ var JSHINT = (function() {
return;
}
if (t.id !== "(endline)") {
if (t.id === "function") {
if (t.id === "function" || t.id === "async") {
if (state.option.latedef === true) {
warning("W026", t);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8267,6 +8267,21 @@ exports.unreachable = {
TestRun(test)
.test(src);

test.done();
},
'async function': function (test) {
var src = [
"(function() {",
" return f(4);",
" async function f(p) {",
" return p + 1;",
" }",
"}());"
];

TestRun(test)
.test(src, { esversion: 8, latedef: 'nofunc' });

test.done();
}
};
Expand Down

0 comments on commit 86d212d

Please sign in to comment.