fix(es/parser): Report errors for array patterns without comma (#2365)

This commit is contained in:
Pig Fang 2021-10-07 16:03:06 +08:00 committed by GitHub
parent 521e6717ad
commit d65ce85030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 22 additions and 13 deletions

2
Cargo.lock generated
View File

@ -2683,7 +2683,7 @@ dependencies = [
[[package]]
name = "swc_ecma_parser"
version = "0.73.2"
version = "0.73.3"
dependencies = [
"either",
"enum_kind",

View File

@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.73.2"
version = "0.73.3"
[package.metadata.docs.rs]
all-features = true

View File

@ -96,9 +96,7 @@ impl<'a, I: Tokens> Parser<I> {
continue;
}
if comma > 0 {
// One comma is used for separating elements
let cnt = if elems.is_empty() { comma } else { comma - 1 };
elems.extend(iter::repeat(None).take(cnt));
elems.extend(iter::repeat(None).take(comma));
comma = 0;
}
let start = cur_pos!(self);
@ -119,6 +117,10 @@ impl<'a, I: Tokens> Parser<I> {
} else {
elems.push(self.parse_binding_element().map(Some)?);
}
if !is!(self, ']') {
expect!(self, ',');
}
}
expect!(self, ']');

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/235adc0d4af204c6.js:1:7
|
1 | var [a.b] = 0

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/3f9ce9123e9ea7cb.js:1:14
|
1 | function a([a.b]) {}

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/6bc739c23342216d.js:1:11
|
1 | ({set a([a.b]){}})

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/7de586a1b43f8f7a.js:1:15
|
1 | function* a([a.b]) {}

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/b508d676bbb2b2af.js:1:14
|
1 | (function ([a.b]) {})

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/ca424e812e0896bd.js:1:15
|
1 | (function* ([a.b]) {})

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/d5512eff7d8174e4.js:1:8
|
1 | ({*a([a.b]){}})

View File

@ -1,4 +1,4 @@
error: Unexpected token `.`. Expected yield, an identifier, [ or {
error: Expected ',', got '.'
--> $DIR/tests/test262-parser/fail/dee9ac08aa5be125.js:1:7
|
1 | ({a([a.b]){}})

View File

@ -0,0 +1 @@
const [a b] = arr

View File

@ -0,0 +1,6 @@
error: Expected ',', got 'b'
--> $DIR/tests/typescript-errors/array-pattern/input.ts:1:10
|
1 | const [a b] = arr
| ^