Disallow await inside async arrow params (#10469)

* Disallow await inside async arrow params

* Use -1 as default for awaitPos/yieldPos
This commit is contained in:
Nicolò Ribaudo
2019-10-02 07:37:40 +02:00
committed by GitHub
parent fa5057f9fb
commit a219b6de7a
11 changed files with 526 additions and 41 deletions

View File

@@ -0,0 +1 @@
async (a = ({ await }) => {}) => {};

View File

@@ -0,0 +1,3 @@
{
"throws": "Await cannot be used as name inside an async function (1:20)"
}

View File

@@ -0,0 +1,3 @@
async function f() {
function g(x = async(await)) {}
}

View File

@@ -0,0 +1,224 @@
{
"type": "File",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "f"
},
"name": "f"
},
"generator": false,
"async": true,
"params": [],
"body": {
"type": "BlockStatement",
"start": 19,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "FunctionDeclaration",
"start": 23,
"end": 54,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 33
}
},
"id": {
"type": "Identifier",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "g"
},
"name": "g"
},
"generator": false,
"async": false,
"params": [
{
"type": "AssignmentPattern",
"start": 34,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 13
},
"end": {
"line": 2,
"column": 29
}
},
"left": {
"type": "Identifier",
"start": 34,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 13
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "CallExpression",
"start": 38,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 29
}
},
"callee": {
"type": "Identifier",
"start": 38,
"end": 43,
"loc": {
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 22
},
"identifierName": "async"
},
"name": "async"
},
"arguments": [
{
"type": "Identifier",
"start": 44,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 23
},
"end": {
"line": 2,
"column": 28
},
"identifierName": "await"
},
"name": "await"
}
]
}
}
],
"body": {
"type": "BlockStatement",
"start": 52,
"end": 54,
"loc": {
"start": {
"line": 2,
"column": 31
},
"end": {
"line": 2,
"column": 33
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
async (a = ({ await: x }) => {}) => {};

View File

@@ -0,0 +1,225 @@
{
"type": "File",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"program": {
"type": "Program",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 38
}
},
"id": null,
"generator": false,
"async": true,
"params": [
{
"type": "AssignmentPattern",
"start": 7,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 31
}
},
"left": {
"type": "Identifier",
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "a"
},
"name": "a"
},
"right": {
"type": "ArrowFunctionExpression",
"start": 11,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 31
}
},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "ObjectPattern",
"start": 12,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 12
},
"end": {
"line": 1,
"column": 24
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 14,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 22
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 19
},
"identifierName": "await"
},
"name": "await"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 22
},
"identifierName": "x"
},
"name": "x"
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start": 29,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 29
},
"end": {
"line": 1,
"column": 31
}
},
"body": [],
"directives": []
}
}
}
],
"body": {
"type": "BlockStatement",
"start": 36,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 36
},
"end": {
"line": 1,
"column": 38
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}