diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a45561e7ed6..7acb99d624d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -411,7 +411,12 @@ module ts { bindDeclaration(node, SymbolFlags.ConstructSignature, 0, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Method: - bindDeclaration(node, SymbolFlags.Method, SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); + // If this is an ObjectLiteralExpression method, then it sits in the same space + // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes + // so that it will conflict with any other object literal members with the same + // name. + bindDeclaration(node, SymbolFlags.Method, + isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.IndexSignature: bindDeclaration(node, SymbolFlags.IndexSignature, 0, /*isBlockScopeContainer*/ false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e428b4a4e0..fc67faa8f88 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2839,7 +2839,7 @@ module ts { // The expression is processed as an identifier expression (section 4.3) // or property access expression(section 4.10), // the widened type(section 3.9) of which becomes the result. - links.resolvedType = getWidenedType(checkExpression(node.exprName)); + links.resolvedType = getWidenedType(checkExpressionOrQualifiedName(node.exprName)); } return links.resolvedType; } @@ -3240,26 +3240,35 @@ module ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitiveExpression(node: Expression): boolean { + function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return !(node).typeParameters && !forEach((node).parameters, p => p.type); + return isContextSensitiveFunctionLikeDeclaration(node); case SyntaxKind.ObjectLiteralExpression: - return forEach((node).properties, p => - p.kind === SyntaxKind.PropertyAssignment && isContextSensitiveExpression((p).initializer)); + return forEach((node).properties, isContextSensitive); case SyntaxKind.ArrayLiteralExpression: - return forEach((node).elements, e => isContextSensitiveExpression(e)); + return forEach((node).elements, isContextSensitive); case SyntaxKind.ConditionalExpression: - return isContextSensitiveExpression((node).whenTrue) || - isContextSensitiveExpression((node).whenFalse); + return isContextSensitive((node).whenTrue) || + isContextSensitive((node).whenFalse); case SyntaxKind.BinaryExpression: return (node).operator === SyntaxKind.BarBarToken && - (isContextSensitiveExpression((node).left) || isContextSensitiveExpression((node).right)); + (isContextSensitive((node).left) || isContextSensitive((node).right)); + case SyntaxKind.PropertyAssignment: + return isContextSensitive((node).initializer); + case SyntaxKind.Method: + return isContextSensitiveFunctionLikeDeclaration(node); } + return false; } + function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) { + return !node.typeParameters && !forEach(node.parameters, p => p.type); + } + function getTypeWithoutConstructors(type: Type): Type { if (type.flags & TypeFlags.ObjectType) { var resolved = resolveObjectOrUnionTypeMembers(type); @@ -4750,7 +4759,7 @@ module ts { function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { if (isFunctionExpressionOrArrowFunction(parameter.parent)) { var func = parameter.parent; - if (isContextSensitiveExpression(func)) { + if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { @@ -4890,12 +4899,21 @@ module ts { // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. - function getContextualTypeForPropertyExpression(node: Expression): Type { - var declaration = node.parent; - var objectLiteral = declaration.parent; + function getContextualTypeForObjectLiteralMethod(node: MethodDeclaration): Type { + Debug.assert(isObjectLiteralMethod(node)); + if (isInsideWithStatementBody(node)) { + // We cannot answer semantic questions within a with block, do not proceed any further + return undefined; + } + + return getContextualTypeForObjectLiteralElement(node); + } + + function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) { + var objectLiteral = element.parent; var type = getContextualType(objectLiteral); // TODO(jfreeman): Handle this case for computed names and symbols - var name = (declaration.name).text; + var name = (element.name).text; if (type && name) { return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || @@ -4950,7 +4968,7 @@ module ts { case SyntaxKind.BinaryExpression: return getContextualTypeForBinaryOperand(node); case SyntaxKind.PropertyAssignment: - return getContextualTypeForPropertyExpression(node); + return getContextualTypeForObjectLiteralElement(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: @@ -4985,8 +5003,11 @@ module ts { // If the contextual type is a union type, get the signature from each type possible and if they are // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures - function getContextualSignature(node: FunctionExpression): Signature { - var type = getContextualType(node); + function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + var type = isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getContextualType(node); if (!type) { return undefined; } @@ -5082,11 +5103,14 @@ module ts { for (var id in members) { if (hasProperty(members, id)) { var member = members[id]; - if (member.flags & SymbolFlags.Property) { - var memberDecl = member.declarations[0]; + if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) { + var memberDecl = member.declarations[0]; var type: Type; if (memberDecl.kind === SyntaxKind.PropertyAssignment) { - type = checkExpression(memberDecl.initializer, contextualMapper); + type = checkExpression((memberDecl).initializer, contextualMapper); + } + else if (memberDecl.kind === SyntaxKind.Method) { + type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); @@ -5097,7 +5121,10 @@ module ts { var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; - if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; + if (member.valueDeclaration) { + prop.valueDeclaration = member.valueDeclaration; + } + prop.type = type; prop.target = member; member = prop; @@ -5201,7 +5228,7 @@ module ts { } function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { - var type = checkExpression(left); + var type = checkExpressionOrQualifiedName(left); if (type === unknownType) return type; if (type !== anyType) { var apparentType = getApparentType(getWidenedType(type)); @@ -5242,7 +5269,7 @@ module ts { ? (node).expression : (node).left; - var type = checkExpression(left); + var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { @@ -5601,7 +5628,7 @@ module ts { // because it represents a TemplateStringsArray. var excludeArgument: boolean[]; for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { - if (isContextSensitiveExpression(args[i])) { + if (isContextSensitive(args[i])) { if (!excludeArgument) { excludeArgument = new Array(args.length); } @@ -6024,7 +6051,7 @@ module ts { function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); - if (func.body.kind !== SyntaxKind.FunctionBlock) { + if (func.body.kind !== SyntaxKind.Block) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); @@ -6111,7 +6138,7 @@ module ts { } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. - if (!func.body || func.body.kind !== SyntaxKind.FunctionBlock) { + if (!func.body || func.body.kind !== SyntaxKind.Block) { return; } @@ -6133,7 +6160,9 @@ module ts { error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } - function checkFunctionExpression(node: FunctionExpression, contextualMapper?: TypeMapper): Type { + function checkFunctionExpressionOrObjectLiteralMethod(node: FunctionExpression | MethodDeclaration, contextualMapper?: TypeMapper): Type { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); + // The identityMapper object is used to indicate that function expressions are wildcards if (contextualMapper === identityMapper) { return anyFunctionType; @@ -6150,7 +6179,7 @@ module ts { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { var signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (isContextSensitiveExpression(node)) { + if (isContextSensitive(node)) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } if (!node.type) { @@ -6165,27 +6194,31 @@ module ts { } } - if (fullTypeCheck) { - checkCollisionWithCapturedSuperVariable(node, node.name); - checkCollisionWithCapturedThisVariable(node, node.name); + if (fullTypeCheck && node.kind !== SyntaxKind.Method) { + checkCollisionWithCapturedSuperVariable(node, (node).name); + checkCollisionWithCapturedThisVariable(node,(node).name); } return type; } - function checkFunctionExpressionBody(node: FunctionExpression) { + function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) { + Debug.assert(node.kind !== SyntaxKind.Method || isObjectLiteralMethod(node)); if (node.type) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (node.body.kind === SyntaxKind.FunctionBlock) { - checkSourceElement(node.body); - } - else { - var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined); + + if (node.body) { + if (node.body.kind === SyntaxKind.Block) { + checkSourceElement(node.body); + } + else { + var exprType = checkExpression(node.body); + if (node.type) { + checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined); + } + checkFunctionExpressionBodies(node.body); } - checkFunctionExpressionBodies(node.body); } } @@ -6552,6 +6585,32 @@ module ts { return result; } + function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { + var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); + } + + function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { + if (contextualMapper && contextualMapper !== identityMapper) { + var signature = getSingleCallSignature(type); + if (signature && signature.typeParameters) { + var contextualType = getContextualType(node); + if (contextualType) { + var contextualSignature = getSingleCallSignature(contextualType); + if (contextualSignature && !contextualSignature.typeParameters) { + return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); + } + } + } + } + + return type; + } + + function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type { + return checkExpressionOrQualifiedName(node, contextualMapper); + } + // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When // contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the // expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in @@ -6559,19 +6618,14 @@ module ts { // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude // contextually typed function and arrow expressions in the initial phase. - function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { - var type = checkExpressionNode(node, contextualMapper); - if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) { - var signature = getSingleCallSignature(type); - if (signature && signature.typeParameters) { - var contextualType = getContextualType(node); - if (contextualType) { - var contextualSignature = getSingleCallSignature(contextualType); - if (contextualSignature && !contextualSignature.typeParameters) { - type = getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); - } - } - } + function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type { + var type: Type; + if (node.kind == SyntaxKind.QualifiedName) { + type = checkQualifiedName(node); + } + else { + var uninstantiatedType = checkExpressionWorker(node, contextualMapper); + type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { @@ -6591,7 +6645,7 @@ module ts { return type; } - function checkExpressionNode(node: Expression | QualifiedName, contextualMapper: TypeMapper): Type { + function checkExpressionWorker(node: Expression, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: return checkIdentifier(node); @@ -6613,8 +6667,6 @@ module ts { return stringType; case SyntaxKind.RegularExpressionLiteral: return globalRegExpType; - case SyntaxKind.QualifiedName: - return checkQualifiedName(node); case SyntaxKind.ArrayLiteralExpression: return checkArrayLiteral(node, contextualMapper); case SyntaxKind.ObjectLiteralExpression: @@ -6634,7 +6686,7 @@ module ts { return checkExpression((node).expression); case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return checkFunctionExpression(node, contextualMapper); + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case SyntaxKind.TypeOfExpression: return checkTypeOfExpression(node); case SyntaxKind.DeleteExpression: @@ -7360,6 +7412,9 @@ module ts { function checkBlock(node: Block) { forEach(node.statements, checkSourceElement); + if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) { + checkFunctionExpressionBodies(node); + } } function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { @@ -7904,7 +7959,7 @@ module ts { } // Check that base type can be evaluated as expression - checkExpression(baseTypeNode.typeName); + checkExpressionOrQualifiedName(baseTypeNode.typeName); } var implementedTypeNodes = getClassImplementedTypeNodes(node); @@ -8393,7 +8448,7 @@ module ts { // ensure it can be evaluated as an expression var moduleName = getFirstIdentifier(node.moduleReference); if (resolveEntityName(node, moduleName, SymbolFlags.Value | SymbolFlags.Namespace).flags & SymbolFlags.Namespace) { - checkExpression(node.moduleReference); + checkExpressionOrQualifiedName(node.moduleReference); } else { error(moduleName, Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, declarationNameToString(moduleName)); @@ -8491,10 +8546,8 @@ module ts { case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: - return checkBlock(node); - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: - return checkBody(node); + return checkBlock(node); case SyntaxKind.VariableStatement: return checkVariableStatement(node); case SyntaxKind.ExpressionStatement: @@ -8557,9 +8610,14 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: forEach((node).parameters, checkFunctionExpressionBodies); - checkFunctionExpressionBody(node); + checkFunctionExpressionOrObjectLiteralMethodBody(node); break; case SyntaxKind.Method: + forEach((node).parameters, checkFunctionExpressionBodies); + if (isObjectLiteralMethod(node)) { + checkFunctionExpressionOrObjectLiteralMethodBody(node); + } + break; case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -8589,7 +8647,6 @@ module ts { case SyntaxKind.BinaryExpression: case SyntaxKind.ConditionalExpression: case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.VariableStatement: case SyntaxKind.ExpressionStatement: @@ -8620,11 +8677,6 @@ module ts { } } - function checkBody(node: Block) { - checkBlock(node); - checkFunctionExpressionBodies(node); - } - // Fully type check a source file and collect the relevant diagnostics. function checkSourceFile(node: SourceFile) { var links = getNodeLinks(node); @@ -9022,7 +9074,7 @@ module ts { // This is necessary as an identifier in short-hand property assignment can contains two meaning: // property name and property value. if (location && location.kind === SyntaxKind.ShorthandPropertyAssignment) { - return resolveEntityName(location, (location).name, SymbolFlags.Value); + return resolveEntityName(location, (location).name, SymbolFlags.Value); } return undefined; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7193523bf96..03951f08b4c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2227,6 +2227,30 @@ module ts { emit(node.expression); write("]"); } + + function emitDownlevelMethod(node: MethodDeclaration) { + if (!isObjectLiteralMethod(node)) { + return; + } + + emitLeadingComments(node); + emit(node.name); + write(": "); + write("function "); + emitSignatureAndBody(node); + emitTrailingComments(node); + } + + function emitMethod(node: MethodDeclaration) { + if (!isObjectLiteralMethod(node)) { + return; + } + + emitLeadingComments(node); + emit(node.name); + emitSignatureAndBody(node); + emitTrailingComments(node); + } function emitPropertyAssignment(node: PropertyDeclaration) { emitLeadingComments(node); @@ -2236,7 +2260,7 @@ module ts { emitTrailingComments(node); } - function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) { + function emitDownlevelShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { emitLeadingComments(node); // Emit identifier as an identifier emit(node.name); @@ -2247,7 +2271,7 @@ module ts { emitTrailingComments(node); } - function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) { + function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { // If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example: // module m { // export var y; @@ -2841,17 +2865,17 @@ module ts { scopeEmitStart(node); increaseIndent(); - emitDetachedComments(node.body.kind === SyntaxKind.FunctionBlock ? (node.body).statements : node.body); + emitDetachedComments(node.body.kind === SyntaxKind.Block ? (node.body).statements : node.body); var startIndex = 0; - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { startIndex = emitDirectivePrologues((node.body).statements, /*startWithNewLine*/ true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== SyntaxKind.FunctionBlock && outPos === writer.getTextPos()) { + if (node.body.kind !== SyntaxKind.Block && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -2864,7 +2888,7 @@ module ts { emitEnd(node.body); } else { - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { emitLinesStartingAt((node.body).statements, startIndex); } else { @@ -2876,7 +2900,7 @@ module ts { emitTrailingComments(node.body); } writeLine(); - if (node.body.kind === SyntaxKind.FunctionBlock) { + if (node.body.kind === SyntaxKind.Block) { emitLeadingCommentsOfPosition((node.body).statements.end); decreaseIndent(); emitToken(SyntaxKind.CloseBraceToken, (node.body).statements.end); @@ -3566,7 +3590,6 @@ module ts { case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: return emitBlock(node); case SyntaxKind.VariableStatement: @@ -3628,7 +3651,9 @@ module ts { // Emit node down-level switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: - return emitDownlevelShorthandPropertyAssignment(node); + return emitDownlevelShorthandPropertyAssignment(node); + case SyntaxKind.Method: + return emitDownlevelMethod(node); } } else { @@ -3636,7 +3661,9 @@ module ts { Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above"); switch (node.kind) { case SyntaxKind.ShorthandPropertyAssignment: - return emitShorthandPropertyAssignment(node); + return emitShorthandPropertyAssignment(node); + case SyntaxKind.Method: + return emitMethod(node); } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b36ded65dc4..58c715d721f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -311,7 +311,6 @@ module ts { case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: return children((node).statements); case SyntaxKind.SourceFile: @@ -435,7 +434,6 @@ module ts { case SyntaxKind.ReturnStatement: return visitor(node); case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: @@ -472,6 +470,14 @@ module ts { return false; } + export function isFunctionBlock(node: Node) { + return node !== undefined && node.kind === SyntaxKind.Block && isAnyFunction(node.parent); + } + + export function isObjectLiteralMethod(node: Node) { + return node !== undefined && node.kind === SyntaxKind.Method && node.parent.kind === SyntaxKind.ObjectLiteralExpression; + } + export function getContainingFunction(node: Node): FunctionLikeDeclaration { while (true) { node = node.parent; @@ -1918,16 +1924,10 @@ module ts { return parseInitializer(/*inParameter*/ true); } - function parseSignature(yieldAndGeneratorParameterContext: boolean): ParsedSignature { - var signature = {}; - fillSignature(SyntaxKind.ColonToken, yieldAndGeneratorParameterContext, signature); - return signature; - } - function fillSignature( returnToken: SyntaxKind, yieldAndGeneratorParameterContext: boolean, - signature: ParsedSignature): void { + signature: SignatureDeclaration): void { var returnTokenRequired = returnToken === SyntaxKind.EqualsGreaterThanToken; signature.typeParameters = parseTypeParameters(); signature.parameters = parseParameterList(yieldAndGeneratorParameterContext); @@ -3166,26 +3166,21 @@ module ts { return finishNode(node); } - function parsePropertyAssignment(): Declaration { - var nodePos = scanner.getStartPos(); + function parseObjectLiteralElement(): ObjectLiteralElement { + var fullStart = scanner.getStartPos(); + var initialToken = token; + + if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { + var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; + return parseAccessorDeclaration(kind, fullStart, /*modifiers*/undefined); + } + var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - var node: Declaration; if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - node = createNode(SyntaxKind.PropertyAssignment, nodePos); - node.name = propertyName; - var sig = parseSignature(/*yieldAndGeneratorParameterContext:*/ !!asteriskToken); - - var body = parseFunctionBlock(!!asteriskToken, /* ignoreMissingOpenBrace */ false); - // do not propagate property name as name for function expression - // for scenarios like - // var x = 1; - // var y = { x() { } } - // otherwise this will bring y.x into the scope of x which is incorrect - (node).initializer = makeFunctionExpression(SyntaxKind.FunctionExpression, node.pos, asteriskToken, undefined, sig, body); - return finishNode(node); + return parseMethodDeclaration(fullStart, /*modifiers:*/ undefined, asteriskToken, propertyName, /*questionToken:*/ undefined, /*requireBlock:*/ true); } // Disallowing of optional property assignments happens in the grammar checker. @@ -3193,31 +3188,21 @@ module ts { // Parse to check if it is short-hand property assignment or normal property assignment if ((token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, nodePos); + var shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; return finishNode(shorthandDeclaration); } else { - var propertyDeclaration = createNode(SyntaxKind.PropertyAssignment, nodePos); - propertyDeclaration.name = propertyName; - propertyDeclaration.questionToken = questionToken; + var propertyAssignment = createNode(SyntaxKind.PropertyAssignment, fullStart); + propertyAssignment.name = propertyName; + propertyAssignment.questionToken = questionToken; parseExpected(SyntaxKind.ColonToken); - propertyDeclaration.initializer = allowInAnd(parseAssignmentExpressionOrHigher); - return finishNode(propertyDeclaration); + propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); + return finishNode(propertyAssignment); } } - function parseObjectLiteralMember(): Declaration { - var initialPos = getNodePos(); - var initialToken = token; - if (parseContextualModifier(SyntaxKind.GetKeyword) || parseContextualModifier(SyntaxKind.SetKeyword)) { - var kind = initialToken === SyntaxKind.GetKeyword ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; - return parseMemberAccessorDeclaration(kind, initialPos, /*modifiers*/ undefined); - } - return parsePropertyAssignment(); - } - function parseObjectLiteralExpression(): ObjectLiteralExpression { var node = createNode(SyntaxKind.ObjectLiteralExpression); parseExpected(SyntaxKind.OpenBraceToken); @@ -3225,7 +3210,7 @@ module ts { node.flags |= NodeFlags.MultiLine; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralMember); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -3248,17 +3233,6 @@ module ts { return isIdentifier() ? parseIdentifier() : undefined; } - function makeFunctionExpression(kind: SyntaxKind, pos: number, asteriskToken: Node, name: Identifier, sig: ParsedSignature, body: Block | Expression): FunctionExpression { - var node = createNode(kind, pos); - node.asteriskToken = asteriskToken; - node.name = name; - node.typeParameters = sig.typeParameters; - node.parameters = sig.parameters; - node.type = sig.type; - node.body = body; - return finishNode(node); - } - function parseNewExpression(): NewExpression { var node = createNode(SyntaxKind.NewExpression); parseExpected(SyntaxKind.NewKeyword); @@ -3291,7 +3265,7 @@ module ts { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); - var block = parseBlock(SyntaxKind.FunctionBlock, ignoreMissingOpenBrace, /*checkForStrictMode*/ true); + var block = parseBlock(SyntaxKind.Block, ignoreMissingOpenBrace, /*checkForStrictMode*/ true); setYieldContext(savedYieldContext); @@ -3668,7 +3642,7 @@ module ts { function parseFunctionBlockOrSemicolon(isGenerator: boolean): Block { if (token === SyntaxKind.OpenBraceToken) { - return parseFunctionBlock(isGenerator, /* ignoreMissingOpenBrace */ false); + return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace:*/ false); } parseSemicolon(Diagnostics.or_expected); @@ -3739,7 +3713,18 @@ module ts { return finishNode(node); } - function parsePropertyMemberDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, requireBlock: boolean): MethodDeclaration { + var method = createNode(SyntaxKind.Method, fullStart); + setModifiers(method, modifiers); + method.asteriskToken = asteriskToken; + method.name = name; + method.questionToken = questionToken; + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method); + method.body = requireBlock ? parseFunctionBlock(!!asteriskToken, /*ignoreMissingOpenBrace:*/ false) : parseFunctionBlockOrSemicolon(!!asteriskToken); + return finishNode(method); + } + + function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var name = parsePropertyName(); @@ -3747,14 +3732,7 @@ module ts { // report an error in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - var method = createNode(SyntaxKind.Method, fullStart); - setModifiers(method, modifiers); - method.asteriskToken = asteriskToken; - method.name = name; - method.questionToken = questionToken; - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, method); - method.body = parseFunctionBlockOrSemicolon(!!asteriskToken); - return finishNode(method); + return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, /*requireBlock:*/ false); } else { var property = createNode(SyntaxKind.Property, fullStart); @@ -3772,8 +3750,8 @@ module ts { return parseInitializer(/*inParameter*/ false); } - function parseMemberAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): MethodDeclaration { - var node = createNode(kind, fullStart); + function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + var node = createNode(kind, fullStart); setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, node); @@ -3864,10 +3842,10 @@ module ts { var fullStart = getNodePos(); var modifiers = parseModifiers(); if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); } if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseMemberAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); } if (token === SyntaxKind.ConstructorKeyword) { return parseConstructorDeclaration(fullStart, modifiers); @@ -3879,7 +3857,7 @@ module ts { // the [ token can start an index signature or a computed property name if (isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyMemberDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, modifiers); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -4364,7 +4342,7 @@ module ts { if (!checkModifiers(node)) { var savedInFunctionBlock = inFunctionBlock; - if (node.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(node)) { inFunctionBlock = true; } @@ -4408,7 +4386,7 @@ module ts { case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: case SyntaxKind.FunctionType: - return checkAnyParsedSignature(node); + return checkAnySignatureDeclaration(node); case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: return checkBreakOrContinueStatement(node); @@ -4435,6 +4413,7 @@ module ts { case SyntaxKind.IndexSignature: return checkIndexSignature(node); case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(node); case SyntaxKind.LabeledStatement: return checkLabeledStatement(node); + case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); case SyntaxKind.Method: return checkMethod(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); case SyntaxKind.ObjectLiteralExpression: return checkObjectLiteralExpression(node); @@ -4443,11 +4422,10 @@ module ts { case SyntaxKind.PostfixUnaryExpression: return checkPostfixUnaryExpression(node); case SyntaxKind.PrefixUnaryExpression: return checkPrefixUnaryExpression(node); case SyntaxKind.Property: return checkProperty(node); - case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(node); case SyntaxKind.ReturnStatement: return checkReturnStatement(node); case SyntaxKind.SetAccessor: return checkSetAccessor(node); case SyntaxKind.SourceFile: return checkSourceFile(node); - case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(node); + case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(node); case SyntaxKind.SwitchStatement: return checkSwitchStatement(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); case SyntaxKind.ThrowStatement: return checkThrowStatement(node); @@ -4523,7 +4501,7 @@ module ts { } } - function checkAnyParsedSignature(node: ParsedSignature): boolean { + function checkAnySignatureDeclaration(node: SignatureDeclaration): boolean { return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters); } @@ -4737,7 +4715,7 @@ module ts { } function checkConstructor(node: ConstructorDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ true); @@ -4845,7 +4823,7 @@ module ts { } function checkFunctionDeclaration(node: FunctionLikeDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || checkForGenerator(node); @@ -4858,7 +4836,7 @@ module ts { } function checkFunctionExpression(node: FunctionExpression) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkFunctionName(node.name) || checkForGenerator(node); } @@ -4872,7 +4850,7 @@ module ts { } function checkGetAccessor(node: MethodDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkAccessor(node); } @@ -4970,11 +4948,12 @@ module ts { } function checkMethod(node: MethodDeclaration) { - if (checkAnyParsedSignature(node) || + if (checkAnySignatureDeclaration(node) || checkForBodyInAmbientContext(node.body, /*isConstructor:*/ false) || checkForGenerator(node)) { return true; } + if (node.parent.kind === SyntaxKind.ClassDeclaration) { if (checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; @@ -5000,7 +4979,7 @@ module ts { } function checkForBodyInAmbientContext(body: Block | Expression, isConstructor: boolean): boolean { - if (inAmbientContext && body && body.kind === SyntaxKind.FunctionBlock) { + if (inAmbientContext && body && body.kind === SyntaxKind.Block) { var diagnostic = isConstructor ? Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context; @@ -5060,10 +5039,9 @@ module ts { // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind: number; - if (prop.kind === SyntaxKind.PropertyAssignment) { - currentKind = Property; - } - else if (prop.kind === SyntaxKind.ShorthandPropertyAssignment) { + if (prop.kind === SyntaxKind.PropertyAssignment || + prop.kind === SyntaxKind.ShorthandPropertyAssignment || + prop.kind === SyntaxKind.Method) { currentKind = Property; } else if (prop.kind === SyntaxKind.GetAccessor) { @@ -5364,7 +5342,7 @@ module ts { } } - function checkPropertyAssignment(node: PropertyDeclaration) { + function checkPropertyAssignment(node: PropertyAssignment) { return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); } @@ -5381,7 +5359,7 @@ module ts { } function checkSetAccessor(node: MethodDeclaration) { - return checkAnyParsedSignature(node) || + return checkAnySignatureDeclaration(node) || checkAccessor(node); } @@ -5464,7 +5442,7 @@ module ts { return grammarErrorOnFirstToken(node, Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); } - function checkShorthandPropertyAssignment(node: ShorthandPropertyDeclaration): boolean { + function checkShorthandPropertyAssignment(node: ShorthandPropertyAssignment): boolean { return checkForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index edf052a8876..ab396d13a85 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -212,7 +212,6 @@ module ts { DebuggerStatement, VariableDeclaration, FunctionDeclaration, - FunctionBlock, ClassDeclaration, InterfaceDeclaration, TypeAliasDeclaration, @@ -234,6 +233,7 @@ module ts { // Property assignments PropertyAssignment, ShorthandPropertyAssignment, + // Enum EnumMember, // Top-level nodes @@ -334,13 +334,6 @@ module ts { } export type EntityName = Identifier | QualifiedName; - - export interface ParsedSignature { - typeParameters?: NodeArray; - parameters: NodeArray; - type?: TypeNode; - } - export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName; export interface Declaration extends Node { @@ -360,7 +353,10 @@ module ts { expression?: Expression; } - export interface SignatureDeclaration extends Declaration, ParsedSignature { + export interface SignatureDeclaration extends Declaration { + typeParameters?: NodeArray; + parameters: NodeArray; + type?: TypeNode; } export interface VariableDeclaration extends Declaration { @@ -378,6 +374,7 @@ module ts { } export interface PropertyDeclaration extends Declaration, ClassElement { + _propertyDeclarationBrand: any; questionToken?: Node; type?: TypeNode; initializer?: Expression; @@ -386,11 +383,22 @@ module ts { export type VariableOrParameterDeclaration = VariableDeclaration | ParameterDeclaration; export type VariableOrParameterOrPropertyDeclaration = VariableOrParameterDeclaration | PropertyDeclaration; - export interface ShorthandPropertyDeclaration extends Declaration { + export interface ObjectLiteralElement extends Declaration { + _objectLiteralBrandBrand: any; + } + + export interface ShorthandPropertyAssignment extends ObjectLiteralElement { name: Identifier; questionToken?: Node; } + export interface PropertyAssignment extends ObjectLiteralElement { + _propertyAssignmentBrand: any; + name: DeclarationName; + questionToken?: Node; + initializer: Expression; + } + /** * Several node kinds share function-like features such as a signature, * a name, and a body. These nodes should extend FunctionLikeDeclaration. @@ -412,7 +420,16 @@ module ts { body?: Block; } - export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement { + // Note that a MethodDeclaration is considered both a ClassElement and an ObjectLiteralElement. + // Both the grammars for ClassDeclaration and ObjectLiteralExpression allow for MethodDeclarations + // as child elements, and so a MethodDeclaration satisfies both interfaces. This avoids the + // alternative where we would need separate kinds/types for ClassMethodDeclaration and + // ObjectLiteralMethodDeclaration, which would look identical. + // + // Because of this, it may be necessary to determine what sort of MethodDeclaration you have + // at later stages of the compiler pipeline. In that case, you can either check the parent kind + // of the method, or use helpers like isObjectLiteralMethodDeclaration + export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { body?: Block; } @@ -420,8 +437,11 @@ module ts { body?: Block; } - export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement { - body?: Block; + // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a + // ClassElement and an ObjectLiteralElement. + export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { + _accessorDeclarationBrand: any; + body: Block; } export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement { @@ -576,7 +596,7 @@ module ts { // An ObjectLiteralExpression is the declaration node for an anonymous symbol. export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { - properties: NodeArray; + properties: NodeArray; } export interface PropertyAccessExpression extends MemberExpression { @@ -901,7 +921,7 @@ module ts { getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfType(type: Type): Symbol[]; getRootSymbols(symbol: Symbol): Symbol[]; - getContextualType(node: Node): Type; + getContextualType(node: Expression): Type; getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7e364730ede..0114d213398 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -769,7 +769,7 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } - public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) { + public verifyQuickInfoString(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { this.scenarioActions.push(''); @@ -798,6 +798,39 @@ module FourSlash { } } + + public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: ts.SymbolDisplayPart[], + documentation: ts.SymbolDisplayPart[]) { + this.scenarioActions.push(''); + this.scenarioActions.push(''); + + function getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { + var result = ""; + ts.forEach(displayParts, part => { + if (result) { + result += ",\n "; + } + else { + result = "[\n "; + } + result += JSON.stringify(part); + }); + if (result) { + result += "\n]"; + } + + return result; + } + + var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); + assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); + assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); + assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); + assert.equal(getDisplayPartsJson(actualQuickInfo.displayParts), getDisplayPartsJson(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(getDisplayPartsJson(actualQuickInfo.documentation), getDisplayPartsJson(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + } + public verifyRenameLocations(findInStrings: boolean, findInComments: boolean) { var renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); if (renameInfo.canRename) { diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index 0940f26cac5..5706924e8e3 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -1,4 +1,4 @@ -declare type PropertyKey = string | number | Symbol; +declare type PropertyKey = string | number | Symbol; interface Symbol { /** Returns a string representation of an object. */ diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a67a89dd82f..260fa5892aa 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -101,10 +101,11 @@ module ts.BreakpointResolver { case SyntaxKind.ArrowFunction: return spanInFunctionDeclaration(node); - case SyntaxKind.FunctionBlock: - return spanInFunctionBlock(node); - case SyntaxKind.Block: + if (isFunctionBlock(node)) { + return spanInFunctionBlock(node); + } + // Fall through case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: @@ -414,13 +415,18 @@ module ts.BreakpointResolver { return undefined; } - case SyntaxKind.FunctionBlock: case SyntaxKind.EnumDeclaration: case SyntaxKind.ClassDeclaration: // Span on close brace token return textSpan(node); case SyntaxKind.Block: + if (isFunctionBlock(node.parent)) { + // Span on close brace token + return textSpan(node); + } + // fall through. + case SyntaxKind.TryBlock: case SyntaxKind.CatchClause: case SyntaxKind.FinallyBlock: diff --git a/src/services/formatting.ts b/src/services/formatting.ts index 3322ea1e65b..9660d9af6df 100644 --- a/src/services/formatting.ts +++ b/src/services/formatting.ts @@ -897,7 +897,7 @@ module ts.formatting { function isSomeBlock(kind: SyntaxKind): boolean { switch (kind) { case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: + case SyntaxKind.Block: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 2723b50af7b..5dc44650346 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -526,7 +526,6 @@ module ts.formatting { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: return true; } @@ -582,7 +581,6 @@ module ts.formatting { case SyntaxKind.TryBlock: case SyntaxKind.CatchClause: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.SwitchStatement: return true; diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index deb779bea2c..aebd736d190 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -120,7 +120,7 @@ module ts.NavigationBar { if (functionDeclaration.kind === SyntaxKind.FunctionDeclaration) { // A function declaration is 'top level' if it contains any function declarations // within it. - if (functionDeclaration.body && functionDeclaration.body.kind === SyntaxKind.FunctionBlock) { + if (functionDeclaration.body && functionDeclaration.body.kind === SyntaxKind.Block) { // Proper function declarations can only have identifier names if (forEach((functionDeclaration.body).statements, s => s.kind === SyntaxKind.FunctionDeclaration && !isEmpty((s).name.text))) { @@ -130,7 +130,7 @@ module ts.NavigationBar { // Or if it is not parented by another function. i.e all functions // at module scope are 'top level'. - if (functionDeclaration.parent.kind !== SyntaxKind.FunctionBlock) { + if (!isFunctionBlock(functionDeclaration.parent)) { return true; } } @@ -333,7 +333,7 @@ module ts.NavigationBar { } function createFunctionItem(node: FunctionDeclaration) { - if (node.name && node.body && node.body.kind === SyntaxKind.FunctionBlock) { + if (node.name && node.body && node.body.kind === SyntaxKind.Block) { var childItems = getItemsWorker(sortNodes((node.body).statements), createChildItem); return getNavigationBarItem(node.name.text, diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 68f30bee781..83eef2f4378 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -67,38 +67,39 @@ module ts { } switch (n.kind) { case SyntaxKind.Block: - var parent = n.parent; - var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); - var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); + if (!isFunctionBlock(n)) { + var parent = n.parent; + var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); + var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); - // Check if the block is standalone, or 'attached' to some parent statement. - // If the latter, we want to collaps the block, but consider its hint span - // to be the entire span of the parent. - if (parent.kind === SyntaxKind.DoStatement || - parent.kind === SyntaxKind.ForInStatement || - parent.kind === SyntaxKind.ForStatement || - parent.kind === SyntaxKind.IfStatement || - parent.kind === SyntaxKind.WhileStatement || - parent.kind === SyntaxKind.WithStatement || - parent.kind === SyntaxKind.CatchClause) { - - addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + // Check if the block is standalone, or 'attached' to some parent statement. + // If the latter, we want to collaps the block, but consider its hint span + // to be the entire span of the parent. + if (parent.kind === SyntaxKind.DoStatement || + parent.kind === SyntaxKind.ForInStatement || + parent.kind === SyntaxKind.ForStatement || + parent.kind === SyntaxKind.IfStatement || + parent.kind === SyntaxKind.WhileStatement || + parent.kind === SyntaxKind.WithStatement || + parent.kind === SyntaxKind.CatchClause) { + + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + } + else { + // Block was a standalone block. In this case we want to only collapse + // the span of the block, independent of any parent span. + var span = TextSpan.fromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); + } + break; } - else { - // Block was a standalone block. In this case we want to only collapse - // the span of the block, independent of any parent span. - var span = TextSpan.fromBounds(n.getStart(), n.end); - elements.push({ - textSpan: span, - hintSpan: span, - bannerText: collapseText, - autoCollapse: autoCollapse(n) - }); - } - break; + // Fallthrough. - - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: diff --git a/src/services/services.ts b/src/services/services.ts index 4a6848ef3b0..2ec69e8c661 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -806,10 +806,15 @@ module ts { case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: case SyntaxKind.ModuleBlock: - case SyntaxKind.FunctionBlock: forEachChild(node, visit); break; + case SyntaxKind.Block: + if (isFunctionBlock(node)) { + forEachChild(node, visit); + } + break; + case SyntaxKind.Parameter: // Only consider properties defined as constructor parameters if (!(node.flags & NodeFlags.AccessibilityModifier)) { @@ -1363,7 +1368,10 @@ module ts { function writeIndent() { if (lineStart) { - displayParts.push(displayPart(getIndentString(indent), SymbolDisplayPartKind.space)); + var indentString = getIndentString(indent); + if (indentString) { + displayParts.push(displayPart(indentString, SymbolDisplayPartKind.space)); + } lineStart = false; } } @@ -1441,7 +1449,7 @@ module ts { } // If the parent is not sourceFile or module block it is local variable - for (var parent = declaration.parent; parent.kind !== SyntaxKind.FunctionBlock; parent = parent.parent) { + for (var parent = declaration.parent; !isFunctionBlock(parent); parent = parent.parent) { // Reached source file or module block if (parent.kind === SyntaxKind.SourceFile || parent.kind === SyntaxKind.ModuleBlock) { return false; @@ -1463,6 +1471,8 @@ module ts { return isFirstDeclarationOfSymbolParameter(symbol) ? SymbolDisplayPartKind.parameterName : SymbolDisplayPartKind.localName; } else if (flags & SymbolFlags.Property) { return SymbolDisplayPartKind.propertyName; } + else if (flags & SymbolFlags.GetAccessor) { return SymbolDisplayPartKind.propertyName; } + else if (flags & SymbolFlags.SetAccessor) { return SymbolDisplayPartKind.propertyName; } else if (flags & SymbolFlags.EnumMember) { return SymbolDisplayPartKind.enumMemberName; } else if (flags & SymbolFlags.Function) { return SymbolDisplayPartKind.functionName; } else if (flags & SymbolFlags.Class) { return SymbolDisplayPartKind.className; } @@ -1471,6 +1481,9 @@ module ts { else if (flags & SymbolFlags.Module) { return SymbolDisplayPartKind.moduleName; } else if (flags & SymbolFlags.Method) { return SymbolDisplayPartKind.methodName; } else if (flags & SymbolFlags.TypeParameter) { return SymbolDisplayPartKind.typeParameterName; } + else if (flags & SymbolFlags.TypeAlias) { return SymbolDisplayPartKind.aliasName; } + else if (flags & SymbolFlags.Import) { return SymbolDisplayPartKind.aliasName; } + return SymbolDisplayPartKind.text; } @@ -2748,6 +2761,7 @@ module ts { if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement; if (flags & SymbolFlags.Import) return ScriptElementKind.alias; + if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement; } return result; @@ -2929,6 +2943,7 @@ module ts { case ScriptElementKind.memberVariableElement: case ScriptElementKind.variableElement: case ScriptElementKind.constElement: + case ScriptElementKind.letElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name @@ -2966,7 +2981,8 @@ module ts { if (functionDeclaration.kind === SyntaxKind.Constructor) { // show (constructor) Type(...) signature - addPrefixForAnyFunctionOrVar(type.symbol, ScriptElementKind.constructorImplementationElement); + symbolKind = ScriptElementKind.constructorImplementationElement; + addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { // (function/method) symbol(..signature) @@ -2998,7 +3014,7 @@ module ts { displayParts.push(spacePart()); addFullSymbolName(symbol); displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); displayParts.push.apply(displayParts, typeToDisplayParts(typeResolver, typeResolver.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } @@ -3070,7 +3086,7 @@ module ts { var importDeclaration = declaration; if (isExternalModuleImportDeclaration(importDeclaration)) { displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); displayParts.push(keywordPart(SyntaxKind.RequireKeyword)); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); @@ -3081,7 +3097,7 @@ module ts { var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(spacePart()); - displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); addFullSymbolName(internalAliasSymbol, enclosingDeclaration); } @@ -3515,7 +3531,7 @@ module ts { var func = getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. - if (!(func && hasKind(func.body, SyntaxKind.FunctionBlock))) { + if (!(func && hasKind(func.body, SyntaxKind.Block))) { return undefined; } @@ -3547,7 +3563,7 @@ module ts { // If the "owner" is a function, then we equate 'return' and 'throw' statements in their // ability to "jump out" of the function, and include occurrences for both. - if (owner.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(owner)) { forEachReturnStatement(owner, returnStatement => { pushKeywordIf(keywords, returnStatement.getFirstToken(), SyntaxKind.ReturnKeyword); }); @@ -3603,7 +3619,7 @@ module ts { while (child.parent) { var parent = child.parent; - if (parent.kind === SyntaxKind.FunctionBlock || parent.kind === SyntaxKind.SourceFile) { + if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) { return parent; } @@ -4300,8 +4316,12 @@ module ts { var staticFlag = NodeFlags.Static; switch (searchSpaceNode.kind) { - case SyntaxKind.Property: case SyntaxKind.Method: + if (isObjectLiteralMethod(searchSpaceNode)) { + break; + } + // fall through + case SyntaxKind.Property: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -4354,6 +4374,11 @@ module ts { result.push(getReferenceEntryFromNode(node)); } break; + case SyntaxKind.Method: + if (isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { + result.push(getReferenceEntryFromNode(node)); + } + break; case SyntaxKind.ClassDeclaration: // Make sure the container belongs to the same class // and has the appropriate static modifier from the original container. @@ -4482,7 +4507,7 @@ module ts { function getPropertySymbolsFromContextualType(node: Node): Symbol[] { if (isNameOfPropertyAssignment(node)) { - var objectLiteral = node.parent.parent; + var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); var name = (node).text; if (contextualType) { diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 93363b4676b..bdb76b77e8a 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -396,7 +396,7 @@ module ts.SignatureHelp { function getContainingArgumentInfo(node: Node): ArgumentListInfo { for (var n = node; n.kind !== SyntaxKind.SourceFile; n = n.parent) { - if (n.kind === SyntaxKind.FunctionBlock) { + if (isFunctionBlock(n)) { return undefined; } diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index 82226449b96..e93cb5616a9 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -326,7 +326,6 @@ module ts.formatting { case SyntaxKind.EnumDeclaration: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.Block: - case SyntaxKind.FunctionBlock: case SyntaxKind.TryBlock: case SyntaxKind.FinallyBlock: case SyntaxKind.ModuleBlock: @@ -357,7 +356,6 @@ module ts.formatting { case SyntaxKind.ForInStatement: case SyntaxKind.ForStatement: case SyntaxKind.IfStatement: - return child !== SyntaxKind.Block; case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.Method: @@ -365,7 +363,7 @@ module ts.formatting { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return child !== SyntaxKind.FunctionBlock; + return child !== SyntaxKind.Block; default: return false; } @@ -404,7 +402,6 @@ module ts.formatting { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.Block: case SyntaxKind.FinallyBlock: - case SyntaxKind.FunctionBlock: case SyntaxKind.ModuleBlock: case SyntaxKind.SwitchStatement: return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index be71c720de2..8aeafd29720 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -3444,7 +3444,7 @@ module TypeScript.Parser { parseArrowFunctionBody(/*asyncContext:*/ !!asyncKeyword)); } - function isFunctionBlock(): boolean { + function isStartOfFunctionBlock(): boolean { var currentTokenKind = currentToken().kind; return currentTokenKind === SyntaxKind.OpenBraceToken || currentTokenKind === SyntaxKind.EqualsGreaterThanToken; } diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index 24a12267dc5..b3415c27f29 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,10 +1,7 @@ tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: 'generators' are not currently supported. -tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. -==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (1 errors) ==== var v = { *[foo()]() { } } ~ -!!! error TS9001: 'generators' are not currently supported. - ~~~~~~~ -!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher. \ No newline at end of file +!!! error TS9001: 'generators' are not currently supported. \ No newline at end of file diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index b25aba00837..129440fa463 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -132,18 +132,16 @@ x = i; >i : () => string x = { f() { return 1; } } ->x = { f() { return 1; } } : { f: () => number; } +>x = { f() { return 1; } } : { f(): number; } >x : any ->{ f() { return 1; } } : { f: () => number; } +>{ f() { return 1; } } : { f(): number; } >f : () => number ->f() { return 1; } : () => number x = { f(x: T) { return x; } } ->x = { f(x: T) { return x; } } : { f: (x: T) => T; } +>x = { f(x: T) { return x; } } : { f(x: T): T; } >x : any ->{ f(x: T) { return x; } } : { f: (x: T) => T; } +>{ f(x: T) { return x; } } : { f(x: T): T; } >f : (x: T) => T ->f(x: T) { return x; } : (x: T) => T >T : T >x : T >T : T diff --git a/tests/baselines/reference/callSignaturesWithOptionalParameters.types b/tests/baselines/reference/callSignaturesWithOptionalParameters.types index 8b1e929d9e3..818c52f79d0 100644 --- a/tests/baselines/reference/callSignaturesWithOptionalParameters.types +++ b/tests/baselines/reference/callSignaturesWithOptionalParameters.types @@ -133,12 +133,11 @@ a.foo(1); >foo : (x?: number) => any var b = { ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } ->{ foo(x?: number) { }, a: function foo(x: number, y?: number) { }, b: (x?: number) => { }} : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>{ foo(x?: number) { }, a: function foo(x: number, y?: number) { }, b: (x?: number) => { }} : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } foo(x?: number) { }, >foo : (x?: number) => void ->foo(x?: number) { } : (x?: number) => void >x : number a: function foo(x: number, y?: number) { }, @@ -157,36 +156,36 @@ var b = { b.foo(); >b.foo() : void >b.foo : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >foo : (x?: number) => void b.foo(1); >b.foo(1) : void >b.foo : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >foo : (x?: number) => void b.a(1); >b.a(1) : void >b.a : (x: number, y?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >a : (x: number, y?: number) => void b.a(1, 2); >b.a(1, 2) : void >b.a : (x: number, y?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >a : (x: number, y?: number) => void b.b(); >b.b() : void >b.b : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >b : (x?: number) => void b.b(1); >b.b(1) : void >b.b : (x?: number) => void ->b : { foo: (x?: number) => void; a: (x: number, y?: number) => void; b: (x?: number) => void; } +>b : { foo(x?: number): void; a: (x: number, y?: number) => void; b: (x?: number) => void; } >b : (x?: number) => void diff --git a/tests/baselines/reference/commentsOnObjectLiteral3.types b/tests/baselines/reference/commentsOnObjectLiteral3.types index e7770c7e273..e81bd646b5a 100644 --- a/tests/baselines/reference/commentsOnObjectLiteral3.types +++ b/tests/baselines/reference/commentsOnObjectLiteral3.types @@ -1,8 +1,8 @@ === tests/cases/compiler/commentsOnObjectLiteral3.ts === var v = { ->v : { prop: number; func: () => void; func1: () => void; a: any; } ->{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1: () => void; a: any; } +>v : { prop: number; func: () => void; func1(): void; a: any; } +>{ //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, //property func: function () { }, //PropertyName + CallSignature func1() { }, //getter get a() { return this.prop; } /*trailing 1*/, //setter set a(value) { this.prop = value; } // trailing 2} : { prop: number; func: () => void; func1(): void; a: any; } //property prop: 1 /* multiple trailing comments */ /*trailing comments*/, @@ -17,7 +17,6 @@ var v = { //PropertyName + CallSignature func1() { }, >func1 : () => void ->func1() { } : () => void //getter get a() { diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index 800dd856422..aa1d59aee81 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -265,7 +265,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { const c = 0; n = c; }, diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 355f39af2f2..8be43633d70 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -220,7 +220,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { const c28 = 0; }, f2: function () { diff --git a/tests/baselines/reference/invalidUndefinedValues.types b/tests/baselines/reference/invalidUndefinedValues.types index 9cc71b87c82..3f17deede37 100644 --- a/tests/baselines/reference/invalidUndefinedValues.types +++ b/tests/baselines/reference/invalidUndefinedValues.types @@ -68,11 +68,10 @@ x = M; >M : typeof M x = { f() { } } ->x = { f() { } } : { f: () => void; } +>x = { f() { } } : { f(): void; } >x : any ->{ f() { } } : { f: () => void; } +>{ f() { } } : { f(): void; } >f : () => void ->f() { } : () => void function f(a: T) { >f : (a: T) => void diff --git a/tests/baselines/reference/invalidVoidAssignments.errors.txt b/tests/baselines/reference/invalidVoidAssignments.errors.txt index 64decc2f5e2..9c6be972d3b 100644 --- a/tests/baselines/reference/invalidVoidAssignments.errors.txt +++ b/tests/baselines/reference/invalidVoidAssignments.errors.txt @@ -12,7 +12,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(21,5): e tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(26,1): error TS2322: Type 'typeof E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(27,1): error TS2322: Type 'E' is not assignable to type 'void'. -tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. ==== tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts (13 errors) ==== @@ -72,4 +72,4 @@ tests/cases/conformance/types/primitives/void/invalidVoidAssignments.ts(29,1): e x = { f() { } } ~ -!!! error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. \ No newline at end of file +!!! error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. \ No newline at end of file diff --git a/tests/baselines/reference/invalidVoidValues.errors.txt b/tests/baselines/reference/invalidVoidValues.errors.txt index b8a4400e4e0..eb5ddd02259 100644 --- a/tests/baselines/reference/invalidVoidValues.errors.txt +++ b/tests/baselines/reference/invalidVoidValues.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(7,1): error T tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(8,1): error TS2322: Type 'E' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(12,1): error TS2322: Type 'C' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(16,1): error TS2322: Type 'I' is not assignable to type 'void'. -tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(18,1): error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(18,1): error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(21,1): error TS2322: Type 'typeof M' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(24,5): error TS2322: Type 'T' is not assignable to type 'void'. tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(26,1): error TS2322: Type '(a: T) => void' is not assignable to type 'void'. @@ -45,7 +45,7 @@ tests/cases/conformance/types/primitives/void/invalidVoidValues.ts(26,1): error x = { f() {} } ~ -!!! error TS2322: Type '{ f: () => void; }' is not assignable to type 'void'. +!!! error TS2322: Type '{ f(): void; }' is not assignable to type 'void'. module M { export var x = 1; } x = M; diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index fb16a03f569..d0f70693d7c 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -282,7 +282,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { let l = 0; n = l; }, diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index 13eaafb0712..fe9ed903bf5 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -240,7 +240,7 @@ var C = (function () { })(); // object literals var o = { - f: function () { + f() { let l28 = 0; }, f2: function () { diff --git a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types index 1628b673621..41bcdd99a71 100644 --- a/tests/baselines/reference/nameCollisionsInPropertyAssignments.types +++ b/tests/baselines/reference/nameCollisionsInPropertyAssignments.types @@ -3,10 +3,9 @@ var x = 1 >x : number var y = { x() { x++; } }; ->y : { x: () => void; } ->{ x() { x++; } } : { x: () => void; } +>y : { x(): void; } +>{ x() { x++; } } : { x(): void; } >x : () => void ->x() { x++; } : () => void >x++ : number >x : number diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 19f2c700ccf..bd9a0bcbc93 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. Index signatures are incompatible. Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -108,7 +108,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }'. +!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index f28f25e815c..c34b2ab79b7 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -23,7 +23,7 @@ var x2 = { var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number @@ -36,7 +36,6 @@ var x3 = { d() { }, >d : () => void ->d() { } : () => void x3, >x3 : any diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js index b398a231351..c65087a8da7 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.js @@ -32,7 +32,7 @@ var x3 = { a: 0, b, c, - d: function () { + d() { }, x3, parent: x3 diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 0383a3f5d2e..5d5acc279a5 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -23,7 +23,7 @@ var x2 = { var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d: () => void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } a: 0, >a : number @@ -36,7 +36,6 @@ var x3 = { d() { }, >d : () => void ->d() { } : () => void x3, >x3 : any diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types index f73785fab0d..efe7e32f5d7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures.types @@ -53,10 +53,9 @@ var a: { foo(x: string): string } >x : string var b = { foo(x: string) { return ''; } }; ->b : { foo: (x: string) => string; } ->{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } +>b : { foo(x: string): string; } +>{ foo(x: string) { return ''; } } : { foo(x: string): string; } >foo : (x: string) => string ->foo(x: string) { return ''; } : (x: string) => string >x : string function foo1(x: A); @@ -130,17 +129,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } >x : any function foo5(x: A); @@ -242,17 +241,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // error ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : any function foo12(x: I); @@ -298,17 +297,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // error ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types index 16b658d0e43..9004a267691 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignatures2.types @@ -54,10 +54,9 @@ var a: { foo(x: Date): string } >Date : Date var b = { foo(x: RegExp) { return ''; } }; ->b : { foo: (x: RegExp) => string; } ->{ foo(x: RegExp) { return ''; } } : { foo: (x: RegExp) => string; } +>b : { foo(x: RegExp): string; } +>{ foo(x: RegExp) { return ''; } } : { foo(x: RegExp): string; } >foo : (x: RegExp) => string ->foo(x: RegExp) { return ''; } : (x: RegExp) => string >x : RegExp >RegExp : RegExp @@ -132,17 +131,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: RegExp) => string; }): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo4 : { (x: { foo(x: RegExp): string; }): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo5(x: A); @@ -244,17 +243,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -300,17 +299,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } ->x : { foo: (x: RegExp) => string; } ->b : { foo: (x: RegExp) => string; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } +>x : { foo(x: RegExp): string; } +>b : { foo(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types index 0ebbc639e5f..2f97c721637 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesDifferingParamCounts.types @@ -57,10 +57,9 @@ var a: { foo(x: string, y: string): string } >y : string var b = { foo(x: string) { return ''; } }; ->b : { foo: (x: string) => string; } ->{ foo(x: string) { return ''; } } : { foo: (x: string) => string; } +>b : { foo(x: string): string; } +>{ foo(x: string) { return ''; } } : { foo(x: string): string; } >foo : (x: string) => string ->foo(x: string) { return ''; } : (x: string) => string >x : string function foo1(x: A); @@ -134,17 +133,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: string) => string; }): any; (x: { foo: (x: string) => string; }): any; } +>foo4 : { (x: { foo(x: string): string; }): any; (x: { foo(x: string): string; }): any; } >x : any function foo5(x: A); @@ -246,17 +245,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: string): string; }): any; } >x : any function foo12(x: I); @@ -302,17 +301,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // error ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } ->x : { foo: (x: string) => string; } ->b : { foo: (x: string) => string; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } +>x : { foo(x: string): string; } +>b : { foo(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types index 4d8b8ccb42a..c3ab4ffb837 100644 --- a/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types +++ b/tests/baselines/reference/objectTypesIdentityWithCallSignaturesWithOverloads.types @@ -100,12 +100,11 @@ var a: { } var b = { ->b : { foo: (x: any) => any; } ->{ foo(x: any) { return ''; }} : { foo: (x: any) => any; } +>b : { foo(x: any): any; } +>{ foo(x: any) { return ''; }} : { foo(x: any): any; } foo(x: any) { return ''; } >foo : (x: any) => any ->foo(x: any) { return ''; } : (x: any) => any >x : any >'' : any @@ -182,17 +181,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: any) => any; }): any; (x: { foo: (x: any) => any; }): any; } +>foo4 : { (x: { foo(x: any): any; }): any; (x: { foo(x: any): any; }): any; } >x : any function foo5(x: A); @@ -294,17 +293,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: any) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: any): any; }): any; } >x : any function foo12(x: I); @@ -350,17 +349,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } ->x : { foo: (x: any) => any; } ->b : { foo: (x: any) => any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } +>x : { foo(x: any): any; } +>b : { foo(x: any): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: any) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: any): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types index c530f1ced9b..769682c826a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types @@ -40,10 +40,9 @@ var a: { new(x: Date): string } >Date : Date var b = { new(x: RegExp) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: RegExp) => string; } ->{ new(x: RegExp) { return ''; } } : { new: (x: RegExp) => string; } +>b : { new(x: RegExp): string; } +>{ new(x: RegExp) { return ''; } } : { new(x: RegExp): string; } >new : (x: RegExp) => string ->new(x: RegExp) { return ''; } : (x: RegExp) => string >x : RegExp >RegExp : RegExp @@ -104,17 +103,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: RegExp) => string; }): any; (x: { new: (x: RegExp) => string; }): any; } +>foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo8(x: B); @@ -160,17 +159,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: RegExp) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -216,17 +215,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } ->x : { new: (x: RegExp) => string; } ->b : { new: (x: RegExp) => string; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>x : { new(x: RegExp): string; } +>b : { new(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: RegExp) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types index e5598f874e0..a2779e3bd35 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types @@ -43,10 +43,9 @@ var a: { new(x: string, y: string): string } >y : string var b = { new(x: string) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: string) => string; } ->{ new(x: string) { return ''; } } : { new: (x: string) => string; } +>b : { new(x: string): string; } +>{ new(x: string) { return ''; } } : { new(x: string): string; } >new : (x: string) => string ->new(x: string) { return ''; } : (x: string) => string >x : string function foo1b(x: B); @@ -106,17 +105,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: string) => string; }): any; (x: { new: (x: string) => string; }): any; } +>foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } >x : any function foo8(x: B); @@ -162,17 +161,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: string) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } >x : any function foo12(x: I); @@ -218,17 +217,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } ->x : { new: (x: string) => string; } ->b : { new: (x: string) => string; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>x : { new(x: string): string; } +>b : { new(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: string) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types index 240e12b1c22..d3cf9bc0063 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures.types @@ -65,10 +65,9 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return x; } }; ->b : { foo: (x: T) => T; } ->{ foo(x: T) { return x; } } : { foo: (x: T) => T; } +>b : { foo(x: T): T; } +>{ foo(x: T) { return x; } } : { foo(x: T): T; } >foo : (x: T) => T ->foo(x: T) { return x; } : (x: T) => T >T : T >x : T >T : T @@ -145,17 +144,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => T; }): any; (x: { foo: (x: T) => T; }): any; } +>foo4 : { (x: { foo(x: T): T; }): any; (x: { foo(x: T): T; }): any; } >x : any function foo5(x: A); @@ -257,17 +256,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): T; }): any; } >x : any function foo12(x: I); @@ -313,17 +312,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } ->x : { foo: (x: T) => T; } ->b : { foo: (x: T) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } +>x : { foo(x: T): T; } +>b : { foo(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types index 932dbf7e9b3..0c00e587b78 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignatures2.types @@ -83,10 +83,9 @@ var a: { foo(x: T, y: U): T } >T : T var b = { foo(x: T, y: U) { return x; } }; ->b : { foo: (x: T, y: U) => T; } ->{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } +>b : { foo(x: T, y: U): T; } +>{ foo(x: T, y: U) { return x; } } : { foo(x: T, y: U): T; } >foo : (x: T, y: U) => T ->foo(x: T, y: U) { return x; } : (x: T, y: U) => T >T : T >U : U >x : T @@ -166,17 +165,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo5(x: A); @@ -278,17 +277,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo12(x: I); @@ -334,17 +333,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types index 2a5ab2dfe70..432a618c4e2 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByConstraints.types @@ -67,10 +67,9 @@ var a: { foo>(x: T): string } >T : T var b = { foo(x: T) { return ''; } }; ->b : { foo: (x: T) => string; } ->{ foo(x: T) { return ''; } } : { foo: (x: T) => string; } +>b : { foo(x: T): string; } +>{ foo(x: T) { return ''; } } : { foo(x: T): string; } >foo : (x: T) => string ->foo(x: T) { return ''; } : (x: T) => string >T : T >RegExp : RegExp >x : T @@ -153,17 +152,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => string; }): any; (x: { foo: (x: T) => string; }): any; } +>foo4 : { (x: { foo(x: T): string; }): any; (x: { foo(x: T): string; }): any; } >x : any function foo5(x: A); @@ -273,18 +272,18 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } >x : B >B : B >Array : T[] function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): string; }): any; } >x : any function foo12(x: I); @@ -334,18 +333,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } >x : I >I : I >Number : Number function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } ->x : { foo: (x: T) => string; } ->b : { foo: (x: T) => string; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } +>x : { foo(x: T): string; } +>b : { foo(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types index 9de1a816ab7..8b5a042c1e2 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType.types @@ -64,10 +64,9 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return null; } }; ->b : { foo: (x: T) => any; } ->{ foo(x: T) { return null; } } : { foo: (x: T) => any; } +>b : { foo(x: T): any; } +>{ foo(x: T) { return null; } } : { foo(x: T): any; } >foo : (x: T) => any ->foo(x: T) { return null; } : (x: T) => any >T : T >x : T >T : T @@ -143,17 +142,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } >x : any function foo5(x: A); @@ -255,17 +254,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : any function foo12(x: I); @@ -311,17 +310,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types index f6f33890c07..2863cafa885 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingByReturnType2.types @@ -70,10 +70,9 @@ var a: { foo(x: T): T } >T : T var b = { foo(x: T) { return null; } }; ->b : { foo: (x: T) => any; } ->{ foo(x: T) { return null; } } : { foo: (x: T) => any; } +>b : { foo(x: T): any; } +>{ foo(x: T) { return null; } } : { foo(x: T): any; } >foo : (x: T) => any ->foo(x: T) { return null; } : (x: T) => any >T : T >Date : Date >x : T @@ -156,17 +155,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T) => any; }): any; (x: { foo: (x: T) => any; }): any; } +>foo4 : { (x: { foo(x: T): any; }): any; (x: { foo(x: T): any; }): any; } >x : any function foo5(x: A); @@ -276,18 +275,18 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : B >B : B >Date : Date function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T): any; }): any; } >x : any function foo12(x: I); @@ -337,18 +336,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : I >I : I >Date : Date function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } ->x : { foo: (x: T) => any; } ->b : { foo: (x: T) => any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } +>x : { foo(x: T): any; } +>b : { foo(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types index dbd6d3e7d03..125b82c9915 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterCounts.types @@ -78,10 +78,9 @@ var a: { foo(x: Z): Z } >Z : Z var b = { foo(x: A) { return x; } }; ->b : { foo: (x: A) => A; } ->{ foo(x: A) { return x; } } : { foo: (x: A) => A; } +>b : { foo(x: A): A; } +>{ foo(x: A) { return x; } } : { foo(x: A): A; } >foo : (x: A) => A ->foo(x: A) { return x; } : (x: A) => A >A : A >B : B >C : C @@ -163,17 +162,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } >x : any function foo5(x: A); @@ -278,17 +277,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -341,19 +340,19 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : I >I : I >Date : Date >RegExp : RegExp function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types index 85e83528cd0..fd0b14a4f79 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesDifferingTypeParameterNames.types @@ -65,10 +65,9 @@ var a: { foo(x: Z): Z } >Z : Z var b = { foo(x: A) { return x; } }; ->b : { foo: (x: A) => A; } ->{ foo(x: A) { return x; } } : { foo: (x: A) => A; } +>b : { foo(x: A): A; } +>{ foo(x: A) { return x; } } : { foo(x: A): A; } >foo : (x: A) => A ->foo(x: A) { return x; } : (x: A) => A >A : A >x : A >A : A @@ -145,17 +144,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: A) => A; }): any; (x: { foo: (x: A) => A; }): any; } +>foo4 : { (x: { foo(x: A): A; }): any; (x: { foo(x: A): A; }): any; } >x : any function foo5(x: A); @@ -257,17 +256,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: A): A; }): any; } >x : any function foo12(x: I); @@ -313,17 +312,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } ->x : { foo: (x: A) => A; } ->b : { foo: (x: A) => A; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } +>x : { foo(x: A): A; } +>b : { foo(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: A): A; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types index bef916fc410..33fce5295a7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams.types @@ -79,10 +79,9 @@ var a: { foo(x: T, y?: T): T } >T : T var b = { foo(x: T, y?: T) { return x; } }; ->b : { foo: (x: T, y?: T) => T; } ->{ foo(x: T, y?: T) { return x; } } : { foo: (x: T, y?: T) => T; } +>b : { foo(x: T, y?: T): T; } +>{ foo(x: T, y?: T) { return x; } } : { foo(x: T, y?: T): T; } >foo : (x: T, y?: T) => T ->foo(x: T, y?: T) { return x; } : (x: T, y?: T) => T >T : T >x : T >T : T @@ -161,17 +160,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y?: T) => T; }): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo4 : { (x: { foo(x: T, y?: T): T; }): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo5(x: A); @@ -273,17 +272,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo12(x: I); @@ -329,17 +328,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } ->x : { foo: (x: T, y?: T) => T; } ->b : { foo: (x: T, y?: T) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } +>x : { foo(x: T, y?: T): T; } +>b : { foo(x: T, y?: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types index c8a4ad6be29..2d9eab7c540 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams2.types @@ -85,10 +85,9 @@ var a: { foo(x: T, y?: U): T } >T : T var b = { foo(x: T, y?: U) { return x; } }; ->b : { foo: (x: T, y?: U) => T; } ->{ foo(x: T, y?: U) { return x; } } : { foo: (x: T, y?: U) => T; } +>b : { foo(x: T, y?: U): T; } +>{ foo(x: T, y?: U) { return x; } } : { foo(x: T, y?: U): T; } >foo : (x: T, y?: U) => T ->foo(x: T, y?: U) { return x; } : (x: T, y?: U) => T >T : T >U : U >x : T @@ -168,17 +167,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y?: U) => T; }): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y?: U): T; }): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo5(x: A); @@ -280,17 +279,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo12(x: I); @@ -336,17 +335,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } ->x : { foo: (x: T, y?: U) => T; } ->b : { foo: (x: T, y?: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } +>x : { foo(x: T, y?: U): T; } +>b : { foo(x: T, y?: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y?: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y?: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types index 06c23dcd0b1..54ec438104e 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericCallSignaturesOptionalParams3.types @@ -85,10 +85,9 @@ var a: { foo(x: T, y?: U): T } >T : T var b = { foo(x: T, y: U) { return x; } }; ->b : { foo: (x: T, y: U) => T; } ->{ foo(x: T, y: U) { return x; } } : { foo: (x: T, y: U) => T; } +>b : { foo(x: T, y: U): T; } +>{ foo(x: T, y: U) { return x; } } : { foo(x: T, y: U): T; } >foo : (x: T, y: U) => T ->foo(x: T, y: U) { return x; } : (x: T, y: U) => T >T : T >U : U >x : T @@ -168,17 +167,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo4(x: any) { } ->foo4 : { (x: { foo: (x: T, y: U) => T; }): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo4 : { (x: { foo(x: T, y: U): T; }): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo5(x: A); @@ -280,17 +279,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo11 : { (x: B): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo12(x: I); @@ -336,17 +335,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } ->x : { foo: (x: T, y: U) => T; } ->b : { foo: (x: T, y: U) => T; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } +>x : { foo(x: T, y: U): T; } +>b : { foo(x: T, y: U): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { foo: (x: T, y: U) => T; }): any; } +>foo14 : { (x: I): any; (x: { foo(x: T, y: U): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types index 8a41814e1a9..7acc93db124 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types @@ -51,10 +51,9 @@ var a: { new>(x: T): string } >T : T var b = { new(x: T) { return ''; } }; // not a construct signature, function called new ->b : { new: (x: T) => string; } ->{ new(x: T) { return ''; } } : { new: (x: T) => string; } +>b : { new(x: T): string; } +>{ new(x: T) { return ''; } } : { new(x: T): string; } >new : (x: T) => string ->new(x: T) { return ''; } : (x: T) => string >T : T >RegExp : RegExp >x : T @@ -123,17 +122,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => string; }): any; (x: { new: (x: T) => string; }): any; } +>foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } >x : any function foo8(x: B>); @@ -184,18 +183,18 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } >x : B >B : B >Array : T[] function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => string; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } >x : any function foo12(x: I); @@ -245,17 +244,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } >x : I >I : I >Number : Number function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } ->x : { new: (x: T) => string; } ->b : { new: (x: T) => string; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>x : { new(x: T): string; } +>b : { new(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => string; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types index 1eac69f7f23..4b2e628ad5d 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types @@ -49,10 +49,9 @@ var a: { new(x: T): T } >T : T var b = { new(x: T): T { return null; } }; // not a construct signature, function called new ->b : { new: (x: T) => T; } ->{ new(x: T): T { return null; } } : { new: (x: T) => T; } +>b : { new(x: T): T; } +>{ new(x: T): T { return null; } } : { new(x: T): T; } >new : (x: T) => T ->new(x: T): T { return null; } : (x: T) => T >T : T >x : T >T : T @@ -115,31 +114,31 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => T; }): any; (x: { new: (x: T) => T; }): any; } +>foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } >x : any function foo5(x: typeof a): number; ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } >x : new (x: T) => T >a : new (x: T) => T function foo5(x: typeof b): string; // ok ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo5(x: any): any { } ->foo5 : { (x: new (x: T) => T): number; (x: { new: (x: T) => T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } >x : any function foo8(x: B); @@ -185,17 +184,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => T; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } >x : any function foo12(x: I); @@ -241,17 +240,17 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } ->x : { new: (x: T) => T; } ->b : { new: (x: T) => T; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>x : { new(x: T): T; } +>b : { new(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => T; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types index 308f592ef12..a25fb5b876a 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types @@ -54,10 +54,9 @@ var a: { new(x: T): T } >T : T var b = { new(x: T) { return null; } }; // not a construct signature, function called new ->b : { new: (x: T) => any; } ->{ new(x: T) { return null; } } : { new: (x: T) => any; } +>b : { new(x: T): any; } +>{ new(x: T) { return null; } } : { new(x: T): any; } >new : (x: T) => any ->new(x: T) { return null; } : (x: T) => any >T : T >Date : Date >x : T @@ -126,17 +125,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T) => any; }): any; (x: { new: (x: T) => any; }): any; } +>foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } >x : any function foo8(x: B); @@ -187,18 +186,18 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } >x : B >B : B >Date : Date function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T) => any; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } >x : any function foo12(x: I); @@ -248,18 +247,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } >x : I >I : I >Date : Date function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } ->x : { new: (x: T) => any; } ->b : { new: (x: T) => any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>x : { new(x: T): any; } +>b : { new(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T) => any; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types index 0276458ea91..683c3ace9f9 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types @@ -68,10 +68,9 @@ var a: { new (x: Z): C; } >B : B var b = { new(x: A) { return x; } }; ->b : { new: (x: A) => A; } ->{ new(x: A) { return x; } } : { new: (x: A) => A; } +>b : { new(x: A): A; } +>{ new(x: A) { return x; } } : { new(x: A): A; } >new : (x: A) => A ->new(x: A) { return x; } : (x: A) => A >A : A >B : B >C : C @@ -139,17 +138,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: A) => A; }): any; (x: { new: (x: A) => A; }): any; } +>foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } >x : any function foo8(x: B); @@ -197,17 +196,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: A) => A; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -260,18 +259,18 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } >x : I >I : I >Date : Date >RegExp : RegExp function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } ->x : { new: (x: A) => A; } ->b : { new: (x: A) => A; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>x : { new(x: A): A; } +>b : { new(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: A) => A; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types index 10a8da26907..af65ca5b911 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types @@ -50,10 +50,9 @@ var a: { new(x: Z): B } >Z : Z var b = { new(x: A) { return new C(x); } }; ->b : { new: (x: A) => C; } ->{ new(x: A) { return new C(x); } } : { new: (x: A) => C; } +>b : { new(x: A): C; } +>{ new(x: A) { return new C(x); } } : { new(x: A): C; } >new : (x: A) => C ->new(x: A) { return new C(x); } : (x: A) => C >A : A >x : A >A : A @@ -119,17 +118,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: A) => C; }): any; (x: { new: (x: A) => C; }): any; } +>foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } >x : any function foo8(x: B); @@ -175,17 +174,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: A) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } >x : any function foo12(x: I); @@ -231,16 +230,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } ->x : { new: (x: A) => C; } ->b : { new: (x: A) => C; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>x : { new(x: A): C; } +>b : { new(x: A): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: A) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types index 28ef6a81505..a6dea7c2518 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types @@ -62,10 +62,9 @@ var a: { new(x: T, y?: T): B } >T : T var b = { new(x: T, y?: T) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y?: T) => C; } ->{ new(x: T, y?: T) { return new C(x, y); } } : { new: (x: T, y?: T) => C; } +>b : { new(x: T, y?: T): C; } +>{ new(x: T, y?: T) { return new C(x, y); } } : { new(x: T, y?: T): C; } >new : (x: T, y?: T) => C ->new(x: T, y?: T) { return new C(x, y); } : (x: T, y?: T) => C >T : T >x : T >T : T @@ -134,17 +133,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y?: T) => C; }): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } >x : any function foo8(x: B): string; @@ -190,17 +189,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } >x : any function foo12(x: I); @@ -246,16 +245,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } ->x : { new: (x: T, y?: T) => C; } ->b : { new: (x: T, y?: T) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>x : { new(x: T, y?: T): C; } +>b : { new(x: T, y?: T): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y?: T) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types index e75f1ce7cbb..3c0f09e61da 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types @@ -70,10 +70,9 @@ var a: { new(x: T, y?: U): B } >U : U var b = { new(x: T, y?: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y?: U) => C; } ->{ new(x: T, y?: U) { return new C(x, y); } } : { new: (x: T, y?: U) => C; } +>b : { new(x: T, y?: U): C; } +>{ new(x: T, y?: U) { return new C(x, y); } } : { new(x: T, y?: U): C; } >new : (x: T, y?: U) => C ->new(x: T, y?: U) { return new C(x, y); } : (x: T, y?: U) => C >T : T >U : U >x : T @@ -144,17 +143,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y?: U) => C; }): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } >x : any function foo8(x: B); @@ -200,17 +199,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } >x : any function foo12(x: I); @@ -256,16 +255,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } ->x : { new: (x: T, y?: U) => C; } ->b : { new: (x: T, y?: U) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>x : { new(x: T, y?: U): C; } +>b : { new(x: T, y?: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y?: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types index 5f5d592df34..f21ccc15abb 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types @@ -70,10 +70,9 @@ var a: { new (x: T, y?: U): B }; >U : U var b = { new(x: T, y: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new: (x: T, y: U) => C; } ->{ new(x: T, y: U) { return new C(x, y); } } : { new: (x: T, y: U) => C; } +>b : { new(x: T, y: U): C; } +>{ new(x: T, y: U) { return new C(x, y); } } : { new(x: T, y: U): C; } >new : (x: T, y: U) => C ->new(x: T, y: U) { return new C(x, y); } : (x: T, y: U) => C >T : T >U : U >x : T @@ -144,17 +143,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new: (x: T, y: U) => C; }): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } >x : any function foo8(x: B); @@ -200,17 +199,17 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } >x : B >B : B function foo11(x: typeof b); // ok ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } >x : any function foo12(x: I); @@ -256,16 +255,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } >x : I >I : I function foo14(x: typeof b); // ok ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } ->x : { new: (x: T, y: U) => C; } ->b : { new: (x: T, y: U) => C; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>x : { new(x: T, y: U): C; } +>b : { new(x: T, y: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new: (x: T, y: U) => C; }): any; } +>foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types index 9629d06c114..0424a169331 100644 --- a/tests/baselines/reference/parametersWithNoAnnotationAreAny.types +++ b/tests/baselines/reference/parametersWithNoAnnotationAreAny.types @@ -58,12 +58,11 @@ var a: { } var b = { ->b : { foo: (x: any) => any; a: (x: any) => any; b: (x: any) => any; } ->{ foo(x) { return x; }, a: function foo(x) { return x; }, b: (x) => x} : { foo: (x: any) => any; a: (x: any) => any; b: (x: any) => any; } +>b : { foo(x: any): any; a: (x: any) => any; b: (x: any) => any; } +>{ foo(x) { return x; }, a: function foo(x) { return x; }, b: (x) => x} : { foo(x: any): any; a: (x: any) => any; b: (x: any) => any; } foo(x) { >foo : (x: any) => any ->foo(x) { return x; } : (x: any) => any >x : any return x; diff --git a/tests/baselines/reference/parserComputedPropertyName3.js b/tests/baselines/reference/parserComputedPropertyName3.js index edb8533ad81..2e73fe87d3a 100644 --- a/tests/baselines/reference/parserComputedPropertyName3.js +++ b/tests/baselines/reference/parserComputedPropertyName3.js @@ -2,5 +2,5 @@ var v = { [e]() { } }; //// [parserComputedPropertyName3.js] -var v = { [e]: function () { +var v = { [e]() { } }; diff --git a/tests/baselines/reference/parserComputedPropertyName3.types b/tests/baselines/reference/parserComputedPropertyName3.types index f673d9fbeb8..8a5cfafbd40 100644 --- a/tests/baselines/reference/parserComputedPropertyName3.types +++ b/tests/baselines/reference/parserComputedPropertyName3.types @@ -3,5 +3,4 @@ var v = { [e]() { } }; >v : {} >{ [e]() { } } : {} >e : unknown ->[e]() { } : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment1.types b/tests/baselines/reference/parserFunctionPropertyAssignment1.types index d84e798d023..1b552cdfefd 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment1.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment1.types @@ -1,7 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment1.ts === var v = { foo() { } }; ->v : { foo: () => void; } ->{ foo() { } } : { foo: () => void; } +>v : { foo(): void; } +>{ foo() { } } : { foo(): void; } >foo : () => void ->foo() { } : () => void diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment2.types b/tests/baselines/reference/parserFunctionPropertyAssignment2.types index 21d182993bb..747b66978af 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment2.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment2.types @@ -1,6 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment2.ts === var v = { 0() { } }; ->v : { 0: () => void; } ->{ 0() { } } : { 0: () => void; } ->0() { } : () => void +>v : { 0(): void; } +>{ 0() { } } : { 0(): void; } diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment3.types b/tests/baselines/reference/parserFunctionPropertyAssignment3.types index 2c76fdf07a4..9fb2bb45fef 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment3.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment3.types @@ -1,6 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment3.ts === var v = { "foo"() { } }; ->v : { "foo": () => void; } ->{ "foo"() { } } : { "foo": () => void; } ->"foo"() { } : () => void +>v : { "foo"(): void; } +>{ "foo"() { } } : { "foo"(): void; } diff --git a/tests/baselines/reference/parserFunctionPropertyAssignment4.types b/tests/baselines/reference/parserFunctionPropertyAssignment4.types index 4aec89e265f..6ab031518d4 100644 --- a/tests/baselines/reference/parserFunctionPropertyAssignment4.types +++ b/tests/baselines/reference/parserFunctionPropertyAssignment4.types @@ -1,7 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/PropertyAssignments/parserFunctionPropertyAssignment4.ts === var v = { 0() { } }; ->v : { 0: () => void; } ->{ 0() { } } : { 0: () => void; } ->0() { } : () => void +>v : { 0(): void; } +>{ 0() { } } : { 0(): void; } >T : T diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map index 74b7201ea8f..cc78ea833bb 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationFunctionPropertyAssignment.js.map] -{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC,EAAD;AAAM,CAAC,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationFunctionPropertyAssignment.js","sourceRoot":"","sources":["sourceMapValidationFunctionPropertyAssignment.ts"],"names":["n"],"mappings":"AAAA,IAAI,CAAC,GAAG,EAAE,CAAC;AAAKA,CAACA,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt index c34558a11a3..a1f780ae2fe 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.sourcemap.txt @@ -15,21 +15,18 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts 4 > ^^^ 5 > ^^ 6 > ^ -7 > ^^ 1 > 2 >var 3 > x 4 > = 5 > { 6 > n -7 > 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) 4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0) 5 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) 6 >Emitted(1, 12) Source(1, 12) + SourceIndex(0) -7 >Emitted(1, 14) Source(1, 11) + SourceIndex(0) --- >>>} }; 1 > @@ -37,12 +34,12 @@ sourceFile:sourceMapValidationFunctionPropertyAssignment.ts 3 > ^^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >n() { +1 >() { 2 >} 3 > } 4 > ; -1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0) -2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0) +1 >Emitted(2, 1) Source(1, 17) + SourceIndex(0) name (n) +2 >Emitted(2, 2) Source(1, 18) + SourceIndex(0) name (n) 3 >Emitted(2, 4) Source(1, 20) + SourceIndex(0) 4 >Emitted(2, 5) Source(1, 21) + SourceIndex(0) --- diff --git a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types index a00f5fd0eff..4644782c551 100644 --- a/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types +++ b/tests/baselines/reference/sourceMapValidationFunctionPropertyAssignment.types @@ -1,7 +1,6 @@ === tests/cases/compiler/sourceMapValidationFunctionPropertyAssignment.ts === var x = { n() { } }; ->x : { n: () => void; } ->{ n() { } } : { n: () => void; } +>x : { n(): void; } +>{ n() { } } : { n(): void; } >n : () => void ->n() { } : () => void diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index e4e8de59185..bdb122f6108 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,7 +24,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. Index signatures are incompatible. Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -160,7 +160,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }'. +!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo(): string; }' is not assignable to type '{ [x: string]: string; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/thisInObjectLiterals.types b/tests/baselines/reference/thisInObjectLiterals.types index 8a279923e19..d3853389a9e 100644 --- a/tests/baselines/reference/thisInObjectLiterals.types +++ b/tests/baselines/reference/thisInObjectLiterals.types @@ -29,12 +29,11 @@ class MyClass { //type of 'this' in an object literal property of a function type is Any var obj = { ->obj : { f: () => any; } ->{ f() { return this.spaaace; }} : { f: () => any; } +>obj : { f(): any; } +>{ f() { return this.spaaace; }} : { f(): any; } f() { >f : () => any ->f() { return this.spaaace; } : () => any return this.spaaace; >this.spaaace : any @@ -43,6 +42,6 @@ var obj = { } }; var obj: { f: () => any; }; ->obj : { f: () => any; } +>obj : { f(): any; } >f : () => any diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index d642dc55b0b..dc5b8fb76a5 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -83,15 +83,14 @@ class C { } var aa = { ->aa : { id: number; biz: () => void; } ->{ id:12, biz() { throw this; }} : { id: number; biz: () => void; } +>aa : { id: number; biz(): void; } +>{ id:12, biz() { throw this; }} : { id: number; biz(): void; } id:12, >id : number biz() { >biz : () => void ->biz() { throw this; } : () => void throw this; >this : any diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index a063145ce24..ecb4b8083ea 100644 --- a/tests/baselines/reference/typeGuardsObjectMethods.types +++ b/tests/baselines/reference/typeGuardsObjectMethods.types @@ -14,13 +14,12 @@ var var1: string | number; >var1 : string | number var obj1 = { ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } ->{ // Inside method method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; }, get prop() { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string return strOrNum; }, set prop(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string }} : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } +>{ // Inside method method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; }, get prop() { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string return strOrNum; }, set prop(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string }} : { method(param: string | number): string | number; prop: string | number; } // Inside method method(param: string | number) { >method : (param: string | number) => string | number ->method(param: string | number) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // variables in function declaration var var2: string | number; num = typeof var2 === "string" && var2.length; // string // parameters in function declaration num = typeof param === "string" && param.length; // string return strOrNum; } : (param: string | number) => string | number >param : string | number // global vars in function declaration @@ -153,12 +152,12 @@ strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum); >typeof obj1.method(strOrNum) : string >obj1.method(strOrNum) : string | number >obj1.method : (param: string | number) => string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >method : (param: string | number) => string | number >strOrNum : string | number >obj1.method(strOrNum) : string | number >obj1.method : (param: string | number) => string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >method : (param: string | number) => string | number >strOrNum : string | number @@ -170,9 +169,9 @@ strOrNum = typeof obj1.prop === "string" && obj1.prop; >typeof obj1.prop === "string" : boolean >typeof obj1.prop : string >obj1.prop : string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number >obj1.prop : string | number ->obj1 : { method: (param: string | number) => string | number; prop: string | number; } +>obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index c0372d46063..8940ec98f2c 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -87,6 +87,10 @@ module FourSlashInterface { public ranges(): Range[] { return FourSlash.currentTestState.getRanges(); } + + public markerByName(s: string): Marker { + return FourSlash.currentTestState.getMarkerByName(s); + } } export class diagnostics { @@ -227,7 +231,7 @@ module FourSlashInterface { } public quickInfoIs(expectedText?: string, expectedDocumentation?: string) { - FourSlash.currentTestState.verifyQuickInfo(this.negative, expectedText, expectedDocumentation); + FourSlash.currentTestState.verifyQuickInfoString(this.negative, expectedText, expectedDocumentation); } public quickInfoExists() { @@ -430,6 +434,11 @@ module FourSlashInterface { public renameLocations(findInStrings: boolean, findInComments: boolean) { FourSlash.currentTestState.verifyRenameLocations(findInStrings, findInComments); } + + public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { + FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); + } } export class edit { @@ -650,6 +659,12 @@ module fs { export var diagnostics = new FourSlashInterface.diagnostics(); export var cancellation = new FourSlashInterface.cancellation(); } +module ts { + export interface SymbolDisplayPart { + text: string; + kind: string; + } +} function verifyOperationIsCancelled(f) { FourSlash.verifyOperationIsCancelled(f); } diff --git a/tests/cases/fourslash/functionProperty.ts b/tests/cases/fourslash/functionProperty.ts index e9ffdcf2cdf..f19ac86c01a 100644 --- a/tests/cases/fourslash/functionProperty.ts +++ b/tests/cases/fourslash/functionProperty.ts @@ -31,7 +31,7 @@ goTo.marker('signatureC'); verify.currentSignatureHelpIs('x(a: number): void'); goTo.marker('completionA'); -verify.completionListContains("x", "(property) x: (a: number) => void"); +verify.completionListContains("x", "(method) x(a: number): void"); goTo.marker('completionB'); verify.completionListContains("x", "(property) x: (a: number) => void"); @@ -40,7 +40,7 @@ goTo.marker('completionC'); verify.completionListContains("x", "(property) x: (a: number) => void"); goTo.marker('quickInfoA'); -verify.quickInfoIs("(property) x: (a: number) => void", undefined); +verify.quickInfoIs("(method) x(a: number): void", undefined); goTo.marker('quickInfoB'); verify.quickInfoIs("(property) x: (a: number) => void", undefined); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts new file mode 100644 index 00000000000..3d996ae53ca --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsArrowFunctionExpression.ts @@ -0,0 +1,50 @@ +/// + +////var /*1*/x = /*5*/a => 10; +////var /*2*/y = (/*6*/a, /*7*/b) => 10; +////var /*3*/z = (/*8*/a: number) => 10; +////var /*4*/z2 = () => 10; + +var marker = 0; +function verifyInstance(instanceName: string, paramCount: number, type: string) { + marker++; + goTo.marker(marker.toString()); + var displayParts = [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }]; + + for (var i = 0; i < paramCount; i++) { + if (i) { + displayParts.push({ text: ",", kind: "punctuation" }, { text: " ", kind: "space" }); + } + displayParts.push({ text: !i ? "a" : "b", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "keyword" }); + } + displayParts.push({ text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "number", kind: "keyword" }); + + + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + displayParts, []); +} + +function verifyParameter(parameterName: string, type: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(marker.toString()).position, length: parameterName.length }, + [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterName, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "keyword" }], + []); +} + +verifyInstance("x", 1, "any"); +verifyInstance("y", 2, "any"); +verifyInstance("z", 1, "number"); +verifyInstance("z2", 0, "any"); + +verifyParameter("a", "any"); +verifyParameter("a", "any"); +verifyParameter("b", "any"); +verifyParameter("a", "number"); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClass.ts b/tests/cases/fourslash/quickInfoDisplayPartsClass.ts new file mode 100644 index 00000000000..ee38c717922 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClass.ts @@ -0,0 +1,39 @@ +/// + +////class /*1*/c { +////} +////var /*2*/cInstance = new /*3*/c(); +////var /*4*/cVal = /*5*/c; + +goTo.marker('1'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("1").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('2'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("2").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('3'); +verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName("3").position, length: "c".length }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('4'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("4").position, length: "cVal".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cVal", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('5'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("5").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts new file mode 100644 index 00000000000..f3a0f90ea33 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassAccessors.ts @@ -0,0 +1,129 @@ +/// + +////class c { +//// public get /*1*/publicProperty() { return ""; } +//// public set /*1s*/publicProperty(x: string) { } +//// private get /*2*/privateProperty() { return ""; } +//// private set /*2s*/privateProperty(x: string) { } +//// protected get /*21*/protectedProperty() { return ""; } +//// protected set /*21s*/protectedProperty(x: string) { } +//// static get /*3*/staticProperty() { return ""; } +//// static set /*3s*/staticProperty(x: string) { } +//// private static get /*4*/privateStaticProperty() { return ""; } +//// private static set /*4s*/privateStaticProperty(x: string) { } +//// protected static get /*41*/protectedStaticProperty() { return ""; } +//// protected static set /*41s*/protectedStaticProperty(x: string) { } +//// method() { +//// var x : string; +//// x = this./*5*/publicProperty; +//// x = this./*6*/privateProperty; +//// x = this./*61*/protectedProperty; +//// x = c./*7*/staticProperty; +//// x = c./*8*/privateStaticProperty; +//// x = c./*81*/protectedStaticProperty; +//// this./*5s*/publicProperty = ""; +//// this./*6s*/privateProperty = ""; +//// this./*61s*/protectedProperty = ""; +//// c./*7s*/staticProperty = ""; +//// c./*8s*/privateStaticProperty = ""; +//// c./*81s*/protectedStaticProperty = ""; +//// } +////} +////var cInstance = new c(); +////var y: string; +////y = /*9*/cInstance./*10*/publicProperty; +////y = /*11*/c./*12*/staticProperty; +/////*9s*/cInstance./*10s*/publicProperty = y; +/////*11s*/c./*12s*/staticProperty = y; + +function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyPublicProperty(markerName: string) { + verifyClassProperty(markerName, "public", "publicProperty"); +} + +function verifyPrivateProperty(markerName: string) { + verifyClassProperty(markerName, "private", "privateProperty"); +} + +function verifyProtectedProperty(markerName: string) { + verifyClassProperty(markerName, "protected", "protectedProperty"); +} + +function verifyStaticProperty(markerName: string) { + verifyClassProperty(markerName, "static", "staticProperty"); +} + +function verifyPrivateStaticProperty(markerName: string) { + verifyClassProperty(markerName, "private,static", "privateStaticProperty"); +} + +function verifyProtectedStaticProperty(markerName: string) { + verifyClassProperty(markerName, "protected,static", "protectedStaticProperty"); +} + +verifyPublicProperty('1'); +verifyPublicProperty('1s'); +verifyPrivateProperty('2'); +verifyPrivateProperty('2s'); +verifyProtectedProperty('21'); +verifyProtectedProperty('21s'); +verifyStaticProperty('3'); +verifyStaticProperty('3s'); +verifyPrivateStaticProperty('4'); +verifyPrivateStaticProperty('4s'); +verifyProtectedStaticProperty('41'); +verifyProtectedStaticProperty('41s'); + +verifyPublicProperty('5'); +verifyPublicProperty('5s'); +verifyPrivateProperty('6'); +verifyPrivateProperty('6s'); +verifyProtectedProperty('61'); +verifyProtectedProperty('61s'); +verifyStaticProperty('7'); +verifyStaticProperty('7s'); +verifyPrivateStaticProperty('8'); +verifyPrivateStaticProperty('8s'); +verifyProtectedStaticProperty('81'); +verifyProtectedStaticProperty('81s'); + +goTo.marker('9'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10'); + +goTo.marker('11'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12'); + +goTo.marker('9s'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9s").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10s'); + +goTo.marker('11s'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11s").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12s'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts new file mode 100644 index 00000000000..1145e43e1da --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassConstructor.ts @@ -0,0 +1,126 @@ +/// + +////class c { +//// /*1*/constructor() { +//// } +////} +////var /*2*/cInstance = new /*3*/c(); +////var /*4*/cVal = /*5*/c; +////class cWithOverloads { +//// /*6*/constructor(x: string); +//// /*7*/constructor(x: number); +//// /*8*/constructor(x: any) { +//// } +////} +////var /*9*/cWithOverloadsInstance = new /*10*/cWithOverloads("hello"); +////var /*11*/cWithOverloadsInstance2 = new /*12*/cWithOverloads(10); +////var /*13*/cWithOverloadsVal = /*14*/cWithOverloads; +////class cWithMultipleOverloads { +//// /*15*/constructor(x: string); +//// /*16*/constructor(x: number); +//// /*17*/constructor(x: boolean); +//// /*18*/constructor(x: any) { +//// } +////} +////var /*19*/cWithMultipleOverloadsInstance = new /*20*/cWithMultipleOverloads("hello"); +////var /*21*/cWithMultipleOverloadsInstance2 = new /*22*/cWithMultipleOverloads(10); +////var /*23*/cWithMultipleOverloadsInstance3 = new /*24*/cWithMultipleOverloads(true); +////var /*25*/cWithMultipleOverloadsVal = /*26*/cWithMultipleOverloads; + +function verifyNonOverloadSignature(marker: string, textSpanLength: number) { + goTo.marker(marker); + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +function verifyClassInstance(markerName: string, instanceName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifyClass(markerName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: className.length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifyTypeOfClass(markerName: string, typeOfVarName: string, className: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: typeOfVarName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeOfVarName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: className, kind: "className" }], + []); +} + +function verifySingleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { + goTo.marker(marker); + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, + { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterType, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithOverloads", kind: "className" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overload", kind: "text" }, + { text: ")", kind: "punctuation" }], + []); +} + +function verifyMultipleOverloadSignature(marker: string, textSpanLength: number, parameterType: string) { + goTo.marker(marker); + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(marker).position, length: textSpanLength }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithMultipleOverloads", kind: "className" }, { text: "(", kind: "punctuation" }, + { text: "x", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parameterType, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cWithMultipleOverloads", kind: "className" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "2", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overloads", kind: "text" }, + { text: ")", kind: "punctuation" }], + []); +} + + +verifyNonOverloadSignature("1", "constructor".length); +verifyClassInstance("2", "cInstance", "c"); +verifyNonOverloadSignature("3", "c".length); +verifyTypeOfClass("4", "cVal", "c"); +verifyClass("5", "c"); + +verifySingleOverloadSignature("6", "constructor".length, "string"); +verifySingleOverloadSignature("7", "constructor".length, "number"); +verifySingleOverloadSignature("8", "constructor".length, "string"); +verifyClassInstance("9", "cWithOverloadsInstance", "cWithOverloads"); +verifySingleOverloadSignature("10", "cWithOverloads".length, "string"); +verifyClassInstance("11", "cWithOverloadsInstance2", "cWithOverloads"); +verifySingleOverloadSignature("12", "cWithOverloads".length, "number"); +verifyTypeOfClass("13", "cWithOverloadsVal", "cWithOverloads"); +verifyClass("14", "cWithOverloads"); + +verifyMultipleOverloadSignature("15", "constructor".length, "string"); +verifyMultipleOverloadSignature("16", "constructor".length, "number"); +verifyMultipleOverloadSignature("17", "constructor".length, "boolean"); +verifyMultipleOverloadSignature("18", "constructor".length, "string"); +verifyClassInstance("19", "cWithMultipleOverloadsInstance", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("20", "cWithMultipleOverloads".length, "string"); +verifyClassInstance("21", "cWithMultipleOverloadsInstance2", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("22", "cWithMultipleOverloads".length, "number"); +verifyClassInstance("23", "cWithMultipleOverloadsInstance3", "cWithMultipleOverloads"); +verifyMultipleOverloadSignature("24", "cWithMultipleOverloads".length, "boolean"); +verifyTypeOfClass("25", "cWithMultipleOverloadsVal", "cWithMultipleOverloads"); +verifyClass("26", "cWithMultipleOverloads"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts new file mode 100644 index 00000000000..dbe225aa124 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassMethod.ts @@ -0,0 +1,86 @@ +/// + +////class c { +//// public /*1*/publicMethod() { } +//// private /*2*/privateMethod() { } +//// protected /*21*/protectedMethod() { } +//// static /*3*/staticMethod() { } +//// private static /*4*/privateStaticMethod() { } +//// protected static /*41*/protectedStaticMethod() { } +//// method() { +//// this./*5*/publicMethod(); +//// this./*6*/privateMethod(); +//// this./*61*/protectedMethod(); +//// c./*7*/staticMethod(); +//// c./*8*/privateStaticMethod(); +//// c./*81*/protectedStaticMethod(); +//// } +////} +////var cInstance = new c(); +/////*9*/cInstance./*10*/publicMethod(); +/////*11*/c./*12*/staticMethod(); + +function verifyClassMethod(markerName: string, kindModifiers: string, methodName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("method", kindModifiers, { start: test.markerByName(markerName).position, length: methodName.length }, + [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: methodName, kind: "methodName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyPublicMethod(markerName: string) { + verifyClassMethod(markerName, "public", "publicMethod"); +} + +function verifyPrivateMethod(markerName: string) { + verifyClassMethod(markerName, "private", "privateMethod"); +} + +function verifyProtectedMethod(markerName: string) { + verifyClassMethod(markerName, "protected", "protectedMethod"); +} + +function verifyStaticMethod(markerName: string) { + verifyClassMethod(markerName, "static", "staticMethod"); +} + +function verifyPrivateStaticMethod(markerName: string) { + verifyClassMethod(markerName, "private,static", "privateStaticMethod"); +} + +function verifyProtectedStaticMethod(markerName: string) { + verifyClassMethod(markerName, "protected,static", "protectedStaticMethod"); +} + +verifyPublicMethod('1'); +verifyPrivateMethod('2'); +verifyProtectedMethod('21'); +verifyStaticMethod('3'); +verifyPrivateStaticMethod('4'); +verifyProtectedStaticMethod('41'); + +verifyPublicMethod('5'); +verifyPrivateMethod('6'); +verifyProtectedMethod('61'); +verifyStaticMethod('7'); +verifyPrivateStaticMethod('8'); +verifyProtectedStaticMethod('81'); + +goTo.marker('9'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicMethod('10'); + +goTo.marker('11'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticMethod('12'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts new file mode 100644 index 00000000000..a03bc3cd42b --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassProperty.ts @@ -0,0 +1,85 @@ +/// + +////class c { +//// public /*1*/publicProperty: string; +//// private /*2*/privateProperty: string; +//// protected /*21*/protectedProperty: string; +//// static /*3*/staticProperty: string; +//// private static /*4*/privateStaticProperty: string; +//// protected static /*41*/protectedStaticProperty: string; +//// method() { +//// this./*5*/publicProperty; +//// this./*6*/privateProperty; +//// this./*61*/protectedProperty; +//// c./*7*/staticProperty; +//// c./*8*/privateStaticProperty; +//// c./*81*/protectedStaticProperty; +//// } +////} +////var cInstance = new c(); +/////*9*/cInstance./*10*/publicProperty; +/////*11*/c./*12*/staticProperty; + +function verifyClassProperty(markerName: string, kindModifiers: string, propertyName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("property", kindModifiers, { start: test.markerByName(markerName).position, length: propertyName.length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "c", kind: "className" }, { text: ".", kind: "punctuation" }, { text: propertyName, kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyPublicProperty(markerName: string) { + verifyClassProperty(markerName, "public", "publicProperty"); +} + +function verifyPrivateProperty(markerName: string) { + verifyClassProperty(markerName, "private", "privateProperty"); +} + +function verifyProtectedProperty(markerName: string) { + verifyClassProperty(markerName, "protected", "protectedProperty"); +} + +function verifyStaticProperty(markerName: string) { + verifyClassProperty(markerName, "static", "staticProperty"); +} + +function verifyPrivateStaticProperty(markerName: string) { + verifyClassProperty(markerName, "private,static", "privateStaticProperty"); +} + +function verifyProtectedStaticProperty(markerName: string) { + verifyClassProperty(markerName, "protected,static", "protectedStaticProperty"); +} + +verifyPublicProperty('1'); +verifyPrivateProperty('2'); +verifyProtectedProperty('21'); +verifyStaticProperty('3'); +verifyPrivateStaticProperty('4'); +verifyProtectedStaticProperty('41'); + +verifyPublicProperty('5'); +verifyPrivateProperty('6'); +verifyProtectedProperty('61'); +verifyStaticProperty('7'); +verifyPrivateStaticProperty('8'); +verifyProtectedStaticProperty('81'); + +goTo.marker('9'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyPublicProperty('10'); + +goTo.marker('11'); +verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName("11").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyStaticProperty('12'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsConst.ts b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts new file mode 100644 index 00000000000..62295017dfc --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsConst.ts @@ -0,0 +1,83 @@ +/// + +////const /*1*/a = 10; +////function foo() { +//// const /*2*/b = /*3*/a; +//// if (b) { +//// const /*4*/b1 = 10; +//// } +////} +////module m { +//// const /*5*/c = 10; +//// export const /*6*/d = 10; +//// if (c) { +//// const /*7*/e = 10; +//// } +////} +////const /*8*/f: () => number = () => 10; +////const /*9*/g = /*10*/f; +/////*11*/f(); +////const /*12*/h: { (a: string): number; (a: number): string; } = a => a; +////const /*13*/i = /*14*/h; +/////*15*/h(10); +/////*16*/h("hello"); + +var marker = 0; +function verifyConst(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("const", optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "const", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalNameDisplay || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +var numberTypeDisplay: ts.SymbolDisplayPart[] = [{ text: "number", kind: "keyword" }]; + +verifyConst("a", numberTypeDisplay); +verifyConst("b", numberTypeDisplay); +verifyConst("a", numberTypeDisplay); +verifyConst("b1", numberTypeDisplay); +verifyConst("c", numberTypeDisplay); +verifyConst("d", numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export"); +verifyConst("e", numberTypeDisplay); + +var functionTypeReturningNumber: ts.SymbolDisplayPart[] = [{ text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "number", kind: "keyword" }]; +verifyConst("f", functionTypeReturningNumber); +verifyConst("g", functionTypeReturningNumber); +verifyConst("f", functionTypeReturningNumber); +verifyConst("f", functionTypeReturningNumber); + + +function getFunctionType(parametertype: string, returnType: string, isArrow?: boolean): ts.SymbolDisplayPart[] { + var functionTypeDisplay = [{ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parametertype, kind: "keyword" }, { text: ")", kind: "punctuation" }]; + + if (isArrow) { + functionTypeDisplay = functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }); + } + else { + functionTypeDisplay = functionTypeDisplay.concat({ text: ":", kind: "punctuation" }); + } + + return functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: returnType, kind: "keyword" }); +} + +var typeLiteralWithOverloadCall: ts.SymbolDisplayPart[] = [{ text: "{", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }].concat(getFunctionType("string", "number")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }).concat(getFunctionType("number", "string")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, { text: "}", kind: "punctuation" }); + +verifyConst("h", typeLiteralWithOverloadCall); +verifyConst("i", typeLiteralWithOverloadCall); +verifyConst("h", typeLiteralWithOverloadCall); + +var overloadDisplay: ts.SymbolDisplayPart[] = [{ text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overload", kind: "text" }, { text: ")", kind: "punctuation" }]; + +verifyConst("h", getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay)); +verifyConst("h", getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay)); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts b/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts new file mode 100644 index 00000000000..405f9db936e --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsEnum.ts @@ -0,0 +1,76 @@ +/// + +////enum /*1*/E { +//// /*2*/e1, +//// /*3*/e2 = 10, +//// /*4*/e3 +////} +////var /*5*/eInstance: /*6*/E; +/////*7*/eInstance = /*8*/E./*9*/e1; +/////*10*/eInstance = /*11*/E./*12*/e2; +/////*13*/eInstance = /*14*/E./*15*/e3; +////const enum /*16*/constE { +//// /*17*/e1, +//// /*18*/e2 = 10, +//// /*19*/e3 +////} +////var /*20*/eInstance1: /*21*/constE; +/////*22*/eInstance1 = /*23*/constE./*24*/e1; +/////*25*/eInstance1 = /*26*/constE./*27*/e2; +/////*28*/eInstance1 = /*29*/constE./*30*/e3; + +var marker = 0; +function verifyEnumDeclaration(enumName: string, instanceName: string, isConst?: boolean) { + verifyEnumDisplay(); + + verifyEnumMemberDisplay("e1", 0); + verifyEnumMemberDisplay("e2", 10); + verifyEnumMemberDisplay("e3", 11); + + verifyInstance(); + verifyEnumDisplay(); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e1", 0); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e2", 10); + + verifyInstance(); + verifyEnumDisplay(); + verifyEnumMemberDisplay("e3", 11); + + function verifyEnumDisplay() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("enum", "", { start: test.markerByName(marker.toString()).position, length: enumName.length }, + (isConst ? [{ text: "const", kind: "keyword" }, { text: " ", kind: "space" }] : []).concat( + [{ text: "enum", kind: "keyword" }, { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }]), + []);; + } + + function verifyEnumMemberDisplay(enumMemberName: string, initializer: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: enumMemberName.length }, + [{ text: "(", kind: "punctuation" }, { text: "enum member", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }, { text: ".", kind: "punctuation" }, { text: enumMemberName, kind: "enumMemberName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, { text: initializer.toString(), kind: "numericLiteral" }], + []); + } + + function verifyInstance() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: enumName, kind: "enumName" }], + []); + } +} + +verifyEnumDeclaration("E", "eInstance"); +verifyEnumDeclaration("constE", "eInstance1", /*isConst*/ true); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts new file mode 100644 index 00000000000..2c43326469c --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsExternalModuleAlias.ts @@ -0,0 +1,44 @@ +/// + +// @Filename: quickInfoDisplayPartsExternalModuleAlias_file0.ts +////export module m1 { +//// export class c { +//// } +////} + +// @Filename: quickInfoDisplayPartsExternalModuleAlias_file1.ts +////import /*1*/a1 = require(/*mod1*/"quickInfoDisplayPartsExternalModuleAlias_file0"); +////new /*2*/a1.m1.c(); +////export import /*3*/a2 = require(/*mod2*/"quickInfoDisplayPartsExternalModuleAlias_file0"); +////new /*4*/a2.m1.c(); + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyImport(name: string, isExported: boolean) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("alias", isExported ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "import", kind: "keyword" }, { text: " ", kind: "space" }, { text: name, kind: "aliasName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, + { text: "require", kind: "keyword" }, { text: "(", kind: "punctuation" }, + { text: "\"quickInfoDisplayPartsExternalModuleAlias_file0\"", kind: "stringLiteral" }, + { text: ")", kind: "punctuation" }], + []); +} +verifyImport("a1", /*isExported*/false); +verifyImport("a1", /*isExported*/false); +verifyImport("a2", /*isExported*/true); +verifyImport("a2", /*isExported*/true); + +function verifyExternalModuleStringLiteral(marker: string) { + goTo.marker(marker); + verify.verifyQuickInfoDisplayParts("module", "", { start: test.markerByName(marker).position, length: "\"quickInfoDisplayPartsExternalModuleAlias_file0\"".length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }, { text: "a1", kind: "aliasName" }], + []); +} + +verifyExternalModuleStringLiteral("mod1"); +verifyExternalModuleStringLiteral("mod2"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts b/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts new file mode 100644 index 00000000000..5a2f5e76d7f --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsExternalModules.ts @@ -0,0 +1,63 @@ +/// + +////export module /*1*/m { +//// var /*2*/moduleElemWithoutExport = 10; +//// export var /*3*/moduleElemWithExport = 10; +////} +////export var /*4*/a = /*5*/m; +////export var /*6*/b: typeof /*7*/m; +////export module /*8*/m1./*9*/m2 { +//// var /*10*/moduleElemWithoutExport = 10; +//// export var /*11*/moduleElemWithExport = 10; +////} +////export var /*12*/x = /*13*/m1./*14*/m2; +////export var /*15*/y: typeof /*16*/m1./*17*/m2; + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyModule(name: string, optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "moduleName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("module", "export", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay), + []); +} + +function verifyVar(name: string, optionalFullName?: ts.SymbolDisplayPart[], typeDisplay: ts.SymbolDisplayPart[]= [{ text: "number", kind: "keyword" }]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", name === "moduleElemWithoutExport" ? "" : "export", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalFullName || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +verifyModule("m"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); + +verifyVar("a", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); +verifyVar("b", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); + +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, + { text: "m2", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); +verifyVar("x", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("y", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts new file mode 100644 index 00000000000..a3c94a511b9 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsFunction.ts @@ -0,0 +1,76 @@ +/// + +////function /*1*/foo(param: string, optionalParam?: string, paramWithInitializer = "hello", ...restParam: string[]) { +////} +////function /*2*/foowithoverload(a: string): string; +////function /*3*/foowithoverload(a: number): number; +////function /*4*/foowithoverload(a: any): any { +//// return a; +////} +////function /*5*/foowith3overload(a: string): string; +////function /*6*/foowith3overload(a: number): number; +////function /*7*/foowith3overload(a: boolean): boolean; +////function /*8*/foowith3overload(a: any): any { +//// return a; +////} +/////*9*/foo("hello"); +/////*10*/foowithoverload("hello"); +/////*11*/foowithoverload(10); +/////*12*/foowith3overload("hello"); +/////*13*/foowith3overload(10); +/////*14*/foowith3overload(true); + +var marker = 0; +function verifyFunctionWithoutOverload() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithOverload(functionName: string, type: string, overloadCount: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: "+", kind: "operator" }, { text: overloadCount.toString(), kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: overloadCount === 1 ? "overload" : "overloads", kind: "text" }, { text: ")", kind: "punctuation" }], + []); +} + + +// Declarations +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); +verifyFunctionWithOverload("foowithoverload", "string", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyFunctionWithOverload("foowith3overload", "string", 2); + +// Calls +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts b/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts new file mode 100644 index 00000000000..2b88812d60d --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsFunctionExpression.ts @@ -0,0 +1,45 @@ +/// + +////var /*1*/x = function /*2*/foo() { +//// /*3*/foo(); +////}; +////var /*4*/y = function () { +////}; +////(function /*5*/foo1() { +//// /*6*/foo1(); +////})(); + +var marker = 0; +function verifyInstance(instanceName: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(marker.toString()).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyNamedFunctionExpression(functionName: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +verifyInstance("x"); +// Declaration +verifyNamedFunctionExpression("foo"); +// Call +verifyNamedFunctionExpression("foo"); + +verifyInstance("y"); + +// Declaration +verifyNamedFunctionExpression("foo1"); +// Call +verifyNamedFunctionExpression("foo1"); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsInterface.ts b/tests/cases/fourslash/quickInfoDisplayPartsInterface.ts new file mode 100644 index 00000000000..410d45d32a1 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsInterface.ts @@ -0,0 +1,22 @@ +/// + +////interface /*1*/i { +////} +////var /*2*/iInstance: /*3*/i; + +goTo.marker('1'); +verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName("1").position, length: "i".length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); + +goTo.marker('2'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("2").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); + +goTo.marker('3'); +verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName("3").position, length: "i".length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }, { text: "i", kind: "interfaceName" }], + []); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts b/tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts new file mode 100644 index 00000000000..1b7fdad23aa --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsInterfaceMembers.ts @@ -0,0 +1,75 @@ +/// + +////interface I { +//// /*1*/property: string; +//// /*2*/method(): string; +//// (): string; +//// new (): I; +////} +////var iInstance: I; +/////*3*/iInstance./*4*/property = /*5*/iInstance./*6*/method(); +/////*7*/iInstance(); +////var /*8*/anotherInstance = new /*9*/iInstance(); + +function verifyInterfaceProperty(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("property", "", { start: test.markerByName(markerName).position, length: "property".length }, + [{ text: "(", kind: "punctuation" }, { text: "property", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "property", kind: "propertyName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyInterfaceMethod(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("method", "", { start: test.markerByName(markerName).position, length: "method".length }, + [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "I", kind: "interfaceName" }, { text: ".", kind: "punctuation" }, { text: "method", kind: "methodName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); +} + +function verifyInterfaceInstanceVar(markerName: string, instanceName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: instanceName.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: instanceName, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }], + []); +} + +verifyInterfaceProperty('1'); +verifyInterfaceMethod("2"); + +verifyInterfaceInstanceVar("3", "iInstance"); +verifyInterfaceProperty("4"); +verifyInterfaceInstanceVar("5", "iInstance"); +verifyInterfaceMethod("6"); + +// Call signature +goTo.marker("7"); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("7").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }], + []); + +verifyInterfaceInstanceVar("8", "anotherInstance"); + +// Cosntruct signature +goTo.marker("9"); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("9").position, length: "iInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "iInstance", kind: "localName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "new", kind: "keyword" }, { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "I", kind: "interfaceName" }], + []); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts new file mode 100644 index 00000000000..335544a62db --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsInternalModuleAlias.ts @@ -0,0 +1,47 @@ +/// + +////module m.m1 { +//// export class c { +//// } +////} +////module m2 { +//// import /*1*/a1 = m; +//// new /*2*/a1.m1.c(); +//// import /*3*/a2 = m.m1; +//// new /*4*/a2.c(); +//// export import /*5*/a3 = m; +//// new /*6*/a3.m1.c(); +//// export import /*7*/a4 = m.m1; +//// new /*8*/a4.c(); +////} + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyImport(name: string, assigningDisplay:ts.SymbolDisplayPart[], optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "aliasName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("alias", optionalParentName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "import", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay).concat( + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }).concat(assigningDisplay), + []); +} + +var moduleMDisplay = [{ text: "m", kind: "moduleName" }]; +var moduleMDotM1Display = moduleMDisplay.concat({ text: ".", kind: "punctuation" }, { text: "m1", kind: "moduleName" }); + +verifyImport("a1", moduleMDisplay); +verifyImport("a1", moduleMDisplay); +verifyImport("a2", moduleMDotM1Display); +verifyImport("a2", moduleMDotM1Display); + +verifyImport("a3", moduleMDisplay, "m2"); +verifyImport("a3", moduleMDisplay, "m2"); +verifyImport("a4", moduleMDotM1Display, "m2"); +verifyImport("a4", moduleMDotM1Display, "m2"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsLet.ts b/tests/cases/fourslash/quickInfoDisplayPartsLet.ts new file mode 100644 index 00000000000..b54617faa0e --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsLet.ts @@ -0,0 +1,83 @@ +/// + +////let /*1*/a = 10; +////function foo() { +//// let /*2*/b = /*3*/a; +//// if (b) { +//// let /*4*/b1 = 10; +//// } +////} +////module m { +//// let /*5*/c = 10; +//// export let /*6*/d = 10; +//// if (c) { +//// let /*7*/e = 10; +//// } +////} +////let /*8*/f: () => number; +////let /*9*/g = /*10*/f; +/////*11*/f(); +////let /*12*/h: { (a: string): number; (a: number): string; }; +////let /*13*/i = /*14*/h; +/////*15*/h(10); +/////*16*/h("hello"); + +var marker = 0; +function verifyVar(name: string, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("let", optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "let", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalNameDisplay || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +var numberTypeDisplay: ts.SymbolDisplayPart[] = [{ text: "number", kind: "keyword" }]; + +verifyVar("a", numberTypeDisplay); +verifyVar("b", numberTypeDisplay); +verifyVar("a", numberTypeDisplay); +verifyVar("b1", numberTypeDisplay); +verifyVar("c", numberTypeDisplay); +verifyVar("d", numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export"); +verifyVar("e", numberTypeDisplay); + +var functionTypeReturningNumber: ts.SymbolDisplayPart[] = [{ text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "number", kind: "keyword" }]; +verifyVar("f", functionTypeReturningNumber); +verifyVar("g", functionTypeReturningNumber); +verifyVar("f", functionTypeReturningNumber); +verifyVar("f", functionTypeReturningNumber); + + +function getFunctionType(parametertype: string, returnType: string, isArrow?: boolean): ts.SymbolDisplayPart[] { + var functionTypeDisplay = [{ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parametertype, kind: "keyword" }, { text: ")", kind: "punctuation" }]; + + if (isArrow) { + functionTypeDisplay = functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }); + } + else { + functionTypeDisplay = functionTypeDisplay.concat({ text: ":", kind: "punctuation" }); + } + + return functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: returnType, kind: "keyword" }); +} + +var typeLiteralWithOverloadCall: ts.SymbolDisplayPart[] = [{ text: "{", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }].concat(getFunctionType("string", "number")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }).concat(getFunctionType("number", "string")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, { text: "}", kind: "punctuation" }); + +verifyVar("h", typeLiteralWithOverloadCall); +verifyVar("i", typeLiteralWithOverloadCall); +verifyVar("h", typeLiteralWithOverloadCall); + +var overloadDisplay: ts.SymbolDisplayPart[] = [{ text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overload", kind: "text" }, { text: ")", kind: "punctuation" }]; + +verifyVar("h", getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay)); +verifyVar("h", getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay)); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts new file mode 100644 index 00000000000..b9578c7f522 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts @@ -0,0 +1,92 @@ +/// + +////function /*1*/outerFoo() { +//// function /*2*/foo(param: string, optionalParam?: string, paramWithInitializer = "hello", ...restParam: string[]) { +//// } +//// function /*3*/foowithoverload(a: string): string; +//// function /*4*/foowithoverload(a: number): number; +//// function /*5*/foowithoverload(a: any): any { +//// return a; +//// } +//// function /*6*/foowith3overload(a: string): string; +//// function /*7*/foowith3overload(a: number): number; +//// function /*8*/foowith3overload(a: boolean): boolean; +//// function /*9*/foowith3overload(a: any): any { +//// return a; +//// } +//// /*10*/foo("hello"); +//// /*11*/foowithoverload("hello"); +//// /*12*/foowithoverload(10); +//// /*13*/foowith3overload("hello"); +//// /*14*/foowith3overload(10); +//// /*15*/foowith3overload(true); +////} +/////*16*/outerFoo(); + +var marker = 0; +function verifyOuterFunction() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: "outerFoo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "outerFoo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithoutOverload() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithOverload(functionName: string, type: string, overloadCount: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: "+", kind: "operator" }, { text: overloadCount.toString(), kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: overloadCount === 1 ? "overload" : "overloads", kind: "text" }, { text: ")", kind: "punctuation" }], + []); +} + + +// Declarations +verifyOuterFunction(); + +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); +verifyFunctionWithOverload("foowithoverload", "string", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyFunctionWithOverload("foowith3overload", "string", 2); + +// Calls +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyOuterFunction(); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsModules.ts b/tests/cases/fourslash/quickInfoDisplayPartsModules.ts new file mode 100644 index 00000000000..c86bce474ff --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsModules.ts @@ -0,0 +1,63 @@ +/// + +////module /*1*/m { +//// var /*2*/moduleElemWithoutExport = 10; +//// export var /*3*/moduleElemWithExport = 10; +////} +////var /*4*/a = /*5*/m; +////var /*6*/b: typeof /*7*/m; +////module /*8*/m1./*9*/m2 { +//// var /*10*/moduleElemWithoutExport = 10; +//// export var /*11*/moduleElemWithExport = 10; +////} +////var /*12*/x = /*13*/m1./*14*/m2; +////var /*15*/y: typeof /*16*/m1./*17*/m2; + +var marker = 0; +function goToMarker() { + marker++; + goTo.marker(marker.toString()); +} + +function verifyModule(name: string, optionalParentName?: string) { + goToMarker(); + var moduleNameDisplay = [{ text: name, kind: "moduleName" }]; + if (optionalParentName) { + moduleNameDisplay = [{ text: optionalParentName, kind: "moduleName" }, { text: ".", kind: "punctuation" }].concat(moduleNameDisplay); + } + verify.verifyQuickInfoDisplayParts("module", optionalParentName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "module", kind: "keyword" }, { text: " ", kind: "space" }].concat(moduleNameDisplay), + []); +} + +function verifyVar(name: string, optionalFullName?: ts.SymbolDisplayPart[], typeDisplay: ts.SymbolDisplayPart[]= [{ text: "number", kind: "keyword" }]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", optionalFullName ? "export" : "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalFullName || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +verifyModule("m"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); + +verifyVar("a", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); +verifyVar("b", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "m", kind: "moduleName" }]); +verifyModule("m"); + +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("moduleElemWithoutExport"); +verifyVar("moduleElemWithExport", [{ text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, + { text: "m2", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "moduleElemWithExport", kind: "localName" }]); +verifyVar("x", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); +verifyVar("y", /*optionalFullName*/ undefined, [{ text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, + { text: "m1", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "m2", kind: "moduleName" }]); +verifyModule("m1"); +verifyModule("m2", "m1"); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts b/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts new file mode 100644 index 00000000000..a825030c987 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsParameters.ts @@ -0,0 +1,45 @@ +/// + +////function /*1*/foo(/*2*/param: string, /*3*/optionalParam?: string, /*4*/paramWithInitializer = "hello", .../*5*/restParam: string[]) { +//// /*6*/param = "Hello"; +//// /*7*/optionalParam = "World"; +//// /*8*/paramWithInitializer = "Hello"; +//// /*9*/restParam[0] = "World"; +////} + +goTo.marker("1"); +verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName('1').position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" } , { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); + +var marker = 1; +function verifyParam(parameterName: string, isRest: boolean) { + marker++; + goTo.marker(marker.toString()); + var displayParts = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: parameterName, kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }]; + if (isRest) { + displayParts.push({ text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(marker.toString()).position, length: parameterName.length }, displayParts, []); +} + +verifyParam('param', /*isRest*/false); +verifyParam('optionalParam', /*isRest*/false); +verifyParam('paramWithInitializer', /*isRest*/false); +verifyParam('restParam', /*isRest*/true); + +verifyParam('param', /*isRest*/false); +verifyParam('optionalParam', /*isRest*/false); +verifyParam('paramWithInitializer', /*isRest*/false); +verifyParam('restParam', /*isRest*/true); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts new file mode 100644 index 00000000000..5441ca35364 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeAlias.ts @@ -0,0 +1,42 @@ +/// + +////class /*1*/c { +////} +////type /*2*/t1 = /*3*/c; +////var /*4*/cInstance: /*5*/t1 = new /*6*/c(); + +function verifyClassDisplay(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +function verifyTypeAliasDisplay(markerName: string) { + goTo.marker(markerName); + verify.verifyQuickInfoDisplayParts("type", "", { start: test.markerByName(markerName).position, length: "t1".length }, + [{ text: "type", kind: "keyword" }, { text: " ", kind: "space" }, { text: "t1", kind: "aliasName" }, + { text: " ", kind: "space" }, { text: "=", kind: "operator" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); +} + +verifyClassDisplay('1'); +verifyTypeAliasDisplay('2'); +verifyClassDisplay('3'); + +goTo.marker('4'); +verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName("4").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +verifyTypeAliasDisplay('5'); + +goTo.marker('6'); +verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName("6").position, length: "c".length }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts new file mode 100644 index 00000000000..dd32c8b236a --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInClass.ts @@ -0,0 +1,239 @@ +/// + +////class /*1*/c { +//// /*3*/constructor(/*4*/a: /*5*/T) { +//// } +//// /*6*/method(/*8*/a: /*9*/U, /*10*/b: /*11*/T) { +//// return /*12*/a; +//// } +////} +////var /*13*/cInstance = new /*14*/c("Hello"); +////var /*15*/cVal = /*16*/c; +/////*17*/cInstance./*18*/method("hello", "cello"); +////class /*19*/c2> { +//// /*22*/constructor(/*23*/a: /*24*/T) { +//// } +//// /*25*/method>(/*28*/a: /*29*/U, /*30*/b: /*31*/T) { +//// return /*32*/a; +//// } +////} +////var /*33*/cInstance1 = new /*34*/c2(/*35*/cInstance); +////var /*36*/cVal2 = /*37*/c2; +/////*38*/cInstance1./*39*/method(/*40*/cInstance, /*41*/cInstance); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function getClassDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var classDisplay = [{ text: name, kind: "className" }, { text: "<", kind: "punctuation" }]; + classDisplay = classDisplay.concat(getTypeParameterDisplay(optionalInstanceType, "T", optionalExtends)); + classDisplay.push({ text: ">", kind: "punctuation" }); + return classDisplay; +} + +function verifyClassDisplay(name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + + verify.verifyQuickInfoDisplayParts("class", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }].concat( + getClassDisplay(name, undefined, optionalExtends)), []); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyConstructor(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var constructorDisplay = [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }]; + constructorDisplay = constructorDisplay.concat(getClassDisplay(name, optionalInstanceType, optionalExtends)); + + constructorDisplay.push({ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + constructorDisplay = constructorDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + constructorDisplay.push({ text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + constructorDisplay = constructorDisplay.concat(getClassDisplay(name, optionalInstanceType)); + + verify.verifyQuickInfoDisplayParts("constructor", "", { start: test.markerByName(markerName).position, length: optionalInstanceType ? name.length : "constructor".length }, + constructorDisplay, []); +} + +function verifyParameter(name: string, type: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: type, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getMethodDisplay(name: string, className: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay = getClassDisplay(className, optionalInstanceType, optionalExtends); + + functionDisplay.push({ text: ".", kind: "punctuation" }, { text: name, kind: "methodName" }, + { text: "<", kind: "punctuation" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + functionDisplay.push({ text: ",", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "b", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + functionDisplay.push({ text: ")", kind: "punctuation" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function verifyMethodDisplay(name: string, className: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getMethodDisplay(name, className, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("method", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +function verifyClassInstance(name: string, typeDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(typeDisplay), + []); +} + +function verifyVarTypeOf(name: string, typeOfSymbol: ts.SymbolDisplayPart) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "typeof", kind: "keyword" }, + { text: " ", kind: "space" }].concat(typeOfSymbol), + []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; +var extendsTypeDisplay = getClassDisplay("c", stringTypeDisplay); + +// Declaration +verifyClassDisplay("c"); +verifyTypeParameter("T", getClassDisplay("c")); + +// Constructor declaration +verifyConstructor("c"); +verifyParameter("a", "T"); +verifyTypeParameter("T", getClassDisplay("c")); + +// Method declaration +verifyMethodDisplay("method", "c"); +verifyTypeParameter("U", getMethodDisplay("method", "c")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getMethodDisplay("method", "c")); +verifyParameter("b", "T"); +verifyTypeParameter("T", getClassDisplay("c")); +verifyParameter("a", "U"); + +// Instance creation +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyConstructor("c", stringTypeDisplay); + +// typeof assignment +verifyVarTypeOf("cVal", { text: "c", kind: "className" }); +verifyClassDisplay("c"); + +// Method call +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyMethodDisplay("method", "c", stringTypeDisplay); + +// With constraint +// Declaration +verifyClassDisplay("c2", getClassDisplay("c", stringTypeDisplay)); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); +verifyClassDisplay("c"); + +// Constructor declaration +verifyConstructor("c2", /*instanceType*/undefined, extendsTypeDisplay); +verifyParameter("a", "T", extendsTypeDisplay); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); + +// Method declaration +verifyMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay)); +verifyClassDisplay("c"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "c2", /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getClassDisplay("c2", /*instanceType*/undefined, extendsTypeDisplay)); +verifyParameter("a", "U", extendsTypeDisplay); + +// Instance creation +verifyClassInstance("cInstance1", getClassDisplay("c2", extendsTypeDisplay)); +verifyConstructor("c2", extendsTypeDisplay); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); + +// typeof assignment +verifyVarTypeOf("cVal2", { text: "c2", kind: "className" }); +verifyClassDisplay("c2", getClassDisplay("c", stringTypeDisplay)); + +// Method call +verifyClassInstance("cInstance1", getClassDisplay("c2", extendsTypeDisplay)); +verifyMethodDisplay("method", "c2", extendsTypeDisplay); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); +verifyClassInstance("cInstance", getClassDisplay("c", stringTypeDisplay)); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts new file mode 100644 index 00000000000..0daabd43ad7 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts @@ -0,0 +1,118 @@ +/// + + +////function /*1*/foo(/*3*/a: /*4*/U) { +//// return /*5*/a; +////} +/////*6*/foo("Hello"); +////function /*7*/foo2(/*9*/a: /*10*/U) { +//// return /*11*/a; +////} +/////*12*/foo2("hello"); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyParameter(name: string, typeParameterName: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeParameterName, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getFunctionDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay = [{ text: name, kind: "functionName" }, { text: "<", kind: "punctuation" }]; + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + functionDisplay.push({ text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function verifyFunctionDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getFunctionDisplay(name, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("function", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; + +// Declaration +verifyFunctionDisplay("foo"); +verifyTypeParameter("U", getFunctionDisplay("foo")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getFunctionDisplay("foo")); +verifyParameter("a", "U"); + +// Call +verifyFunctionDisplay("foo", stringTypeDisplay); + +// With constraint +// Declaration +verifyFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay); +verifyTypeParameter("U", getFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay)); +verifyParameter("a", "U", stringTypeDisplay); +verifyTypeParameter("U", getFunctionDisplay("foo2", /*instance*/ undefined, stringTypeDisplay)); +verifyParameter("a", "U", stringTypeDisplay); + +// Call +verifyFunctionDisplay("foo2", stringTypeDisplay); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts new file mode 100644 index 00000000000..95797166ea2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInInterface.ts @@ -0,0 +1,263 @@ +/// + +////interface /*1*/I { +//// new (/*4*/a: /*5*/U, /*6*/b: /*7*/T): /*8*/U; +//// (/*10*/a: /*11*/U, /*12*/b: /*13*/T): /*14*/U; +//// /*15*/method(/*17*/a: /*18*/U, /*19*/b: /*20*/T): /*21*/U; +////} +////var /*22*/iVal: /*23*/I; +////new /*24*/iVal("hello", "hello"); +/////*25*/iVal("hello", "hello"); +/////*26*/iVal./*27*/method("hello", "hello"); +////interface /*28*/I1> { +//// new >(/*33*/a: /*34*/U, /*35*/b: /*36*/T): /*37*/U; +//// >(/*40*/a: /*41*/U, /*42*/b: /*43*/T): /*44*/U; +//// /*45*/method>(/*48*/a: /*49*/U, /*50*/b: /*51*/T): /*52*/U; +////} +////var /*53*/iVal1: /*54*/I1>; +////new /*56*/iVal1(/*57*/iVal, /*58*/iVal); +/////*59*/iVal1(/*60*/iVal, /*61*/iVal); +/////*62*/iVal1./*63*/method(/*64*/iVal, /*65*/iVal); + +var marker = 0; +var markerName: string; + +function goToMarker() { + marker++; + markerName = marker.toString(); + goTo.marker(markerName); +} + +function getTypeParameterDisplay(instanceType: ts.SymbolDisplayPart[], + name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + return instanceType || + function () { + var typeParameterDisplay = [{ text: name, kind: "typeParameterName" }]; + if (optionalExtends) { + typeParameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + typeParameterDisplay = typeParameterDisplay.concat(optionalExtends); + } + return typeParameterDisplay + } (); +} + +function getInterfaceDisplay(name: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var interfaceDisplay = [{ text: name, kind: "interfaceName" }, { text: "<", kind: "punctuation" }]; + interfaceDisplay = interfaceDisplay.concat(getTypeParameterDisplay(optionalInstanceType, "T", optionalExtends)); + interfaceDisplay.push({ text: ">", kind: "punctuation" }); + return interfaceDisplay; +} + +function verifyInterfaceDisplay(name: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + + verify.verifyQuickInfoDisplayParts("interface", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "interface", kind: "keyword" }, { text: " ", kind: "space" }].concat( + getInterfaceDisplay(name, undefined, optionalExtends)), []); +} + +function verifyTypeParameter(name: string, inDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + + var typeParameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "typeParameterName" }, + { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; + typeParameterDisplay = typeParameterDisplay.concat(inDisplay); + + verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + typeParameterDisplay, []); +} + +function verifyParameter(name: string, typeParameterName: string, optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var parameterDisplay = [{ text: "(", kind: "punctuation" }, { text: "parameter", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: typeParameterName, kind: "typeParameterName" }]; + if (optionalExtends) { + parameterDisplay.push({ text: " ", kind: "space" }, { text: "extends", kind: "keyword" }, + { text: " ", kind: "space" }); + parameterDisplay = parameterDisplay.concat(optionalExtends); + } + verify.verifyQuickInfoDisplayParts("parameter", "", { start: test.markerByName(markerName).position, length: name.length }, + parameterDisplay, []); +} + +function getSignatureDisplay(isArrow: boolean, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + var functionDisplay: ts.SymbolDisplayPart[] = []; + + functionDisplay.push({ text: "<", kind: "punctuation" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U", optionalExtends)); + + functionDisplay.push({ text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + functionDisplay.push({ text: ",", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "b", kind: "parameterName" }, + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }); + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "T")); + + functionDisplay.push({ text: ")", kind: "punctuation" }); + if (isArrow) { + functionDisplay.push({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }); + } + else { + functionDisplay.push({ text: ":", kind: "punctuation" }); + } + functionDisplay.push({ text: " ", kind: "space" }); + + functionDisplay = functionDisplay.concat( + getTypeParameterDisplay(optionalInstanceType, "U")); + + return functionDisplay; +} + +function getMethodDisplay(name: string, interfaceName: string, optionalInstanceType?: ts.SymbolDisplayPart[], + optionalExtends?: ts.SymbolDisplayPart[]) { + return getInterfaceDisplay(interfaceName, optionalInstanceType, optionalExtends).concat( + { text: ".", kind: "punctuation" }, { text: name, kind: "methodName" }).concat( + getSignatureDisplay(/*isArrow*/ false, optionalInstanceType, optionalExtends)); +} + +function getCallOrNewSignatureDisplay(isNew: boolean, isArrow: boolean, interfaceName?: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + var result: ts.SymbolDisplayPart[] = []; + if (isNew) { + result.push({ text: "new", kind: "keyword" }, { text: " ", kind: "space" }); + } + if (interfaceName) { + result.push({ text: interfaceName, kind: "interfaceName" }); + } + + return result.concat(getSignatureDisplay(isArrow, optionalInstanceType, optionalExtends)); +} + +function verifyMethodDisplay(name: string, interfaceName: string, + optionalInstanceType?: ts.SymbolDisplayPart[], optionalExtends?: ts.SymbolDisplayPart[]) { + goToMarker(); + var functionDisplay = [{ text: "(", kind: "punctuation" }, { text: "method", kind: "text" }, + { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }].concat( + getMethodDisplay(name, interfaceName, optionalInstanceType, optionalExtends)); + + verify.verifyQuickInfoDisplayParts("method", "", + { start: test.markerByName(markerName).position, length: name.length }, + functionDisplay, []); +} + +function verifyInterfaceVar(name: string, typeDisplay: ts.SymbolDisplayPart[]) { + goToMarker(); + verify.verifyQuickInfoDisplayParts("var", "", { start: test.markerByName(markerName).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: name, kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(typeDisplay), + []); +} + +var stringTypeDisplay = [{ text: "string", kind: "keyword" }]; +var extendsTypeDisplay = getInterfaceDisplay("I", stringTypeDisplay); + + +// Declaration +verifyInterfaceDisplay("I"); +verifyTypeParameter("T", getInterfaceDisplay("I")); + +// New declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); +verifyParameter("a", "U"); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false)); + +// Call declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); +verifyParameter("a", "U"); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false)); + +// Method declaration +verifyMethodDisplay("method", "I"); +verifyTypeParameter("U", getMethodDisplay("method", "I")); +verifyParameter("a", "U"); +verifyTypeParameter("U", getMethodDisplay("method", "I")); +verifyParameter("b", "T"); +verifyTypeParameter("T", getInterfaceDisplay("I")); +verifyTypeParameter("U", getMethodDisplay("method", "I")); + +// Instance +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceDisplay("I"); + +// new +verifyInterfaceVar("iVal", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ true, "I", stringTypeDisplay)); + +// call +verifyInterfaceVar("iVal", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ true, "I", stringTypeDisplay)); + +// Method call +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyMethodDisplay("method", "I", stringTypeDisplay); + +// With constraint +// Declaration +verifyInterfaceDisplay("I1", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); + +// New declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); + +// Call declaration +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ false, /*interfaceName*/undefined, /*instance*/undefined, extendsTypeDisplay)); + +// Method declaration +verifyMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); +verifyInterfaceDisplay("I"); +verifyParameter("a", "U", extendsTypeDisplay); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); +verifyParameter("b", "T", extendsTypeDisplay); +verifyTypeParameter("T", getInterfaceDisplay("I1", /*instance*/undefined, extendsTypeDisplay)); +verifyTypeParameter("U", getMethodDisplay("method", "I1", /*instance*/ undefined, extendsTypeDisplay)); + +// Instance +verifyInterfaceVar("iVal1", getInterfaceDisplay("I1", extendsTypeDisplay)); +verifyInterfaceDisplay("I1", extendsTypeDisplay); +verifyInterfaceDisplay("I"); + +// new +verifyInterfaceVar("iVal1", getCallOrNewSignatureDisplay(/*isNew*/ true, /*isArrow*/ true, "I1", extendsTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); + +// call +verifyInterfaceVar("iVal1", getCallOrNewSignatureDisplay(/*isNew*/ false, /*isArrow*/ true, "I1", extendsTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); + +// Method call +verifyInterfaceVar("iVal1", getInterfaceDisplay("I1", extendsTypeDisplay)); +verifyMethodDisplay("method", "I1", extendsTypeDisplay); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); +verifyInterfaceVar("iVal", getInterfaceDisplay("I", stringTypeDisplay)); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsVar.ts b/tests/cases/fourslash/quickInfoDisplayPartsVar.ts new file mode 100644 index 00000000000..56ccceb3ab3 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsVar.ts @@ -0,0 +1,76 @@ +/// + +////var /*1*/a = 10; +////function foo() { +//// var /*2*/b = /*3*/a; +////} +////module m { +//// var /*4*/c = 10; +//// export var /*5*/d = 10; +////} +////var /*6*/f: () => number; +////var /*7*/g = /*8*/f; +/////*9*/f(); +////var /*10*/h: { (a: string): number; (a: number): string; }; +////var /*11*/i = /*12*/h; +/////*13*/h(10); +/////*14*/h("hello"); + +var marker = 0; +function verifyVar(name: string, isLocal: boolean, typeDisplay: ts.SymbolDisplayPart[], optionalNameDisplay?: ts.SymbolDisplayPart[], optionalKindModifiers?: string) { + marker++; + goTo.marker(marker.toString()); + var kind = isLocal ? "local var" : "var"; + verify.verifyQuickInfoDisplayParts(kind, optionalKindModifiers || "", { start: test.markerByName(marker.toString()).position, length: name.length }, + [{ text: "(", kind: "punctuation" }, { text: kind, kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }].concat(optionalNameDisplay || [{ text: name, kind: "localName" }]).concat( + { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }).concat(typeDisplay), + []); +} + +var numberTypeDisplay: ts.SymbolDisplayPart[] = [{ text: "number", kind: "keyword" }]; + +verifyVar("a", /*isLocal*/false, numberTypeDisplay); +verifyVar("b", /*isLocal*/true, numberTypeDisplay); +verifyVar("a", /*isLocal*/false, numberTypeDisplay); +verifyVar("c", /*isLocal*/false, numberTypeDisplay); +verifyVar("d", /*isLocal*/false, numberTypeDisplay, [{ text: "m", kind: "moduleName" }, { text: ".", kind: "punctuation" }, { text: "d", kind: "localName" }], "export"); + +var functionTypeReturningNumber: ts.SymbolDisplayPart[] = [{ text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "number", kind: "keyword" }]; +verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber); +verifyVar("g", /*isLocal*/ false, functionTypeReturningNumber); +verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber); +verifyVar("f", /*isLocal*/ false, functionTypeReturningNumber); + + +function getFunctionType(parametertype: string, returnType: string, isArrow?: boolean): ts.SymbolDisplayPart[] { + var functionTypeDisplay = [{ text: "(", kind: "punctuation" }, { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: parametertype, kind: "keyword" }, { text: ")", kind: "punctuation" }]; + + if (isArrow) { + functionTypeDisplay = functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: "=>", kind: "punctuation" }); + } + else { + functionTypeDisplay = functionTypeDisplay.concat({ text: ":", kind: "punctuation" }); + } + + return functionTypeDisplay.concat({ text: " ", kind: "space" }, { text: returnType, kind: "keyword" }); +} + +var typeLiteralWithOverloadCall: ts.SymbolDisplayPart[] = [{ text: "{", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }].concat(getFunctionType("string", "number")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, + { text: " ", kind: "space" }).concat(getFunctionType("number", "string")).concat( + { text: ";", kind: "punctuation" }, { text: "\n", kind: "lineBreak" }, { text: "}", kind: "punctuation" }); + +verifyVar("h", /*isLocal*/ false, typeLiteralWithOverloadCall); +verifyVar("i", /*isLocal*/ false, typeLiteralWithOverloadCall); +verifyVar("h", /*isLocal*/ false, typeLiteralWithOverloadCall); + +var overloadDisplay: ts.SymbolDisplayPart[] = [{ text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, + { text: "+", kind: "operator" }, { text: "1", kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: "overload", kind: "text" }, { text: ")", kind: "punctuation" }]; + +verifyVar("h", /*isLocal*/ false, getFunctionType("number", "string", /*isArrow*/true).concat(overloadDisplay)); +verifyVar("h", /*isLocal*/ false, getFunctionType("string", "number", /*isArrow*/true).concat(overloadDisplay)); \ No newline at end of file