mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
feat(es/parser): Reject indirect opt chain in assignment (#4447)
This commit is contained in:
parent
20f35cbcbd
commit
df7b3f611a
@ -269,7 +269,13 @@ pub(super) trait ExprExt {
|
||||
expr.is_valid_simple_assignment_target(strict)
|
||||
}
|
||||
|
||||
Expr::Member(..) | Expr::SuperProp(..) => true,
|
||||
Expr::Member(MemberExpr { ref obj, .. }) => match obj.as_ref() {
|
||||
Expr::Member(..) => obj.is_valid_simple_assignment_target(strict),
|
||||
Expr::OptChain(..) => false,
|
||||
_ => true,
|
||||
},
|
||||
|
||||
Expr::SuperProp(..) => true,
|
||||
|
||||
Expr::New(..) | Expr::Call(..) => false,
|
||||
// TODO: Spec only mentions `new.target`
|
||||
|
@ -0,0 +1 @@
|
||||
a.b.c?.d.e[f] = 0;
|
@ -0,0 +1,6 @@
|
||||
|
||||
x The left-hand side of an assignment expression must be a variable or a property access.
|
||||
,-[$DIR/tests/typescript-errors/optional-chaining/indirect-assign/input.ts:1:1]
|
||||
1 | a.b.c?.d.e[f] = 0;
|
||||
: ^^^^^^^^^^^^^
|
||||
`----
|
@ -0,0 +1 @@
|
||||
obj[0]['foo'] = 1
|
@ -0,0 +1,100 @@
|
||||
{
|
||||
"type": "Script",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "AssignmentExpression",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"operator": "=",
|
||||
"left": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 13,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "MemberExpression",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 6,
|
||||
"ctxt": 0
|
||||
},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 3,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "obj",
|
||||
"optional": false
|
||||
},
|
||||
"property": {
|
||||
"type": "Computed",
|
||||
"span": {
|
||||
"start": 3,
|
||||
"end": 6,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "NumericLiteral",
|
||||
"span": {
|
||||
"start": 4,
|
||||
"end": 5,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": 0.0,
|
||||
"raw": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"property": {
|
||||
"type": "Computed",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"end": 13,
|
||||
"ctxt": 0
|
||||
},
|
||||
"expression": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 12,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "foo",
|
||||
"raw": "'foo'"
|
||||
}
|
||||
}
|
||||
},
|
||||
"right": {
|
||||
"type": "NumericLiteral",
|
||||
"span": {
|
||||
"start": 16,
|
||||
"end": 17,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": 1.0,
|
||||
"raw": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
Loading…
Reference in New Issue
Block a user