fix(es/parser): Allow as in destructuring assignment (#5948)

This commit is contained in:
John Daly 2022-09-24 18:29:33 -07:00 committed by GitHub
parent e5ba9636ac
commit cdd69d0145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -510,6 +510,15 @@ fn issue_3672_2() {
); );
} }
#[test]
fn issue_5947() {
test_parser(
"[a as number, b as number, c as string] = [1, 2, '3']",
Syntax::Typescript(Default::default()),
|p| p.parse_module(),
);
}
#[bench] #[bench]
fn bench_new_expr_ts(b: &mut Bencher) { fn bench_new_expr_ts(b: &mut Bencher) {
bench_parser( bench_parser(

View File

@ -566,7 +566,8 @@ impl<I: Tokens> Parser<I> {
| Expr::Fn(..) | Expr::Fn(..)
| Expr::Class(..) | Expr::Class(..)
| Expr::Paren(..) | Expr::Paren(..)
| Expr::Tpl(..) => { | Expr::Tpl(..)
| Expr::TsAs(..) => {
if !expr.is_valid_simple_assignment_target(self.ctx().strict) { if !expr.is_valid_simple_assignment_target(self.ctx().strict) {
self.emit_err(span, SyntaxError::NotSimpleAssign) self.emit_err(span, SyntaxError::NotSimpleAssign)
} }

View File

@ -0,0 +1,2 @@
let a, b;
[a as number, b as number] = [1, 2];

View File

@ -0,0 +1,2 @@
let a, b;
[a, b] = [1, 2];