Function declaration name is mistakenly treated as function code
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
Description
(As reported by @michaelficarra and explained by @bakkot as case 14,15,18-25 in #1502).
Test case:
esprima.parse('function eval() {"use strict"; }');
Actual: An exception "Function name may not be eval or arguments in strict mode".
Expected: A valid syntax tree.
A similar test case:
esprima.parse('function static() {"use strict"; }');
Actual: An exception "Use of future reserved word in strict mode".
Expected: A valid syntax tree.
A reference for this in the specification is on Types of Source Code:
Function code is source text that is parsed to supply the value of the [[ECMAScriptCode]] and [[FormalParameters]] internal slots (see 9.2) of an ECMAScript function object.
While the formal parameters are part of the function code, the declaration name however is not.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the esprima.parse reproductions in the issue and trace how function declarations are parsed and validated in strict mode. Confirm that declaration names such as eval and static are not treated as function code, then verify both examples produce valid syntax trees.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100