diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33931ac304..a60866b90f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17794,6 +17794,8 @@ namespace ts { case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ExportDeclaration: case SyntaxKind.ExportAssignment: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: case SyntaxKind.Parameter: break; case SyntaxKind.FunctionDeclaration: diff --git a/tests/baselines/reference/disallowAsyncModifierInES5.errors.txt b/tests/baselines/reference/disallowAsyncModifierInES5.errors.txt new file mode 100644 index 0000000000..655416f784 --- /dev/null +++ b/tests/baselines/reference/disallowAsyncModifierInES5.errors.txt @@ -0,0 +1,27 @@ +error TS2318: Cannot find global type 'Promise'. +tests/cases/compiler/disallowAsyncModifierInES5.ts(2,1): error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/disallowAsyncModifierInES5.ts(2,16): error TS1057: An async function or method must have a valid awaitable return type. +tests/cases/compiler/disallowAsyncModifierInES5.ts(3,11): error TS1057: An async function or method must have a valid awaitable return type. +tests/cases/compiler/disallowAsyncModifierInES5.ts(3,11): error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/disallowAsyncModifierInES5.ts(4,11): error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. +tests/cases/compiler/disallowAsyncModifierInES5.ts(4,11): error TS1057: An async function or method must have a valid awaitable return type. + + +!!! error TS2318: Cannot find global type 'Promise'. +==== tests/cases/compiler/disallowAsyncModifierInES5.ts (6 errors) ==== + + async function foo() { return 42; } // ERROR: Async functions are only available in ES6+ + ~~~~~ +!!! error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. + ~~~ +!!! error TS1057: An async function or method must have a valid awaitable return type. + let bar = async function () { return 42; } // OK, but should be an error + ~~~~~ +!!! error TS1057: An async function or method must have a valid awaitable return type. + ~~~~~ +!!! error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. + let baz = async () => 42; // OK, but should be an error + ~~~~~ +!!! error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. + ~~~~~~~~~~~~~~ +!!! error TS1057: An async function or method must have a valid awaitable return type. \ No newline at end of file diff --git a/tests/baselines/reference/disallowAsyncModifierInES5.js b/tests/baselines/reference/disallowAsyncModifierInES5.js new file mode 100644 index 0000000000..8216e5fd0e --- /dev/null +++ b/tests/baselines/reference/disallowAsyncModifierInES5.js @@ -0,0 +1,22 @@ +//// [disallowAsyncModifierInES5.ts] + +async function foo() { return 42; } // ERROR: Async functions are only available in ES6+ +let bar = async function () { return 42; } // OK, but should be an error +let baz = async () => 42; // OK, but should be an error + +//// [disallowAsyncModifierInES5.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +function foo() { + return __awaiter(this, void 0, void 0, function* () { return 42; }); +} // ERROR: Async functions are only available in ES6+ +var bar = function () { + return __awaiter(this, void 0, void 0, function* () { return 42; }); +}; // OK, but should be an error +var baz = function () __awaiter(this, void 0, void 0, function* () { return 42; }); // OK, but should be an error diff --git a/tests/cases/compiler/disallowAsyncModifierInES5.ts b/tests/cases/compiler/disallowAsyncModifierInES5.ts new file mode 100644 index 0000000000..5417e678dc --- /dev/null +++ b/tests/cases/compiler/disallowAsyncModifierInES5.ts @@ -0,0 +1,5 @@ +// @target: es5 + +async function foo() { return 42; } // ERROR: Async functions are only available in ES6+ +let bar = async function () { return 42; } // OK, but should be an error +let baz = async () => 42; // OK, but should be an error \ No newline at end of file