jquery / jquery/esprima

Esprima is failing to parse `ThrowStatement` with newlines on template literals

Open
#1,814 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

defect es6
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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.