Cleaned up async return type check

This commit is contained in:
Ron Buckton 2015-06-18 11:31:03 -07:00
parent 7443ecc6a5
commit 2891a1d1b7
34 changed files with 534 additions and 172 deletions

View File

@ -824,7 +824,7 @@ namespace ts {
}
// Resolves a qualified name and any involved aliases
function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, location?: Node): Symbol {
function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags): Symbol {
if (nodeIsMissing(name)) {
return undefined;
}
@ -833,7 +833,7 @@ namespace ts {
if (name.kind === SyntaxKind.Identifier) {
let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0;
symbol = resolveName(location || name, (<Identifier>name).text, meaning, message, <Identifier>name);
symbol = resolveName(name, (<Identifier>name).text, meaning, message, <Identifier>name);
if (!symbol) {
return undefined;
}
@ -842,7 +842,7 @@ namespace ts {
let left = name.kind === SyntaxKind.QualifiedName ? (<QualifiedName>name).left : (<PropertyAccessExpression>name).expression;
let right = name.kind === SyntaxKind.QualifiedName ? (<QualifiedName>name).right : (<PropertyAccessExpression>name).name;
let namespace = resolveEntityName(left, SymbolFlags.Namespace, location);
let namespace = resolveEntityName(left, SymbolFlags.Namespace);
if (!namespace || namespace === unknownSymbol || nodeIsMissing(right)) {
return undefined;
}
@ -8839,7 +8839,6 @@ namespace ts {
}
if (produceDiagnostics) {
checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name);
checkCollisionWithArgumentsInGeneratedCode(node);
if (compilerOptions.noImplicitAny && !node.type) {
switch (node.kind) {
@ -9632,7 +9631,7 @@ namespace ts {
* a `resolve` function as one of its arguments and results in an object with a
* callable `then` signature.
*/
function checkAsyncFunctionReturnType(node: SignatureDeclaration): Type {
function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type {
let globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
if (globalPromiseConstructorLikeType === emptyObjectType) {
// If we couldn't resolve the global PromiseConstructorLike type we cannot verify
@ -9640,10 +9639,10 @@ namespace ts {
return unknownType;
}
// The return type of an async function will be the type of the instance. For this
// to be a type compatible with our async function emit, we must also check that
// the type of the declaration (e.g. the static side or "constructor" type of the
// promise) is a compatible `PromiseConstructorLike`.
// As part of our emit for an async function, we will need to emit the entity name of
// the return type annotation as an expression. To meet the necessary runtime semantics
// for __awaiter, we must also check that the type of the declaration (e.g. the static
// side or "constructor" of the promise type) is compatible `PromiseConstructorLike`.
//
// An example might be (from lib.es6.d.ts):
//
@ -9666,36 +9665,33 @@ namespace ts {
//
// When we get the type of the `Promise` symbol here, we get the type of the static
// side of the `Promise` class, which would be `{ new <T>(...): Promise<T> }`.
let returnType = getTypeFromTypeNode(node.type);
let entityName = getEntityNameFromTypeNode(node.type);
let resolvedName = entityName ? resolveEntityName(entityName, SymbolFlags.Value, node) : undefined;
if (!resolvedName || !returnType.symbol) {
error(node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
return unknownType;
}
if (getMergedSymbol(resolvedName) !== getMergedSymbol(returnType.symbol)) {
// If we were unable to resolve the return type as a value, report an error.
let identifier = getFirstIdentifier(entityName);
error(resolvedName.valueDeclaration, Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions,
identifier.text,
identifier.text);
return unknownType;
}
// When we emit the async function, we need to ensure we emit any imports that might
// otherwise have been elided if the return type were only ever referenced in a type
// position. As such, we check the entity name as an expression.
let declaredType = checkExpression(entityName);
if (!isTypeAssignableTo(declaredType, globalPromiseConstructorLikeType)) {
// If the declared type of the return type is not assignable to a PromiseConstructorLike, report an error.
error(node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
return unknownType;
let promiseType = getTypeFromTypeNode(node.type);
let promiseConstructor = getMergedSymbol(promiseType.symbol);
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType));
return unknownType
}
// Validate the promise constructor type.
let promiseConstructorType = getTypeOfSymbol(promiseConstructor);
if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
return unknownType;
}
// Verify there is no local declaration that could collide with the promise constructor.
let promiseName = getEntityNameFromTypeNode(node.type);
let root = getFirstIdentifier(promiseName);
let rootSymbol = getSymbol(node.locals, root.text, SymbolFlags.Value);
if (rootSymbol) {
error(rootSymbol.valueDeclaration, Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions,
root.text,
getFullyQualifiedName(promiseConstructor));
return unknownType;
}
// Get and return the awaited type of the return type.
return getAwaitedType(returnType, node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
return getAwaitedType(promiseType, node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
}
/** Check a decorator */
@ -10093,22 +10089,6 @@ namespace ts {
}
}
}
function checkCollisionWithAwaiterVariablesInGeneratedCode(node: Node, name: DeclarationName): void {
if (!name || name.kind !== SyntaxKind.Identifier || isTypeNode(name)) {
return;
}
let identifier = <Identifier>name;
let container = getContainingFunction(name);
if (container && isAsyncFunctionLike(container) && node.kind !== SyntaxKind.Identifier) {
let promiseConstructorName = getEntityNameFromTypeNode(container.type);
let firstIdentifier = promiseConstructorName ? getFirstIdentifier(promiseConstructorName) : undefined;
if (firstIdentifier && firstIdentifier.text === identifier.text) {
error(node, Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, getTextOfNode(promiseConstructorName));
}
}
}
// Check that a parameter initializer contains no references to parameters declared to the right of itself
function checkParameterInitializer(node: VariableLikeDeclaration): void {
@ -10954,7 +10934,6 @@ namespace ts {
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name);
}
checkTypeParameters(node.typeParameters);
checkExportsOnMergedDeclarations(node);
@ -11398,7 +11377,6 @@ namespace ts {
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
computeEnumMemberValues(node);

View File

@ -48,6 +48,7 @@ namespace ts {
A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
A_get_accessor_cannot_have_parameters: { code: 1054, category: DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
Type_0_is_not_a_valid_async_function_return_type: { code: 1055, category: DiagnosticCategory.Error, key: "Type '{0}' is not a valid async function return type." },
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: DiagnosticCategory.Error, key: "Accessors are only available when targeting ECMAScript 5 and higher." },
An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: DiagnosticCategory.Error, key: "An async function or method must have a valid awaitable return type." },
Operand_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: DiagnosticCategory.Error, key: "Operand for 'await' does not have a valid callable 'then' member." },

View File

@ -179,6 +179,10 @@
"category": "Error",
"code": 1054
},
"Type '{0}' is not a valid async function return type.": {
"category": "Error",
"code": 1055
},
"Accessors are only available when targeting ECMAScript 5 and higher.": {
"category": "Error",
"code": 1056

View File

@ -49,10 +49,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
};`;
const awaiterHelper = `
var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args, PromiseConstructor) {
PromiseConstructor || (PromiseConstructor = Promise);
var __awaiter = (this && this.__awaiter) || function (args, generator) {
var PromiseConstructor = args[1] || Promise;
return new PromiseConstructor(function (resolve, reject) {
generator = generator.call(thisArg, args);
generator = generator.call(args[0], args[2]);
function cast(value) { return value instanceof PromiseConstructor ? value : new PromiseConstructor(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
@ -3359,6 +3359,7 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
function emitAsyncFunctionBodyForES6(node: FunctionLikeDeclaration) {
let promiseConstructor = getEntityNameFromTypeNode(node.type);
let isArrowFunction = node.kind === SyntaxKind.ArrowFunction;
let hasLexicalArguments = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureArguments) !== 0;
let args: string;
// An async function is emit as an outer function that calls an inner
@ -3373,7 +3374,7 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
// let a = async (b) => { await b; }
//
// // output
// let a = (b) => __awaiter(function* (b) {
// let a = (b) => __awaiter([this], function* (b) {
// yield b;
// }, this);
//
@ -3383,9 +3384,9 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
// let a = async (b) => { await arguments[0]; }
//
// // output
// let a = (b) => __awaiter(function* (arguments) {
// let a = (b) => __awaiter([this, arguments], function* (arguments) {
// yield arguments[0];
// }, this, arguments);
// });
//
// The emit for an async function expression without a lexical `arguments` binding
// might be:
@ -3397,7 +3398,7 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
//
// // output
// let a = function (b) {
// return __awaiter(function* () {
// return __awaiter([this], function* () {
// yield b;
// }, this);
// }
@ -3412,9 +3413,24 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
//
// // output
// let a = function (b) {
// return __awaiter(function* (arguments) {
// return __awaiter([this, arguments], function* (arguments) {
// yield arguments[0];
// }, this, arguments);
// });
// }
//
// The emit for an async function expression with a lexical `arguments` binding
// and a return type annotation might be:
//
// // input
// let a = async function (b): MyPromise<any> {
// await arguments[0];
// }
//
// // output
// let a = function (b) {
// return __awaiter([this, arguments, MyPromise], function* (arguments) {
// yield arguments[0];
// });
// }
//
@ -3427,42 +3443,27 @@ var __awaiter = (this && this.__awaiter) || function (generator, thisArg, args,
write("return");
}
write(" __awaiter([this");
if (promiseConstructor || hasLexicalArguments) {
write(", ");
if (promiseConstructor) {
emitNodeWithoutSourceMap(promiseConstructor);
}
if (hasLexicalArguments) {
write(", arguments");
}
}
// Emit the call to __awaiter.
let hasLexicalArguments = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureArguments) !== 0;
if (hasLexicalArguments) {
write(" __awaiter(function* (arguments)");
write("], function* (arguments)");
}
else {
write(" __awaiter(function* ()");
write("], function* ()");
}
// Emit the signature and body for the inner generator function.
emitFunctionBody(node);
// Emit the current `this` binding.
write(",");
writeLine();
write("this");
// Optionally emit the lexical arguments.
if (hasLexicalArguments) {
write(", arguments");
}
// If the function has an explicit type annotation for a promise, emit the
// constructor.
if (promiseConstructor) {
// If we did not have lexical arguments, supply undefined (void 0) for
// the `arguments` parameter.
if (!hasLexicalArguments) {
write(", void 0");
}
write(", ");
emitNodeWithoutSourceMap(promiseConstructor);
}
write(")");
// If this is not an async arrow, emit the closing brace of the outer function body.

View File

@ -4,6 +4,5 @@ var foo = async (): Promise<void> => {
};
//// [asyncArrowFunction1_es6.js]
var foo = () => __awaiter(function* () {
},
this, void 0, Promise);
var foo = () => __awaiter([this, Promise], function* () {
});

View File

@ -4,6 +4,5 @@ var foo = async (a = await): Promise<void> => {
}
//// [asyncArrowFunction6_es6.js]
var foo = (a = yield ) => __awaiter(function* () {
},
this, void 0, Promise);
var foo = (a = yield ) => __awaiter([this, Promise], function* () {
});

View File

@ -7,10 +7,8 @@ var bar = async (): Promise<void> => {
}
//// [asyncArrowFunction7_es6.js]
var bar = () => __awaiter(function* () {
var bar = () => __awaiter([this, Promise], function* () {
// 'await' here is an identifier, and not an await expression.
var foo = (a = yield ) => __awaiter(function* () {
},
this, void 0, Promise);
},
this, void 0, Promise);
var foo = (a = yield ) => __awaiter([this, Promise], function* () {
});
});

View File

@ -5,7 +5,6 @@ var foo = async (): Promise<void> => {
}
//// [asyncArrowFunction8_es6.js]
var foo = () => __awaiter(function* () {
var foo = () => __awaiter([this, Promise], function* () {
var v = { [yield ]: foo };
},
this, void 0, Promise);
});

View File

@ -11,7 +11,6 @@ class C {
class C {
method() {
function other() { }
var fn = () => __awaiter(function* (arguments) { return yield other.apply(this, arguments); },
this, arguments);
var fn = () => __awaiter([this, , arguments], function* (arguments) { return yield other.apply(this, arguments); });
}
}

View File

@ -9,7 +9,6 @@ class C {
//// [asyncArrowFunctionCapturesThis_es6.js]
class C {
method() {
var fn = () => __awaiter(function* () { return yield this; },
this);
var fn = () => __awaiter([this], function* () { return yield this; });
}
}

View File

@ -0,0 +1,119 @@
//// [asyncAwait_es6.ts]
type MyPromise<T> = Promise<T>;
declare var MyPromise: typeof Promise;
declare var p: Promise<number>;
declare var mp: MyPromise<number>;
async function f0() { }
async function f1(): Promise<void> { }
async function f3(): MyPromise<void> { }
let f4 = async function() { }
let f5 = async function(): Promise<void> { }
let f6 = async function(): MyPromise<void> { }
let f7 = async () => { };
let f8 = async (): Promise<void> => { };
let f9 = async (): MyPromise<void> => { };
let f10 = async () => p;
let f11 = async () => mp;
let f12 = async (): Promise<number> => mp;
let f13 = async (): MyPromise<number> => p;
let o = {
async m1() { },
async m2(): Promise<void> { },
async m3(): MyPromise<void> { }
};
class C {
async m1() { }
async m2(): Promise<void> { }
async m3(): MyPromise<void> { }
static async m4() { }
static async m5(): Promise<void> { }
static async m6(): MyPromise<void> { }
}
module M {
export async function f1() { }
}
//// [asyncAwait_es6.js]
var __awaiter = (this && this.__awaiter) || function (args, generator) {
var PromiseConstructor = args[1] || Promise;
return new PromiseConstructor(function (resolve, reject) {
generator = generator.call(args[0], args[2]);
function cast(value) { return value instanceof PromiseConstructor ? value : new PromiseConstructor(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
function step(verb, value) {
var result = generator[verb](value);
result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
}
step("next", void 0);
});
};
function f0() {
return __awaiter([this], function* () { });
}
function f1() {
return __awaiter([this, Promise], function* () { });
}
function f3() {
return __awaiter([this, MyPromise], function* () { });
}
let f4 = function () {
return __awaiter([this], function* () { });
};
let f5 = function () {
return __awaiter([this, Promise], function* () { });
};
let f6 = function () {
return __awaiter([this, MyPromise], function* () { });
};
let f7 = () => __awaiter([this], function* () { });
let f8 = () => __awaiter([this, Promise], function* () { });
let f9 = () => __awaiter([this, MyPromise], function* () { });
let f10 = () => __awaiter([this], function* () { return p; });
let f11 = () => __awaiter([this], function* () { return mp; });
let f12 = () => __awaiter([this, Promise], function* () { return mp; });
let f13 = () => __awaiter([this, MyPromise], function* () { return p; });
let o = {
m1() {
return __awaiter([this], function* () { });
},
m2() {
return __awaiter([this, Promise], function* () { });
},
m3() {
return __awaiter([this, MyPromise], function* () { });
}
};
class C {
m1() {
return __awaiter([this], function* () { });
}
m2() {
return __awaiter([this, Promise], function* () { });
}
m3() {
return __awaiter([this, MyPromise], function* () { });
}
static m4() {
return __awaiter([this], function* () { });
}
static m5() {
return __awaiter([this, Promise], function* () { });
}
static m6() {
return __awaiter([this, MyPromise], function* () { });
}
}
var M;
(function (M) {
function f1() {
return __awaiter([this], function* () { });
}
M.f1 = f1;
})(M || (M = {}));

View File

@ -0,0 +1,118 @@
=== tests/cases/conformance/async/es6/asyncAwait_es6.ts ===
type MyPromise<T> = Promise<T>;
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
>T : Symbol(T, Decl(asyncAwait_es6.ts, 0, 15))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
>T : Symbol(T, Decl(asyncAwait_es6.ts, 0, 15))
declare var MyPromise: typeof Promise;
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
declare var p: Promise<number>;
>p : Symbol(p, Decl(asyncAwait_es6.ts, 2, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
declare var mp: MyPromise<number>;
>mp : Symbol(mp, Decl(asyncAwait_es6.ts, 3, 11))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
async function f0() { }
>f0 : Symbol(f0, Decl(asyncAwait_es6.ts, 3, 34))
async function f1(): Promise<void> { }
>f1 : Symbol(f1, Decl(asyncAwait_es6.ts, 5, 23))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
async function f3(): MyPromise<void> { }
>f3 : Symbol(f3, Decl(asyncAwait_es6.ts, 6, 38))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
let f4 = async function() { }
>f4 : Symbol(f4, Decl(asyncAwait_es6.ts, 9, 3))
let f5 = async function(): Promise<void> { }
>f5 : Symbol(f5, Decl(asyncAwait_es6.ts, 10, 3))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
let f6 = async function(): MyPromise<void> { }
>f6 : Symbol(f6, Decl(asyncAwait_es6.ts, 11, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
let f7 = async () => { };
>f7 : Symbol(f7, Decl(asyncAwait_es6.ts, 13, 3))
let f8 = async (): Promise<void> => { };
>f8 : Symbol(f8, Decl(asyncAwait_es6.ts, 14, 3))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
let f9 = async (): MyPromise<void> => { };
>f9 : Symbol(f9, Decl(asyncAwait_es6.ts, 15, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
let f10 = async () => p;
>f10 : Symbol(f10, Decl(asyncAwait_es6.ts, 16, 3))
>p : Symbol(p, Decl(asyncAwait_es6.ts, 2, 11))
let f11 = async () => mp;
>f11 : Symbol(f11, Decl(asyncAwait_es6.ts, 17, 3))
>mp : Symbol(mp, Decl(asyncAwait_es6.ts, 3, 11))
let f12 = async (): Promise<number> => mp;
>f12 : Symbol(f12, Decl(asyncAwait_es6.ts, 18, 3))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
>mp : Symbol(mp, Decl(asyncAwait_es6.ts, 3, 11))
let f13 = async (): MyPromise<number> => p;
>f13 : Symbol(f13, Decl(asyncAwait_es6.ts, 19, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
>p : Symbol(p, Decl(asyncAwait_es6.ts, 2, 11))
let o = {
>o : Symbol(o, Decl(asyncAwait_es6.ts, 21, 3))
async m1() { },
>m1 : Symbol(m1, Decl(asyncAwait_es6.ts, 21, 9))
async m2(): Promise<void> { },
>m2 : Symbol(m2, Decl(asyncAwait_es6.ts, 22, 16))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
async m3(): MyPromise<void> { }
>m3 : Symbol(m3, Decl(asyncAwait_es6.ts, 23, 31))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
};
class C {
>C : Symbol(C, Decl(asyncAwait_es6.ts, 25, 2))
async m1() { }
>m1 : Symbol(m1, Decl(asyncAwait_es6.ts, 27, 9))
async m2(): Promise<void> { }
>m2 : Symbol(m2, Decl(asyncAwait_es6.ts, 28, 15))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
async m3(): MyPromise<void> { }
>m3 : Symbol(m3, Decl(asyncAwait_es6.ts, 29, 30))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
static async m4() { }
>m4 : Symbol(C.m4, Decl(asyncAwait_es6.ts, 30, 32))
static async m5(): Promise<void> { }
>m5 : Symbol(C.m5, Decl(asyncAwait_es6.ts, 31, 22))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
static async m6(): MyPromise<void> { }
>m6 : Symbol(C.m6, Decl(asyncAwait_es6.ts, 32, 37))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es6.ts, 0, 0), Decl(asyncAwait_es6.ts, 1, 11))
}
module M {
>M : Symbol(M, Decl(asyncAwait_es6.ts, 34, 1))
export async function f1() { }
>f1 : Symbol(f1, Decl(asyncAwait_es6.ts, 36, 10))
}

View File

@ -0,0 +1,129 @@
=== tests/cases/conformance/async/es6/asyncAwait_es6.ts ===
type MyPromise<T> = Promise<T>;
>MyPromise : Promise<T>
>T : T
>Promise : Promise<T>
>T : T
declare var MyPromise: typeof Promise;
>MyPromise : PromiseConstructor
>Promise : PromiseConstructor
declare var p: Promise<number>;
>p : Promise<number>
>Promise : Promise<T>
declare var mp: MyPromise<number>;
>mp : Promise<number>
>MyPromise : Promise<T>
async function f0() { }
>f0 : () => Promise<void>
async function f1(): Promise<void> { }
>f1 : () => Promise<void>
>Promise : Promise<T>
async function f3(): MyPromise<void> { }
>f3 : () => Promise<void>
>MyPromise : Promise<T>
let f4 = async function() { }
>f4 : () => Promise<void>
>async function() { } : () => Promise<void>
let f5 = async function(): Promise<void> { }
>f5 : () => Promise<void>
>async function(): Promise<void> { } : () => Promise<void>
>Promise : Promise<T>
let f6 = async function(): MyPromise<void> { }
>f6 : () => Promise<void>
>async function(): MyPromise<void> { } : () => Promise<void>
>MyPromise : Promise<T>
let f7 = async () => { };
>f7 : () => Promise<void>
>async () => { } : () => Promise<void>
let f8 = async (): Promise<void> => { };
>f8 : () => Promise<void>
>async (): Promise<void> => { } : () => Promise<void>
>Promise : Promise<T>
let f9 = async (): MyPromise<void> => { };
>f9 : () => Promise<void>
>async (): MyPromise<void> => { } : () => Promise<void>
>MyPromise : Promise<T>
let f10 = async () => p;
>f10 : () => Promise<number>
>async () => p : () => Promise<number>
>p : Promise<number>
let f11 = async () => mp;
>f11 : () => Promise<number>
>async () => mp : () => Promise<number>
>mp : Promise<number>
let f12 = async (): Promise<number> => mp;
>f12 : () => Promise<number>
>async (): Promise<number> => mp : () => Promise<number>
>Promise : Promise<T>
>mp : Promise<number>
let f13 = async (): MyPromise<number> => p;
>f13 : () => Promise<number>
>async (): MyPromise<number> => p : () => Promise<number>
>MyPromise : Promise<T>
>p : Promise<number>
let o = {
>o : { m1(): Promise<void>; m2(): Promise<void>; m3(): Promise<void>; }
>{ async m1() { }, async m2(): Promise<void> { }, async m3(): MyPromise<void> { }} : { m1(): Promise<void>; m2(): Promise<void>; m3(): Promise<void>; }
async m1() { },
>m1 : () => Promise<void>
async m2(): Promise<void> { },
>m2 : () => Promise<void>
>Promise : Promise<T>
async m3(): MyPromise<void> { }
>m3 : () => Promise<void>
>MyPromise : Promise<T>
};
class C {
>C : C
async m1() { }
>m1 : () => Promise<void>
async m2(): Promise<void> { }
>m2 : () => Promise<void>
>Promise : Promise<T>
async m3(): MyPromise<void> { }
>m3 : () => Promise<void>
>MyPromise : Promise<T>
static async m4() { }
>m4 : () => Promise<void>
static async m5(): Promise<void> { }
>m5 : () => Promise<void>
>Promise : Promise<T>
static async m6(): MyPromise<void> { }
>m6 : () => Promise<void>
>MyPromise : Promise<T>
}
module M {
>M : typeof M
export async function f1() { }
>f1 : () => Promise<void>
}

View File

@ -4,7 +4,6 @@ async function await(): Promise<void> {
//// [asyncFunctionDeclaration11_es6.js]
function await() {
return __awaiter(function* () {
},
this, void 0, Promise);
return __awaiter([this, Promise], function* () {
});
}

View File

@ -7,9 +7,8 @@ async function foo(): Promise<void> {
//// [asyncFunctionDeclaration13_es6.js]
function foo() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
// Legal to use 'await' in a type context.
var v;
},
this, void 0, Promise);
});
}

View File

@ -5,8 +5,7 @@ async function foo(): Promise<void> {
//// [asyncFunctionDeclaration14_es6.js]
function foo() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
return;
},
this, void 0, Promise);
});
}

View File

@ -4,7 +4,6 @@ async function foo(): Promise<void> {
//// [asyncFunctionDeclaration1_es6.js]
function foo() {
return __awaiter(function* () {
},
this, void 0, Promise);
return __awaiter([this, Promise], function* () {
});
}

View File

@ -4,7 +4,6 @@ async function foo(a = await): Promise<void> {
//// [asyncFunctionDeclaration6_es6.js]
function foo(a = yield ) {
return __awaiter(function* () {
},
this, void 0, Promise);
return __awaiter([this, Promise], function* () {
});
}

View File

@ -7,13 +7,11 @@ async function bar(): Promise<void> {
//// [asyncFunctionDeclaration7_es6.js]
function bar() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
// 'await' here is an identifier, and not a yield expression.
function foo(a = yield ) {
return __awaiter(function* () {
},
this, void 0, Promise);
return __awaiter([this, Promise], function* () {
});
}
},
this, void 0, Promise);
});
}

View File

@ -5,8 +5,7 @@ async function foo(): Promise<void> {
//// [asyncFunctionDeclaration9_es6.js]
function foo() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
var v = { [yield ]: foo };
},
this, void 0, Promise);
});
}

View File

@ -9,10 +9,9 @@ async function func(): Promise<void> {
//// [awaitBinaryExpression1_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = (yield p) || a;
"after";
},
this, void 0, Promise);
});
}

View File

@ -9,10 +9,9 @@ async function func(): Promise<void> {
//// [awaitBinaryExpression2_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = (yield p) && a;
"after";
},
this, void 0, Promise);
});
}

View File

@ -9,10 +9,9 @@ async function func(): Promise<void> {
//// [awaitBinaryExpression3_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = (yield p) + a;
"after";
},
this, void 0, Promise);
});
}

View File

@ -9,10 +9,9 @@ async function func(): Promise<void> {
//// [awaitBinaryExpression4_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = yield p, a;
"after";
},
this, void 0, Promise);
});
}

View File

@ -10,11 +10,10 @@ async function func(): Promise<void> {
//// [awaitBinaryExpression5_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var o;
o.a = yield p;
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression1_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = fn(a, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression2_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = fn(yield p, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression3_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = fn(a, yield p, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression4_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = (yield pfn)(a, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression5_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = o.fn(a, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression6_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = o.fn(yield p, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression7_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = o.fn(a, yield p, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -13,10 +13,9 @@ async function func(): Promise<void> {
//// [awaitCallExpression8_es6.js]
function func() {
return __awaiter(function* () {
return __awaiter([this, Promise], function* () {
"before";
var b = (yield po).fn(a, a, a);
"after";
},
this, void 0, Promise);
});
}

View File

@ -0,0 +1,40 @@
// @target: ES6
type MyPromise<T> = Promise<T>;
declare var MyPromise: typeof Promise;
declare var p: Promise<number>;
declare var mp: MyPromise<number>;
async function f0() { }
async function f1(): Promise<void> { }
async function f3(): MyPromise<void> { }
let f4 = async function() { }
let f5 = async function(): Promise<void> { }
let f6 = async function(): MyPromise<void> { }
let f7 = async () => { };
let f8 = async (): Promise<void> => { };
let f9 = async (): MyPromise<void> => { };
let f10 = async () => p;
let f11 = async () => mp;
let f12 = async (): Promise<number> => mp;
let f13 = async (): MyPromise<number> => p;
let o = {
async m1() { },
async m2(): Promise<void> { },
async m3(): MyPromise<void> { }
};
class C {
async m1() { }
async m2(): Promise<void> { }
async m3(): MyPromise<void> { }
static async m4() { }
static async m5(): Promise<void> { }
static async m6(): MyPromise<void> { }
}
module M {
export async function f1() { }
}