New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
magano opened this Issue Mar 31, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@magano

magano commented Mar 31, 2017

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"
}
@mikesherov

This comment has been minimized.

Show comment
Hide comment
@mikesherov

mikesherov Mar 31, 2017

Member

Thanks for contributing! We'll take a look soon!

Member

mikesherov commented Mar 31, 2017

Thanks for contributing! We'll take a look soon!

@ariya ariya added defect es6 labels Mar 31, 2017

magano pushed a commit to magano/esprima that referenced this issue Apr 3, 2017

Vítor Magano
Fix ThrowStatement parsing for multiline TemplateLiterals
Currently esprima fails to parse multiline `TemplateLiterals`

Issue reported: jquery#1814

magano pushed a commit to magano/esprima that referenced this issue Apr 4, 2017

Vítor Magano
Fix multiline `throwStatement` edge-cases
With the previous fix, a `throwStatement` with a newline between the arguments would not throw any error and it should.

Related to: jquery#1814
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment