mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
feat(es/parser): Raise a syntax error on an invalid shorthand assignment (#3734)
This commit is contained in:
parent
3152da285a
commit
2aa3b2123f
@ -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
|
||||
|
@ -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
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user