Should throw on invalid LHS in postfix operation
Open
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
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
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