mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-15 08:20:53 -06:00
parent
430f361353
commit
2cc209459b
@ -107,7 +107,7 @@ module ts {
|
||||
isImplementationOfOverload: isImplementationOfOverload
|
||||
};
|
||||
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Undefined | SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
var argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
|
||||
var unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
|
||||
var resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
|
||||
@ -1067,7 +1067,12 @@ module ts {
|
||||
return writeType(type, flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
|
||||
function writeType(type: Type, flags: TypeFormatFlags) {
|
||||
if (type.flags & TypeFlags.Intrinsic) {
|
||||
// Write undefined/null type as any
|
||||
if ((flags & TypeFormatFlags.WriteUndefinedAndNullAsAny) &&
|
||||
((type.flags & TypeFlags.Undefined) || (type.flags & TypeFlags.Null))) {
|
||||
writeKeyword(writer, SyntaxKind.AnyKeyword);
|
||||
}
|
||||
else if (type.flags & TypeFlags.Intrinsic) {
|
||||
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving
|
||||
writer.writeKind(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) &&
|
||||
(type.flags & TypeFlags.Any) ? "any" : (<IntrinsicType>type).intrinsicName, SymbolDisplayPartKind.keyword);
|
||||
|
||||
@ -679,13 +679,14 @@ module ts {
|
||||
}
|
||||
|
||||
export enum TypeFormatFlags {
|
||||
None = 0x00000000,
|
||||
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
|
||||
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
|
||||
NoTruncation = 0x00000004, // Don't truncate typeToString result
|
||||
WriteArrowStyleSignature= 0x00000008, // Write arrow style signature
|
||||
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
|
||||
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
|
||||
None = 0x00000000,
|
||||
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
|
||||
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
|
||||
NoTruncation = 0x00000004, // Don't truncate typeToString result
|
||||
WriteArrowStyleSignature = 0x00000008, // Write arrow style signature
|
||||
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
|
||||
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
|
||||
WriteUndefinedAndNullAsAny = 0x00000040, // Write undefined and null as any
|
||||
}
|
||||
|
||||
export enum SymbolFormatFlags {
|
||||
@ -763,6 +764,8 @@ module ts {
|
||||
Transient = 0x02000000, // Transient symbol (created during type check)
|
||||
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
|
||||
|
||||
Undefined = 0x08000000, // Symbol for the undefined
|
||||
|
||||
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
|
||||
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
|
||||
Namespace = ValueModule | NamespaceModule,
|
||||
|
||||
@ -1415,7 +1415,7 @@ module ts {
|
||||
|
||||
export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.writeType(type, writer, enclosingDeclaration, flags);
|
||||
typechecker.writeType(type, writer, enclosingDeclaration, flags | TypeFormatFlags.WriteUndefinedAndNullAsAny);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1427,7 +1427,7 @@ module ts {
|
||||
|
||||
function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.writeSignature(signature, writer, enclosingDeclaration, flags);
|
||||
typechecker.writeSignature(signature, writer, enclosingDeclaration, flags | TypeFormatFlags.WriteUndefinedAndNullAsAny);
|
||||
});
|
||||
}
|
||||
|
||||
@ -2626,6 +2626,9 @@ module ts {
|
||||
}
|
||||
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
|
||||
}
|
||||
if (flags & SymbolFlags.Undefined) {
|
||||
return ScriptElementKind.variableElement;
|
||||
}
|
||||
if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement;
|
||||
if (flags & SymbolFlags.GetAccessor) return ScriptElementKind.memberGetAccessorElement;
|
||||
if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement;
|
||||
@ -2705,6 +2708,10 @@ module ts {
|
||||
if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) {
|
||||
symbolKind = ScriptElementKind.memberVariableElement;
|
||||
}
|
||||
else if (symbol.name === "undefined") {
|
||||
// undefined is symbol and not property
|
||||
symbolKind = ScriptElementKind.variableElement;
|
||||
}
|
||||
|
||||
var type = typeResolver.getTypeOfSymbol(symbol);
|
||||
if (type) {
|
||||
@ -2874,7 +2881,7 @@ module ts {
|
||||
// If the type is type parameter, format it specially
|
||||
if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) {
|
||||
var typeParameterParts = mapToDisplayParts(writer => {
|
||||
typeResolver.writeTypeParameter(<TypeParameter>type, writer, enclosingDeclaration, TypeFormatFlags.NoTruncation);
|
||||
typeResolver.writeTypeParameter(<TypeParameter>type, writer, enclosingDeclaration, TypeFormatFlags.NoTruncation | TypeFormatFlags.WriteUndefinedAndNullAsAny);
|
||||
});
|
||||
displayParts.push.apply(displayParts, typeParameterParts);
|
||||
}
|
||||
@ -2941,7 +2948,7 @@ module ts {
|
||||
|
||||
function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) {
|
||||
var typeParameterParts = mapToDisplayParts(writer => {
|
||||
typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration, TypeFormatFlags.NoTruncation);
|
||||
typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration, TypeFormatFlags.NoTruncation | TypeFormatFlags.WriteUndefinedAndNullAsAny);
|
||||
});
|
||||
displayParts.push.apply(displayParts, typeParameterParts);
|
||||
}
|
||||
|
||||
@ -262,7 +262,7 @@ verify.quickInfoIs("(parameter) s: any");
|
||||
goTo.marker('33');
|
||||
verify.quickInfoIs("(var) c3t14: IFoo");
|
||||
goTo.marker('34');
|
||||
verify.quickInfoIs("(property) a: undefined[]");
|
||||
verify.quickInfoIs("(property) a: any[]");
|
||||
goTo.marker('35');
|
||||
verify.quickInfoIs("(property) C4T5.foo: (i: number, s: string) => string");
|
||||
goTo.marker('36');
|
||||
@ -334,7 +334,7 @@ verify.quickInfoIs("(parameter) s: any");
|
||||
goTo.marker('69');
|
||||
verify.quickInfoIs("(property) t14: IFoo");
|
||||
goTo.marker('70');
|
||||
verify.quickInfoIs("(property) a: undefined[]");
|
||||
verify.quickInfoIs("(property) a: any[]");
|
||||
goTo.marker('71');
|
||||
verify.quickInfoIs("(parameter) n: number");
|
||||
goTo.marker('72');
|
||||
@ -394,7 +394,7 @@ verify.quickInfoIs("(parameter) s: any");
|
||||
goTo.marker('99');
|
||||
verify.quickInfoIs("(var) c12t14: IFoo");
|
||||
goTo.marker('100');
|
||||
verify.quickInfoIs("(property) a: undefined[]");
|
||||
verify.quickInfoIs("(property) a: any[]");
|
||||
goTo.marker('101');
|
||||
verify.quickInfoIs("(function) EF1(a: number, b: number): number");
|
||||
goTo.marker('102');
|
||||
|
||||
8
tests/cases/fourslash/quickInfoOnUndefined.ts
Normal file
8
tests/cases/fourslash/quickInfoOnUndefined.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////function foo(a: string) {
|
||||
////}
|
||||
////foo(/*1*/undefined);
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs('(var) undefined');
|
||||
Loading…
x
Reference in New Issue
Block a user