diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ac1038a4cdbe..43cf8f622c68b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28739,17 +28739,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return errorType; } - const container = getContainingFunction(node)!; - if (languageVersion < ScriptTarget.ES2015) { - 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); + let container = getContainingFunction(node); + if (container) { + if (languageVersion < ScriptTarget.ES2015) { + 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 (hasSyntacticModifier(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); + } } - else if (hasSyntacticModifier(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); + + getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; + while (container && isArrowFunction(container)) { + container = getContainingFunction(container); + if (container) { + getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; + } } } - - getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; return getTypeOfSymbol(symbol); } diff --git a/src/compiler/factory/emitHelpers.ts b/src/compiler/factory/emitHelpers.ts index 0fd25b6bf6346..8d995def558f2 100644 --- a/src/compiler/factory/emitHelpers.ts +++ b/src/compiler/factory/emitHelpers.ts @@ -26,6 +26,7 @@ import { isIdentifier, memoize, ObjectLiteralElementLike, + ParameterDeclaration, PrivateIdentifier, ScriptTarget, setEmitFlags, @@ -115,7 +116,7 @@ export interface EmitHelperFactory { // ES2018 Destructuring Helpers createRestHelper(value: Expression, elements: readonly BindingOrAssignmentElement[], computedTempVariables: readonly Expression[] | undefined, location: TextRange): Expression; // ES2017 Helpers - createAwaiterHelper(hasLexicalThis: boolean, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression | undefined, body: Block): Expression; + createAwaiterHelper(hasLexicalThis: boolean, argumentsExpression: Expression | undefined, promiseConstructor: EntityName | Expression | undefined, parameters: readonly ParameterDeclaration[] | undefined, body: Block): Expression; // ES2015 Helpers createExtendsHelper(name: Identifier): Expression; createTemplateObjectHelper(cooked: ArrayLiteralExpression, raw: ArrayLiteralExpression): Expression; @@ -497,7 +498,7 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel // ES2017 Helpers - function createAwaiterHelper(hasLexicalThis: boolean, hasLexicalArguments: boolean, promiseConstructor: EntityName | Expression | undefined, body: Block) { + function createAwaiterHelper(hasLexicalThis: boolean, argumentsExpression: Expression | undefined, promiseConstructor: EntityName | Expression | undefined, parameters: readonly ParameterDeclaration[], body: Block) { context.requestEmitHelper(awaiterHelper); const generatorFunc = factory.createFunctionExpression( @@ -505,7 +506,7 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel factory.createToken(SyntaxKind.AsteriskToken), /*name*/ undefined, /*typeParameters*/ undefined, - /*parameters*/ [], + parameters ?? [], /*type*/ undefined, body, ); @@ -518,7 +519,7 @@ export function createEmitHelperFactory(context: TransformationContext): EmitHel /*typeArguments*/ undefined, [ hasLexicalThis ? factory.createThis() : factory.createVoidZero(), - hasLexicalArguments ? factory.createIdentifier("arguments") : factory.createVoidZero(), + argumentsExpression ?? factory.createVoidZero(), promiseConstructor ? createExpressionFromEntityName(factory, promiseConstructor) : factory.createVoidZero(), generatorFunc, ], diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index d30b25e2a4580..7aeb18db18b54 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -1,6 +1,7 @@ import { __String, AccessorDeclaration, + addEmitFlags, addEmitHelper, addEmitHelpers, advancedAsyncSuperHelper, @@ -14,7 +15,6 @@ import { CatchClause, chainBundle, ClassDeclaration, - concatenate, ConciseBody, ConstructorDeclaration, Debug, @@ -41,6 +41,7 @@ import { getInitializedVariables, getNodeId, getOriginalNode, + Identifier, insertStatementsAfterStandardPrologue, isAwaitKeyword, isBlock, @@ -57,6 +58,7 @@ import { isNodeWithPossibleHoistedDeclaration, isOmittedExpression, isPropertyAccessExpression, + isSimpleParameterList, isStatement, isSuperProperty, isVariableDeclarationList, @@ -64,6 +66,7 @@ import { map, MethodDeclaration, Node, + NodeArray, NodeCheckFlags, NodeFactory, NodeFlags, @@ -76,8 +79,8 @@ import { setOriginalNode, setSourceMapRange, setTextRange, - some, SourceFile, + startOnNewLine, Statement, SyntaxKind, TextRange, @@ -145,6 +148,7 @@ export function transformES2017(context: TransformationContext): (x: SourceFile let capturedSuperProperties: Set<__String>; /** Whether the async function contains an element access on super (`super[x]`). */ let hasSuperElementAccess: boolean; + let lexicalArgumentsBinding: Identifier | undefined; /** A set of node IDs for generated super accessors (variable statements). */ const substitutedSuperAccessors: boolean[] = []; @@ -203,9 +207,31 @@ export function transformES2017(context: TransformationContext): (x: SourceFile return visitEachChild(node, visitor, context); } + function argumentsVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + return node; + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.VariableDeclaration: + break; + case SyntaxKind.Identifier: + if (lexicalArgumentsBinding && resolver.isArgumentsLocalBinding(node as Identifier)) { + return lexicalArgumentsBinding; + } + break; + } + return visitEachChild(node, argumentsVisitor, context); + } + function visitor(node: Node): VisitResult { if ((node.transformFlags & TransformFlags.ContainsES2017) === 0) { - return node; + return lexicalArgumentsBinding ? argumentsVisitor(node) : node; } switch (node.kind) { case SyntaxKind.AsyncKeyword: @@ -382,12 +408,16 @@ export function transformES2017(context: TransformationContext): (x: SourceFile } function visitConstructorDeclaration(node: ConstructorDeclaration) { - return factory.updateConstructorDeclaration( + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const updated = factory.updateConstructorDeclaration( node, visitNodes(node.modifiers, visitor, isModifier), visitParameterList(node.parameters, visitor, context), transformMethodBody(node), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } /** @@ -399,23 +429,33 @@ export function transformES2017(context: TransformationContext): (x: SourceFile * @param node The node to visit. */ function visitMethodDeclaration(node: MethodDeclaration) { - return factory.updateMethodDeclaration( + let parameters: NodeArray; + const functionFlags = getFunctionFlags(node); + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const updated = factory.updateMethodDeclaration( node, visitNodes(node.modifiers, visitor, isModifierLike), node.asteriskToken, node.name, /*questionToken*/ undefined, /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), + parameters = functionFlags & FunctionFlags.Async ? + transformAsyncFunctionParameterList(node) : + visitParameterList(node.parameters, visitor, context), /*type*/ undefined, - getFunctionFlags(node) & FunctionFlags.Async - ? transformAsyncFunctionBody(node) - : transformMethodBody(node), + functionFlags & FunctionFlags.Async ? + transformAsyncFunctionBody(node, parameters) : + transformMethodBody(node), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } function visitGetAccessorDeclaration(node: GetAccessorDeclaration) { - return factory.updateGetAccessorDeclaration( + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const updated = factory.updateGetAccessorDeclaration( node, visitNodes(node.modifiers, visitor, isModifierLike), node.name, @@ -423,16 +463,22 @@ export function transformES2017(context: TransformationContext): (x: SourceFile /*type*/ undefined, transformMethodBody(node), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } function visitSetAccessorDeclaration(node: SetAccessorDeclaration) { - return factory.updateSetAccessorDeclaration( + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const updated = factory.updateSetAccessorDeclaration( node, visitNodes(node.modifiers, visitor, isModifierLike), node.name, visitParameterList(node.parameters, visitor, context), transformMethodBody(node), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } /** @@ -444,18 +490,26 @@ export function transformES2017(context: TransformationContext): (x: SourceFile * @param node The node to visit. */ function visitFunctionDeclaration(node: FunctionDeclaration): VisitResult { - return factory.updateFunctionDeclaration( + let parameters: NodeArray; + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const functionFlags = getFunctionFlags(node); + const updated = factory.updateFunctionDeclaration( node, visitNodes(node.modifiers, visitor, isModifierLike), node.asteriskToken, node.name, /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), + parameters = functionFlags & FunctionFlags.Async ? + transformAsyncFunctionParameterList(node) : + visitParameterList(node.parameters, visitor, context), /*type*/ undefined, - getFunctionFlags(node) & FunctionFlags.Async - ? transformAsyncFunctionBody(node) - : visitFunctionBody(node.body, visitor, context), + functionFlags & FunctionFlags.Async ? + transformAsyncFunctionBody(node, parameters) : + visitFunctionBody(node.body, visitor, context), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } /** @@ -467,18 +521,26 @@ export function transformES2017(context: TransformationContext): (x: SourceFile * @param node The node to visit. */ function visitFunctionExpression(node: FunctionExpression): Expression { - return factory.updateFunctionExpression( + let parameters: NodeArray; + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; + lexicalArgumentsBinding = undefined; + const functionFlags = getFunctionFlags(node); + const updated = factory.updateFunctionExpression( node, visitNodes(node.modifiers, visitor, isModifier), node.asteriskToken, node.name, /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), + parameters = functionFlags & FunctionFlags.Async ? + transformAsyncFunctionParameterList(node) : + visitParameterList(node.parameters, visitor, context), /*type*/ undefined, - getFunctionFlags(node) & FunctionFlags.Async - ? transformAsyncFunctionBody(node) - : visitFunctionBody(node.body, visitor, context), + functionFlags & FunctionFlags.Async ? + transformAsyncFunctionBody(node, parameters) : + visitFunctionBody(node.body, visitor, context), ); + lexicalArgumentsBinding = savedLexicalArgumentsBinding; + return updated; } /** @@ -490,16 +552,20 @@ export function transformES2017(context: TransformationContext): (x: SourceFile * @param node The node to visit. */ function visitArrowFunction(node: ArrowFunction) { + let parameters: NodeArray; + const functionFlags = getFunctionFlags(node); return factory.updateArrowFunction( node, visitNodes(node.modifiers, visitor, isModifier), /*typeParameters*/ undefined, - visitParameterList(node.parameters, visitor, context), + parameters = functionFlags & FunctionFlags.Async ? + transformAsyncFunctionParameterList(node) : + visitParameterList(node.parameters, visitor, context), /*type*/ undefined, node.equalsGreaterThanToken, - getFunctionFlags(node) & FunctionFlags.Async - ? transformAsyncFunctionBody(node) - : visitFunctionBody(node.body, visitor, context), + functionFlags & FunctionFlags.Async ? + transformAsyncFunctionBody(node, parameters) : + visitFunctionBody(node.body, visitor, context), ); } @@ -623,16 +689,91 @@ export function transformES2017(context: TransformationContext): (x: SourceFile return updated; } - function transformAsyncFunctionBody(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression): FunctionBody; - function transformAsyncFunctionBody(node: ArrowFunction): ConciseBody; - function transformAsyncFunctionBody(node: FunctionLikeDeclaration): ConciseBody { + function createCaptureArgumentsStatement() { + Debug.assert(lexicalArgumentsBinding); + const variable = factory.createVariableDeclaration(lexicalArgumentsBinding, /*exclamationToken*/ undefined, /*type*/ undefined, factory.createIdentifier("arguments")); + const statement = factory.createVariableStatement(/*modifiers*/ undefined, [variable]); + startOnNewLine(statement); + addEmitFlags(statement, EmitFlags.CustomPrologue); + return statement; + } + + function transformAsyncFunctionParameterList(node: FunctionLikeDeclaration) { + if (isSimpleParameterList(node.parameters)) { + return visitParameterList(node.parameters, visitor, context); + } + + const newParameters: ParameterDeclaration[] = []; + for (const parameter of node.parameters) { + if (parameter.initializer || parameter.dotDotDotToken) { + // for an arrow function, capture the remaining arguments in a rest parameter. + // for any other function/method this isn't necessary as we can just use `arguments`. + if (node.kind === SyntaxKind.ArrowFunction) { + const restParameter = factory.createParameterDeclaration( + /*modifiers*/ undefined, + factory.createToken(SyntaxKind.DotDotDotToken), + factory.createUniqueName("args", GeneratedIdentifierFlags.ReservedInNestedScopes), + ); + newParameters.push(restParameter); + } + break; + } + // for arrow functions we capture fixed parameters to forward to `__awaiter`. For all other functions + // we add fixed parameters to preserve the function's `length` property. + const newParameter = factory.createParameterDeclaration( + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + factory.getGeneratedNameForNode(parameter.name, GeneratedIdentifierFlags.ReservedInNestedScopes), + ); + newParameters.push(newParameter); + } + const newParametersArray = factory.createNodeArray(newParameters); + setTextRange(newParametersArray, node.parameters); + return newParametersArray; + } + + function transformAsyncFunctionBody(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression, outerParameters: NodeArray): FunctionBody; + function transformAsyncFunctionBody(node: ArrowFunction, outerParameters: NodeArray): ConciseBody; + function transformAsyncFunctionBody(node: FunctionLikeDeclaration, outerParameters: NodeArray): ConciseBody { + const innerParameters = !isSimpleParameterList(node.parameters) ? visitParameterList(node.parameters, visitor, context) : undefined; resumeLexicalEnvironment(); const original = getOriginalNode(node, isFunctionLike); const nodeType = original.type; const promiseConstructor = languageVersion < ScriptTarget.ES2015 ? getPromiseConstructor(nodeType) : undefined; const isArrowFunction = node.kind === SyntaxKind.ArrowFunction; + const savedLexicalArgumentsBinding = lexicalArgumentsBinding; const hasLexicalArguments = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.CaptureArguments) !== 0; + const captureLexicalArguments = hasLexicalArguments && !lexicalArgumentsBinding; + if (captureLexicalArguments) { + lexicalArgumentsBinding = factory.createUniqueName("arguments"); + } + + let argumentsExpression: Expression | undefined; + if (innerParameters) { + if (isArrowFunction) { + // `node` does not have a simple parameter list, so `outerParameters` refers to placeholders that are + // forwarded to `innerParameters`, matching how they are introduced in `transformAsyncFunctionParameterList`. + const parameterBindings: Expression[] = []; + Debug.assert(outerParameters.length <= node.parameters.length); + for (let i = 0; i < node.parameters.length; i++) { + Debug.assert(i < outerParameters.length); + const originalParameter = node.parameters[i]; + const outerParameter = outerParameters[i]; + Debug.assertNode(outerParameter.name, isIdentifier); + if (originalParameter.initializer || originalParameter.dotDotDotToken) { + Debug.assert(i === outerParameters.length - 1); + parameterBindings.push(factory.createSpreadElement(outerParameter.name)); + break; + } + parameterBindings.push(outerParameter.name); + } + argumentsExpression = factory.createArrayLiteralExpression(parameterBindings); + } + else { + argumentsExpression = factory.createIdentifier("arguments"); + } + } // An async function is emit as an outer function that calls an inner // generator function. To preserve lexical bindings, we pass the current @@ -653,23 +794,26 @@ export function transformES2017(context: TransformationContext): (x: SourceFile hasSuperElementAccess = false; } + const hasLexicalThis = inHasLexicalThisContext(); + + let asyncBody = transformAsyncFunctionBodyWorker(node.body as Block); + asyncBody = factory.updateBlock(asyncBody, factory.mergeLexicalEnvironment(asyncBody.statements, endLexicalEnvironment())); + let result: ConciseBody; if (!isArrowFunction) { const statements: Statement[] = []; - const statementOffset = factory.copyPrologue((node.body as Block).statements, statements, /*ensureUseStrict*/ false, visitor); statements.push( factory.createReturnStatement( emitHelpers().createAwaiterHelper( - inHasLexicalThisContext(), - hasLexicalArguments, + hasLexicalThis, + argumentsExpression, promiseConstructor, - transformAsyncFunctionBodyWorker(node.body as Block, statementOffset), + innerParameters, + asyncBody, ), ), ); - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - // Minor optimization, emit `_super` helper to capture `super` access in an arrow. // This step isn't needed if we eventually transform this to ES5. const emitSuperHelpers = languageVersion >= ScriptTarget.ES2015 && resolver.getNodeCheckFlags(node) & (NodeCheckFlags.MethodWithSuperPropertyAssignmentInAsync | NodeCheckFlags.MethodWithSuperPropertyAccessInAsync); @@ -683,6 +827,10 @@ export function transformES2017(context: TransformationContext): (x: SourceFile } } + if (captureLexicalArguments) { + insertStatementsAfterStandardPrologue(statements, [createCaptureArgumentsStatement()]); + } + const block = factory.createBlock(statements, /*multiLine*/ true); setTextRange(block, node.body); @@ -699,20 +847,17 @@ export function transformES2017(context: TransformationContext): (x: SourceFile result = block; } else { - const expression = emitHelpers().createAwaiterHelper( - inHasLexicalThisContext(), - hasLexicalArguments, + result = emitHelpers().createAwaiterHelper( + hasLexicalThis, + argumentsExpression, promiseConstructor, - transformAsyncFunctionBodyWorker(node.body), + innerParameters, + asyncBody, ); - const declarations = endLexicalEnvironment(); - if (some(declarations)) { - const block = factory.converters.convertToFunctionBlock(expression); - result = factory.updateBlock(block, setTextRange(factory.createNodeArray(concatenate(declarations, block.statements)), block.statements)); - } - else { - result = expression; + if (captureLexicalArguments) { + const block = factory.converters.convertToFunctionBlock(result); + result = factory.updateBlock(block, factory.mergeLexicalEnvironment(block.statements, [createCaptureArgumentsStatement()])); } } @@ -720,6 +865,7 @@ export function transformES2017(context: TransformationContext): (x: SourceFile if (!isArrowFunction) { capturedSuperProperties = savedCapturedSuperProperties; hasSuperElementAccess = savedHasSuperElementAccess; + lexicalArgumentsBinding = savedLexicalArgumentsBinding; } return result; } diff --git a/src/compiler/transformers/es2018.ts b/src/compiler/transformers/es2018.ts index e04d1c679e848..421bb548bf26f 100644 --- a/src/compiler/transformers/es2018.ts +++ b/src/compiler/transformers/es2018.ts @@ -63,6 +63,7 @@ import { isPropertyAccessExpression, isPropertyName, isQuestionToken, + isSimpleParameterList, isStatement, isSuperProperty, isVariableDeclarationList, @@ -103,7 +104,6 @@ import { VariableStatement, visitEachChild, visitIterationBody, - visitLexicalEnvironment, visitNode, visitNodes, visitParameterList, @@ -1050,11 +1050,13 @@ export function transformES2018(context: TransformationContext): (x: SourceFile visitNode(node.name, visitor, isPropertyName), visitNode(/*node*/ undefined, visitor, isQuestionToken), /*typeParameters*/ undefined, - visitParameterList(node.parameters, parameterVisitor, context), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionParameterList(node) : + visitParameterList(node.parameters, parameterVisitor, context), /*type*/ undefined, - enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator - ? transformAsyncGeneratorFunctionBody(node) - : transformFunctionBody(node), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionBody(node) : + transformFunctionBody(node), ); enclosingFunctionFlags = savedEnclosingFunctionFlags; parametersWithPrecedingObjectRestOrSpread = savedParametersWithPrecedingObjectRestOrSpread; @@ -1076,11 +1078,13 @@ export function transformES2018(context: TransformationContext): (x: SourceFile : node.asteriskToken, node.name, /*typeParameters*/ undefined, - visitParameterList(node.parameters, parameterVisitor, context), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionParameterList(node) : + visitParameterList(node.parameters, parameterVisitor, context), /*type*/ undefined, - enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator - ? transformAsyncGeneratorFunctionBody(node) - : transformFunctionBody(node), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionBody(node) : + transformFunctionBody(node), ); enclosingFunctionFlags = savedEnclosingFunctionFlags; parametersWithPrecedingObjectRestOrSpread = savedParametersWithPrecedingObjectRestOrSpread; @@ -1121,28 +1125,54 @@ export function transformES2018(context: TransformationContext): (x: SourceFile : node.asteriskToken, node.name, /*typeParameters*/ undefined, - visitParameterList(node.parameters, parameterVisitor, context), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionParameterList(node) : + visitParameterList(node.parameters, parameterVisitor, context), /*type*/ undefined, - enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator - ? transformAsyncGeneratorFunctionBody(node) - : transformFunctionBody(node), + enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator ? + transformAsyncGeneratorFunctionBody(node) : + transformFunctionBody(node), ); enclosingFunctionFlags = savedEnclosingFunctionFlags; parametersWithPrecedingObjectRestOrSpread = savedParametersWithPrecedingObjectRestOrSpread; return updated; } + function transformAsyncGeneratorFunctionParameterList(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression) { + if (isSimpleParameterList(node.parameters)) { + return visitParameterList(node.parameters, visitor, context); + } + // Add fixed parameters to preserve the function's `length` property. + const newParameters: ParameterDeclaration[] = []; + for (const parameter of node.parameters) { + if (parameter.initializer || parameter.dotDotDotToken) { + break; + } + const newParameter = factory.createParameterDeclaration( + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + factory.getGeneratedNameForNode(parameter.name, GeneratedIdentifierFlags.ReservedInNestedScopes), + ); + newParameters.push(newParameter); + } + const newParametersArray = factory.createNodeArray(newParameters); + setTextRange(newParametersArray, node.parameters); + return newParametersArray; + } + function transformAsyncGeneratorFunctionBody(node: MethodDeclaration | AccessorDeclaration | FunctionDeclaration | FunctionExpression): FunctionBody { + const innerParameters = !isSimpleParameterList(node.parameters) ? visitParameterList(node.parameters, visitor, context) : undefined; resumeLexicalEnvironment(); - const statements: Statement[] = []; - const statementOffset = factory.copyPrologue(node.body!.statements, statements, /*ensureUseStrict*/ false, visitor); - appendObjectRestAssignmentsIfNeeded(statements, node); const savedCapturedSuperProperties = capturedSuperProperties; const savedHasSuperElementAccess = hasSuperElementAccess; capturedSuperProperties = new Set(); hasSuperElementAccess = false; + const outerStatements: Statement[] = []; + let asyncBody = factory.updateBlock(node.body!, visitNodes(node.body!.statements, visitor, isStatement)); + asyncBody = factory.updateBlock(asyncBody, factory.mergeLexicalEnvironment(asyncBody.statements, appendObjectRestAssignmentsIfNeeded(endLexicalEnvironment(), node))); + const returnStatement = factory.createReturnStatement( emitHelpers().createAsyncGeneratorHelper( factory.createFunctionExpression( @@ -1150,12 +1180,9 @@ export function transformES2018(context: TransformationContext): (x: SourceFile factory.createToken(SyntaxKind.AsteriskToken), node.name && factory.getGeneratedNameForNode(node.name), /*typeParameters*/ undefined, - /*parameters*/ [], + innerParameters ?? [], /*type*/ undefined, - factory.updateBlock( - node.body!, - visitLexicalEnvironment(node.body!.statements, visitor, context, statementOffset), - ), + asyncBody, ), !!(hierarchyFacts & HierarchyFacts.HasLexicalThis), ), @@ -1164,19 +1191,16 @@ export function transformES2018(context: TransformationContext): (x: SourceFile // Minor optimization, emit `_super` helper to capture `super` access in an arrow. // This step isn't needed if we eventually transform this to ES5. const emitSuperHelpers = languageVersion >= ScriptTarget.ES2015 && resolver.getNodeCheckFlags(node) & (NodeCheckFlags.MethodWithSuperPropertyAssignmentInAsync | NodeCheckFlags.MethodWithSuperPropertyAccessInAsync); - if (emitSuperHelpers) { enableSubstitutionForAsyncMethodsWithSuper(); const variableStatement = createSuperAccessVariableStatement(factory, resolver, node, capturedSuperProperties); substitutedSuperAccessors[getNodeId(variableStatement)] = true; - insertStatementsAfterStandardPrologue(statements, [variableStatement]); + insertStatementsAfterStandardPrologue(outerStatements, [variableStatement]); } - statements.push(returnStatement); - - insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment()); - const block = factory.updateBlock(node.body!, statements); + outerStatements.push(returnStatement); + const block = factory.updateBlock(node.body!, outerStatements); if (emitSuperHelpers && hasSuperElementAccess) { if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.MethodWithSuperPropertyAssignmentInAsync) { addEmitHelper(block, advancedAsyncSuperHelper); diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 900a409ee9681..9056403e0c1a4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -16,6 +16,7 @@ import { CoreTransformationContext, createExternalHelpersImportDeclarationIfNeeded, Decorator, + every, ExportAssignment, ExportDeclaration, ExportSpecifier, @@ -71,6 +72,7 @@ import { NamespaceExport, Node, NodeArray, + ParameterDeclaration, parameterIsThisKeyword, PrivateIdentifier, PrivateIdentifierAccessorDeclaration, @@ -831,3 +833,13 @@ export function accessPrivateIdentifier< ) { return walkUpLexicalEnvironments(env, env => getPrivateIdentifier(env.privateEnv, name)); } + +/** @internal */ +export function isSimpleParameter(node: ParameterDeclaration) { + return !node.initializer && isIdentifier(node.name); +} + +/** @internal */ +export function isSimpleParameterList(nodes: NodeArray) { + return every(nodes, isSimpleParameter); +} diff --git a/tests/baselines/reference/asyncArrowFunction6_es5.js b/tests/baselines/reference/asyncArrowFunction6_es5.js index 80f48d6e47e85..52cfc0427eca5 100644 --- a/tests/baselines/reference/asyncArrowFunction6_es5.js +++ b/tests/baselines/reference/asyncArrowFunction6_es5.js @@ -6,11 +6,18 @@ var foo = async (a = await): Promise => { //// [asyncArrowFunction6_es5.js] var _this = this; -var foo = function (a) { - if (a === void 0) { a = yield ; } - return __awaiter(_this, void 0, void 0, function () { +var foo = function () { + var args_1 = []; + for (var _i = 0; _i < arguments.length; _i++) { + args_1[_i] = arguments[_i]; + } + return __awaiter(_this, __spreadArray([], args_1, true), void 0, function (a) { + if (a === void 0) { a = _a.sent(); } return __generator(this, function (_a) { - return [2 /*return*/]; + switch (_a.label) { + case 0: return [4 /*yield*/, ]; + case 1: return [2 /*return*/]; + } }); }); }; diff --git a/tests/baselines/reference/asyncArrowFunction6_es6.js b/tests/baselines/reference/asyncArrowFunction6_es6.js index 52726cebb0a87..4fc2e2b4113e7 100644 --- a/tests/baselines/reference/asyncArrowFunction6_es6.js +++ b/tests/baselines/reference/asyncArrowFunction6_es6.js @@ -5,5 +5,5 @@ var foo = async (a = await): Promise => { } //// [asyncArrowFunction6_es6.js] -var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { +var foo = (...args_1) => __awaiter(this, [...args_1], void 0, function* (a = yield ) { }); diff --git a/tests/baselines/reference/asyncArrowFunction7_es5.js b/tests/baselines/reference/asyncArrowFunction7_es5.js index 4bc3a52e1d391..7144ebad6adaf 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es5.js +++ b/tests/baselines/reference/asyncArrowFunction7_es5.js @@ -13,11 +13,18 @@ var bar = function () { return __awaiter(_this, void 0, void 0, function () { var foo; var _this = this; return __generator(this, function (_a) { - foo = function (a) { - if (a === void 0) { a = yield ; } - return __awaiter(_this, void 0, void 0, function () { + foo = function () { + var args_1 = []; + for (var _i = 0; _i < arguments.length; _i++) { + args_1[_i] = arguments[_i]; + } + return __awaiter(_this, __spreadArray([], args_1, true), void 0, function (a) { + if (a === void 0) { a = _a.sent(); } return __generator(this, function (_a) { - return [2 /*return*/]; + switch (_a.label) { + case 0: return [4 /*yield*/, ]; + case 1: return [2 /*return*/]; + } }); }); }; diff --git a/tests/baselines/reference/asyncArrowFunction7_es6.js b/tests/baselines/reference/asyncArrowFunction7_es6.js index 7e3182d9e2b48..7a1ee0eeef4b5 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es6.js +++ b/tests/baselines/reference/asyncArrowFunction7_es6.js @@ -10,6 +10,6 @@ var bar = async (): Promise => { //// [asyncArrowFunction7_es6.js] var bar = () => __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not an await expression. - var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { + var foo = (...args_1) => __awaiter(this, [...args_1], void 0, function* (a = yield ) { }); }); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js index 4ff229a21149e..5594f77accd7e 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es5.js @@ -16,12 +16,15 @@ var C = /** @class */ (function () { 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()]; - } - }); }); }; + var fn = function () { + var arguments_1 = arguments; + return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, other.apply(this, arguments_1)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); + }; }; return C; }()); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js index 5fffa66d65eba..ae0db7fbe7cca 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js @@ -4,15 +4,27 @@ class C { method() { function other() {} - var fn = async () => await other.apply(this, arguments); + var fn = async () => await other.apply(this, arguments); } } - + +function f() { + return async () => async () => arguments.length; +} //// [asyncArrowFunctionCapturesArguments_es6.js] class C { method() { function other() { } - var fn = () => __awaiter(this, arguments, void 0, function* () { return yield other.apply(this, arguments); }); + var fn = () => { + var arguments_1 = arguments; + return __awaiter(this, void 0, void 0, function* () { return yield other.apply(this, arguments_1); }); + }; } } +function f() { + return () => { + var arguments_2 = arguments; + return __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_2.length; }); }); + }; +} diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols index 1a1c7f7e35058..dd1e59a5d8360 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.symbols @@ -10,7 +10,7 @@ class C { function other() {} >other : Symbol(other, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 1, 13)) - var fn = async () => await other.apply(this, arguments); + var fn = async () => await other.apply(this, arguments); >fn : Symbol(fn, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 3, 9)) >other.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --)) >other : Symbol(other, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 1, 13)) @@ -20,3 +20,11 @@ class C { } } +function f() { +>f : Symbol(f, Decl(asyncArrowFunctionCapturesArguments_es6.ts, 5, 1)) + + return async () => async () => arguments.length; +>arguments.length : Symbol(IArguments.length, Decl(lib.es5.d.ts, --, --)) +>arguments : Symbol(arguments) +>length : Symbol(IArguments.length, Decl(lib.es5.d.ts, --, --)) +} diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types index bb38f6f43c34d..a8d8bd8e3c320 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.types @@ -10,7 +10,7 @@ class C { function other() {} >other : () => void - var fn = async () => await other.apply(this, arguments); + var fn = async () => await other.apply(this, arguments); >fn : () => Promise >async () => await other.apply(this, arguments) : () => Promise >await other.apply(this, arguments) : any @@ -23,3 +23,13 @@ class C { } } +function f() { +>f : () => () => Promise<() => Promise> + + return async () => async () => arguments.length; +>async () => async () => arguments.length : () => Promise<() => Promise> +>async () => arguments.length : () => Promise +>arguments.length : number +>arguments : IArguments +>length : number +} diff --git a/tests/baselines/reference/asyncFunctionDeclaration10_es5.js b/tests/baselines/reference/asyncFunctionDeclaration10_es5.js index b8bdd55fde011..3e4b240577f72 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration10_es5.js +++ b/tests/baselines/reference/asyncFunctionDeclaration10_es5.js @@ -5,11 +5,14 @@ async function foo(a = await => await): Promise { } //// [asyncFunctionDeclaration10_es5.js] -function foo(a, await) { - if (a === void 0) { a = yield ; } - return __awaiter(this, void 0, void 0, function () { +function foo() { + return __awaiter(this, arguments, void 0, function (a, await) { + if (a === void 0) { a = _a.sent(); } return __generator(this, function (_a) { - return [2 /*return*/]; + switch (_a.label) { + case 0: return [4 /*yield*/, ]; + case 1: return [2 /*return*/]; + } }); }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration10_es6.js b/tests/baselines/reference/asyncFunctionDeclaration10_es6.js index 75a83863abe3a..f9f438cc67c02 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration10_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration10_es6.js @@ -5,7 +5,7 @@ async function foo(a = await => await): Promise { } //// [asyncFunctionDeclaration10_es6.js] -function foo(a = yield , await) { - return __awaiter(this, void 0, void 0, function* () { +function foo() { + return __awaiter(this, arguments, void 0, function* (a = yield , await) { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es5.js b/tests/baselines/reference/asyncFunctionDeclaration6_es5.js index df1ff577c9a40..955e59b233202 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration6_es5.js +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es5.js @@ -5,11 +5,14 @@ async function foo(a = await): Promise { } //// [asyncFunctionDeclaration6_es5.js] -function foo(a) { - if (a === void 0) { a = yield ; } - return __awaiter(this, void 0, void 0, function () { +function foo() { + return __awaiter(this, arguments, void 0, function (a) { + if (a === void 0) { a = _a.sent(); } return __generator(this, function (_a) { - return [2 /*return*/]; + switch (_a.label) { + case 0: return [4 /*yield*/, ]; + case 1: return [2 /*return*/]; + } }); }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js index 986375ea359f3..419d67e8e0df0 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js @@ -5,7 +5,7 @@ async function foo(a = await): Promise { } //// [asyncFunctionDeclaration6_es6.js] -function foo(a = yield ) { - return __awaiter(this, void 0, void 0, function* () { +function foo() { + return __awaiter(this, arguments, void 0, function* (a = yield ) { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es5.js b/tests/baselines/reference/asyncFunctionDeclaration7_es5.js index afab23a54e73a..39cd2ed76a95c 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration7_es5.js +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es5.js @@ -11,11 +11,14 @@ async function bar(): Promise { function bar() { return __awaiter(this, void 0, void 0, function () { // 'await' here is an identifier, and not a yield expression. - function foo(a) { - if (a === void 0) { a = yield ; } - return __awaiter(this, void 0, void 0, function () { + function foo() { + return __awaiter(this, arguments, void 0, function (a) { + if (a === void 0) { a = _a.sent(); } return __generator(this, function (_a) { - return [2 /*return*/]; + switch (_a.label) { + case 0: return [4 /*yield*/, ]; + case 1: return [2 /*return*/]; + } }); }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js index 4cbe0c2e25c42..bec37abf44280 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js @@ -11,8 +11,8 @@ async function bar(): Promise { function bar() { return __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not a yield expression. - function foo(a = yield ) { - return __awaiter(this, void 0, void 0, function* () { + function foo() { + return __awaiter(this, arguments, void 0, function* (a = yield ) { }); } }); diff --git a/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js index 0f19b34c128f5..b254df413ba4d 100644 --- a/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js +++ b/tests/baselines/reference/asyncFunctionDeclarationCapturesArguments_es5.js @@ -18,10 +18,11 @@ var C = /** @class */ (function () { C.prototype.method = function () { function other() { } function fn() { - return __awaiter(this, arguments, void 0, function () { + var arguments_1 = arguments; + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, other.apply(this, arguments)]; + case 0: return [4 /*yield*/, other.apply(this, arguments_1)]; case 1: _a.sent(); return [2 /*return*/]; diff --git a/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).errors.txt b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).errors.txt new file mode 100644 index 0000000000000..3b57c8c86f477 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).errors.txt @@ -0,0 +1,100 @@ +asyncFunctionDeclarationParameterEvaluation.ts(2,26): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(3,21): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(3,21): error TS2538: Type 'any' cannot be used as an index type. +asyncFunctionDeclarationParameterEvaluation.ts(4,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(5,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(6,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(7,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(8,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(9,41): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(10,41): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(11,24): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(12,36): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(13,36): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(15,30): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(16,25): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(16,25): error TS2538: Type 'any' cannot be used as an index type. +asyncFunctionDeclarationParameterEvaluation.ts(17,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(18,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(19,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(20,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(21,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(22,48): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(23,48): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(24,28): error TS2304: Cannot find name 'z'. + + +==== asyncFunctionDeclarationParameterEvaluation.ts (24 errors) ==== + // https://github.com/microsoft/TypeScript/issues/40410 + async function f1(x, y = z) {} + ~ +!!! error TS2304: Cannot find name 'z'. + async function f2({[z]: x}) {} + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + async function f3(x = z) { return async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f4(x = z) { return async () => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f5(x = z, ...args) { } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f6(x = z, ...args) { return async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f7(x = z, ...args) { return async () => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f8() { return async (x = z) => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f9() { return async (x = z) => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f10(x = z) { return async () => async function () { return async () => arguments; }; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f11() { return async (x = z) => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f12() { return async (x = z) => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f() { + const a1 = async (x, y = z) => {}; + ~ +!!! error TS2304: Cannot find name 'z'. + const a2 = async ({[z]: x}) => {}; + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + const a3 = async (x = z) => { return async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a4 = async (x = z) => { return async () => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a5 = async (x = z, ...args) => { }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a6 = async (x = z, ...args) => { return async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a8 = async () => { return async (x = z) => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a9 = async () => { return async (x = z) => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; + ~ +!!! error TS2304: Cannot find name 'z'. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).js b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).js new file mode 100644 index 0000000000000..e9282352c199b --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2015).js @@ -0,0 +1,96 @@ +//// [tests/cases/conformance/async/asyncFunctionDeclarationParameterEvaluation.ts] //// + +//// [asyncFunctionDeclarationParameterEvaluation.ts] +// https://github.com/microsoft/TypeScript/issues/40410 +async function f1(x, y = z) {} +async function f2({[z]: x}) {} +async function f3(x = z) { return async () => arguments; } +async function f4(x = z) { return async () => async () => arguments; } +async function f5(x = z, ...args) { } +async function f6(x = z, ...args) { return async () => arguments; } +async function f7(x = z, ...args) { return async () => async () => arguments; } +async function f8() { return async (x = z) => arguments; } +async function f9() { return async (x = z) => async () => arguments; } +async function f10(x = z) { return async () => async function () { return async () => arguments; }; } +function f11() { return async (x = z) => arguments; } +function f12() { return async (x = z) => async () => arguments; } +function f() { + const a1 = async (x, y = z) => {}; + const a2 = async ({[z]: x}) => {}; + const a3 = async (x = z) => { return async () => arguments; }; + const a4 = async (x = z) => { return async () => async () => arguments; }; + const a5 = async (x = z, ...args) => { }; + const a6 = async (x = z, ...args) => { return async () => arguments; }; + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + const a8 = async () => { return async (x = z) => arguments; }; + const a9 = async () => { return async (x = z) => async () => arguments; }; + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; +} + +//// [asyncFunctionDeclarationParameterEvaluation.js] +// https://github.com/microsoft/TypeScript/issues/40410 +function f1(x_1) { + return __awaiter(this, arguments, void 0, function* (x, y = z) { }); +} +function f2(_a) { + return __awaiter(this, arguments, void 0, function* ({ [z]: x }) { }); +} +function f3() { + var arguments_1 = arguments; + return __awaiter(this, arguments, void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_1; }); }); +} +function f4() { + var arguments_2 = arguments; + return __awaiter(this, arguments, void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_2; }); }); }); +} +function f5() { + return __awaiter(this, arguments, void 0, function* (x = z, ...args) { }); +} +function f6() { + var arguments_3 = arguments; + return __awaiter(this, arguments, void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_3; }); }); +} +function f7() { + var arguments_4 = arguments; + return __awaiter(this, arguments, void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_4; }); }); }); +} +function f8() { + var arguments_5 = arguments; + return __awaiter(this, void 0, void 0, function* () { return (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return arguments_5; }); }); +} +function f9() { + var arguments_6 = arguments; + return __awaiter(this, void 0, void 0, function* () { return (...args_1) => __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_6; }); }); }); +} +function f10() { + return __awaiter(this, arguments, void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return function () { + var arguments_7 = arguments; + return __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_7; }); }); + }; }); }); +} +function f11() { return (...args_1) => { + var arguments_8 = arguments; + return __awaiter(this, [...args_1], void 0, function* (x = z) { return arguments_8; }); +}; } +function f12() { return (...args_1) => { + var arguments_9 = arguments; + return __awaiter(this, [...args_1], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_9; }); }); +}; } +function f() { + const a1 = (x_1, ...args_1) => __awaiter(this, [x_1, ...args_1], void 0, function* (x, y = z) { }); + const a2 = (_a) => __awaiter(this, [_a], void 0, function* ({ [z]: x }) { }); + const a3 = (...args_2) => { + var arguments_10 = arguments; + return __awaiter(this, [...args_2], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); + }; + const a4 = (...args_2) => __awaiter(this, [...args_2], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); }); + const a5 = (...args_3) => __awaiter(this, [...args_3], void 0, function* (x = z, ...args) { }); + const a6 = (...args_4) => __awaiter(this, [...args_4], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); + const a7 = (...args_5) => __awaiter(this, [...args_5], void 0, function* (x = z, ...args) { return () => __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); }); + const a8 = () => __awaiter(this, void 0, void 0, function* () { return (...args_6) => __awaiter(this, [...args_6], void 0, function* (x = z) { return arguments_10; }); }); + const a9 = () => __awaiter(this, void 0, void 0, function* () { return (...args_7) => __awaiter(this, [...args_7], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return arguments_10; }); }); }); + const a10 = (...args_8) => __awaiter(this, [...args_8], void 0, function* (x = z) { return () => __awaiter(this, void 0, void 0, function* () { return function () { + var arguments_11 = arguments; + return __awaiter(this, void 0, void 0, function* () { return () => __awaiter(this, void 0, void 0, function* () { return arguments_11; }); }); + }; }); }); +} diff --git a/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).errors.txt b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).errors.txt new file mode 100644 index 0000000000000..3b57c8c86f477 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).errors.txt @@ -0,0 +1,100 @@ +asyncFunctionDeclarationParameterEvaluation.ts(2,26): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(3,21): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(3,21): error TS2538: Type 'any' cannot be used as an index type. +asyncFunctionDeclarationParameterEvaluation.ts(4,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(5,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(6,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(7,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(8,23): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(9,41): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(10,41): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(11,24): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(12,36): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(13,36): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(15,30): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(16,25): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(16,25): error TS2538: Type 'any' cannot be used as an index type. +asyncFunctionDeclarationParameterEvaluation.ts(17,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(18,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(19,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(20,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(21,27): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(22,48): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(23,48): error TS2304: Cannot find name 'z'. +asyncFunctionDeclarationParameterEvaluation.ts(24,28): error TS2304: Cannot find name 'z'. + + +==== asyncFunctionDeclarationParameterEvaluation.ts (24 errors) ==== + // https://github.com/microsoft/TypeScript/issues/40410 + async function f1(x, y = z) {} + ~ +!!! error TS2304: Cannot find name 'z'. + async function f2({[z]: x}) {} + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + async function f3(x = z) { return async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f4(x = z) { return async () => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f5(x = z, ...args) { } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f6(x = z, ...args) { return async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f7(x = z, ...args) { return async () => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f8() { return async (x = z) => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f9() { return async (x = z) => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + async function f10(x = z) { return async () => async function () { return async () => arguments; }; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f11() { return async (x = z) => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f12() { return async (x = z) => async () => arguments; } + ~ +!!! error TS2304: Cannot find name 'z'. + function f() { + const a1 = async (x, y = z) => {}; + ~ +!!! error TS2304: Cannot find name 'z'. + const a2 = async ({[z]: x}) => {}; + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + const a3 = async (x = z) => { return async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a4 = async (x = z) => { return async () => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a5 = async (x = z, ...args) => { }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a6 = async (x = z, ...args) => { return async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a8 = async () => { return async (x = z) => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a9 = async () => { return async (x = z) => async () => arguments; }; + ~ +!!! error TS2304: Cannot find name 'z'. + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; + ~ +!!! error TS2304: Cannot find name 'z'. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).js b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).js new file mode 100644 index 0000000000000..ec09c5f4d8883 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionDeclarationParameterEvaluation(target=es2017).js @@ -0,0 +1,55 @@ +//// [tests/cases/conformance/async/asyncFunctionDeclarationParameterEvaluation.ts] //// + +//// [asyncFunctionDeclarationParameterEvaluation.ts] +// https://github.com/microsoft/TypeScript/issues/40410 +async function f1(x, y = z) {} +async function f2({[z]: x}) {} +async function f3(x = z) { return async () => arguments; } +async function f4(x = z) { return async () => async () => arguments; } +async function f5(x = z, ...args) { } +async function f6(x = z, ...args) { return async () => arguments; } +async function f7(x = z, ...args) { return async () => async () => arguments; } +async function f8() { return async (x = z) => arguments; } +async function f9() { return async (x = z) => async () => arguments; } +async function f10(x = z) { return async () => async function () { return async () => arguments; }; } +function f11() { return async (x = z) => arguments; } +function f12() { return async (x = z) => async () => arguments; } +function f() { + const a1 = async (x, y = z) => {}; + const a2 = async ({[z]: x}) => {}; + const a3 = async (x = z) => { return async () => arguments; }; + const a4 = async (x = z) => { return async () => async () => arguments; }; + const a5 = async (x = z, ...args) => { }; + const a6 = async (x = z, ...args) => { return async () => arguments; }; + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + const a8 = async () => { return async (x = z) => arguments; }; + const a9 = async () => { return async (x = z) => async () => arguments; }; + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; +} + +//// [asyncFunctionDeclarationParameterEvaluation.js] +// https://github.com/microsoft/TypeScript/issues/40410 +async function f1(x, y = z) { } +async function f2({ [z]: x }) { } +async function f3(x = z) { return async () => arguments; } +async function f4(x = z) { return async () => async () => arguments; } +async function f5(x = z, ...args) { } +async function f6(x = z, ...args) { return async () => arguments; } +async function f7(x = z, ...args) { return async () => async () => arguments; } +async function f8() { return async (x = z) => arguments; } +async function f9() { return async (x = z) => async () => arguments; } +async function f10(x = z) { return async () => async function () { return async () => arguments; }; } +function f11() { return async (x = z) => arguments; } +function f12() { return async (x = z) => async () => arguments; } +function f() { + const a1 = async (x, y = z) => { }; + const a2 = async ({ [z]: x }) => { }; + const a3 = async (x = z) => { return async () => arguments; }; + const a4 = async (x = z) => { return async () => async () => arguments; }; + const a5 = async (x = z, ...args) => { }; + const a6 = async (x = z, ...args) => { return async () => arguments; }; + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + const a8 = async () => { return async (x = z) => arguments; }; + const a9 = async () => { return async (x = z) => async () => arguments; }; + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; +} diff --git a/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.symbols b/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.symbols index d7c1605b9721f..c039dfabf9144 100644 --- a/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.symbols +++ b/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.symbols @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts] //// +//// [tests/cases/conformance/asyncGenerators/asyncGeneratorGenericNonWrappedReturn.ts] //// === asyncGeneratorGenericNonWrappedReturn.ts === // #48966 diff --git a/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.types b/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.types index f0dbaca258920..90eeb4ac32e8a 100644 --- a/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.types +++ b/tests/baselines/reference/asyncGeneratorGenericNonWrappedReturn.types @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts] //// +//// [tests/cases/conformance/asyncGenerators/asyncGeneratorGenericNonWrappedReturn.ts] //// === asyncGeneratorGenericNonWrappedReturn.ts === // #48966 diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).errors.txt b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).errors.txt new file mode 100644 index 0000000000000..057f47cc6c8fb --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).errors.txt @@ -0,0 +1,24 @@ +asyncGeneratorParameterEvaluation.ts(2,27): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2538: Type 'any' cannot be used as an index type. +asyncGeneratorParameterEvaluation.ts(7,22): error TS2304: Cannot find name 'z'. + + +==== asyncGeneratorParameterEvaluation.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/40410 + async function* f1(x, y = z) {} + ~ +!!! error TS2304: Cannot find name 'z'. + async function* f2({[z]: x}) {} + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + + declare class Super { foo(): void; } + class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } + ~ +!!! error TS2304: Cannot find name 'z'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).js b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).js new file mode 100644 index 0000000000000..2cbad17364e65 --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2015).js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts] //// + +//// [asyncGeneratorParameterEvaluation.ts] +// https://github.com/microsoft/TypeScript/issues/40410 +async function* f1(x, y = z) {} +async function* f2({[z]: x}) {} + +declare class Super { foo(): void; } +class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } +} + + +//// [asyncGeneratorParameterEvaluation.js] +// https://github.com/microsoft/TypeScript/issues/40410 +function f1(x_1) { return __asyncGenerator(this, arguments, function* f1_1(x, y = z) { }); } +function f2(_a) { return __asyncGenerator(this, arguments, function* f2_1({ [z]: x }) { }); } +class Sub extends Super { + m(x_1) { const _super = Object.create(null, { + foo: { get: () => super.foo } + }); return __asyncGenerator(this, arguments, function* m_1(x, y = z, _a) { var w = __rest(_a, []); _super.foo.call(this); }); } +} diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).errors.txt b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).errors.txt new file mode 100644 index 0000000000000..057f47cc6c8fb --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).errors.txt @@ -0,0 +1,24 @@ +asyncGeneratorParameterEvaluation.ts(2,27): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2538: Type 'any' cannot be used as an index type. +asyncGeneratorParameterEvaluation.ts(7,22): error TS2304: Cannot find name 'z'. + + +==== asyncGeneratorParameterEvaluation.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/40410 + async function* f1(x, y = z) {} + ~ +!!! error TS2304: Cannot find name 'z'. + async function* f2({[z]: x}) {} + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + + declare class Super { foo(): void; } + class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } + ~ +!!! error TS2304: Cannot find name 'z'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).js b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).js new file mode 100644 index 0000000000000..2cbad17364e65 --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2017).js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts] //// + +//// [asyncGeneratorParameterEvaluation.ts] +// https://github.com/microsoft/TypeScript/issues/40410 +async function* f1(x, y = z) {} +async function* f2({[z]: x}) {} + +declare class Super { foo(): void; } +class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } +} + + +//// [asyncGeneratorParameterEvaluation.js] +// https://github.com/microsoft/TypeScript/issues/40410 +function f1(x_1) { return __asyncGenerator(this, arguments, function* f1_1(x, y = z) { }); } +function f2(_a) { return __asyncGenerator(this, arguments, function* f2_1({ [z]: x }) { }); } +class Sub extends Super { + m(x_1) { const _super = Object.create(null, { + foo: { get: () => super.foo } + }); return __asyncGenerator(this, arguments, function* m_1(x, y = z, _a) { var w = __rest(_a, []); _super.foo.call(this); }); } +} diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).errors.txt b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).errors.txt new file mode 100644 index 0000000000000..057f47cc6c8fb --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).errors.txt @@ -0,0 +1,24 @@ +asyncGeneratorParameterEvaluation.ts(2,27): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2304: Cannot find name 'z'. +asyncGeneratorParameterEvaluation.ts(3,22): error TS2538: Type 'any' cannot be used as an index type. +asyncGeneratorParameterEvaluation.ts(7,22): error TS2304: Cannot find name 'z'. + + +==== asyncGeneratorParameterEvaluation.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/40410 + async function* f1(x, y = z) {} + ~ +!!! error TS2304: Cannot find name 'z'. + async function* f2({[z]: x}) {} + ~ +!!! error TS2304: Cannot find name 'z'. + ~ +!!! error TS2538: Type 'any' cannot be used as an index type. + + declare class Super { foo(): void; } + class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } + ~ +!!! error TS2304: Cannot find name 'z'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).js b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).js new file mode 100644 index 0000000000000..1e72faf417bae --- /dev/null +++ b/tests/baselines/reference/asyncGeneratorParameterEvaluation(target=es2018).js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts] //// + +//// [asyncGeneratorParameterEvaluation.ts] +// https://github.com/microsoft/TypeScript/issues/40410 +async function* f1(x, y = z) {} +async function* f2({[z]: x}) {} + +declare class Super { foo(): void; } +class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } +} + + +//// [asyncGeneratorParameterEvaluation.js] +// https://github.com/microsoft/TypeScript/issues/40410 +async function* f1(x, y = z) { } +async function* f2({ [z]: x }) { } +class Sub extends Super { + async *m(x, y = z, { ...w }) { super.foo(); } +} diff --git a/tests/baselines/reference/asyncUseStrict_es5.js b/tests/baselines/reference/asyncUseStrict_es5.js index 26eae828f0ed2..52b21660678df 100644 --- a/tests/baselines/reference/asyncUseStrict_es5.js +++ b/tests/baselines/reference/asyncUseStrict_es5.js @@ -10,8 +10,8 @@ async function func(): Promise { //// [asyncUseStrict_es5.js] function func() { - "use strict"; return __awaiter(this, void 0, void 0, function () { + "use strict"; var b; return __generator(this, function (_a) { switch (_a.label) { diff --git a/tests/baselines/reference/asyncUseStrict_es6.js b/tests/baselines/reference/asyncUseStrict_es6.js index a27aa89e637f7..013cd747f0293 100644 --- a/tests/baselines/reference/asyncUseStrict_es6.js +++ b/tests/baselines/reference/asyncUseStrict_es6.js @@ -10,8 +10,8 @@ async function func(): Promise { //// [asyncUseStrict_es6.js] function func() { - "use strict"; return __awaiter(this, void 0, void 0, function* () { + "use strict"; var b = (yield p) || a; }); } diff --git a/tests/baselines/reference/asyncWithVarShadowing_es6.js b/tests/baselines/reference/asyncWithVarShadowing_es6.js index 0d2060e9fa3ce..b9ba6480b99bf 100644 --- a/tests/baselines/reference/asyncWithVarShadowing_es6.js +++ b/tests/baselines/reference/asyncWithVarShadowing_es6.js @@ -226,13 +226,13 @@ async function fn40(x) { //// [asyncWithVarShadowing_es6.js] function fn1(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; }); } function fn2(x) { - var x, z; return __awaiter(this, void 0, void 0, function* () { + var x, z; }); } function fn3(x) { @@ -241,116 +241,116 @@ function fn3(x) { }); } function fn4(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; x = y; }); } function fn5(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; ({ x } = y); }); } function fn6(x) { - var x, z; return __awaiter(this, void 0, void 0, function* () { + var x, z; ({ x, z } = y); }); } function fn7(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; ({ x = y } = y); }); } function fn8(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; ({ z: x } = y); }); } function fn9(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; ({ z: { x } } = y); }); } function fn10(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; ({ z: { x } = y } = y); }); } function fn11(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; x = __rest(y, []); }); } function fn12(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [x] = y; }); } function fn13(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [x = y] = y; }); } function fn14(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [, x] = y; }); } function fn15(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [...x] = y; }); } function fn16(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [[x]] = y; }); } function fn17(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; [[x] = y] = y; }); } -function fn18({ x }) { - var x; - return __awaiter(this, void 0, void 0, function* () { +function fn18(_a) { + return __awaiter(this, arguments, void 0, function* ({ x }) { + var x; }); } -function fn19([x]) { - var x; - return __awaiter(this, void 0, void 0, function* () { +function fn19(_a) { + return __awaiter(this, arguments, void 0, function* ([x]) { + var x; }); } function fn20(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; { } }); } function fn21(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; if (y) { } }); } function fn22(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; if (y) { } else { @@ -358,8 +358,8 @@ function fn22(x) { }); } function fn23(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; try { } catch (e) { @@ -367,8 +367,8 @@ function fn23(x) { }); } function fn24(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; try { } catch (e) { @@ -394,8 +394,8 @@ function fn26(x) { }); } function fn27(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; try { } finally { @@ -403,94 +403,94 @@ function fn27(x) { }); } function fn28(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; while (y) { } }); } function fn29(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; do { } while (y); }); } function fn30(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (x = y;;) { } }); } function fn31(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for ({ x } = y;;) { } }); } function fn32(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (;;) { } }); } function fn33(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (x in y) { } }); } function fn34(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (var z in y) { } }); } function fn35(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (x of y) { } }); } function fn36(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for ({ x } of y) { } }); } function fn37(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; for (var z of y) { } }); } function fn38(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; switch (y) { case y: } }); } function fn39(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; foo: { break foo; } }); } function fn40(x) { - var x; return __awaiter(this, void 0, void 0, function* () { + var x; try { } catch (_a) { diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js index d9256e21a2bcd..3c28b672a261f 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es2015).js @@ -69,8 +69,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function main() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { + var _a, e_1, _b, _c; try { for (var _d = true, _e = __asyncValues([{ [Symbol.asyncDispose]() { return __awaiter(this, void 0, void 0, function* () { }); diff --git a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js index 9f6518c1e034b..436667622b0a1 100644 --- a/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js +++ b/tests/baselines/reference/awaitUsingDeclarationsInForAwaitOf(target=es5).js @@ -96,26 +96,26 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function main() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { - var _d, _e, _f, d1_1, env_1, d1, e_2, result_1, e_1_1; - var _g, _h; + var _a, _b, _c, d1_1, env_1, d1, e_1, result_1, e_2_1; + var _d, _e; + var _f, e_2, _g, _h; return __generator(this, function (_j) { switch (_j.label) { case 0: _j.trys.push([0, 10, 11, 16]); - _d = true, _e = __asyncValues([(_g = {}, _g[Symbol.asyncDispose] = function () { + _a = true, _b = __asyncValues([(_d = {}, _d[Symbol.asyncDispose] = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/]; }); }); - }, _g), (_h = {}, _h[Symbol.dispose] = function () { }, _h), null, undefined]); + }, _d), (_e = {}, _e[Symbol.dispose] = function () { }, _e), null, undefined]); _j.label = 1; - case 1: return [4 /*yield*/, _e.next()]; + case 1: return [4 /*yield*/, _b.next()]; case 2: - if (!(_f = _j.sent(), _a = _f.done, !_a)) return [3 /*break*/, 9]; - _c = _f.value; - _d = false; - d1_1 = _c; + if (!(_c = _j.sent(), _f = _c.done, !_f)) return [3 /*break*/, 9]; + _h = _c.value; + _a = false; + d1_1 = _h; env_1 = { stack: [], error: void 0, hasError: false }; _j.label = 3; case 3: @@ -123,8 +123,8 @@ function main() { d1 = __addDisposableResource(env_1, d1_1, true); return [3 /*break*/, 8]; case 4: - e_2 = _j.sent(); - env_1.error = e_2; + e_1 = _j.sent(); + env_1.error = e_1; env_1.hasError = true; return [3 /*break*/, 8]; case 5: @@ -136,23 +136,23 @@ function main() { _j.label = 7; case 7: return [7 /*endfinally*/]; case 8: - _d = true; + _a = true; return [3 /*break*/, 1]; case 9: return [3 /*break*/, 16]; case 10: - e_1_1 = _j.sent(); - e_1 = { error: e_1_1 }; + e_2_1 = _j.sent(); + e_2 = { error: e_2_1 }; return [3 /*break*/, 16]; case 11: _j.trys.push([11, , 14, 15]); - if (!(!_d && !_a && (_b = _e.return))) return [3 /*break*/, 13]; - return [4 /*yield*/, _b.call(_e)]; + if (!(!_a && !_f && (_g = _b.return))) return [3 /*break*/, 13]; + return [4 /*yield*/, _g.call(_b)]; case 12: _j.sent(); _j.label = 13; case 13: return [3 /*break*/, 15]; case 14: - if (e_1) throw e_1.error; + if (e_2) throw e_2.error; return [7 /*endfinally*/]; case 15: return [7 /*endfinally*/]; case 16: return [2 /*return*/]; diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 22e6748d92c17..ff75c42c44a50 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -180,11 +180,12 @@ function foo() { arguments; yield ; function ff() { - return __awaiter(this, arguments, void 0, function () { + var arguments_1 = arguments; + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: - arguments; + arguments_1; return [4 /*yield*/, ]; case 1: _a.sent(); diff --git a/tests/baselines/reference/emitter.forAwait(target=es2015).js b/tests/baselines/reference/emitter.forAwait(target=es2015).js index 134259e0b9c68..5e77358f5efab 100644 --- a/tests/baselines/reference/emitter.forAwait(target=es2015).js +++ b/tests/baselines/reference/emitter.forAwait(target=es2015).js @@ -68,8 +68,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function f1() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { + var _a, e_1, _b, _c; let y; try { for (var _d = true, y_1 = __asyncValues(y), y_1_1; y_1_1 = yield y_1.next(), _a = y_1_1.done, !_a; _d = true) { @@ -105,8 +105,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function f2() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { + var _a, e_1, _b, _c; let x, y; try { for (var _d = true, y_1 = __asyncValues(y), y_1_1; y_1_1 = yield y_1.next(), _a = y_1_1.done, !_a; _d = true) { @@ -225,8 +225,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { }; // https://github.com/Microsoft/TypeScript/issues/21363 function f5() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { + var _a, e_1, _b, _c; let y; try { outer: for (var _d = true, y_1 = __asyncValues(y), y_1_1; y_1_1 = yield y_1.next(), _a = y_1_1.done, !_a; _d = true) { diff --git a/tests/baselines/reference/emitter.forAwait(target=es5).js b/tests/baselines/reference/emitter.forAwait(target=es5).js index 01b176d224539..da767cdc76492 100644 --- a/tests/baselines/reference/emitter.forAwait(target=es5).js +++ b/tests/baselines/reference/emitter.forAwait(target=es5).js @@ -95,24 +95,24 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function f1() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { - var y, _d, y_1, y_1_1, x, e_1_1; + var y, _a, y_1, y_1_1, x, e_1_1; + var _b, e_1, _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: _e.trys.push([0, 5, 6, 11]); - _d = true, y_1 = __asyncValues(y); + _a = true, y_1 = __asyncValues(y); _e.label = 1; case 1: return [4 /*yield*/, y_1.next()]; case 2: - if (!(y_1_1 = _e.sent(), _a = y_1_1.done, !_a)) return [3 /*break*/, 4]; - _c = y_1_1.value; - _d = false; - x = _c; + if (!(y_1_1 = _e.sent(), _b = y_1_1.done, !_b)) return [3 /*break*/, 4]; + _d = y_1_1.value; + _a = false; + x = _d; _e.label = 3; case 3: - _d = true; + _a = true; return [3 /*break*/, 1]; case 4: return [3 /*break*/, 11]; case 5: @@ -121,8 +121,8 @@ function f1() { return [3 /*break*/, 11]; case 6: _e.trys.push([6, , 9, 10]); - if (!(!_d && !_a && (_b = y_1.return))) return [3 /*break*/, 8]; - return [4 /*yield*/, _b.call(y_1)]; + if (!(!_a && !_b && (_c = y_1.return))) return [3 /*break*/, 8]; + return [4 /*yield*/, _c.call(y_1)]; case 7: _e.sent(); _e.label = 8; @@ -181,24 +181,24 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function f2() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { - var x, y, _d, y_1, y_1_1, e_1_1; + var x, y, _a, y_1, y_1_1, e_1_1; + var _b, e_1, _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: _e.trys.push([0, 5, 6, 11]); - _d = true, y_1 = __asyncValues(y); + _a = true, y_1 = __asyncValues(y); _e.label = 1; case 1: return [4 /*yield*/, y_1.next()]; case 2: - if (!(y_1_1 = _e.sent(), _a = y_1_1.done, !_a)) return [3 /*break*/, 4]; - _c = y_1_1.value; - _d = false; - x = _c; + if (!(y_1_1 = _e.sent(), _b = y_1_1.done, !_b)) return [3 /*break*/, 4]; + _d = y_1_1.value; + _a = false; + x = _d; _e.label = 3; case 3: - _d = true; + _a = true; return [3 /*break*/, 1]; case 4: return [3 /*break*/, 11]; case 5: @@ -207,8 +207,8 @@ function f2() { return [3 /*break*/, 11]; case 6: _e.trys.push([6, , 9, 10]); - if (!(!_d && !_a && (_b = y_1.return))) return [3 /*break*/, 8]; - return [4 /*yield*/, _b.call(y_1)]; + if (!(!_a && !_b && (_c = y_1.return))) return [3 /*break*/, 8]; + return [4 /*yield*/, _c.call(y_1)]; case 7: _e.sent(); _e.label = 8; @@ -448,24 +448,24 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { }; // https://github.com/Microsoft/TypeScript/issues/21363 function f5() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { - var y, _d, y_1, y_1_1, x, e_1_1; + var y, _a, y_1, y_1_1, x, e_1_1; + var _b, e_1, _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: _e.trys.push([0, 5, 6, 11]); - _d = true, y_1 = __asyncValues(y); + _a = true, y_1 = __asyncValues(y); _e.label = 1; case 1: return [4 /*yield*/, y_1.next()]; case 2: - if (!(y_1_1 = _e.sent(), _a = y_1_1.done, !_a)) return [3 /*break*/, 4]; - _c = y_1_1.value; - _d = false; - x = _c; + if (!(y_1_1 = _e.sent(), _b = y_1_1.done, !_b)) return [3 /*break*/, 4]; + _d = y_1_1.value; + _a = false; + x = _d; return [3 /*break*/, 3]; case 3: - _d = true; + _a = true; return [3 /*break*/, 1]; case 4: return [3 /*break*/, 11]; case 5: @@ -474,8 +474,8 @@ function f5() { return [3 /*break*/, 11]; case 6: _e.trys.push([6, , 9, 10]); - if (!(!_d && !_a && (_b = y_1.return))) return [3 /*break*/, 8]; - return [4 /*yield*/, _b.call(y_1)]; + if (!(!_a && !_b && (_c = y_1.return))) return [3 /*break*/, 8]; + return [4 /*yield*/, _c.call(y_1)]; case 7: _e.sent(); _e.label = 8; diff --git a/tests/baselines/reference/expressionsForbiddenInParameterInitializers.js b/tests/baselines/reference/expressionsForbiddenInParameterInitializers.js index 60e3bbc7143b5..004aca10262e5 100644 --- a/tests/baselines/reference/expressionsForbiddenInParameterInitializers.js +++ b/tests/baselines/reference/expressionsForbiddenInParameterInitializers.js @@ -49,10 +49,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) { Object.defineProperty(exports, "__esModule", { value: true }); exports.foo2 = exports.foo = void 0; function foo(_a) { - var _b = _a.foo, foo = _b === void 0 ? yield Promise.resolve().then(function () { return require("./bar"); }) : _b; - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_c) { - return [2 /*return*/]; + return __awaiter(this, arguments, void 0, function (_b) { + var _c, foo, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _c = _b.foo; + if (!(_c === void 0)) return [3 /*break*/, 2]; + return [4 /*yield*/, Promise.resolve().then(function () { return require("./bar"); })]; + case 1: + _d = _e.sent(); + return [3 /*break*/, 3]; + case 2: + _d = _c; + _e.label = 3; + case 3: + foo = _d; + return [2 /*return*/]; + } }); }); } diff --git a/tests/baselines/reference/jsDeclarationsNestedParams.js b/tests/baselines/reference/jsDeclarationsNestedParams.js index 99fce3b69bd6e..c675fd800992d 100644 --- a/tests/baselines/reference/jsDeclarationsNestedParams.js +++ b/tests/baselines/reference/jsDeclarationsNestedParams.js @@ -44,8 +44,8 @@ class X { * @param {string?} error.code the error code to send the cancellation with * @returns {Promise.<*>} resolves when the event has been sent. */ - cancel({ reason, code }) { - return __awaiter(this, void 0, void 0, function* () { }); + cancel(_a) { + return __awaiter(this, arguments, void 0, function* ({ reason, code }) { }); } } class Y { @@ -58,8 +58,8 @@ class Y { * @param {string?} error.suberr.code the error code to send the cancellation with * @returns {Promise.<*>} resolves when the event has been sent. */ - cancel({ reason, suberr }) { - return __awaiter(this, void 0, void 0, function* () { }); + cancel(_a) { + return __awaiter(this, arguments, void 0, function* ({ reason, suberr }) { }); } } diff --git a/tests/baselines/reference/jsxElementType.js b/tests/baselines/reference/jsxElementType.js index 7e29df748a16f..b2864d2740ce0 100644 --- a/tests/baselines/reference/jsxElementType.js +++ b/tests/baselines/reference/jsxElementType.js @@ -204,12 +204,12 @@ React.createElement(RenderArray, null); React.createElement(RenderArray, { title: "react" }); React.createElement(RenderArray, { excessProp: true }); // React Server Component -var RenderPromise = function (_a) { - var title = _a.title; - return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_b) { +var RenderPromise = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { + var title = _b.title; + return __generator(this, function (_c) { return [2 /*return*/, "react"]; - }); }); -}; + }); +}); }; Component = RenderPromise; React.createElement(RenderPromise, null); React.createElement(RenderPromise, { title: "react" }); diff --git a/tests/baselines/reference/noImplicitReturnsInAsync1.js b/tests/baselines/reference/noImplicitReturnsInAsync1.js index cb67a4ff6dd31..fd6446e196634 100644 --- a/tests/baselines/reference/noImplicitReturnsInAsync1.js +++ b/tests/baselines/reference/noImplicitReturnsInAsync1.js @@ -18,8 +18,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -function test(isError = false) { - return __awaiter(this, void 0, void 0, function* () { +function test() { + return __awaiter(this, arguments, void 0, function* (isError = false) { if (isError === true) { return; } diff --git a/tests/baselines/reference/noImplicitReturnsInAsync2.js b/tests/baselines/reference/noImplicitReturnsInAsync2.js index f41ccb5953e89..b378a7637ab18 100644 --- a/tests/baselines/reference/noImplicitReturnsInAsync2.js +++ b/tests/baselines/reference/noImplicitReturnsInAsync2.js @@ -48,40 +48,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; // Should be an error, Promise, currently retorted correctly -function test3(isError = true) { - return __awaiter(this, void 0, void 0, function* () { +function test3() { + return __awaiter(this, arguments, void 0, function* (isError = true) { if (isError === true) { return 6; } }); } // Should not be an error, Promise, currently **not** working -function test4(isError = true) { - return __awaiter(this, void 0, void 0, function* () { +function test4() { + return __awaiter(this, arguments, void 0, function* (isError = true) { if (isError === true) { return undefined; } }); } // should not be error, Promise currently working correctly -function test5(isError = true) { - return __awaiter(this, void 0, void 0, function* () { +function test5() { + return __awaiter(this, arguments, void 0, function* (isError = true) { if (isError === true) { return undefined; } }); } // should be error, currently reported correctly -function test6(isError = true) { - return __awaiter(this, void 0, void 0, function* () { +function test6() { + return __awaiter(this, arguments, void 0, function* (isError = true) { if (isError === true) { return undefined; } }); } // infered to be Promise, should not be an error, currently reported correctly -function test7(isError = true) { - return __awaiter(this, void 0, void 0, function* () { +function test7() { + return __awaiter(this, arguments, void 0, function* (isError = true) { if (isError === true) { return; } diff --git a/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es2015).js b/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es2015).js index 4cd5bee88a2e8..4e9cf2dea6f18 100644 --- a/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es2015).js +++ b/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es2015).js @@ -13,8 +13,8 @@ async function* f(a: { b?: number }) { //// [nullishCoalescingOperatorInAsyncGenerator.js] // https://github.com/microsoft/TypeScript/issues/37686 function f(a) { - var _a; return __asyncGenerator(this, arguments, function* f_1() { + var _a; let c = (_a = a.b) !== null && _a !== void 0 ? _a : 10; while (c) { yield yield __await(c--); diff --git a/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es5).js b/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es5).js index a438d145e24d6..d02228bac340e 100644 --- a/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es5).js +++ b/tests/baselines/reference/nullishCoalescingOperatorInAsyncGenerator(target=es5).js @@ -13,9 +13,9 @@ async function* f(a: { b?: number }) { //// [nullishCoalescingOperatorInAsyncGenerator.js] // https://github.com/microsoft/TypeScript/issues/37686 function f(a) { - var _a; return __asyncGenerator(this, arguments, function f_1() { var c; + var _a; return __generator(this, function (_b) { switch (_b.label) { case 0: diff --git a/tests/baselines/reference/operationsAvailableOnPromisedType.js b/tests/baselines/reference/operationsAvailableOnPromisedType.js index bdb3ecb432cc2..8ba23a7a47c6e 100644 --- a/tests/baselines/reference/operationsAvailableOnPromisedType.js +++ b/tests/baselines/reference/operationsAvailableOnPromisedType.js @@ -85,10 +85,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { return to.concat(ar || Array.prototype.slice.call(from)); }; function fn(a, b, c, d, e, f, g) { - var _a, c_1, c_1_1; - var _b, e_1, _c, _d; return __awaiter(this, void 0, void 0, function () { - var _i, c_2, s, s, e_1_1; + var _i, c_1, s, s, e_1_1; + var _a, e_1, _b, _c, _d, c_2, c_2_1; return __generator(this, function (_e) { switch (_e.label) { case 0: @@ -101,25 +100,25 @@ function fn(a, b, c, d, e, f, g) { --b; a === b; __spreadArray([], c, true); - for (_i = 0, c_2 = c; _i < c_2.length; _i++) { - s = c_2[_i]; + for (_i = 0, c_1 = c; _i < c_1.length; _i++) { + s = c_1[_i]; fn(b, b, c, d, e, f, g); d.prop; } _e.label = 1; case 1: _e.trys.push([1, 6, 7, 12]); - _a = true, c_1 = __asyncValues(c); + _d = true, c_2 = __asyncValues(c); _e.label = 2; - case 2: return [4 /*yield*/, c_1.next()]; + case 2: return [4 /*yield*/, c_2.next()]; case 3: - if (!(c_1_1 = _e.sent(), _b = c_1_1.done, !_b)) return [3 /*break*/, 5]; - _d = c_1_1.value; - _a = false; - s = _d; + if (!(c_2_1 = _e.sent(), _a = c_2_1.done, !_a)) return [3 /*break*/, 5]; + _c = c_2_1.value; + _d = false; + s = _c; _e.label = 4; case 4: - _a = true; + _d = true; return [3 /*break*/, 2]; case 5: return [3 /*break*/, 12]; case 6: @@ -128,8 +127,8 @@ function fn(a, b, c, d, e, f, g) { return [3 /*break*/, 12]; case 7: _e.trys.push([7, , 10, 11]); - if (!(!_a && !_b && (_c = c_1.return))) return [3 /*break*/, 9]; - return [4 /*yield*/, _c.call(c_1)]; + if (!(!_d && !_a && (_b = c_2.return))) return [3 /*break*/, 9]; + return [4 /*yield*/, _b.call(c_2)]; case 8: _e.sent(); _e.label = 9; diff --git a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.js b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.js index 27d894505900e..6283c4097c898 100644 --- a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.js +++ b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.js @@ -207,14 +207,12 @@ var simpleAction = function (payload) { return ({ type: "SIMPLE_ACTION", payload: payload }); }; -var thunkAction = function (param1, param2) { return function (dispatch, _a) { - var foo = _a.foo; - return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_b) { - return [2 /*return*/, foo]; - }); +var thunkAction = function (param1, param2) { return function (dispatch_1, _a) { return __awaiter(void 0, [dispatch_1, _a], void 0, function (dispatch, _b) { + var foo = _b.foo; + return __generator(this, function (_c) { + return [2 /*return*/, foo]; }); -}; }; +}); }; }; var TestComponent = /** @class */ (function (_super) { __extends(TestComponent, _super); function TestComponent() { diff --git a/tests/baselines/reference/superMethodCall.js b/tests/baselines/reference/superMethodCall.js index 9553b46706001..3afe9167ae032 100644 --- a/tests/baselines/reference/superMethodCall.js +++ b/tests/baselines/reference/superMethodCall.js @@ -38,8 +38,8 @@ class Derived extends Base { const _super = Object.create(null, { method: { get: () => super.method } }); - var _a; return __awaiter(this, void 0, void 0, function* () { + var _a; return (_a = _super.method) === null || _a === void 0 ? void 0 : _a.call(this); }); } diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js index 68c576899e1a0..bf465c494d0b9 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es2015).js @@ -70,8 +70,8 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function main() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function* () { + var _a, e_1, _b, _c; try { for (var _d = true, _e = __asyncValues([{ [Symbol.dispose]() { } }, null, undefined]), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) { _c = _f.value; diff --git a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js index 6e4858db55c51..7398cb6ba0e22 100644 --- a/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js +++ b/tests/baselines/reference/usingDeclarationsInForAwaitOf(target=es5).js @@ -97,22 +97,22 @@ var __asyncValues = (this && this.__asyncValues) || function (o) { function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; function main() { - var _a, e_1, _b, _c; return __awaiter(this, void 0, void 0, function () { - var _d, _e, _f, d1_1, env_1, d1, e_1_1; - var _g; + var _a, _b, _c, d1_1, env_1, d1, e_1_1; + var _d; + var _e, e_1, _f, _g; return __generator(this, function (_h) { switch (_h.label) { case 0: _h.trys.push([0, 5, 6, 11]); - _d = true, _e = __asyncValues([(_g = {}, _g[Symbol.dispose] = function () { }, _g), null, undefined]); + _a = true, _b = __asyncValues([(_d = {}, _d[Symbol.dispose] = function () { }, _d), null, undefined]); _h.label = 1; - case 1: return [4 /*yield*/, _e.next()]; + case 1: return [4 /*yield*/, _b.next()]; case 2: - if (!(_f = _h.sent(), _a = _f.done, !_a)) return [3 /*break*/, 4]; - _c = _f.value; - _d = false; - d1_1 = _c; + if (!(_c = _h.sent(), _e = _c.done, !_e)) return [3 /*break*/, 4]; + _g = _c.value; + _a = false; + d1_1 = _g; env_1 = { stack: [], error: void 0, hasError: false }; try { d1 = __addDisposableResource(env_1, d1_1, false); @@ -126,7 +126,7 @@ function main() { } _h.label = 3; case 3: - _d = true; + _a = true; return [3 /*break*/, 1]; case 4: return [3 /*break*/, 11]; case 5: @@ -135,8 +135,8 @@ function main() { return [3 /*break*/, 11]; case 6: _h.trys.push([6, , 9, 10]); - if (!(!_d && !_a && (_b = _e.return))) return [3 /*break*/, 8]; - return [4 /*yield*/, _b.call(_e)]; + if (!(!_a && !_e && (_f = _b.return))) return [3 /*break*/, 8]; + return [4 /*yield*/, _f.call(_b)]; case 7: _h.sent(); _h.label = 8; diff --git a/tests/cases/conformance/async/asyncFunctionDeclarationParameterEvaluation.ts b/tests/cases/conformance/async/asyncFunctionDeclarationParameterEvaluation.ts new file mode 100644 index 0000000000000..034f10412d07f --- /dev/null +++ b/tests/cases/conformance/async/asyncFunctionDeclarationParameterEvaluation.ts @@ -0,0 +1,30 @@ +// @target: es2015,es2017 +// @lib: esnext +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/40410 +async function f1(x, y = z) {} +async function f2({[z]: x}) {} +async function f3(x = z) { return async () => arguments; } +async function f4(x = z) { return async () => async () => arguments; } +async function f5(x = z, ...args) { } +async function f6(x = z, ...args) { return async () => arguments; } +async function f7(x = z, ...args) { return async () => async () => arguments; } +async function f8() { return async (x = z) => arguments; } +async function f9() { return async (x = z) => async () => arguments; } +async function f10(x = z) { return async () => async function () { return async () => arguments; }; } +function f11() { return async (x = z) => arguments; } +function f12() { return async (x = z) => async () => arguments; } +function f() { + const a1 = async (x, y = z) => {}; + const a2 = async ({[z]: x}) => {}; + const a3 = async (x = z) => { return async () => arguments; }; + const a4 = async (x = z) => { return async () => async () => arguments; }; + const a5 = async (x = z, ...args) => { }; + const a6 = async (x = z, ...args) => { return async () => arguments; }; + const a7 = async (x = z, ...args) => { return async () => async () => arguments; }; + const a8 = async () => { return async (x = z) => arguments; }; + const a9 = async () => { return async (x = z) => async () => arguments; }; + const a10 = async (x = z) => { return async () => async function () { return async () => arguments; }; }; +} \ No newline at end of file diff --git a/tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es6.ts b/tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es6.ts index 8dab2c0408630..acb6c3c951afe 100644 --- a/tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es6.ts +++ b/tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es6.ts @@ -3,6 +3,10 @@ class C { method() { function other() {} - var fn = async () => await other.apply(this, arguments); + var fn = async () => await other.apply(this, arguments); } } + +function f() { + return async () => async () => arguments.length; +} \ No newline at end of file diff --git a/tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts b/tests/cases/conformance/asyncGenerators/asyncGeneratorGenericNonWrappedReturn.ts similarity index 100% rename from tests/cases/conformance/generators/asyncGeneratorGenericNonWrappedReturn.ts rename to tests/cases/conformance/asyncGenerators/asyncGeneratorGenericNonWrappedReturn.ts diff --git a/tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts b/tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts new file mode 100644 index 0000000000000..b4aef8f71d995 --- /dev/null +++ b/tests/cases/conformance/asyncGenerators/asyncGeneratorParameterEvaluation.ts @@ -0,0 +1,13 @@ +// @target: es2015,es2017,es2018 +// @lib: esnext +// @noEmitHelpers: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/40410 +async function* f1(x, y = z) {} +async function* f2({[z]: x}) {} + +declare class Super { foo(): void; } +class Sub extends Super { + async * m(x, y = z, { ...w }) { super.foo(); } +}