Merge branch 'transforms' into transforms-visitPerf

This commit is contained in:
Ron Buckton
2016-07-20 12:19:56 -07:00
406 changed files with 20321 additions and 461 deletions
+2 -1
View File
@@ -50,6 +50,7 @@ var compilerSources = [
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es7.ts",
"transformers/generators.ts",
"transformers/es6.ts",
"transformer.ts",
"sourcemap.ts",
@@ -82,6 +83,7 @@ var servicesSources = [
"transformers/module/module.ts",
"transformers/jsx.ts",
"transformers/es7.ts",
"transformers/generators.ts",
"transformers/es6.ts",
"transformer.ts",
"sourcemap.ts",
@@ -747,7 +749,6 @@ function writeTestConfigFile(tests, light, taskConfigsFolder, workerCount, stack
taskConfigsFolder: taskConfigsFolder,
stackTraceLimit: stackTraceLimit
});
console.log('Running tests with config: ' + testConfigContents);
fs.writeFileSync('test.config', testConfigContents);
}
+47 -12
View File
@@ -1638,7 +1638,7 @@ namespace ts {
}
}
function checkStrictModeNumericLiteral(node: LiteralExpression) {
function checkStrictModeNumericLiteral(node: NumericLiteral) {
if (inStrictMode && node.isOctalLiteral) {
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
}
@@ -1786,7 +1786,7 @@ namespace ts {
case SyntaxKind.DeleteExpression:
return checkStrictModeDeleteExpression(<DeleteExpression>node);
case SyntaxKind.NumericLiteral:
return checkStrictModeNumericLiteral(<LiteralExpression>node);
return checkStrictModeNumericLiteral(<NumericLiteral>node);
case SyntaxKind.PostfixUnaryExpression:
return checkStrictModePostfixUnaryExpression(<PostfixUnaryExpression>node);
case SyntaxKind.PrefixUnaryExpression:
@@ -2568,6 +2568,7 @@ namespace ts {
const modifierFlags = getModifierFlags(node);
const body = node.body;
const typeParameters = node.typeParameters;
const asteriskToken = node.asteriskToken;
// A MethodDeclaration is TypeScript syntax if it is either async, abstract, overloaded,
// generic, or has a decorator.
@@ -2578,6 +2579,11 @@ namespace ts {
transformFlags |= TransformFlags.AssertTypeScript;
}
// Currently, we only support generators that were originally async function bodies.
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
transformFlags |= TransformFlags.AssertGenerator;
}
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
return transformFlags & ~TransformFlags.MethodOrAccessorExcludes;
}
@@ -2625,7 +2631,7 @@ namespace ts {
transformFlags = TransformFlags.AssertTypeScript;
}
else {
transformFlags = subtreeFlags;
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
if (modifierFlags & ModifierFlags.Export) {
@@ -2637,12 +2643,21 @@ namespace ts {
transformFlags |= TransformFlags.AssertTypeScript;
}
// If a FunctionDeclaration has an asterisk token, is exported, or its
// subtree has marked the container as needing to capture the lexical `this`,
// then this node is ES6 syntax.
if (asteriskToken || (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask)) {
// If a FunctionDeclaration's subtree has marked the container as needing to capture the
// lexical this, or the function contains parameters with initializers, then this node is
// ES6 syntax.
if (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask) {
transformFlags |= TransformFlags.AssertES6;
}
// If a FunctionDeclaration is generator function and is the body of a
// transformed async function, then this node can be transformed to a
// down-level generator.
// Currently we do not support transforming any other generator fucntions
// down level.
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
transformFlags |= TransformFlags.AssertGenerator;
}
}
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
@@ -2659,12 +2674,22 @@ namespace ts {
transformFlags |= TransformFlags.AssertTypeScript;
}
// If a FunctionExpression contains an asterisk token, or its subtree has marked the container
// as needing to capture the lexical this, then this node is ES6 syntax.
if (asteriskToken || (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask)) {
// If a FunctionExpression's subtree has marked the container as needing to capture the
// lexical this, or the function contains parameters with initializers, then this node is
// ES6 syntax.
if (subtreeFlags & TransformFlags.ES6FunctionSyntaxMask) {
transformFlags |= TransformFlags.AssertES6;
}
// If a FunctionExpression is generator function and is the body of a
// transformed async function, then this node can be transformed to a
// down-level generator.
// Currently we do not support transforming any other generator fucntions
// down level.
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
transformFlags |= TransformFlags.AssertGenerator;
}
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
return transformFlags & ~TransformFlags.FunctionExcludes;
}
@@ -2794,7 +2819,7 @@ namespace ts {
}
function computeVariableDeclarationList(node: VariableDeclarationList, subtreeFlags: TransformFlags) {
let transformFlags = subtreeFlags;
let transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;
if (subtreeFlags & TransformFlags.ContainsBindingPattern) {
transformFlags |= TransformFlags.AssertES6;
@@ -2859,11 +2884,15 @@ namespace ts {
case SyntaxKind.TaggedTemplateExpression:
case SyntaxKind.ShorthandPropertyAssignment:
case SyntaxKind.ForOfStatement:
case SyntaxKind.YieldExpression:
// These nodes are ES6 syntax.
transformFlags |= TransformFlags.AssertES6;
break;
case SyntaxKind.YieldExpression:
// This node is ES6 syntax.
transformFlags |= TransformFlags.AssertES6 | TransformFlags.ContainsYield;
break;
case SyntaxKind.AnyKeyword:
case SyntaxKind.NumberKeyword:
case SyntaxKind.NeverKeyword:
@@ -2985,6 +3014,12 @@ namespace ts {
}
break;
case SyntaxKind.ReturnStatement:
case SyntaxKind.ContinueStatement:
case SyntaxKind.BreakStatement:
transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion;
break;
}
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
+29 -20
View File
@@ -149,6 +149,7 @@ namespace ts {
let getGlobalESSymbolConstructorSymbol: () => Symbol;
let getGlobalPromiseConstructorSymbol: () => Symbol;
let tryGetGlobalPromiseConstructorSymbol: () => Symbol;
let globalObjectType: ObjectType;
let globalFunctionType: ObjectType;
@@ -8337,10 +8338,13 @@ namespace ts {
// can explicitly bound arguments objects
if (symbol === argumentsSymbol) {
const container = getContainingFunction(node);
if (container.kind === SyntaxKind.ArrowFunction) {
if (languageVersion < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (container.kind === SyntaxKind.ArrowFunction) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
}
else if (hasModifier(container, ModifierFlags.Async)) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_async_function_or_method_in_ES3_and_ES5_Consider_using_a_standard_function_or_method);
}
}
if (node.flags & NodeFlags.AwaitContext) {
@@ -12991,7 +12995,7 @@ namespace ts {
return type;
}
function checkNumericLiteral(node: LiteralExpression): Type {
function checkNumericLiteral(node: NumericLiteral): Type {
// Grammar checking
checkGrammarNumericLiteral(node);
return numberType;
@@ -13011,7 +13015,7 @@ namespace ts {
case SyntaxKind.FalseKeyword:
return booleanType;
case SyntaxKind.NumericLiteral:
return checkNumericLiteral(<LiteralExpression>node);
return checkNumericLiteral(<NumericLiteral>node);
case SyntaxKind.TemplateExpression:
return checkTemplateExpression(<TemplateExpression>node);
case SyntaxKind.StringLiteral:
@@ -14194,7 +14198,7 @@ namespace ts {
* @param returnType The return type of a FunctionLikeDeclaration
* @param location The node on which to report the error.
*/
function checkCorrectPromiseType(returnType: Type, location: Node) {
function checkCorrectPromiseType(returnType: Type, location: Node, diagnostic: DiagnosticMessage, typeName?: string) {
if (returnType === unknownType) {
// The return type already had some other error, so we ignore and return
// the unknown type.
@@ -14213,7 +14217,7 @@ namespace ts {
// The promise type was not a valid type reference to the global promise type, so we
// report an error and return the unknown type.
error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type);
error(location, diagnostic, typeName);
return unknownType;
}
@@ -14233,7 +14237,7 @@ namespace ts {
function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type {
if (languageVersion >= ScriptTarget.ES6) {
const returnType = getTypeFromTypeNode(node.type);
return checkCorrectPromiseType(returnType, node.type);
return checkCorrectPromiseType(returnType, node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type);
}
const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
@@ -14279,11 +14283,11 @@ namespace ts {
const promiseConstructor = getNodeLinks(node.type).resolvedSymbol;
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
// try to fall back to global promise type.
const typeName = promiseConstructor
? symbolToString(promiseConstructor)
: typeToString(promiseType);
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
return unknownType;
return checkCorrectPromiseType(promiseType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
}
// If the Promise constructor, resolved locally, is an alias symbol we should mark it as referenced.
@@ -14291,7 +14295,7 @@ namespace ts {
// Validate the promise constructor type.
const promiseConstructorType = getTypeOfSymbol(promiseConstructor);
if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
return unknownType;
}
@@ -16272,7 +16276,7 @@ namespace ts {
}
return undefined;
case SyntaxKind.NumericLiteral:
return +(<LiteralExpression>e).text;
return +(<NumericLiteral>e).text;
case SyntaxKind.ParenthesizedExpression:
return evalConstant((<ParenthesizedExpression>e).expression);
case SyntaxKind.Identifier:
@@ -17491,7 +17495,7 @@ namespace ts {
if (objectType === unknownType) return undefined;
const apparentType = getApparentType(objectType);
if (apparentType === unknownType) return undefined;
return getPropertyOfType(apparentType, (<LiteralExpression>node).text);
return getPropertyOfType(apparentType, (<NumericLiteral>node).text);
}
break;
}
@@ -17976,6 +17980,11 @@ namespace ts {
function getTypeReferenceSerializationKind(typeName: EntityName, location?: Node): TypeReferenceSerializationKind {
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);
const globalPromiseSymbol = tryGetGlobalPromiseConstructorSymbol();
if (globalPromiseSymbol && valueSymbol === globalPromiseSymbol) {
return TypeReferenceSerializationKind.Promise;
}
const constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
if (constructorType && isConstructorType(constructorType)) {
return TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
@@ -17994,8 +18003,8 @@ namespace ts {
else if (type.flags & TypeFlags.Any) {
return TypeReferenceSerializationKind.ObjectType;
}
else if (isTypeOfKind(type, TypeFlags.Void)) {
return TypeReferenceSerializationKind.VoidType;
else if (isTypeOfKind(type, TypeFlags.Void | TypeFlags.Nullable | TypeFlags.Never)) {
return TypeReferenceSerializationKind.VoidNullableOrNeverType;
}
else if (isTypeOfKind(type, TypeFlags.Boolean)) {
return TypeReferenceSerializationKind.BooleanType;
@@ -18293,6 +18302,7 @@ namespace ts {
getGlobalPromiseLikeType = memoize(() => getGlobalType("PromiseLike", /*arity*/ 1));
getInstantiatedGlobalPromiseLikeType = memoize(createInstantiatedPromiseLikeType);
getGlobalPromiseConstructorSymbol = memoize(() => getGlobalValueSymbol("Promise"));
tryGetGlobalPromiseConstructorSymbol = memoize(() => getGlobalSymbol("Promise", SymbolFlags.Value, /*diagnostic*/ undefined) && getGlobalPromiseConstructorSymbol());
getGlobalPromiseConstructorLikeType = memoize(() => getGlobalType("PromiseConstructorLike"));
getGlobalThenableType = memoize(createThenableType);
@@ -18348,6 +18358,9 @@ namespace ts {
}
if (requestedExternalEmitHelpers & NodeFlags.HasAsyncFunctions) {
verifyHelperSymbol(exports, "__awaiter", SymbolFlags.Value);
if (languageVersion < ScriptTarget.ES6) {
verifyHelperSymbol(exports, "__generator", SymbolFlags.Value);
}
}
}
}
@@ -18654,10 +18667,6 @@ namespace ts {
}
function checkGrammarAsyncModifier(node: Node, asyncModifier: Node): boolean {
if (languageVersion < ScriptTarget.ES6) {
return grammarErrorOnNode(asyncModifier, Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_2015_or_higher);
}
switch (node.kind) {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.FunctionDeclaration:
@@ -18967,7 +18976,7 @@ namespace ts {
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
checkGrammarForInvalidQuestionMark(prop, (<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
if (name.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumericLiteral(<LiteralExpression>name);
checkGrammarNumericLiteral(<NumericLiteral>name);
}
currentKind = Property;
}
@@ -19489,7 +19498,7 @@ namespace ts {
}
}
function checkGrammarNumericLiteral(node: LiteralExpression): boolean {
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
// Grammar checking
if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
+15 -12
View File
@@ -426,13 +426,14 @@ namespace ts {
return ~low;
}
export function reduceLeft<T, U>(array: T[], f: (memo: U, value: T, i: number) => U, initial: U): U;
export function reduceLeft<T, U>(array: T[], f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U;
export function reduceLeft<T>(array: T[], f: (memo: T, value: T, i: number) => T): T;
export function reduceLeft<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T): T {
if (array) {
const count = array.length;
if (count > 0) {
let pos = 0;
export function reduceLeft<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T {
if (array && array.length > 0) {
const size = array.length;
if (size > 0) {
let pos = start === undefined || start < 0 ? 0 : start;
const end = count === undefined || pos + count > size - 1 ? size - 1 : pos + count;
let result: T;
if (arguments.length <= 2) {
result = array[pos];
@@ -441,7 +442,7 @@ namespace ts {
else {
result = initial;
}
while (pos < count) {
while (pos <= end) {
result = f(result, array[pos], pos);
pos++;
}
@@ -451,12 +452,14 @@ namespace ts {
return initial;
}
export function reduceRight<T, U>(array: T[], f: (memo: U, value: T, i: number) => U, initial: U): U;
export function reduceRight<T, U>(array: T[], f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U;
export function reduceRight<T>(array: T[], f: (memo: T, value: T, i: number) => T): T;
export function reduceRight<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T): T {
export function reduceRight<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T {
if (array) {
let pos = array.length - 1;
if (pos >= 0) {
const size = array.length;
if (size > 0) {
let pos = start === undefined || start > size - 1 ? size - 1 : start;
const end = count === undefined || pos - count < 0 ? 0 : pos - count;
let result: T;
if (arguments.length <= 2) {
result = array[pos];
@@ -465,7 +468,7 @@ namespace ts {
else {
result = initial;
}
while (pos >= 0) {
while (pos >= end) {
result = f(result, array[pos], pos);
pos--;
}
+1 -5
View File
@@ -827,10 +827,6 @@
"category": "Error",
"code": 1308
},
"Async functions are only available when targeting ECMAScript 2015 or higher.": {
"category": "Error",
"code": 1311
},
"'=' can only be used in an object literal property inside a destructuring assignment.": {
"category": "Error",
"code": 1312
@@ -1703,7 +1699,7 @@
"category": "Error",
"code": 2521
},
"The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression.": {
"The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method.": {
"category": "Error",
"code": 2522
},
+64 -6
View File
@@ -71,6 +71,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};`;
const generatorHelper = `
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f;
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (1) {
if (_.done) switch (op[0]) {
case 0: return { value: void 0, done: true };
case 1: case 6: throw op[1];
case 2: return { value: op[1], done: true };
}
try {
switch (f = 1, op[0]) {
case 0: case 1: sent = op; break;
case 4: return _.label++, { value: op[1], done: false };
case 7: op = _.stack.pop(), _.trys.pop(); continue;
default:
var r = _.trys.length > 0 && _.trys[_.trys.length - 1];
if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; }
if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; }
if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; }
if (r[2]) { _.stack.pop(); }
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) { op = [6, e]; }
finally { f = 0, sent = void 0; }
}
}
return {
next: function (v) { return step([0, v]); },
"throw": function (v) { return step([1, v]); },
"return": function (v) { return step([2, v]); }
};
};`;
// emit output for the __export helper function
const exportStarHelper = `
function __export(m) {
@@ -685,6 +724,8 @@ const _super = (function (geti, seti) {
switch (kind) {
// Literals
case SyntaxKind.NumericLiteral:
return emitNumericLiteral(<NumericLiteral>node);
case SyntaxKind.StringLiteral:
case SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
@@ -773,6 +814,13 @@ const _super = (function (geti, seti) {
//
// SyntaxKind.NumericLiteral
function emitNumericLiteral(node: NumericLiteral) {
emitLiteral(node);
if (node.trailingComment) {
write(` /*${node.trailingComment}*/`);
}
}
// SyntaxKind.StringLiteral
// SyntaxKind.RegularExpressionLiteral
// SyntaxKind.NoSubstitutionTemplateLiteral
@@ -1563,15 +1611,21 @@ const _super = (function (geti, seti) {
increaseIndent();
}
const savedTempFlags = tempFlags;
tempFlags = 0;
emitSignatureHead(node);
emitBlockFunctionBody(node, body);
if (node.emitFlags & NodeEmitFlags.ReuseTempVariableScope) {
emitSignatureHead(node);
emitBlockFunctionBody(node, body);
}
else {
const savedTempFlags = tempFlags;
tempFlags = 0;
emitSignatureHead(node);
emitBlockFunctionBody(node, body);
tempFlags = savedTempFlags;
}
if (indentedFlag) {
decreaseIndent();
}
tempFlags = savedTempFlags;
}
else {
emitSignatureHead(node);
@@ -2157,6 +2211,10 @@ const _super = (function (geti, seti) {
if (!awaiterEmitted && node.flags & NodeFlags.HasAsyncFunctions) {
writeLines(awaiterHelper);
if (languageVersion < ScriptTarget.ES6) {
writeLines(generatorHelper);
}
awaiterEmitted = true;
helpersEmitted = true;
}
+187 -29
View File
@@ -104,7 +104,7 @@ namespace ts {
export function createLiteral(textSource: StringLiteral | Identifier, location?: TextRange): StringLiteral;
export function createLiteral(value: string, location?: TextRange): StringLiteral;
export function createLiteral(value: number, location?: TextRange): LiteralExpression;
export function createLiteral(value: number, location?: TextRange): NumericLiteral;
export function createLiteral(value: string | number | boolean, location?: TextRange): PrimaryExpression;
export function createLiteral(value: string | number | boolean | StringLiteral | Identifier, location?: TextRange): PrimaryExpression {
if (typeof value === "number") {
@@ -141,7 +141,7 @@ namespace ts {
return node;
}
export function createTempVariable(recordTempVariable: (node: Identifier) => void, location?: TextRange): Identifier {
export function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, location?: TextRange): Identifier {
const name = <Identifier>createNode(SyntaxKind.Identifier, location);
name.text = "";
name.originalKeywordKind = SyntaxKind.Unknown;
@@ -430,8 +430,9 @@ namespace ts {
const node = <ArrayLiteralExpression>createNode(SyntaxKind.ArrayLiteralExpression, location);
node.elements = parenthesizeListElements(createNodeArray(elements));
if (multiLine) {
node.multiLine = multiLine;
node.multiLine = true;
}
return node;
}
@@ -446,7 +447,7 @@ namespace ts {
const node = <ObjectLiteralExpression>createNode(SyntaxKind.ObjectLiteralExpression, location);
node.properties = createNodeArray(properties);
if (multiLine) {
node.multiLine = multiLine;
node.multiLine = true;
}
return node;
}
@@ -996,6 +997,22 @@ namespace ts {
return node;
}
export function createTryCatchFinally(tryBlock: Block, catchClause: CatchClause, finallyBlock: Block, location?: TextRange) {
const node = <TryStatement>createNode(SyntaxKind.TryStatement, location);
node.tryBlock = tryBlock;
node.catchClause = catchClause;
node.finallyBlock = finallyBlock;
return node;
}
export function createTryCatch(tryBlock: Block, catchClause: CatchClause, location?: TextRange) {
return createTryCatchFinally(tryBlock, catchClause, /*finallyBlock*/ undefined, location);
}
export function createTryFinally(tryBlock: Block, finallyBlock: Block, location?: TextRange) {
return createTryCatchFinally(tryBlock, /*catchClause*/ undefined, finallyBlock, location);
}
export function updateReturn(node: ReturnStatement, expression: Expression) {
if (node.expression !== expression) {
return updateNode(createReturn(expression, /*location*/ node), node);
@@ -1391,13 +1408,13 @@ namespace ts {
return node;
}
export function createMemberAccessForPropertyName(target: Expression, memberName: PropertyName, setNodeEmitFlags: (node: Node, flags: NodeEmitFlags) => void, location?: TextRange): MemberExpression {
export function createMemberAccessForPropertyName(target: Expression, memberName: PropertyName, location?: TextRange): MemberExpression {
if (isComputedPropertyName(memberName)) {
return createElementAccess(target, memberName.expression, location);
}
else {
const expression = isIdentifier(memberName) ? createPropertyAccess(target, memberName, location) : createElementAccess(target, memberName, location);
setNodeEmitFlags(expression, expression.emitFlags ? NodeEmitFlags.NoNestedSourceMaps | expression.emitFlags : NodeEmitFlags.NoNestedSourceMaps);
expression.emitFlags |= NodeEmitFlags.NoNestedSourceMaps;
return expression;
}
}
@@ -1564,6 +1581,18 @@ namespace ts {
}
export function createAwaiterHelper(externalHelpersModuleName: Identifier | undefined, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression, body: Block) {
const generatorFunc = createFunctionExpression(
createNode(SyntaxKind.AsteriskToken),
/*name*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ [],
/*type*/ undefined,
body
);
// Mark this node as originally an async function
generatorFunc.emitFlags |= NodeEmitFlags.AsyncFunctionBody;
return createCall(
createHelperName(externalHelpersModuleName, "__awaiter"),
/*typeArguments*/ undefined,
@@ -1571,14 +1600,7 @@ namespace ts {
createThis(),
hasLexicalArguments ? createIdentifier("arguments") : createVoidZero(),
promiseConstructor ? createExpressionFromEntityName(promiseConstructor) : createVoidZero(),
createFunctionExpression(
createNode(SyntaxKind.AsteriskToken),
/*name*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ [],
/*type*/ undefined,
body
)
generatorFunc
]
);
}
@@ -1776,19 +1798,29 @@ namespace ts {
thisArg: Expression;
}
function shouldBeCapturedInTempVariable(node: Expression): boolean {
switch (skipParentheses(node).kind) {
function shouldBeCapturedInTempVariable(node: Expression, cacheIdentifiers: boolean): boolean {
const target = skipParentheses(node);
switch (target.kind) {
case SyntaxKind.Identifier:
return cacheIdentifiers;
case SyntaxKind.ThisKeyword:
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
return false;
case SyntaxKind.ArrayLiteralExpression:
const elements = (<ArrayLiteralExpression>target).elements;
if (elements.length === 0) {
return false;
}
return true;
case SyntaxKind.ObjectLiteralExpression:
return (<ObjectLiteralExpression>target).properties.length > 0;
default:
return true;
}
}
export function createCallBinding(expression: Expression, recordTempVariable: (temp: Identifier) => void, languageVersion?: ScriptTarget): CallBinding {
export function createCallBinding(expression: Expression, recordTempVariable: (temp: Identifier) => void, languageVersion?: ScriptTarget, cacheIdentifiers?: boolean): CallBinding {
const callee = skipOuterExpressions(expression, OuterExpressionKinds.All);
let thisArg: Expression;
let target: LeftHandSideExpression;
@@ -1803,7 +1835,7 @@ namespace ts {
else {
switch (callee.kind) {
case SyntaxKind.PropertyAccessExpression: {
if (shouldBeCapturedInTempVariable((<PropertyAccessExpression>callee).expression)) {
if (shouldBeCapturedInTempVariable((<PropertyAccessExpression>callee).expression, cacheIdentifiers)) {
// for `a.b()` target is `(_a = a).b` and thisArg is `_a`
thisArg = createTempVariable(recordTempVariable);
target = createPropertyAccess(
@@ -1824,7 +1856,7 @@ namespace ts {
}
case SyntaxKind.ElementAccessExpression: {
if (shouldBeCapturedInTempVariable((<ElementAccessExpression>callee).expression)) {
if (shouldBeCapturedInTempVariable((<ElementAccessExpression>callee).expression, cacheIdentifiers)) {
// for `a[b]()` target is `(_a = a)[b]` and thisArg is `_a`
thisArg = createTempVariable(recordTempVariable);
target = createElementAccess(
@@ -1884,6 +1916,124 @@ namespace ts {
}
}
export function createExpressionForObjectLiteralElement(node: ObjectLiteralExpression, property: ObjectLiteralElement, receiver: Expression): Expression {
switch (property.kind) {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return createExpressionForAccessorDeclaration(node.properties, <AccessorDeclaration>property, receiver, node.multiLine);
case SyntaxKind.PropertyAssignment:
return createExpressionForPropertyAssignment(<PropertyAssignment>property, receiver);
case SyntaxKind.ShorthandPropertyAssignment:
return createExpressionForShorthandPropertyAssignment(<ShorthandPropertyAssignment>property, receiver);
case SyntaxKind.MethodDeclaration:
return createExpressionForMethodDeclaration(<MethodDeclaration>property, receiver);
}
}
function createExpressionForAccessorDeclaration(properties: NodeArray<Declaration>, property: AccessorDeclaration, receiver: Expression, multiLine: boolean) {
const { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(properties, property);
if (property === firstAccessor) {
const properties: ObjectLiteralElement[] = [];
if (getAccessor) {
const getterFunction = createFunctionExpression(
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
getAccessor.parameters,
/*type*/ undefined,
getAccessor.body,
/*location*/ getAccessor
);
setOriginalNode(getterFunction, getAccessor);
const getter = createPropertyAssignment("get", getterFunction);
properties.push(getter);
}
if (setAccessor) {
const setterFunction = createFunctionExpression(
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
setAccessor.parameters,
/*type*/ undefined,
setAccessor.body,
/*location*/ setAccessor
);
setOriginalNode(setterFunction, setAccessor);
const setter = createPropertyAssignment("set", setterFunction);
properties.push(setter);
}
properties.push(createPropertyAssignment("enumerable", createLiteral(true)));
properties.push(createPropertyAssignment("configurable", createLiteral(true)));
const expression = createCall(
createPropertyAccess(createIdentifier("Object"), "defineProperty"),
/*typeArguments*/ undefined,
[
receiver,
createExpressionForPropertyName(property.name),
createObjectLiteral(properties, /*location*/ undefined, multiLine)
],
/*location*/ firstAccessor
);
return aggregateTransformFlags(expression);
}
return undefined;
}
function createExpressionForPropertyAssignment(property: PropertyAssignment, receiver: Expression) {
return aggregateTransformFlags(
setOriginalNode(
createAssignment(
createMemberAccessForPropertyName(receiver, property.name, /*location*/ property.name),
property.initializer,
/*location*/ property
),
/*original*/ property
)
);
}
function createExpressionForShorthandPropertyAssignment(property: ShorthandPropertyAssignment, receiver: Expression) {
return aggregateTransformFlags(
setOriginalNode(
createAssignment(
createMemberAccessForPropertyName(receiver, property.name, /*location*/ property.name),
getSynthesizedClone(property.name),
/*location*/ property
),
/*original*/ property
)
);
}
function createExpressionForMethodDeclaration(method: MethodDeclaration, receiver: Expression) {
return aggregateTransformFlags(
setOriginalNode(
createAssignment(
createMemberAccessForPropertyName(receiver, method.name, /*location*/ method.name),
setOriginalNode(
createFunctionExpression(
method.asteriskToken,
/*name*/ undefined,
/*typeParameters*/ undefined,
method.parameters,
/*type*/ undefined,
method.body,
/*location*/ method
),
/*original*/ method
),
/*location*/ method
),
/*original*/ method
)
);
}
// Utilities
function isUseStrictPrologue(node: ExpressionStatement): boolean {
@@ -1899,28 +2049,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<Node>): 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;
}
/**
+2
View File
@@ -3,6 +3,7 @@
/// <reference path="transformers/jsx.ts" />
/// <reference path="transformers/es7.ts" />
/// <reference path="transformers/es6.ts" />
/// <reference path="transformers/generators.ts" />
/// <reference path="transformers/module/module.ts" />
/// <reference path="transformers/module/system.ts" />
/// <reference path="transformers/module/es6.ts" />
@@ -179,6 +180,7 @@ namespace ts {
if (languageVersion < ScriptTarget.ES6) {
transformers.push(transformES6);
transformers.push(transformGenerators);
}
return transformers;
+63 -43
View File
@@ -376,6 +376,9 @@ namespace ts {
case SyntaxKind.TemplateExpression:
return visitTemplateExpression(<TemplateExpression>node);
case SyntaxKind.YieldExpression:
return visitYieldExpression(<YieldExpression>node);
case SyntaxKind.SuperKeyword:
return visitSuperKeyword(<PrimaryExpression>node);
@@ -927,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
)
);
}
@@ -978,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);
}
@@ -1020,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
)
);
@@ -1062,7 +1074,7 @@ namespace ts {
])
);
setNodeEmitFlags(forStatement, NodeEmitFlags.SourceMapAdjustRestParameterLoop);
setNodeEmitFlags(forStatement, NodeEmitFlags.SourceMapAdjustRestParameterLoop | NodeEmitFlags.CustomPrologue);
startOnNewLine(forStatement);
statements.push(forStatement);
}
@@ -1087,7 +1099,7 @@ namespace ts {
])
);
setNodeEmitFlags(captureThisStatement, NodeEmitFlags.NoComments);
setNodeEmitFlags(captureThisStatement, NodeEmitFlags.NoComments | NodeEmitFlags.CustomPrologue);
setSourceMapRange(captureThisStatement, node);
statements.push(captureThisStatement);
}
@@ -1159,7 +1171,6 @@ namespace ts {
createMemberAccessForPropertyName(
receiver,
visitNode(member.name, visitor, isPropertyName),
setNodeEmitFlags,
/*location*/ member.name
),
func
@@ -1345,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);
@@ -1859,22 +1870,24 @@ namespace ts {
*
* @param node An ObjectLiteralExpression node.
*/
function visitObjectLiteralExpression(node: ObjectLiteralExpression): LeftHandSideExpression {
function visitObjectLiteralExpression(node: ObjectLiteralExpression): Expression {
// We are here because a ComputedPropertyName was used somewhere in the expression.
const properties = node.properties;
const numProperties = properties.length;
// Find the first computed property.
// Everything until that point can be emitted as part of the initial object literal.
let numInitialNonComputedProperties = numProperties;
for (let i = 0, n = properties.length; i < n; i++) {
if (properties[i].name.kind === SyntaxKind.ComputedPropertyName) {
numInitialNonComputedProperties = i;
let numInitialProperties = numProperties;
for (let i = 0; i < numProperties; i++) {
const property = properties[i];
if (property.transformFlags & TransformFlags.ContainsYield
|| property.name.kind === SyntaxKind.ComputedPropertyName) {
numInitialProperties = i;
break;
}
}
Debug.assert(numInitialNonComputedProperties !== numProperties);
Debug.assert(numInitialProperties !== numProperties);
// For computed properties, we need to create a unique handle to the object
// literal so we can modify it without risking internal assignments tainting the object.
@@ -1887,7 +1900,7 @@ namespace ts {
temp,
setNodeEmitFlags(
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialNonComputedProperties),
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties),
/*location*/ undefined,
node.multiLine
),
@@ -1897,12 +1910,12 @@ namespace ts {
node.multiLine
);
addObjectLiteralMembers(expressions, node, temp, numInitialNonComputedProperties);
addObjectLiteralMembers(expressions, node, temp, numInitialProperties);
// We need to clone the temporary identifier so that we can write it on a
// new line
addNode(expressions, getMutableClone(temp), node.multiLine);
return createParen(inlineExpressions(expressions));
return inlineExpressions(expressions);
}
function shouldConvertIterationStatementBody(node: IterationStatement): boolean {
@@ -2290,10 +2303,10 @@ namespace ts {
* @param numInitialNonComputedProperties The number of initial properties without
* computed property names.
*/
function addObjectLiteralMembers(expressions: Expression[], node: ObjectLiteralExpression, receiver: Identifier, numInitialNonComputedProperties: number) {
function addObjectLiteralMembers(expressions: Expression[], node: ObjectLiteralExpression, receiver: Identifier, start: number) {
const properties = node.properties;
const numProperties = properties.length;
for (let i = numInitialNonComputedProperties; i < numProperties; i++) {
for (let i = start; i < numProperties; i++) {
const property = properties[i];
switch (property.kind) {
case SyntaxKind.GetAccessor:
@@ -2335,8 +2348,7 @@ namespace ts {
return createAssignment(
createMemberAccessForPropertyName(
receiver,
visitNode(property.name, visitor, isPropertyName),
setNodeEmitFlags
visitNode(property.name, visitor, isPropertyName)
),
visitNode(property.initializer, visitor, isExpression),
/*location*/ property
@@ -2354,8 +2366,7 @@ namespace ts {
return createAssignment(
createMemberAccessForPropertyName(
receiver,
visitNode(property.name, visitor, isPropertyName),
setNodeEmitFlags
visitNode(property.name, visitor, isPropertyName)
),
getSynthesizedClone(property.name),
/*location*/ property
@@ -2373,8 +2384,7 @@ namespace ts {
return createAssignment(
createMemberAccessForPropertyName(
receiver,
visitNode(method.name, visitor, isPropertyName),
setNodeEmitFlags
visitNode(method.name, visitor, isPropertyName)
),
transformFunctionLikeToExpression(method, /*location*/ method, /*name*/ undefined),
/*location*/ method
@@ -2414,6 +2424,16 @@ namespace ts {
);
}
/**
* Visits a YieldExpression node.
*
* @param node A YieldExpression node.
*/
function visitYieldExpression(node: YieldExpression): Expression {
// `yield` expressions are transformed using the generators transformer.
return visitEachChild(node, visitor, context);
}
/**
* Visits an ArrayLiteralExpression that contains a spread element.
*
@@ -2982,4 +3002,4 @@ namespace ts {
return isIdentifier(expression) && expression === parameter.name;
}
}
}
}
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -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));
+1 -1
View File
@@ -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,
+27 -9
View File
@@ -425,7 +425,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)),
@@ -938,7 +938,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;
@@ -1089,7 +1089,7 @@ namespace ts {
function transformInitializedProperty(node: ClassExpression | ClassDeclaration, property: PropertyDeclaration, receiver: LeftHandSideExpression) {
const propertyName = visitPropertyNameOfClassElement(property);
const initializer = visitNode(property.initializer, visitor, isExpression);
const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, setNodeEmitFlags, /*location*/ propertyName);
const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName);
return createAssignment(memberAccess, initializer);
}
@@ -1776,7 +1776,7 @@ namespace ts {
case TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue:
return serializeEntityNameAsExpression(node.typeName, /*useFallback*/ false);
case TypeReferenceSerializationKind.VoidType:
case TypeReferenceSerializationKind.VoidNullableOrNeverType:
return createVoidZero();
case TypeReferenceSerializationKind.BooleanType:
@@ -1799,6 +1799,9 @@ namespace ts {
case TypeReferenceSerializationKind.TypeWithCallSignature:
return createIdentifier("Function");
case TypeReferenceSerializationKind.Promise:
return createIdentifier("Promise");
case TypeReferenceSerializationKind.ObjectType:
default:
return createIdentifier("Object");
@@ -2186,11 +2189,13 @@ namespace ts {
return transformFunctionBodyWorker(node.body);
}
function transformFunctionBodyWorker(body: Block) {
function transformFunctionBodyWorker(body: Block, start = 0) {
const savedCurrentScope = currentScope;
currentScope = body;
startLexicalEnvironment();
const visited = visitEachChild(body, visitor, context);
const statements = visitNodes(body.statements, visitor, isStatement, start);
const visited = updateBlock(body, statements);
const declarations = endLexicalEnvironment();
currentScope = savedCurrentScope;
return mergeFunctionBodyLexicalEnvironment(visited, declarations);
@@ -2224,8 +2229,21 @@ namespace ts {
}
}
function getPromiseConstructor(type: TypeNode) {
const typeName = getEntityNameFromTypeNode(type);
if (typeName && isEntityName(typeName)) {
const serializationKind = resolver.getTypeReferenceSerializationKind(typeName);
if (serializationKind === TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue
|| serializationKind === TypeReferenceSerializationKind.Unknown) {
return typeName;
}
}
return undefined;
}
function transformAsyncFunctionBody(node: FunctionLikeDeclaration): ConciseBody | FunctionBody {
const promiseConstructor = languageVersion < ScriptTarget.ES6 ? getEntityNameFromTypeNode(node.type) : undefined;
const promiseConstructor = languageVersion < ScriptTarget.ES6 ? getPromiseConstructor(node.type) : undefined;
const isArrowFunction = node.kind === SyntaxKind.ArrowFunction;
const hasLexicalArguments = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureArguments) !== 0;
@@ -2238,14 +2256,14 @@ namespace ts {
if (!isArrowFunction) {
const statements: Statement[] = [];
const statementOffset = addPrologueDirectives(statements, (<Block>node.body).statements, /*ensureUseStrict*/ false, visitor);
statements.push(
createReturn(
createAwaiterHelper(
currentSourceFileExternalHelpersModuleName,
hasLexicalArguments,
promiseConstructor,
transformFunctionBodyWorker(<Block>node.body)
transformFunctionBodyWorker(<Block>node.body, statementOffset)
)
)
);
+1
View File
@@ -23,6 +23,7 @@
"transformers/jsx.ts",
"transformers/es7.ts",
"transformers/es6.ts",
"transformers/generators.ts",
"transformers/destructuring.ts",
"transformers/module/module.ts",
"transformers/module/system.ts",
+38 -22
View File
@@ -359,6 +359,8 @@ namespace ts {
// Markers
FirstAssignment = EqualsToken,
LastAssignment = CaretEqualsToken,
FirstCompoundAssignment = PlusEqualsToken,
LastCompoundAssignment = CaretEqualsToken,
FirstReservedWord = BreakKeyword,
LastReservedWord = WithKeyword,
FirstKeyword = BreakKeyword,
@@ -975,13 +977,18 @@ namespace ts {
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
// @kind(SyntaxKind.NumericLiteral)
// @kind(SyntaxKind.RegularExpressionLiteral)
// @kind(SyntaxKind.NoSubstitutionTemplateLiteral)
export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression {
_literalExpressionBrand: any;
}
// @kind(SyntaxKind.NumericLiteral)
export interface NumericLiteral extends LiteralExpression {
_numericLiteralBrand: any;
trailingComment?: string;
}
// @kind(SyntaxKind.TemplateHead)
// @kind(SyntaxKind.TemplateMiddle)
// @kind(SyntaxKind.TemplateTail)
@@ -2058,12 +2065,13 @@ namespace ts {
// function that can be reached at runtime (e.g. a `class`
// declaration or a `var` declaration for the static side
// of a type, such as the global `Promise` type in lib.d.ts).
VoidType, // The TypeReferenceNode resolves to a Void-like type.
VoidNullableOrNeverType, // The TypeReferenceNode resolves to a Void-like, Nullable, or Never type.
NumberLikeType, // The TypeReferenceNode resolves to a Number-like type.
StringLikeType, // The TypeReferenceNode resolves to a String-like type.
BooleanType, // The TypeReferenceNode resolves to a Boolean-like type.
ArrayLikeType, // The TypeReferenceNode resolves to an Array-like type.
ESSymbolType, // The TypeReferenceNode resolves to the ESSymbol type.
Promise, // The TypeReferenceNode resolved to the global Promise constructor symbol.
TypeWithCallSignature, // The TypeReferenceNode resolves to a Function type or a type
// with call signatures.
ObjectType, // The TypeReferenceNode resolves to any other type.
@@ -3022,20 +3030,24 @@ namespace ts {
ES6 = 1 << 6,
ContainsES6 = 1 << 7,
DestructuringAssignment = 1 << 8,
Generator = 1 << 9,
ContainsGenerator = 1 << 10,
// Markers
// - Flags used to indicate that a subtree contains a specific transformation.
ContainsDecorators = 1 << 9,
ContainsPropertyInitializer = 1 << 10,
ContainsLexicalThis = 1 << 11,
ContainsCapturedLexicalThis = 1 << 12,
ContainsLexicalThisInComputedPropertyName = 1 << 13,
ContainsDefaultValueAssignments = 1 << 14,
ContainsParameterPropertyAssignments = 1 << 15,
ContainsSpreadElementExpression = 1 << 16,
ContainsComputedPropertyName = 1 << 17,
ContainsBlockScopedBinding = 1 << 18,
ContainsBindingPattern = 1 << 19,
ContainsDecorators = 1 << 11,
ContainsPropertyInitializer = 1 << 12,
ContainsLexicalThis = 1 << 13,
ContainsCapturedLexicalThis = 1 << 14,
ContainsLexicalThisInComputedPropertyName = 1 << 15,
ContainsDefaultValueAssignments = 1 << 16,
ContainsParameterPropertyAssignments = 1 << 17,
ContainsSpreadElementExpression = 1 << 18,
ContainsComputedPropertyName = 1 << 19,
ContainsBlockScopedBinding = 1 << 20,
ContainsBindingPattern = 1 << 21,
ContainsYield = 1 << 22,
ContainsHoistedDeclarationOrCompletion = 1 << 23,
HasComputedFlags = 1 << 29, // Transform flags have been computed.
@@ -3045,17 +3057,18 @@ namespace ts {
AssertJsx = Jsx | ContainsJsx,
AssertES7 = ES7 | ContainsES7,
AssertES6 = ES6 | ContainsES6,
AssertGenerator = Generator | ContainsGenerator,
// Scope Exclusions
// - Bitmasks that exclude flags from propagating out of a specific context
// into the subtree flags of their container.
NodeExcludes = TypeScript | Jsx | ES7 | ES6 | DestructuringAssignment | HasComputedFlags,
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding,
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding,
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding,
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding,
NodeExcludes = TypeScript | Jsx | ES7 | ES6 | DestructuringAssignment | Generator | HasComputedFlags,
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion,
ClassExcludes = NodeExcludes | ContainsDecorators | ContainsPropertyInitializer | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsParameterPropertyAssignments | ContainsLexicalThisInComputedPropertyName,
ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding,
ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion,
TypeExcludes = ~ContainsTypeScript,
ObjectLiteralExcludes = NodeExcludes | ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName,
ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpreadElementExpression,
@@ -3093,14 +3106,17 @@ namespace ts {
ExportName = 1 << 17, // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal).
LocalName = 1 << 18, // Ensure an export prefix is not added for an identifier that points to an exported declaration.
Indented = 1 << 19, // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter).
NoIndentation = 1 << 20, // Do not indent the node.
NoIndentation = 1 << 20, // Do not indent the node.
AsyncFunctionBody = 1 << 21,
ReuseTempVariableScope = 1 << 22, // Reuse the existing temp variable scope during emit.
CustomPrologue = 1 << 23, // 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
// emitter and new baselines are taken. This exists solely to
// align with the old emitter.
SourceMapEmitOpenBraceAsToken = 1 << 21, // Emits the open brace of a block function body as a source mapped token.
SourceMapAdjustRestParameterLoop = 1 << 22, // Emits adjusted source map positions for a ForStatement generated when transforming a rest parameter for ES5/3.
SourceMapEmitOpenBraceAsToken = 1 << 24, // Emits the open brace of a block function body as a source mapped token.
SourceMapAdjustRestParameterLoop = 1 << 25, // Emits adjusted source map positions for a ForStatement generated when transforming a rest parameter for ES5/3.
}
/** Additional context provided to `visitEachChild` */
+6
View File
@@ -3038,6 +3038,12 @@ namespace ts {
return ModifierFlags.None;
}
export function isLogicalOperator(token: SyntaxKind): boolean {
return token === SyntaxKind.BarBarToken
|| token === SyntaxKind.AmpersandAmpersandToken
|| token === SyntaxKind.ExclamationToken;
}
export function isAssignmentOperator(token: SyntaxKind): boolean {
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
}
+2 -1
View File
@@ -1197,8 +1197,9 @@ namespace ts {
/**
* Aggregates the TransformFlags for a Node and its subtree.
*/
export function aggregateTransformFlags(node: Node): void {
export function aggregateTransformFlags<T extends Node>(node: T): T {
aggregateTransformFlagsForNode(node);
return node;
}
/**
+1
View File
@@ -24,6 +24,7 @@
"../compiler/transformers/jsx.ts",
"../compiler/transformers/es7.ts",
"../compiler/transformers/es6.ts",
"../compiler/transformers/generators.ts",
"../compiler/transformers/destructuring.ts",
"../compiler/transformers/module/module.ts",
"../compiler/transformers/module/system.ts",
@@ -1,6 +0,0 @@
//// [arrowFunctionWithParameterNameAsync.ts]
const x = async => async;
//// [arrowFunctionWithParameterNameAsync.js]
var x = function (async) { return async; };
@@ -1,7 +0,0 @@
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts ===
const x = async => async;
>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 5))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync.ts, 1, 9))
@@ -0,0 +1,6 @@
//// [arrowFunctionWithParameterNameAsync_es5.ts]
const x = async => async;
//// [arrowFunctionWithParameterNameAsync_es5.js]
var x = function (async) { return async; };
@@ -0,0 +1,7 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts ===
const x = async => async;
>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 5))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es5.ts, 1, 9))
@@ -0,0 +1,8 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es5.ts ===
const x = async => async;
>x : (async: any) => any
>async => async : (async: any) => any
>async : any
>async : any
@@ -0,0 +1,6 @@
//// [arrowFunctionWithParameterNameAsync_es6.ts]
const x = async => async;
//// [arrowFunctionWithParameterNameAsync_es6.js]
var x = function (async) { return async; };
@@ -0,0 +1,7 @@
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es6.ts ===
const x = async => async;
>x : Symbol(x, Decl(arrowFunctionWithParameterNameAsync_es6.ts, 1, 5))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es6.ts, 1, 9))
>async : Symbol(async, Decl(arrowFunctionWithParameterNameAsync_es6.ts, 1, 9))
@@ -1,4 +1,4 @@
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync.ts ===
=== tests/cases/conformance/async/es6/asyncArrowFunction/arrowFunctionWithParameterNameAsync_es6.ts ===
const x = async => async;
>x : (async: any) => any
@@ -0,0 +1,14 @@
//// [asyncAliasReturnType_es5.ts]
type PromiseAlias<T> = Promise<T>;
async function f(): PromiseAlias<void> {
}
//// [asyncAliasReturnType_es5.js]
function f() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
}
@@ -0,0 +1,11 @@
=== tests/cases/conformance/async/es5/asyncAliasReturnType_es5.ts ===
type PromiseAlias<T> = Promise<T>;
>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es5.ts, 0, 0))
>T : Symbol(T, Decl(asyncAliasReturnType_es5.ts, 0, 18))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>T : Symbol(T, Decl(asyncAliasReturnType_es5.ts, 0, 18))
async function f(): PromiseAlias<void> {
>f : Symbol(f, Decl(asyncAliasReturnType_es5.ts, 0, 34))
>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es5.ts, 0, 0))
}
@@ -0,0 +1,11 @@
=== tests/cases/conformance/async/es5/asyncAliasReturnType_es5.ts ===
type PromiseAlias<T> = Promise<T>;
>PromiseAlias : Promise<T>
>T : T
>Promise : Promise<T>
>T : T
async function f(): PromiseAlias<void> {
>f : () => Promise<void>
>PromiseAlias : Promise<T>
}
@@ -0,0 +1,12 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts(4,11): error TS2304: Cannot find name 'await'.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts (1 errors) ====
var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
}
@@ -0,0 +1,16 @@
//// [asyncArrowFunction10_es5.ts]
var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
}
//// [asyncArrowFunction10_es5.js]
var _this = this;
var foo = function () { return __awaiter(_this, void 0, void 0, function () {
var v;
return __generator(this, function (_a) {
return [2 /*return*/];
});
}); };
@@ -1,21 +1,9 @@
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(2,11): error TS2304: Cannot find name 'async'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(2,17): error TS1005: ',' expected.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(2,20): error TS1005: '=' expected.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(2,24): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(4,11): error TS2304: Cannot find name 'await'.
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts (5 errors) ====
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts (1 errors) ====
var foo = async foo(): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'async'.
~~~
!!! error TS1005: ',' expected.
~
!!! error TS1005: '=' expected.
~~~~~~~~~~~~~
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
~~~~~
@@ -1,13 +1,13 @@
//// [asyncArrowFunction10_es6.ts]
var foo = async foo(): Promise<void> => {
var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
}
//// [asyncArrowFunction10_es6.js]
var foo = async, foo = () => {
var foo = () => __awaiter(this, void 0, void 0, function* () {
// Legal to use 'await' in a type context.
var v;
};
});
@@ -0,0 +1,12 @@
//// [asyncArrowFunction1_es5.ts]
var foo = async (): Promise<void> => {
};
//// [asyncArrowFunction1_es5.js]
var _this = this;
var foo = function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
}); };
@@ -0,0 +1,7 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts ===
var foo = async (): Promise<void> => {
>foo : Symbol(foo, Decl(asyncArrowFunction1_es5.ts, 1, 3))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
};
@@ -0,0 +1,8 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction1_es5.ts ===
var foo = async (): Promise<void> => {
>foo : () => Promise<void>
>async (): Promise<void> => {} : () => Promise<void>
>Promise : Promise<T>
};
@@ -0,0 +1,7 @@
//// [asyncArrowFunction2_es5.ts]
var f = (await) => {
}
//// [asyncArrowFunction2_es5.js]
var f = function (await) {
};
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts ===
var f = (await) => {
>f : Symbol(f, Decl(asyncArrowFunction2_es5.ts, 0, 3))
>await : Symbol(await, Decl(asyncArrowFunction2_es5.ts, 0, 9))
}
@@ -0,0 +1,6 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction2_es5.ts ===
var f = (await) => {
>f : (await: any) => void
>(await) => {} : (await: any) => void
>await : any
}
@@ -0,0 +1,8 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts(1,20): error TS2372: Parameter 'await' cannot be referenced in its initializer.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction3_es5.ts (1 errors) ====
function f(await = await) {
~~~~~
!!! error TS2372: Parameter 'await' cannot be referenced in its initializer.
}
@@ -0,0 +1,8 @@
//// [asyncArrowFunction3_es5.ts]
function f(await = await) {
}
//// [asyncArrowFunction3_es5.js]
function f(await) {
if (await === void 0) { await = await; }
}
@@ -0,0 +1,7 @@
//// [asyncArrowFunction4_es5.ts]
var await = () => {
}
//// [asyncArrowFunction4_es5.js]
var await = function () {
};
@@ -0,0 +1,4 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts ===
var await = () => {
>await : Symbol(await, Decl(asyncArrowFunction4_es5.ts, 0, 3))
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction4_es5.ts ===
var await = () => {
>await : () => void
>() => {} : () => void
}
@@ -0,0 +1,24 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,11): error TS2304: Cannot find name 'async'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,18): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,24): error TS1005: ',' expected.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,26): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,33): error TS1005: '=' expected.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts(2,40): error TS1109: Expression expected.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts (6 errors) ====
var foo = async (await): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'async'.
~~~~~
!!! error TS2304: Cannot find name 'await'.
~
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
~
!!! error TS1005: '=' expected.
~~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,9 @@
//// [asyncArrowFunction5_es5.ts]
var foo = async (await): Promise<void> => {
}
//// [asyncArrowFunction5_es5.js]
var foo = async(await), Promise = ;
{
}
@@ -0,0 +1,12 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts(2,22): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts(2,27): error TS1109: Expression expected.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction6_es5.ts (2 errors) ====
var foo = async (a = await): Promise<void> => {
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,15 @@
//// [asyncArrowFunction6_es5.ts]
var foo = async (a = await): Promise<void> => {
}
//// [asyncArrowFunction6_es5.js]
var _this = this;
var foo = function (a) {
if (a === void 0) { a = yield ; }
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
};
@@ -0,0 +1,15 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts(4,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts(4,29): error TS1109: Expression expected.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction7_es5.ts (2 errors) ====
var bar = async (): Promise<void> => {
// 'await' here is an identifier, and not an await expression.
var foo = async (a = await): Promise<void> => {
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}
}
@@ -0,0 +1,25 @@
//// [asyncArrowFunction7_es5.ts]
var bar = async (): Promise<void> => {
// 'await' here is an identifier, and not an await expression.
var foo = async (a = await): Promise<void> => {
}
}
//// [asyncArrowFunction7_es5.js]
var _this = this;
var bar = function () { return __awaiter(_this, void 0, void 0, function () {
_this = this;
var foo;
return __generator(this, function (_a) {
foo = function (a) {
if (a === void 0) { a = yield ; }
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
};
return [2 /*return*/];
});
}); var _this; };
@@ -0,0 +1,10 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts(3,19): error TS1109: Expression expected.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction8_es5.ts (1 errors) ====
var foo = async (): Promise<void> => {
var v = { [await]: foo }
~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,21 @@
//// [asyncArrowFunction8_es5.ts]
var foo = async (): Promise<void> => {
var v = { [await]: foo }
}
//// [asyncArrowFunction8_es5.js]
var _this = this;
var foo = function () { return __awaiter(_this, void 0, void 0, function () {
var v, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = {};
return [4 /*yield*/, ];
case 1:
v = (_a[_b.sent()] = foo, _a);
return [2 /*return*/];
}
});
}); };
@@ -0,0 +1,23 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,11): error TS2304: Cannot find name 'async'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,18): error TS2304: Cannot find name 'a'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,37): error TS1005: ',' expected.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,39): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,46): error TS1005: '=' expected.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts(1,53): error TS1109: Expression expected.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts (6 errors) ====
var foo = async (a = await => await): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'async'.
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
~
!!! error TS1005: '=' expected.
~~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,8 @@
//// [asyncArrowFunction9_es5.ts]
var foo = async (a = await => await): Promise<void> => {
}
//// [asyncArrowFunction9_es5.js]
var foo = async(a = function (await) { return await; }), Promise = ;
{
}
@@ -0,0 +1,13 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts(4,52): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es5.ts (1 errors) ====
class C {
method() {
function other() {}
var fn = async () => await other.apply(this, arguments);
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
}
}
@@ -0,0 +1,25 @@
//// [asyncArrowFunctionCapturesArguments_es5.ts]
class C {
method() {
function other() {}
var fn = async () => await other.apply(this, arguments);
}
}
//// [asyncArrowFunctionCapturesArguments_es5.js]
var C = (function () {
function C() {
}
C.prototype.method = function () {
var _this = this;
function other() { }
var fn = function () { return __awaiter(_this, arguments, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, other.apply(this, arguments)];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); };
};
return C;
}());
@@ -0,0 +1,23 @@
//// [asyncArrowFunctionCapturesThis_es5.ts]
class C {
method() {
var fn = async () => await this;
}
}
//// [asyncArrowFunctionCapturesThis_es5.js]
var C = (function () {
function C() {
}
C.prototype.method = function () {
var _this = this;
var fn = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this];
case 1: return [2 /*return*/, _a.sent()];
}
}); }); };
};
return C;
}());
@@ -0,0 +1,13 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts ===
class C {
>C : Symbol(C, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 0))
method() {
>method : Symbol(C.method, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 9))
var fn = async () => await this;
>fn : Symbol(fn, Decl(asyncArrowFunctionCapturesThis_es5.ts, 2, 9))
>this : Symbol(C, Decl(asyncArrowFunctionCapturesThis_es5.ts, 0, 0))
}
}
@@ -0,0 +1,15 @@
=== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunctionCapturesThis_es5.ts ===
class C {
>C : C
method() {
>method : () => void
var fn = async () => await this;
>fn : () => Promise<this>
>async () => await this : () => Promise<this>
>await this : this
>this : this
}
}
@@ -0,0 +1,45 @@
tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts(1,27): error TS2307: Cannot find module 'missing'.
==== tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts (1 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing'.
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() { }
}
@@ -0,0 +1,201 @@
//// [asyncAwaitIsolatedModules_es5.ts]
import { MyPromise } from "missing";
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() { }
}
//// [asyncAwaitIsolatedModules_es5.js]
"use strict";
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f;
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (1) {
if (_.done) switch (op[0]) {
case 0: return { value: void 0, done: true };
case 1: case 6: throw op[1];
case 2: return { value: op[1], done: true };
}
try {
switch (f = 1, op[0]) {
case 0: case 1: sent = op; break;
case 4: return _.label++, { value: op[1], done: false };
case 7: op = _.stack.pop(), _.trys.pop(); continue;
default:
var r = _.trys.length > 0 && _.trys[_.trys.length - 1];
if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; }
if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; }
if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; }
if (r[2]) { _.stack.pop(); }
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) { op = [6, e]; }
finally { f = 0, sent = void 0; }
}
}
return {
next: function (v) { return step([0, v]); },
"throw": function (v) { return step([1, v]); },
"return": function (v) { return step([2, v]); }
};
};
var _this = this;
function f0() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
function f1() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
function f3() {
return __awaiter(this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
var f4 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f5 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f6 = function () {
return __awaiter(this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f7 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f8 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f9 = function () { return __awaiter(_this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f10 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, p];
}); }); };
var f11 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, mp];
}); }); };
var f12 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, mp];
}); }); };
var f13 = function () { return __awaiter(_this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/, p];
}); }); };
var o = {
m1: function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
},
m2: function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
},
m3: function () {
return __awaiter(this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
};
var C = (function () {
function C() {
}
C.prototype.m1 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.prototype.m2 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.prototype.m3 = function () {
return __awaiter(this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m4 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m5 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m6 = function () {
return __awaiter(this, void 0, missing_1.MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
return C;
}());
var M;
(function (M) {
function f1() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
M.f1 = f1;
})(M || (M = {}));
+200
View File
@@ -0,0 +1,200 @@
//// [asyncAwait_es5.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_es5.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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (sent[0] === 1) throw sent[1]; return sent[1]; }, trys: [], stack: [] }, sent, f;
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (1) {
if (_.done) switch (op[0]) {
case 0: return { value: void 0, done: true };
case 1: case 6: throw op[1];
case 2: return { value: op[1], done: true };
}
try {
switch (f = 1, op[0]) {
case 0: case 1: sent = op; break;
case 4: return _.label++, { value: op[1], done: false };
case 7: op = _.stack.pop(), _.trys.pop(); continue;
default:
var r = _.trys.length > 0 && _.trys[_.trys.length - 1];
if (!r && (op[0] === 6 || op[0] === 2)) { _.done = 1; continue; }
if (op[0] === 3 && (!r || (op[1] > r[0] && op[1] < r[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < r[1]) { _.label = r[1], sent = op; break; }
if (r && _.label < r[2]) { _.label = r[2], _.stack.push(op); break; }
if (r[2]) { _.stack.pop(); }
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) { op = [6, e]; }
finally { f = 0, sent = void 0; }
}
}
return {
next: function (v) { return step([0, v]); },
"throw": function (v) { return step([1, v]); },
"return": function (v) { return step([2, v]); }
};
};
var _this = this;
function f0() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
function f1() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
function f3() {
return __awaiter(this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
var f4 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f5 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f6 = function () {
return __awaiter(this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
var f7 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f8 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f9 = function () { return __awaiter(_this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
var f10 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, p];
}); }); };
var f11 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, mp];
}); }); };
var f12 = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, mp];
}); }); };
var f13 = function () { return __awaiter(_this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/, p];
}); }); };
var o = {
m1: function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
},
m2: function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
},
m3: function () {
return __awaiter(this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
};
var C = (function () {
function C() {
}
C.prototype.m1 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.prototype.m2 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.prototype.m3 = function () {
return __awaiter(this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m4 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m5 = function () {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
C.m6 = function () {
return __awaiter(this, void 0, MyPromise, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
};
return C;
}());
var M;
(function (M) {
function f1() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
}
M.f1 = f1;
})(M || (M = {}));
@@ -0,0 +1,118 @@
=== tests/cases/conformance/async/es5/asyncAwait_es5.ts ===
type MyPromise<T> = Promise<T>;
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
>T : Symbol(T, Decl(asyncAwait_es5.ts, 0, 15))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>T : Symbol(T, Decl(asyncAwait_es5.ts, 0, 15))
declare var MyPromise: typeof Promise;
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
declare var p: Promise<number>;
>p : Symbol(p, Decl(asyncAwait_es5.ts, 2, 11))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
declare var mp: MyPromise<number>;
>mp : Symbol(mp, Decl(asyncAwait_es5.ts, 3, 11))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
async function f0() { }
>f0 : Symbol(f0, Decl(asyncAwait_es5.ts, 3, 34))
async function f1(): Promise<void> { }
>f1 : Symbol(f1, Decl(asyncAwait_es5.ts, 5, 23))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
async function f3(): MyPromise<void> { }
>f3 : Symbol(f3, Decl(asyncAwait_es5.ts, 6, 38))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
let f4 = async function() { }
>f4 : Symbol(f4, Decl(asyncAwait_es5.ts, 9, 3))
let f5 = async function(): Promise<void> { }
>f5 : Symbol(f5, Decl(asyncAwait_es5.ts, 10, 3))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
let f6 = async function(): MyPromise<void> { }
>f6 : Symbol(f6, Decl(asyncAwait_es5.ts, 11, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
let f7 = async () => { };
>f7 : Symbol(f7, Decl(asyncAwait_es5.ts, 13, 3))
let f8 = async (): Promise<void> => { };
>f8 : Symbol(f8, Decl(asyncAwait_es5.ts, 14, 3))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
let f9 = async (): MyPromise<void> => { };
>f9 : Symbol(f9, Decl(asyncAwait_es5.ts, 15, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
let f10 = async () => p;
>f10 : Symbol(f10, Decl(asyncAwait_es5.ts, 16, 3))
>p : Symbol(p, Decl(asyncAwait_es5.ts, 2, 11))
let f11 = async () => mp;
>f11 : Symbol(f11, Decl(asyncAwait_es5.ts, 17, 3))
>mp : Symbol(mp, Decl(asyncAwait_es5.ts, 3, 11))
let f12 = async (): Promise<number> => mp;
>f12 : Symbol(f12, Decl(asyncAwait_es5.ts, 18, 3))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>mp : Symbol(mp, Decl(asyncAwait_es5.ts, 3, 11))
let f13 = async (): MyPromise<number> => p;
>f13 : Symbol(f13, Decl(asyncAwait_es5.ts, 19, 3))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
>p : Symbol(p, Decl(asyncAwait_es5.ts, 2, 11))
let o = {
>o : Symbol(o, Decl(asyncAwait_es5.ts, 21, 3))
async m1() { },
>m1 : Symbol(m1, Decl(asyncAwait_es5.ts, 21, 9))
async m2(): Promise<void> { },
>m2 : Symbol(m2, Decl(asyncAwait_es5.ts, 22, 16))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
async m3(): MyPromise<void> { }
>m3 : Symbol(m3, Decl(asyncAwait_es5.ts, 23, 31))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
};
class C {
>C : Symbol(C, Decl(asyncAwait_es5.ts, 25, 2))
async m1() { }
>m1 : Symbol(C.m1, Decl(asyncAwait_es5.ts, 27, 9))
async m2(): Promise<void> { }
>m2 : Symbol(C.m2, Decl(asyncAwait_es5.ts, 28, 15))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
async m3(): MyPromise<void> { }
>m3 : Symbol(C.m3, Decl(asyncAwait_es5.ts, 29, 30))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
static async m4() { }
>m4 : Symbol(C.m4, Decl(asyncAwait_es5.ts, 30, 32))
static async m5(): Promise<void> { }
>m5 : Symbol(C.m5, Decl(asyncAwait_es5.ts, 31, 22))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
static async m6(): MyPromise<void> { }
>m6 : Symbol(C.m6, Decl(asyncAwait_es5.ts, 32, 37))
>MyPromise : Symbol(MyPromise, Decl(asyncAwait_es5.ts, 0, 0), Decl(asyncAwait_es5.ts, 1, 11))
}
module M {
>M : Symbol(M, Decl(asyncAwait_es5.ts, 34, 1))
export async function f1() { }
>f1 : Symbol(f1, Decl(asyncAwait_es5.ts, 36, 10))
}
@@ -0,0 +1,129 @@
=== tests/cases/conformance/async/es5/asyncAwait_es5.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>
}
@@ -0,0 +1,8 @@
tests/cases/conformance/async/es5/asyncClass_es5.ts(1,1): error TS1042: 'async' modifier cannot be used here.
==== tests/cases/conformance/async/es5/asyncClass_es5.ts (1 errors) ====
async class C {
~~~~~
!!! error TS1042: 'async' modifier cannot be used here.
}
@@ -0,0 +1,10 @@
//// [asyncClass_es5.ts]
async class C {
}
//// [asyncClass_es5.js]
var C = (function () {
function C() {
}
return C;
}());
@@ -0,0 +1,10 @@
tests/cases/conformance/async/es5/asyncConstructor_es5.ts(2,3): error TS1089: 'async' modifier cannot appear on a constructor declaration.
==== tests/cases/conformance/async/es5/asyncConstructor_es5.ts (1 errors) ====
class C {
async constructor() {
~~~~~
!!! error TS1089: 'async' modifier cannot appear on a constructor declaration.
}
}
@@ -0,0 +1,12 @@
//// [asyncConstructor_es5.ts]
class C {
async constructor() {
}
}
//// [asyncConstructor_es5.js]
var C = (function () {
function C() {
}
return C;
}());
@@ -0,0 +1,7 @@
tests/cases/conformance/async/es5/asyncDeclare_es5.ts(1,9): error TS1040: 'async' modifier cannot be used in an ambient context.
==== tests/cases/conformance/async/es5/asyncDeclare_es5.ts (1 errors) ====
declare async function foo(): Promise<void>;
~~~~~
!!! error TS1040: 'async' modifier cannot be used in an ambient context.
@@ -0,0 +1,4 @@
//// [asyncDeclare_es5.ts]
declare async function foo(): Promise<void>;
//// [asyncDeclare_es5.js]
@@ -0,0 +1,9 @@
tests/cases/conformance/async/es5/asyncEnum_es5.ts(1,1): error TS1042: 'async' modifier cannot be used here.
==== tests/cases/conformance/async/es5/asyncEnum_es5.ts (1 errors) ====
async enum E {
~~~~~
!!! error TS1042: 'async' modifier cannot be used here.
Value
}
@@ -0,0 +1,10 @@
//// [asyncEnum_es5.ts]
async enum E {
Value
}
//// [asyncEnum_es5.js]
var E;
(function (E) {
E[E["Value"] = 0] = "Value";
})(E || (E = {}));
@@ -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<void> {
~~~~~~~~~
!!! 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.
}
@@ -0,0 +1,7 @@
//// [asyncFunctionDeclaration10_es5.ts]
async function foo(a = await => await): Promise<void> {
}
//// [asyncFunctionDeclaration10_es5.js]
await;
Promise < void > {};
@@ -0,0 +1,12 @@
//// [asyncFunctionDeclaration11_es5.ts]
async function await(): Promise<void> {
}
//// [asyncFunctionDeclaration11_es5.js]
function await() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts ===
async function await(): Promise<void> {
>await : Symbol(await, Decl(asyncFunctionDeclaration11_es5.ts, 0, 0))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration11_es5.ts ===
async function await(): Promise<void> {
>await : () => Promise<void>
>Promise : Promise<T>
}
@@ -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<void> { }
~~~~~
!!! 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.
@@ -0,0 +1,5 @@
//// [asyncFunctionDeclaration12_es5.ts]
var v = async function await(): Promise<void> { }
//// [asyncFunctionDeclaration12_es5.js]
var v = , await = function () { };
@@ -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<void> {
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
}
@@ -0,0 +1,16 @@
//// [asyncFunctionDeclaration13_es5.ts]
async function foo(): Promise<void> {
// Legal to use 'await' in a type context.
var v: await;
}
//// [asyncFunctionDeclaration13_es5.js]
function foo() {
return __awaiter(this, void 0, void 0, function () {
var v;
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
}
@@ -0,0 +1,13 @@
//// [asyncFunctionDeclaration14_es5.ts]
async function foo(): Promise<void> {
return;
}
//// [asyncFunctionDeclaration14_es5.js]
function foo() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts ===
async function foo(): Promise<void> {
>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;
}
@@ -0,0 +1,7 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration14_es5.ts ===
async function foo(): Promise<void> {
>foo : () => Promise<void>
>Promise : Promise<T>
return;
}
@@ -0,0 +1,59 @@
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(6,23): error TS1055: Type '{}' is not a valid async function return type.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(7,23): error TS1055: Type 'any' is not a valid async function return type.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(8,23): error TS1055: Type 'number' is not a valid async function return type.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type.
Type 'Thenable' is not assignable to type 'PromiseLike<any>'.
Types of property 'then' are incompatible.
Type '() => void' is not assignable to type '{ <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>; }'.
Type 'void' is not assignable to type 'PromiseLike<any>'.
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<void>
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<void> { } // 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<any>'.
!!! error TS1055: Types of property 'then' are incompatible.
!!! error TS1055: Type '() => void' is not assignable to type '{ <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>; <TResult>(onfulfilled?: (value: any) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>; }'.
!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike<any>'.
async function fn7() { return; } // valid: Promise<void>
async function fn8() { return 1; } // valid: Promise<number>
async function fn9() { return null; } // valid: Promise<any>
async function fn10() { return undefined; } // valid: Promise<any>
async function fn11() { return a; } // valid: Promise<any>
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<void>
async function fn15() { await null; } // valid: Promise<void>
async function fn16() { await undefined; } // valid: Promise<void>
async function fn17() { await a; } // valid: Promise<void>
async function fn18() { await obj; } // valid: Promise<void>
async function fn19() { await thenable; } // error
~~~~~~~~~~~~~~
!!! error TS1058: Operand for 'await' does not have a valid callable 'then' member.
@@ -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<void>
async function fn2(): { } { } // error
async function fn3(): any { } // error
async function fn4(): number { } // error
async function fn5(): PromiseLike<void> { } // error
async function fn6(): Thenable { } // error
async function fn7() { return; } // valid: Promise<void>
async function fn8() { return 1; } // valid: Promise<number>
async function fn9() { return null; } // valid: Promise<any>
async function fn10() { return undefined; } // valid: Promise<any>
async function fn11() { return a; } // valid: Promise<any>
async function fn12() { return obj; } // valid: Promise<{ then: string; }>
async function fn13() { return thenable; } // error
async function fn14() { await 1; } // valid: Promise<void>
async function fn15() { await null; } // valid: Promise<void>
async function fn16() { await undefined; } // valid: Promise<void>
async function fn17() { await a; } // valid: Promise<void>
async function fn18() { await obj; } // valid: Promise<void>
async function fn19() { await thenable; } // error
//// [asyncFunctionDeclaration15_es5.js]
function fn1() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // valid: Promise<void>
function fn2() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // error
function fn3() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // error
function fn4() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // error
function fn5() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // error
function fn6() {
return __awaiter(this, void 0, Thenable, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // error
function fn7() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); });
} // valid: Promise<void>
function fn8() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, 1];
}); });
} // valid: Promise<number>
function fn9() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, null];
}); });
} // valid: Promise<any>
function fn10() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, undefined];
}); });
} // valid: Promise<any>
function fn11() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, a];
}); });
} // valid: Promise<any>
function fn12() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, obj];
}); });
} // valid: Promise<{ then: string; }>
function fn13() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, thenable];
}); });
} // error
function fn14() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, 1];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // valid: Promise<void>
function fn15() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, null];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // valid: Promise<void>
function fn16() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, undefined];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // valid: Promise<void>
function fn17() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, a];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // valid: Promise<void>
function fn18() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, obj];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // valid: Promise<void>
function fn19() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, thenable];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
} // error
@@ -0,0 +1,12 @@
//// [asyncFunctionDeclaration1_es5.ts]
async function foo(): Promise<void> {
}
//// [asyncFunctionDeclaration1_es5.js]
function foo() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts ===
async function foo(): Promise<void> {
>foo : Symbol(foo, Decl(asyncFunctionDeclaration1_es5.ts, 0, 0))
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1_es5.ts ===
async function foo(): Promise<void> {
>foo : () => Promise<void>
>Promise : Promise<T>
}
@@ -0,0 +1,7 @@
//// [asyncFunctionDeclaration2_es5.ts]
function f(await) {
}
//// [asyncFunctionDeclaration2_es5.js]
function f(await) {
}
@@ -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))
}
@@ -0,0 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration2_es5.ts ===
function f(await) {
>f : (await: any) => void
>await : any
}
@@ -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.
}
@@ -0,0 +1,8 @@
//// [asyncFunctionDeclaration3_es5.ts]
function f(await = await) {
}
//// [asyncFunctionDeclaration3_es5.js]
function f(await) {
if (await === void 0) { await = await; }
}
@@ -0,0 +1,7 @@
//// [asyncFunctionDeclaration4_es5.ts]
function await() {
}
//// [asyncFunctionDeclaration4_es5.js]
function await() {
}
@@ -0,0 +1,4 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts ===
function await() {
>await : Symbol(await, Decl(asyncFunctionDeclaration4_es5.ts, 0, 0))
}
@@ -0,0 +1,4 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration4_es5.ts ===
function await() {
>await : () => void
}
@@ -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<void> {
~~~~~
!!! error TS1138: Parameter declaration expected.
~~~~~
!!! error TS2304: Cannot find name 'await'.
~
!!! error TS1005: ';' expected.
~
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1109: Expression expected.
}
@@ -0,0 +1,7 @@
//// [asyncFunctionDeclaration5_es5.ts]
async function foo(await): Promise<void> {
}
//// [asyncFunctionDeclaration5_es5.js]
await;
Promise < void > {};
@@ -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<void> {
~~~~~
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}

Some files were not shown because too many files have changed in this diff Show More