[TS] Correctly forget awaits after parsing async arrows with type args (#9593)

This commit is contained in:
Nicolò Ribaudo 2019-02-26 20:35:18 +01:00 committed by GitHub
parent 244e4580e9
commit a029071b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 359 additions and 17 deletions

View File

@ -6,13 +6,7 @@ import { types as ct } from "../tokenizer/context";
import * as N from "../types";
import type { Pos, Position } from "../util/location";
import Parser from "../parser";
import {
type BindingTypes,
functionFlags,
BIND_NONE,
SCOPE_ARROW,
SCOPE_OTHER,
} from "../util/scopeflags";
import { type BindingTypes, BIND_NONE, SCOPE_OTHER } from "../util/scopeflags";
type TsModifier =
| "readonly"
@ -1381,14 +1375,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return undefined;
}
this.scope.enter(functionFlags(true, false) | SCOPE_ARROW);
res.id = null;
res.generator = false;
res.expression = true; // May be set again by parseFunctionBody.
res.async = true;
this.parseFunctionBody(res, true);
return this.finishNode(res, "ArrowFunctionExpression");
return this.parseArrowExpression(
res,
/* params are already set */ null,
/* async */ true,
);
}
tsParseTypeArguments(): N.TsTypeParameterInstantiation {

View File

@ -93,7 +93,6 @@
"params": [],
"id": null,
"generator": false,
"expression": true,
"async": true,
"body": {
"type": "AwaitExpression",

View File

@ -205,7 +205,6 @@
},
"id": null,
"generator": false,
"expression": true,
"async": true,
"body": {
"type": "Identifier",

View File

@ -0,0 +1,8 @@
class Cl {
a = async<T>() => {
await 0;
};
b = async<T>() => {
};
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["typescript", "classProperties"]
}

View File

@ -0,0 +1,342 @@
{
"type": "File",
"start": 0,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 8,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 8,
"column": 1
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 8,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 8
},
"identifierName": "Cl"
},
"name": "Cl"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 9,
"end": 80,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 8,
"column": 1
}
},
"body": [
{
"type": "ClassProperty",
"start": 13,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 4,
"column": 4
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "a"
},
"name": "a"
},
"computed": false,
"value": {
"type": "ArrowFunctionExpression",
"start": 17,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 4,
"column": 3
}
},
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start": 22,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 14
}
},
"params": [
{
"type": "TSTypeParameter",
"start": 23,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
}
},
"name": "T"
}
]
},
"params": [],
"id": null,
"generator": false,
"async": true,
"body": {
"type": "BlockStatement",
"start": 31,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 20
},
"end": {
"line": 4,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 37,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 12
}
},
"expression": {
"type": "AwaitExpression",
"start": 37,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 11
}
},
"argument": {
"type": "NumericLiteral",
"start": 43,
"end": 44,
"loc": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 11
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
}
],
"directives": []
}
}
},
{
"type": "ClassProperty",
"start": 54,
"end": 78,
"loc": {
"start": {
"line": 6,
"column": 2
},
"end": {
"line": 7,
"column": 4
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 54,
"end": 55,
"loc": {
"start": {
"line": 6,
"column": 2
},
"end": {
"line": 6,
"column": 3
},
"identifierName": "b"
},
"name": "b"
},
"computed": false,
"value": {
"type": "ArrowFunctionExpression",
"start": 58,
"end": 77,
"loc": {
"start": {
"line": 6,
"column": 6
},
"end": {
"line": 7,
"column": 3
}
},
"typeParameters": {
"type": "TSTypeParameterDeclaration",
"start": 63,
"end": 66,
"loc": {
"start": {
"line": 6,
"column": 11
},
"end": {
"line": 6,
"column": 14
}
},
"params": [
{
"type": "TSTypeParameter",
"start": 64,
"end": 65,
"loc": {
"start": {
"line": 6,
"column": 12
},
"end": {
"line": 6,
"column": 13
}
},
"name": "T"
}
]
},
"params": [],
"id": null,
"generator": false,
"async": true,
"body": {
"type": "BlockStatement",
"start": 72,
"end": 77,
"loc": {
"start": {
"line": 6,
"column": 20
},
"end": {
"line": 7,
"column": 3
}
},
"body": [],
"directives": []
}
}
}
]
}
}
],
"directives": []
}
}