Skip to content

Commit

Permalink
fix(parser): fix missing rejection on function name
Browse files Browse the repository at this point in the history
closes #182
  • Loading branch information
3cp committed Mar 4, 2021
1 parent 3c0b156 commit 3327326
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4817,7 +4817,11 @@ export function parseFunctionDeclaration(

firstRestricted = parser.token;

id = parseIdentifier(parser, context, 0);
if (parser.token & Token.IsIdentifier) {
id = parseIdentifier(parser, context, 0);
} else {
report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
}
}

context =
Expand Down
3 changes: 3 additions & 0 deletions test/parser/declarations/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Declarations - Function', () => {
}

for (const arg of [
'function 10() {}',
'function 0x7F() {}',
'function "str"() {}',
'try function foo() {} catch (e) {}',
'do function foo() {} while (0);',
'for (;false;) function foo() {}',
Expand Down

0 comments on commit 3327326

Please sign in to comment.