fix(es/parser): Allow using async as the first one in parameters (#2386)

This commit is contained in:
Pig Fang 2021-10-09 16:09:09 +08:00 committed by GitHub
parent ac3fbd91ac
commit 2379fe1ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 3 deletions

2
Cargo.lock generated
View File

@ -2687,7 +2687,7 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_parser" name = "swc_ecma_parser"
version = "0.73.4" version = "0.73.5"
dependencies = [ dependencies = [
"either", "either",
"enum_kind", "enum_kind",

View File

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

View File

@ -1266,7 +1266,7 @@ impl<'a, I: Tokens> Parser<I> {
// as a pattern instead of reparsing) // as a pattern instead of reparsing)
while !eof!(self) && !is!(self, ')') { while !eof!(self) && !is!(self, ')') {
if first { if first {
if is!(self, "async") { if is!(self, "async") && !peeked_is!(self, ',') {
// https://github.com/swc-project/swc/issues/410 // https://github.com/swc-project/swc/issues/410
self.state.potential_arrow_start = Some(cur_pos!(self)); self.state.potential_arrow_start = Some(cur_pos!(self));
let expr = self.parse_assignment_expr()?; let expr = self.parse_assignment_expr()?;

View File

@ -0,0 +1 @@
let fn = (async, x) => {};

View File

@ -0,0 +1,88 @@
{
"type": "Script",
"span": {
"start": 0,
"end": 26,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 0,
"end": 26,
"ctxt": 0
},
"kind": "let",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 4,
"end": 25,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 4,
"end": 6,
"ctxt": 0
},
"value": "fn",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 9,
"end": 25,
"ctxt": 0
},
"params": [
{
"type": "Identifier",
"span": {
"start": 10,
"end": 15,
"ctxt": 0
},
"value": "async",
"optional": false,
"typeAnnotation": null
},
{
"type": "Identifier",
"span": {
"start": 17,
"end": 18,
"ctxt": 0
},
"value": "x",
"optional": false,
"typeAnnotation": null
}
],
"body": {
"type": "BlockStatement",
"span": {
"start": 23,
"end": 25,
"ctxt": 0
},
"stmts": []
},
"async": false,
"generator": false,
"typeParameters": null,
"returnType": null
},
"definite": false
}
]
}
],
"interpreter": null
}