mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/parser): Emit an error for non-last rest element in an object pattern (#3675)
This commit is contained in:
parent
e65c0609ac
commit
6a9d77808b
@ -510,11 +510,7 @@ impl<'a, I: Tokens> Parser<I> {
|
|||||||
self.reparse_expr_as_pat_inner(pat_ty, expr)
|
self.reparse_expr_as_pat_inner(pat_ty, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn reparse_expr_as_pat_inner(
|
fn reparse_expr_as_pat_inner(&mut self, pat_ty: PatType, expr: Box<Expr>) -> PResult<Pat> {
|
||||||
&mut self,
|
|
||||||
pat_ty: PatType,
|
|
||||||
expr: Box<Expr>,
|
|
||||||
) -> PResult<Pat> {
|
|
||||||
// In dts, we do not reparse.
|
// In dts, we do not reparse.
|
||||||
debug_assert!(!self.input.syntax().dts());
|
debug_assert!(!self.input.syntax().dts());
|
||||||
|
|
||||||
@ -608,11 +604,13 @@ impl<'a, I: Tokens> Parser<I> {
|
|||||||
}
|
}
|
||||||
Expr::Object(ObjectLit { span, props }) => {
|
Expr::Object(ObjectLit { span, props }) => {
|
||||||
// {}
|
// {}
|
||||||
|
let len = props.len();
|
||||||
Ok(Pat::Object(ObjectPat {
|
Ok(Pat::Object(ObjectPat {
|
||||||
span,
|
span,
|
||||||
props: props
|
props: props
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|prop| {
|
.enumerate()
|
||||||
|
.map(|(idx, prop)| {
|
||||||
let span = prop.span();
|
let span = prop.span();
|
||||||
match prop {
|
match prop {
|
||||||
PropOrSpread::Prop(prop) => match *prop {
|
PropOrSpread::Prop(prop) => match *prop {
|
||||||
@ -643,6 +641,9 @@ impl<'a, I: Tokens> Parser<I> {
|
|||||||
},
|
},
|
||||||
|
|
||||||
PropOrSpread::Spread(SpreadElement { dot3_token, expr }) => {
|
PropOrSpread::Spread(SpreadElement { dot3_token, expr }) => {
|
||||||
|
if idx != len - 1 {
|
||||||
|
self.emit_err(span, SyntaxError::NonLastRestParam)
|
||||||
|
};
|
||||||
Ok(ObjectPatProp::Rest(RestPat {
|
Ok(ObjectPatProp::Rest(RestPat {
|
||||||
span,
|
span,
|
||||||
dot3_token,
|
dot3_token,
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
var rest, b;
|
||||||
|
|
||||||
|
for ({...rest, b} of [{}
|
||||||
|
]) ;
|
@ -0,0 +1,6 @@
|
|||||||
|
error: Rest element must be final element
|
||||||
|
--> $DIR/tests/jsx/errors/issue-3523/input.js:3:7
|
||||||
|
|
|
||||||
|
3 | for ({...rest, b} of [{}
|
||||||
|
| ^^^^^^^
|
||||||
|
|
Loading…
Reference in New Issue
Block a user