feat(es/parser): Raise a syntax error on an invalid shorthand assignment (#3734)

This commit is contained in:
Satish Srinivasan 2022-03-01 17:54:41 +05:30 committed by GitHub
parent 3152da285a
commit 2aa3b2123f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -785,6 +785,23 @@ impl<'a, I: Tokens> Parser<I> {
}
}
return Ok(Box::new(Expr::Arrow(arrow_expr)));
} else {
// If there's no arrow function, we have to check there's no
// AssignProp in lhs to check against assignment in object literals
// like (a, {b = 1});
for expr_or_spread in paren_items.iter() {
if let PatOrExprOrSpread::ExprOrSpread(e) = expr_or_spread {
if let Expr::Object(o) = &*e.expr {
for p in o.props.iter() {
if let PropOrSpread::Prop(prop) = p {
if let Prop::Assign(..) = **prop {
self.emit_err(prop.span(), SyntaxError::AssignProperty);
}
}
}
}
}
}
}
let expr_or_spreads = paren_items

View File

@ -1,12 +1,12 @@
error: The left-hand side of an assignment expression must be a variable or a property access.
--> $DIR/tests/test262-parser/fail/ab9d14c2ef38f180.js:1:1
|
1 | (0, {a = 0}) = 0
| ^^^^^^^^^^^^
error: assignment property is invalid syntax
--> $DIR/tests/test262-parser/fail/ab9d14c2ef38f180.js:1:6
|
1 | (0, {a = 0}) = 0
| ^^^^^
error: The left-hand side of an assignment expression must be a variable or a property access.
--> $DIR/tests/test262-parser/fail/ab9d14c2ef38f180.js:1:1
|
1 | (0, {a = 0}) = 0
| ^^^^^^^^^^^^