diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 40c63cb7ac9..d6571dfdb75 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1649,28 +1649,36 @@ namespace ts { * @param target: result statements array * @param source: origin statements array * @param ensureUseStrict: boolean determining whether the function need to add prologue-directives + * @param visitor: Optional callback used to visit any custom prologue directives. */ - export function addPrologueDirectives(target: Statement[], source: Statement[], ensureUseStrict?: boolean): number { + export function addPrologueDirectives(target: Statement[], source: Statement[], ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult): number { Debug.assert(target.length === 0, "PrologueDirectives should be at the first statement in the target statements array"); let foundUseStrict = false; - for (let i = 0; i < source.length; i++) { - if (isPrologueDirective(source[i])) { - if (isUseStrictPrologue(source[i] as ExpressionStatement)) { + let statementOffset = 0; + const numStatements = source.length; + while (statementOffset < numStatements) { + const statement = source[statementOffset]; + if (isPrologueDirective(statement)) { + if (isUseStrictPrologue(statement as ExpressionStatement)) { foundUseStrict = true; } - - target.push(source[i]); + target.push(statement); } else { if (ensureUseStrict && !foundUseStrict) { target.push(startOnNewLine(createStatement(createLiteral("use strict")))); + foundUseStrict = true; + } + if (statement.emitFlags & NodeEmitFlags.CustomPrologue) { + target.push(visitor ? visitNode(statement, visitor, isStatement) : statement); + } + else { + break; } - - return i; } + statementOffset++; } - - return source.length; + return statementOffset; } /** diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 110d7440212..7deaa38d148 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -930,21 +930,27 @@ namespace ts { // of an initializer, we must emit that expression to preserve side effects. if (name.elements.length > 0) { statements.push( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList( - flattenParameterDestructuring(context, parameter, temp, visitor) - ) + setNodeEmitFlags( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList( + flattenParameterDestructuring(context, parameter, temp, visitor) + ) + ), + NodeEmitFlags.CustomPrologue ) ); } else if (initializer) { statements.push( - createStatement( - createAssignment( - temp, - visitNode(initializer, visitor, isExpression) - ) + setNodeEmitFlags( + createStatement( + createAssignment( + temp, + visitNode(initializer, visitor, isExpression) + ) + ), + NodeEmitFlags.CustomPrologue ) ); } @@ -981,7 +987,7 @@ namespace ts { /*location*/ parameter ); statement.startsOnNewLine = true; - setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap); + setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.CustomPrologue); statements.push(statement); } @@ -1023,16 +1029,19 @@ namespace ts { // var param = []; statements.push( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - declarationName, - /*type*/ undefined, - createArrayLiteral([]) - ) - ]), - /*location*/ parameter + setNodeEmitFlags( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + declarationName, + /*type*/ undefined, + createArrayLiteral([]) + ) + ]), + /*location*/ parameter + ), + NodeEmitFlags.CustomPrologue ) ); @@ -1065,7 +1074,7 @@ namespace ts { ]) ); - setNodeEmitFlags(forStatement, NodeEmitFlags.SourceMapAdjustRestParameterLoop); + setNodeEmitFlags(forStatement, NodeEmitFlags.SourceMapAdjustRestParameterLoop | NodeEmitFlags.CustomPrologue); startOnNewLine(forStatement); statements.push(forStatement); } @@ -1090,7 +1099,7 @@ namespace ts { ]) ); - setNodeEmitFlags(captureThisStatement, NodeEmitFlags.NoComments); + setNodeEmitFlags(captureThisStatement, NodeEmitFlags.NoComments | NodeEmitFlags.CustomPrologue); setSourceMapRange(captureThisStatement, node); statements.push(captureThisStatement); } @@ -1347,7 +1356,7 @@ namespace ts { if (isBlock(body)) { // ensureUseStrict is false because no new prologue-directive should be added. // addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array - statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false); + statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); } addCaptureThisForNodeIfNeeded(statements, node); diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 234f39550a7..adb62f117ef 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -309,10 +309,7 @@ namespace ts { */ function visitor(node: Node): VisitResult { const transformFlags = node.transformFlags; - if (transformFlags & TransformFlags.ContainsYield) { - return visitJavaScriptContainingYield(node); - } - else if (inStatementContainingYield) { + if (inStatementContainingYield) { return visitJavaScriptInStatementContainingYield(node); } else if (inGeneratorFunctionBody) { @@ -329,34 +326,6 @@ namespace ts { } } - /** - * Visits a node that contains a YieldExpression. - * - * @param node The node to visit. - */ - function visitJavaScriptContainingYield(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.BinaryExpression: - return visitBinaryExpression(node); - case SyntaxKind.ConditionalExpression: - return visitConditionalExpression(node); - case SyntaxKind.YieldExpression: - return visitYieldExpression(node); - case SyntaxKind.ArrayLiteralExpression: - return visitArrayLiteralExpression(node); - case SyntaxKind.ObjectLiteralExpression: - return visitObjectLiteralExpression(node); - case SyntaxKind.ElementAccessExpression: - return visitElementAccessExpression(node); - case SyntaxKind.CallExpression: - return visitCallExpression(node); - case SyntaxKind.NewExpression: - return visitNewExpression(node); - default: - return visitJavaScriptInStatementContainingYield(node); - } - } - /** * Visits a node that is contained within a statement that contains yield. * @@ -404,7 +373,10 @@ namespace ts { case SyntaxKind.ReturnStatement: return visitReturnStatement(node); default: - if (node.transformFlags & (TransformFlags.ContainsGenerator | TransformFlags.ContainsYield | TransformFlags.ContainsHoistedDeclarationOrCompletion)) { + if (node.transformFlags & TransformFlags.ContainsYield) { + return visitJavaScriptContainingYield(node); + } + else if (node.transformFlags & (TransformFlags.ContainsGenerator | TransformFlags.ContainsHoistedDeclarationOrCompletion)) { return visitEachChild(node, visitor, context); } else { @@ -413,6 +385,34 @@ namespace ts { } } + /** + * Visits a node that contains a YieldExpression. + * + * @param node The node to visit. + */ + function visitJavaScriptContainingYield(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.BinaryExpression: + return visitBinaryExpression(node); + case SyntaxKind.ConditionalExpression: + return visitConditionalExpression(node); + case SyntaxKind.YieldExpression: + return visitYieldExpression(node); + case SyntaxKind.ArrayLiteralExpression: + return visitArrayLiteralExpression(node); + case SyntaxKind.ObjectLiteralExpression: + return visitObjectLiteralExpression(node); + case SyntaxKind.ElementAccessExpression: + return visitElementAccessExpression(node); + case SyntaxKind.CallExpression: + return visitCallExpression(node); + case SyntaxKind.NewExpression: + return visitNewExpression(node); + default: + return visitEachChild(node, visitor, context); + } + } + /** * Visits a generator function. * @@ -572,7 +572,7 @@ namespace ts { operationLocations = undefined; state = createTempVariable(/*recordTempVariable*/ undefined); - const statementOffset = addPrologueDirectives(statements, body.statements); + const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); // Build the generator startLexicalEnvironment(); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 7eb86a1143b..ce699630ba7 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -84,7 +84,7 @@ namespace ts { startLexicalEnvironment(); const statements: Statement[] = []; - const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); + const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, visitor); addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); addRange(statements, endLexicalEnvironment()); addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false); @@ -203,7 +203,7 @@ namespace ts { startLexicalEnvironment(); const statements: Statement[] = []; - const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); + const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, visitor); // Visit each statement of the module body. addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 1f601ae4b55..8f956c19adc 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -194,7 +194,7 @@ namespace ts { startLexicalEnvironment(); // Add any prologue directives. - const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict); + const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, visitSourceElement); // var __moduleName = context_1 && context_1.id; addNode(statements, diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index f2157e5a5c0..57de884da33 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -431,7 +431,7 @@ namespace ts { && (isExternalModule(node) || compilerOptions.isolatedModules)) { startLexicalEnvironment(); const statements: Statement[] = []; - const statementOffset = addPrologueDirectives(statements, node.statements); + const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ false, visitor); const externalHelpersModuleName = createUniqueName(externalHelpersModuleNameText); const externalHelpersModuleImport = createImportDeclaration( createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), @@ -933,7 +933,7 @@ namespace ts { if (ctor.body) { const statements = ctor.body.statements; // add prologue directives to the list (if any) - const index = addPrologueDirectives(result, statements); + const index = addPrologueDirectives(result, statements, /*ensureUseStrict*/ false, visitor); if (index === statements.length) { // list contains nothing but prologue directives (or empty) - exit return index; @@ -2235,7 +2235,7 @@ namespace ts { if (!isArrowFunction) { const statements: Statement[] = []; - const statementOffset = addPrologueDirectives(statements, (node.body).statements); + const statementOffset = addPrologueDirectives(statements, (node.body).statements, /*ensureUseStrict*/ false, visitor); statements.push( createReturn( createAwaiterHelper( diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e827265dd29..71e4a202b40 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3064,6 +3064,7 @@ namespace ts { Indented = 1 << 19, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter). AsyncFunctionBody = 1 << 20, ReuseTempVariableScope = 1 << 21, // Reuse the existing temp variable scope during emit. + CustomPrologue = 1 << 22, // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed). // SourceMap Specialization. // TODO(rbuckton): These should be removed once source maps are aligned with the old diff --git a/tests/baselines/reference/asyncFunctionDeclaration10_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration10_es5.errors.txt new file mode 100644 index 00000000000..dc814e9c887 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration10_es5.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,30): error TS1109: Expression expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS1138: Parameter declaration expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS2304: Cannot find name 'await'. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,38): error TS1005: ';' expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,39): error TS1128: Declaration or statement expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,53): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts (7 errors) ==== + async function foo(a = await => await): Promise { + ~~~~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. + ~~ +!!! error TS1109: Expression expected. + ~~~~~ +!!! error TS1138: Parameter declaration expected. + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration10_es5.js b/tests/baselines/reference/asyncFunctionDeclaration10_es5.js new file mode 100644 index 00000000000..05ff9daa9da --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration10_es5.js @@ -0,0 +1,7 @@ +//// [asyncFunctionDeclaration10_es5.ts] +async function foo(a = await => await): Promise { +} + +//// [asyncFunctionDeclaration10_es5.js] +await; +Promise < void > {}; diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es5.js b/tests/baselines/reference/asyncFunctionDeclaration11_es5.js new file mode 100644 index 00000000000..166f4c9c5ca --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es5.js @@ -0,0 +1,12 @@ +//// [asyncFunctionDeclaration11_es5.ts] +async function await(): Promise { +} + +//// [asyncFunctionDeclaration11_es5.js] +function await() { + return __awaiter(this, void 0, Promise, function () { + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es5.symbols b/tests/baselines/reference/asyncFunctionDeclaration11_es5.symbols new file mode 100644 index 00000000000..fc20251d567 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es5.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts === +async function await(): Promise { +>await : Symbol(await, Decl(asyncFunctionDeclaration11_es5.ts, 0, 0)) +>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es5.types b/tests/baselines/reference/asyncFunctionDeclaration11_es5.types new file mode 100644 index 00000000000..fdda0b0a084 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es5.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts === +async function await(): Promise { +>await : () => Promise +>Promise : Promise +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration12_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration12_es5.errors.txt new file mode 100644 index 00000000000..6468ec69716 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration12_es5.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts(1,24): error TS1005: '(' expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts(1,29): error TS1005: '=' expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts(1,33): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts(1,47): error TS1005: '=>' expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts (4 errors) ==== + var v = async function await(): Promise { } + ~~~~~ +!!! error TS1005: '(' expected. + ~ +!!! error TS1005: '=' expected. + ~~~~~~~~~~~~~ +!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value. + ~ +!!! error TS1005: '=>' expected. \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration12_es5.js b/tests/baselines/reference/asyncFunctionDeclaration12_es5.js new file mode 100644 index 00000000000..4123175b22c --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration12_es5.js @@ -0,0 +1,5 @@ +//// [asyncFunctionDeclaration12_es5.ts] +var v = async function await(): Promise { } + +//// [asyncFunctionDeclaration12_es5.js] +var v = , await = function () { }; diff --git a/tests/baselines/reference/asyncFunctionDeclaration13_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration13_es5.errors.txt new file mode 100644 index 00000000000..ce83aabc4be --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration13_es5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts(3,11): error TS2304: Cannot find name 'await'. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts (1 errors) ==== + async function foo(): Promise { + // Legal to use 'await' in a type context. + var v: await; + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration13_es5.js b/tests/baselines/reference/asyncFunctionDeclaration13_es5.js new file mode 100644 index 00000000000..2ab2f5c7b7b --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration13_es5.js @@ -0,0 +1,16 @@ +//// [asyncFunctionDeclaration13_es5.ts] +async function foo(): Promise { + // Legal to use 'await' in a type context. + var v: await; +} + + +//// [asyncFunctionDeclaration13_es5.js] +function foo() { + return __awaiter(this, void 0, Promise, function () { + var v; + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es5.js b/tests/baselines/reference/asyncFunctionDeclaration14_es5.js new file mode 100644 index 00000000000..d0e747e0f84 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es5.js @@ -0,0 +1,13 @@ +//// [asyncFunctionDeclaration14_es5.ts] +async function foo(): Promise { + return; +} + +//// [asyncFunctionDeclaration14_es5.js] +function foo() { + return __awaiter(this, void 0, Promise, function () { + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es5.symbols b/tests/baselines/reference/asyncFunctionDeclaration14_es5.symbols new file mode 100644 index 00000000000..1126618cfe7 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts === +async function foo(): Promise { +>foo : Symbol(foo, Decl(asyncFunctionDeclaration14_es5.ts, 0, 0)) +>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + + return; +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es5.types b/tests/baselines/reference/asyncFunctionDeclaration14_es5.types new file mode 100644 index 00000000000..5c2575c9cc9 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es5.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts === +async function foo(): Promise { +>foo : () => Promise +>Promise : Promise + + return; +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt new file mode 100644 index 00000000000..752feb261b3 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt @@ -0,0 +1,59 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(6,16): error TS1055: Type '{}' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(7,16): error TS1055: Type 'any' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,16): error TS1055: Type 'number' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. + Type 'Thenable' is not assignable to type 'PromiseLike'. + Types of property 'then' are incompatible. + Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. + Type 'void' is not assignable to type 'PromiseLike'. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts (8 errors) ==== + declare class Thenable { then(): void; } + declare let a: any; + declare let obj: { then: string; }; + declare let thenable: Thenable; + async function fn1() { } // valid: Promise + async function fn2(): { } { } // error + ~~~ +!!! error TS1055: Type '{}' is not a valid async function return type. + async function fn3(): any { } // error + ~~~ +!!! error TS1055: Type 'any' is not a valid async function return type. + async function fn4(): number { } // error + ~~~ +!!! error TS1055: Type 'number' is not a valid async function return type. + async function fn5(): PromiseLike { } // error + ~~~ +!!! error TS1055: Type 'PromiseLike' is not a valid async function return type. + async function fn6(): Thenable { } // error + ~~~ +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. + ~~~ +!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. +!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. +!!! error TS1055: Types of property 'then' are incompatible. +!!! error TS1055: Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. +!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. + async function fn7() { return; } // valid: Promise + async function fn8() { return 1; } // valid: Promise + async function fn9() { return null; } // valid: Promise + async function fn10() { return undefined; } // valid: Promise + async function fn11() { return a; } // valid: Promise + async function fn12() { return obj; } // valid: Promise<{ then: string; }> + async function fn13() { return thenable; } // error + ~~~~ +!!! error TS1059: Return expression in async function does not have a valid callable 'then' member. + async function fn14() { await 1; } // valid: Promise + async function fn15() { await null; } // valid: Promise + async function fn16() { await undefined; } // valid: Promise + async function fn17() { await a; } // valid: Promise + async function fn18() { await obj; } // valid: Promise + async function fn19() { await thenable; } // error + ~~~~~~~~~~~~~~ +!!! error TS1058: Operand for 'await' does not have a valid callable 'then' member. + \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es5.js b/tests/baselines/reference/asyncFunctionDeclaration15_es5.js new file mode 100644 index 00000000000..47e1fe45c80 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es5.js @@ -0,0 +1,152 @@ +//// [asyncFunctionDeclaration15_es5.ts] +declare class Thenable { then(): void; } +declare let a: any; +declare let obj: { then: string; }; +declare let thenable: Thenable; +async function fn1() { } // valid: Promise +async function fn2(): { } { } // error +async function fn3(): any { } // error +async function fn4(): number { } // error +async function fn5(): PromiseLike { } // error +async function fn6(): Thenable { } // error +async function fn7() { return; } // valid: Promise +async function fn8() { return 1; } // valid: Promise +async function fn9() { return null; } // valid: Promise +async function fn10() { return undefined; } // valid: Promise +async function fn11() { return a; } // valid: Promise +async function fn12() { return obj; } // valid: Promise<{ then: string; }> +async function fn13() { return thenable; } // error +async function fn14() { await 1; } // valid: Promise +async function fn15() { await null; } // valid: Promise +async function fn16() { await undefined; } // valid: Promise +async function fn17() { await a; } // valid: Promise +async function fn18() { await obj; } // valid: Promise +async function fn19() { await thenable; } // error + + +//// [asyncFunctionDeclaration15_es5.js] +function fn1() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // valid: Promise +function fn2() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // error +function fn3() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // error +function fn4() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // error +function fn5() { + return __awaiter(this, void 0, PromiseLike, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // error +function fn6() { + return __awaiter(this, void 0, Thenable, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // error +function fn7() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/]; + }); }); +} // valid: Promise +function fn8() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, 1]; + }); }); +} // valid: Promise +function fn9() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, null]; + }); }); +} // valid: Promise +function fn10() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, undefined]; + }); }); +} // valid: Promise +function fn11() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, a]; + }); }); +} // valid: Promise +function fn12() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, obj]; + }); }); +} // valid: Promise<{ then: string; }> +function fn13() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + return [2 /*return*/, thenable]; + }); }); +} // error +function fn14() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // valid: Promise +function fn15() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, null]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // valid: Promise +function fn16() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, undefined]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // valid: Promise +function fn17() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, a]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // valid: Promise +function fn18() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, obj]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // valid: Promise +function fn19() { + return __awaiter(this, void 0, void 0, function () { return __generator(function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, thenable]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); }); +} // error diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es5.js b/tests/baselines/reference/asyncFunctionDeclaration1_es5.js new file mode 100644 index 00000000000..3f020ec6ece --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es5.js @@ -0,0 +1,12 @@ +//// [asyncFunctionDeclaration1_es5.ts] +async function foo(): Promise { +} + +//// [asyncFunctionDeclaration1_es5.js] +function foo() { + return __awaiter(this, void 0, Promise, function () { + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es5.symbols b/tests/baselines/reference/asyncFunctionDeclaration1_es5.symbols new file mode 100644 index 00000000000..ba7616ac293 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es5.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts === +async function foo(): Promise { +>foo : Symbol(foo, Decl(asyncFunctionDeclaration1_es5.ts, 0, 0)) +>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es5.types b/tests/baselines/reference/asyncFunctionDeclaration1_es5.types new file mode 100644 index 00000000000..b1336715bfb --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es5.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts === +async function foo(): Promise { +>foo : () => Promise +>Promise : Promise +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration2_es5.js b/tests/baselines/reference/asyncFunctionDeclaration2_es5.js new file mode 100644 index 00000000000..427fb2b1bf9 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration2_es5.js @@ -0,0 +1,7 @@ +//// [asyncFunctionDeclaration2_es5.ts] +function f(await) { +} + +//// [asyncFunctionDeclaration2_es5.js] +function f(await) { +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration2_es5.symbols b/tests/baselines/reference/asyncFunctionDeclaration2_es5.symbols new file mode 100644 index 00000000000..78f4da3c25e --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration2_es5.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts === +function f(await) { +>f : Symbol(f, Decl(asyncFunctionDeclaration2_es5.ts, 0, 0)) +>await : Symbol(await, Decl(asyncFunctionDeclaration2_es5.ts, 0, 11)) +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration2_es5.types b/tests/baselines/reference/asyncFunctionDeclaration2_es5.types new file mode 100644 index 00000000000..7add17dd5d6 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration2_es5.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts === +function f(await) { +>f : (await: any) => void +>await : any +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration3_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration3_es5.errors.txt new file mode 100644 index 00000000000..1192e396a64 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration3_es5.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration3_es5.ts(1,20): error TS2372: Parameter 'await' cannot be referenced in its initializer. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration3_es5.ts (1 errors) ==== + function f(await = await) { + ~~~~~ +!!! error TS2372: Parameter 'await' cannot be referenced in its initializer. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration3_es5.js b/tests/baselines/reference/asyncFunctionDeclaration3_es5.js new file mode 100644 index 00000000000..0bcc99b6bc7 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration3_es5.js @@ -0,0 +1,8 @@ +//// [asyncFunctionDeclaration3_es5.ts] +function f(await = await) { +} + +//// [asyncFunctionDeclaration3_es5.js] +function f(await) { + if (await === void 0) { await = await; } +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration4_es5.js b/tests/baselines/reference/asyncFunctionDeclaration4_es5.js new file mode 100644 index 00000000000..8b6f58b84ab --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration4_es5.js @@ -0,0 +1,7 @@ +//// [asyncFunctionDeclaration4_es5.ts] +function await() { +} + +//// [asyncFunctionDeclaration4_es5.js] +function await() { +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration4_es5.symbols b/tests/baselines/reference/asyncFunctionDeclaration4_es5.symbols new file mode 100644 index 00000000000..0690c333095 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration4_es5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts === +function await() { +>await : Symbol(await, Decl(asyncFunctionDeclaration4_es5.ts, 0, 0)) +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration4_es5.types b/tests/baselines/reference/asyncFunctionDeclaration4_es5.types new file mode 100644 index 00000000000..8dac2282032 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration4_es5.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts === +function await() { +>await : () => void +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration5_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration5_es5.errors.txt new file mode 100644 index 00000000000..3060c2c836b --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration5_es5.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts(1,20): error TS1138: Parameter declaration expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts(1,20): error TS2304: Cannot find name 'await'. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts(1,25): error TS1005: ';' expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts(1,26): error TS1128: Declaration or statement expected. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts(1,40): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts (5 errors) ==== + async function foo(await): Promise { + ~~~~~ +!!! error TS1138: Parameter declaration expected. + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration5_es5.js b/tests/baselines/reference/asyncFunctionDeclaration5_es5.js new file mode 100644 index 00000000000..22c18ff6ad4 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration5_es5.js @@ -0,0 +1,7 @@ +//// [asyncFunctionDeclaration5_es5.ts] +async function foo(await): Promise { +} + +//// [asyncFunctionDeclaration5_es5.js] +await; +Promise < void > {}; diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration6_es5.errors.txt new file mode 100644 index 00000000000..d8cf82fbc28 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts(1,29): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts (2 errors) ==== + async function foo(a = await): Promise { + ~~~~~ +!!! error TS2524: 'await' expressions cannot be used in a parameter initializer. + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es5.js b/tests/baselines/reference/asyncFunctionDeclaration6_es5.js new file mode 100644 index 00000000000..2ee26f29e62 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es5.js @@ -0,0 +1,13 @@ +//// [asyncFunctionDeclaration6_es5.ts] +async function foo(a = await): Promise { +} + +//// [asyncFunctionDeclaration6_es5.js] +function foo(a) { + if (a === void 0) { a = yield ; } + return __awaiter(this, void 0, Promise, function () { + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration7_es5.errors.txt new file mode 100644 index 00000000000..48984724e4c --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts(3,26): error TS2524: 'await' expressions cannot be used in a parameter initializer. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts(3,31): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts (2 errors) ==== + async function bar(): Promise { + // 'await' here is an identifier, and not a yield expression. + async function foo(a = await): Promise { + ~~~~~ +!!! error TS2524: 'await' expressions cannot be used in a parameter initializer. + ~ +!!! error TS1109: Expression expected. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es5.js b/tests/baselines/reference/asyncFunctionDeclaration7_es5.js new file mode 100644 index 00000000000..7bcf3be59ad --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es5.js @@ -0,0 +1,24 @@ +//// [asyncFunctionDeclaration7_es5.ts] +async function bar(): Promise { + // 'await' here is an identifier, and not a yield expression. + async function foo(a = await): Promise { + } +} + +//// [asyncFunctionDeclaration7_es5.js] +function bar() { + return __awaiter(this, void 0, Promise, function () { + // 'await' here is an identifier, and not a yield expression. + function foo(a) { + if (a === void 0) { a = yield ; } + return __awaiter(this, void 0, Promise, function () { + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); + } + return __generator(function (_a) { + return [2 /*return*/]; + }); + }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration8_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration8_es5.errors.txt new file mode 100644 index 00000000000..7f2a4cc650b --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration8_es5.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts(1,12): error TS2304: Cannot find name 'await'. +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts(1,20): error TS2304: Cannot find name 'foo'. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts (2 errors) ==== + var v = { [await]: foo } + ~~~~~ +!!! error TS2304: Cannot find name 'await'. + ~~~ +!!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration8_es5.js b/tests/baselines/reference/asyncFunctionDeclaration8_es5.js new file mode 100644 index 00000000000..3e518481178 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration8_es5.js @@ -0,0 +1,6 @@ +//// [asyncFunctionDeclaration8_es5.ts] +var v = { [await]: foo } + +//// [asyncFunctionDeclaration8_es5.js] +var v = (_a = {}, _a[await] = foo, _a); +var _a; diff --git a/tests/baselines/reference/asyncFunctionDeclaration9_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration9_es5.errors.txt new file mode 100644 index 00000000000..8eed8dade45 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration9_es5.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration9_es5.ts(2,19): error TS1109: Expression expected. + + +==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration9_es5.ts (1 errors) ==== + async function foo(): Promise { + var v = { [await]: foo } + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration9_es5.js b/tests/baselines/reference/asyncFunctionDeclaration9_es5.js new file mode 100644 index 00000000000..2da28f95cff --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclaration9_es5.js @@ -0,0 +1,21 @@ +//// [asyncFunctionDeclaration9_es5.ts] +async function foo(): Promise { + var v = { [await]: foo } +} + +//// [asyncFunctionDeclaration9_es5.js] +function foo() { + return __awaiter(this, void 0, Promise, function () { + var v, _a; + return __generator(function (_b) { + switch (_b.label) { + case 0: + _a = {}; + return [4 /*yield*/, ]; + case 1: + v = (_a[_b.sent()] = foo, _a); + return [2 /*return*/]; + } + }); + }); +} diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts new file mode 100644 index 00000000000..f1cb80162bd --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(a = await => await): Promise { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts new file mode 100644 index 00000000000..8edf36f9a2f --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function await(): Promise { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts new file mode 100644 index 00000000000..4601fba6ea2 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration12_es5.ts @@ -0,0 +1,4 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +var v = async function await(): Promise { } \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts new file mode 100644 index 00000000000..2b70bc4c641 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts @@ -0,0 +1,7 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(): Promise { + // Legal to use 'await' in a type context. + var v: await; +} diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts new file mode 100644 index 00000000000..eedfd438b7c --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(): Promise { + return; +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts new file mode 100644 index 00000000000..373677bf58f --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts @@ -0,0 +1,26 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +declare class Thenable { then(): void; } +declare let a: any; +declare let obj: { then: string; }; +declare let thenable: Thenable; +async function fn1() { } // valid: Promise +async function fn2(): { } { } // error +async function fn3(): any { } // error +async function fn4(): number { } // error +async function fn5(): PromiseLike { } // error +async function fn6(): Thenable { } // error +async function fn7() { return; } // valid: Promise +async function fn8() { return 1; } // valid: Promise +async function fn9() { return null; } // valid: Promise +async function fn10() { return undefined; } // valid: Promise +async function fn11() { return a; } // valid: Promise +async function fn12() { return obj; } // valid: Promise<{ then: string; }> +async function fn13() { return thenable; } // error +async function fn14() { await 1; } // valid: Promise +async function fn15() { await null; } // valid: Promise +async function fn16() { await undefined; } // valid: Promise +async function fn17() { await a; } // valid: Promise +async function fn18() { await obj; } // valid: Promise +async function fn19() { await thenable; } // error diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts new file mode 100644 index 00000000000..1448b335992 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(): Promise { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts new file mode 100644 index 00000000000..b1e337938e0 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +function f(await) { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration3_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration3_es5.ts new file mode 100644 index 00000000000..810d7bc7e05 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration3_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +function f(await = await) { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts new file mode 100644 index 00000000000..40bd69d592f --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +function await() { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts new file mode 100644 index 00000000000..3c71741da14 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration5_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(await): Promise { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts new file mode 100644 index 00000000000..34ff3b3c4c5 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration6_es5.ts @@ -0,0 +1,5 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(a = await): Promise { +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts new file mode 100644 index 00000000000..53d7bc5edb5 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration7_es5.ts @@ -0,0 +1,8 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function bar(): Promise { + // 'await' here is an identifier, and not a yield expression. + async function foo(a = await): Promise { + } +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts new file mode 100644 index 00000000000..27db170b080 --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts @@ -0,0 +1,4 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +var v = { [await]: foo } \ No newline at end of file diff --git a/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration9_es5.ts b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration9_es5.ts new file mode 100644 index 00000000000..7a1130f8abf --- /dev/null +++ b/tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration9_es5.ts @@ -0,0 +1,6 @@ +// @target: ES5 +// @lib: es5,es2015.promise +// @noEmitHelpers: true +async function foo(): Promise { + var v = { [await]: foo } +} \ No newline at end of file