esprima icon indicating copy to clipboard operation
esprima copied to clipboard

Should throw on invalid LHS in postfix operation

Open KFlash opened this issue 7 years ago • 0 comments

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

KFlash avatar Feb 08 '18 04:02 KFlash