jquery / jquery/esprima

Should throw on invalid LHS in postfix operation

Open
#1,912 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
773
PR merge metrics
No merged PRs in 30d

Description

Esprima allow invalid LHS in both postfix and prefix operations.

Steps to reproduce
esprima.parse('function f() { (new.target)--; }')
Expected output

Should have thrown an error.

Actual output
{
    "type": "Program",
    "body": [
        {
            "type": "FunctionDeclaration",
            "id": {
                "type": "Identifier",
                "name": "f"
            },
            "params": [],
            "body": {
                "type": "BlockStatement",
                "body": [
                    {
                        "type": "ExpressionStatement",
                        "expression": {
                            "type": "UpdateExpression",
                            "operator": "--",
                            "argument": {
                                "type": "MetaProperty",
                                "meta": {
                                    "type": "Identifier",
                                    "name": "new"
                                },
                                "property": {
                                    "type": "Identifier",
                                    "name": "target"
                                }
                            },
                            "prefix": false
                        }
                    }
                ]
            },
            "generator": false,
            "expression": false,
            "async": false
        }
    ],
    "sourceType": "script"
}
Relevant references

Test262 test

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

Start with Esprima's handling of postfix and prefix update expressions and compare its behavior with the linked Test262 test, target-cover-newtarget.js. Reproduce the parse call from the issue, then verify that invalid left-hand sides such as (new.target)-- produce an error instead of an UpdateExpression AST.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.