Esprima is failing to parse `ThrowStatement` with newlines on template literals
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Esprima is failing to parse ThrowStatement with newlines on template literals
Configuration
- esprima 3.1.3
Description
Parsing a ThrowStatement with a template literal including a newline displays the following error: Error: Line 1: Illegal newline after throw.
The following sample code is syntatically valid but throws an error while parsing.
throw `new Error: Error on loop
For more details:
http://example.com`
This issue was also tested on the latest released version as a npm package
Steps to Reproduce
- Go to http://esprima.org/demo/parse.html
- Add the code above
- Check the error.
Actual Results
Error: Line 1: Illegal newline after throw
Expected Results
{
"type": "Program",
"body": [
{
"type": "ThrowStatement",
"argument": {
"type": "TemplateLiteral",
"quasis": [
{
"type": "TemplateElement",
"value": {
"raw": "new Error: Error on loop\nFor more details:\nhttp://example.com",
"cooked": "new Error: Error on loop\nFor more details:\nhttp://example.com"
},
"tail": true
}
],
"expressions": []
}
}
],
"sourceType": "script"
}
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
Reproduce the failure in the Esprima demo or npm package using the provided throw statement with a multiline template literal, then trace how ThrowStatement parsing handles the template literal. Done means the sample parses successfully and produces the expected ThrowStatement and TemplateLiteral structure shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100