mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into numbersAreHard
Conflicts: tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt
This commit is contained in:
+274
-244
@@ -23,28 +23,34 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface SymbolWriter {
|
||||
writeKind(text: string, kind: SymbolDisplayPartKind): void;
|
||||
writeSymbol(text: string, symbol: Symbol): void;
|
||||
writeLine(): void;
|
||||
increaseIndent(): void;
|
||||
decreaseIndent(): void;
|
||||
clear(): void;
|
||||
|
||||
// Called when the symbol writer encounters a symbol to write. Currently only used by the
|
||||
// declaration emitter to help determine if it should patch up the final declaration file
|
||||
// with import statements it previously saw (but chose not to emit).
|
||||
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
|
||||
}
|
||||
|
||||
interface DisplayPartsSymbolWriter extends SymbolWriter {
|
||||
displayParts(): SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
interface StringSymbolWriter extends SymbolWriter {
|
||||
export interface StringSymbolWriter extends SymbolWriter {
|
||||
string(): string;
|
||||
}
|
||||
|
||||
// Pool writers to avoid needing to allocate them for every symbol we write.
|
||||
var stringWriters: StringSymbolWriter[] = [];
|
||||
export function getSingleLineStringWriter(): StringSymbolWriter {
|
||||
if (stringWriters.length == 0) {
|
||||
var str = "";
|
||||
|
||||
return {
|
||||
string: () => str,
|
||||
writeKind: text => str += text,
|
||||
writeSymbol: text => str += text,
|
||||
|
||||
// Completely ignore indentation for string writers. And map newlines to
|
||||
// a single space.
|
||||
writeLine: () => str += " ",
|
||||
increaseIndent: () => { },
|
||||
decreaseIndent: () => { },
|
||||
clear: () => str = "",
|
||||
trackSymbol: () => { }
|
||||
};
|
||||
}
|
||||
|
||||
return stringWriters.pop();
|
||||
}
|
||||
|
||||
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
|
||||
/// If fullTypeCheck === true, then the typechecker should do every possible check to produce all errors
|
||||
/// If fullTypeCheck === false, the typechecker can take shortcuts and skip checks that only produce errors.
|
||||
@@ -84,9 +90,9 @@ module ts {
|
||||
getTypeOfNode: getTypeOfNode,
|
||||
getApparentType: getApparentType,
|
||||
typeToString: typeToString,
|
||||
typeToDisplayParts: typeToDisplayParts,
|
||||
writeType: writeType,
|
||||
symbolToString: symbolToString,
|
||||
symbolToDisplayParts: symbolToDisplayParts,
|
||||
writeSymbol: writeSymbol,
|
||||
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType,
|
||||
getRootSymbol: getRootSymbol,
|
||||
getContextualType: getContextualType,
|
||||
@@ -94,10 +100,15 @@ module ts {
|
||||
getResolvedSignature: getResolvedSignature,
|
||||
getEnumMemberValue: getEnumMemberValue,
|
||||
isValidPropertyAccess: isValidPropertyAccess,
|
||||
getSignatureFromDeclaration: getSignatureFromDeclaration,
|
||||
writeSignature: writeSignature,
|
||||
writeTypeParameter: writeTypeParameter,
|
||||
writeTypeParametersOfSymbol: writeTypeParametersOfSymbol,
|
||||
isImplementationOfOverload: isImplementationOfOverload,
|
||||
getAliasedSymbol: resolveImport
|
||||
};
|
||||
|
||||
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__");
|
||||
@@ -923,58 +934,6 @@ module ts {
|
||||
{ accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: firstIdentifierName };
|
||||
}
|
||||
|
||||
// Pool writers to avoid needing to allocate them for every symbol we write.
|
||||
var displayPartWriters: DisplayPartsSymbolWriter[] = [];
|
||||
var stringWriters: StringSymbolWriter[] = [];
|
||||
|
||||
function getDisplayPartWriter(): DisplayPartsSymbolWriter {
|
||||
if (displayPartWriters.length == 0) {
|
||||
var displayParts: SymbolDisplayPart[] = [];
|
||||
return {
|
||||
displayParts: () => displayParts,
|
||||
writeKind: (text, kind) => displayParts.push(new SymbolDisplayPart(text, kind, undefined)),
|
||||
writeSymbol: (text, symbol) => displayParts.push(symbolPart(text, symbol)),
|
||||
|
||||
// Completely ignore indentation for display part writers. And map newlines to
|
||||
// a single space.
|
||||
writeLine: () => displayParts.push(spacePart()),
|
||||
increaseIndent: () => { },
|
||||
decreaseIndent: () => { },
|
||||
clear: () => displayParts = [],
|
||||
trackSymbol: () => { }
|
||||
};
|
||||
}
|
||||
|
||||
return displayPartWriters.pop();
|
||||
}
|
||||
|
||||
function getStringWriter(): StringSymbolWriter {
|
||||
if (stringWriters.length == 0) {
|
||||
var str = "";
|
||||
|
||||
return {
|
||||
string: () => str,
|
||||
writeKind: text => str += text,
|
||||
writeSymbol: text => str += text,
|
||||
|
||||
// Completely ignore indentation for string writers. And map newlines to
|
||||
// a single space.
|
||||
writeLine: () => str += " ",
|
||||
increaseIndent: () => { },
|
||||
decreaseIndent: () => { },
|
||||
clear: () => str = "",
|
||||
trackSymbol: () => { }
|
||||
};
|
||||
}
|
||||
|
||||
return stringWriters.pop();
|
||||
}
|
||||
|
||||
function releaseDisplayPartWriter(writer: DisplayPartsSymbolWriter) {
|
||||
writer.clear();
|
||||
displayPartWriters.push(writer);
|
||||
}
|
||||
|
||||
function releaseStringWriter(writer: StringSymbolWriter) {
|
||||
writer.clear()
|
||||
stringWriters.push(writer);
|
||||
@@ -997,7 +956,7 @@ module ts {
|
||||
}
|
||||
|
||||
function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string {
|
||||
var writer = getStringWriter();
|
||||
var writer = getSingleLineStringWriter();
|
||||
writeSymbol(symbol, writer, enclosingDeclaration, meaning);
|
||||
|
||||
var result = writer.string();
|
||||
@@ -1006,20 +965,25 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[] {
|
||||
var writer = getDisplayPartWriter();
|
||||
writeSymbol(symbol, writer, enclosingDeclaration, meaning);
|
||||
|
||||
var result = writer.displayParts();
|
||||
releaseDisplayPartWriter(writer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
|
||||
// Meaning needs to be specified if the enclosing declaration is given
|
||||
function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags): void {
|
||||
function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void {
|
||||
var parentSymbol: Symbol;
|
||||
function writeSymbolName(symbol: Symbol): void {
|
||||
if (parentSymbol) {
|
||||
// Write type arguments of instantiated class/interface here
|
||||
if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) {
|
||||
if (symbol.flags & SymbolFlags.Instantiated) {
|
||||
writeTypeArguments(getTypeParametersOfClassOrInterface(parentSymbol),
|
||||
(<TransientSymbol>symbol).mapper, writer, enclosingDeclaration);
|
||||
}
|
||||
else {
|
||||
writeTypeParametersOfSymbol(parentSymbol, writer, enclosingDeclaration);
|
||||
}
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.DotToken);
|
||||
}
|
||||
parentSymbol = symbol;
|
||||
if (symbol.declarations && symbol.declarations.length > 0) {
|
||||
var declaration = symbol.declarations[0];
|
||||
if (declaration.name) {
|
||||
@@ -1031,16 +995,14 @@ module ts {
|
||||
writer.writeSymbol(symbol.name, symbol);
|
||||
}
|
||||
|
||||
// Let the writer know we just wrote out a symbol. The declarationemitter writer uses
|
||||
// this to determine if an import it has previously seen (and not writter out) needs
|
||||
// Let the writer know we just wrote out a symbol. The declaration emitter writer uses
|
||||
// this to determine if an import it has previously seen (and not written out) needs
|
||||
// to be written to the file once the walk of the tree is complete.
|
||||
//
|
||||
// NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree
|
||||
// up front (for example, during checking) could determien if we need to emit the imports
|
||||
// up front (for example, during checking) could determine if we need to emit the imports
|
||||
// and we could then access that data during declaration emit.
|
||||
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
|
||||
|
||||
var needsDot = false;
|
||||
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
|
||||
if (symbol) {
|
||||
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning);
|
||||
@@ -1056,26 +1018,21 @@ module ts {
|
||||
|
||||
if (accessibleSymbolChain) {
|
||||
for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) {
|
||||
if (needsDot) {
|
||||
writePunctuation(writer, SyntaxKind.DotToken);
|
||||
}
|
||||
|
||||
writeSymbolName(accessibleSymbolChain[i]);
|
||||
needsDot = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If we didn't find accessible symbol chain for this symbol, break if this is external module
|
||||
if (!needsDot && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) {
|
||||
if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsDot) {
|
||||
writePunctuation(writer, SyntaxKind.DotToken);
|
||||
// if this is anonymous type break
|
||||
if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) {
|
||||
return;
|
||||
}
|
||||
|
||||
writeSymbolName(symbol);
|
||||
needsDot = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1092,12 +1049,8 @@ module ts {
|
||||
return writeSymbolName(symbol);
|
||||
}
|
||||
|
||||
function writeSymbolToTextWriter(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, writer: TextWriter) {
|
||||
writer.write(symbolToString(symbol, enclosingDeclaration, meaning));
|
||||
}
|
||||
|
||||
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
|
||||
var writer = getStringWriter();
|
||||
var writer = getSingleLineStringWriter();
|
||||
writeType(type, writer, enclosingDeclaration, flags);
|
||||
|
||||
var result = writer.string();
|
||||
@@ -1111,23 +1064,15 @@ module ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function typeToDisplayParts(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
var writer = getDisplayPartWriter();
|
||||
writeType(type, writer, enclosingDeclaration, flags);
|
||||
function writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
|
||||
return writeType(type, flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
|
||||
var result = writer.displayParts();
|
||||
releaseDisplayPartWriter(writer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags) {
|
||||
var typeStack: Type[];
|
||||
return writeType(type, /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
|
||||
function writeType(type: Type, allowFunctionOrConstructorTypeLiteral: boolean) {
|
||||
function writeType(type: Type, flags: TypeFormatFlags) {
|
||||
// Write undefined/null type as any
|
||||
if (type.flags & TypeFlags.Intrinsic) {
|
||||
writer.writeKind((<IntrinsicType>type).intrinsicName, SymbolDisplayPartKind.keyword);
|
||||
// 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);
|
||||
}
|
||||
else if (type.flags & TypeFlags.Reference) {
|
||||
writeTypeReference(<TypeReference>type);
|
||||
@@ -1139,7 +1084,7 @@ module ts {
|
||||
writeTupleType(<TupleType>type);
|
||||
}
|
||||
else if (type.flags & TypeFlags.Anonymous) {
|
||||
writeAnonymousType(<ObjectType>type, allowFunctionOrConstructorTypeLiteral);
|
||||
writeAnonymousType(<ObjectType>type, flags);
|
||||
}
|
||||
else if (type.flags & TypeFlags.StringLiteral) {
|
||||
writer.writeKind((<StringLiteralType>type).text, SymbolDisplayPartKind.stringLiteral);
|
||||
@@ -1161,7 +1106,7 @@ module ts {
|
||||
writePunctuation(writer, SyntaxKind.CommaToken);
|
||||
writeSpace(writer);
|
||||
}
|
||||
writeType(types[i], /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
writeType(types[i], flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1169,7 +1114,7 @@ module ts {
|
||||
if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) {
|
||||
// If we are writing array element type the arrow style signatures are not allowed as
|
||||
// we need to surround it by curlies, e.g. { (): T; }[]; as () => T[] would mean something different
|
||||
writeType(type.typeArguments[0], /*allowFunctionOrConstructorTypeLiteral*/ false);
|
||||
writeType(type.typeArguments[0], flags & ~TypeFormatFlags.WriteArrowStyleSignature);
|
||||
writePunctuation(writer, SyntaxKind.OpenBracketToken);
|
||||
writePunctuation(writer, SyntaxKind.CloseBracketToken);
|
||||
}
|
||||
@@ -1187,7 +1132,7 @@ module ts {
|
||||
writePunctuation(writer, SyntaxKind.CloseBracketToken);
|
||||
}
|
||||
|
||||
function writeAnonymousType(type: ObjectType, allowFunctionOrConstructorTypeLiteral: boolean) {
|
||||
function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) {
|
||||
// Always use 'typeof T' for type of class, enum, and module objects
|
||||
if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
|
||||
writeTypeofSymbol(type);
|
||||
@@ -1205,7 +1150,7 @@ module ts {
|
||||
typeStack = [];
|
||||
}
|
||||
typeStack.push(type);
|
||||
writeLiteralType(type, allowFunctionOrConstructorTypeLiteral);
|
||||
writeLiteralType(type, flags);
|
||||
typeStack.pop();
|
||||
}
|
||||
|
||||
@@ -1233,7 +1178,7 @@ module ts {
|
||||
writeSymbol(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value);
|
||||
}
|
||||
|
||||
function writeLiteralType(type: ObjectType, allowFunctionOrConstructorTypeLiteral: boolean) {
|
||||
function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) {
|
||||
var resolved = resolveObjectTypeMembers(type);
|
||||
if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
|
||||
if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
|
||||
@@ -1242,15 +1187,15 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
if (allowFunctionOrConstructorTypeLiteral) {
|
||||
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
|
||||
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
|
||||
writeSignature(resolved.callSignatures[0], /*arrowStyle*/ true);
|
||||
writeSignature(resolved.callSignatures[0], writer, enclosingDeclaration, flags, typeStack);
|
||||
return;
|
||||
}
|
||||
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
|
||||
writeKeyword(writer, SyntaxKind.NewKeyword);
|
||||
writeSpace(writer);
|
||||
writeSignature(resolved.constructSignatures[0], /*arrowStyle*/ true);
|
||||
writeSignature(resolved.constructSignatures[0], writer, enclosingDeclaration, flags, typeStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1260,7 +1205,7 @@ module ts {
|
||||
writer.writeLine();
|
||||
writer.increaseIndent();
|
||||
for (var i = 0; i < resolved.callSignatures.length; i++) {
|
||||
writeSignature(resolved.callSignatures[i]);
|
||||
writeSignature(resolved.callSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1268,7 +1213,7 @@ module ts {
|
||||
writeKeyword(writer, SyntaxKind.NewKeyword);
|
||||
writeSpace(writer);
|
||||
|
||||
writeSignature(resolved.constructSignatures[i]);
|
||||
writeSignature(resolved.constructSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1282,7 +1227,7 @@ module ts {
|
||||
writePunctuation(writer, SyntaxKind.CloseBracketToken);
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
writeSpace(writer);
|
||||
writeType(resolved.stringIndexType, /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
writeType(resolved.stringIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1296,7 +1241,7 @@ module ts {
|
||||
writePunctuation(writer, SyntaxKind.CloseBracketToken);
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
writeSpace(writer);
|
||||
writeType(resolved.numberIndexType, /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
writeType(resolved.numberIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1310,7 +1255,7 @@ module ts {
|
||||
if (isOptionalProperty(p)) {
|
||||
writePunctuation(writer, SyntaxKind.QuestionToken);
|
||||
}
|
||||
writeSignature(signatures[j]);
|
||||
writeSignature(signatures[j], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1322,7 +1267,7 @@ module ts {
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
writeSpace(writer);
|
||||
writeType(t, /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
writeType(t, flags | TypeFormatFlags.WriteArrowStyleSignature);
|
||||
writePunctuation(writer, SyntaxKind.SemicolonToken);
|
||||
writer.writeLine();
|
||||
}
|
||||
@@ -1330,59 +1275,93 @@ module ts {
|
||||
writer.decreaseIndent();
|
||||
writePunctuation(writer, SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
}
|
||||
|
||||
function writeSignature(signature: Signature, arrowStyle?: boolean) {
|
||||
if (signature.typeParameters) {
|
||||
writePunctuation(writer, SyntaxKind.LessThanToken);
|
||||
for (var i = 0; i < signature.typeParameters.length; i++) {
|
||||
if (i > 0) {
|
||||
writePunctuation(writer, SyntaxKind.CommaToken);
|
||||
writeSpace(writer);
|
||||
}
|
||||
var tp = signature.typeParameters[i];
|
||||
writeSymbol(tp.symbol, writer);
|
||||
var constraint = getConstraintOfTypeParameter(tp);
|
||||
if (constraint) {
|
||||
writeSpace(writer);
|
||||
writeKeyword(writer, SyntaxKind.ExtendsKeyword);
|
||||
writeSpace(writer);
|
||||
writeType(constraint, /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
}
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.GreaterThanToken);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.OpenParenToken);
|
||||
for (var i = 0; i < signature.parameters.length; i++) {
|
||||
function writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
|
||||
writeSymbol(tp.symbol, writer);
|
||||
var constraint = getConstraintOfTypeParameter(tp);
|
||||
if (constraint) {
|
||||
writeSpace(writer);
|
||||
writeKeyword(writer, SyntaxKind.ExtendsKeyword);
|
||||
writeSpace(writer);
|
||||
writeType(constraint, writer, enclosingDeclaration, flags, typeStack);
|
||||
}
|
||||
}
|
||||
|
||||
function writeTypeParameters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
|
||||
if (typeParameters && typeParameters.length) {
|
||||
writePunctuation(writer, SyntaxKind.LessThanToken);
|
||||
for (var i = 0; i < typeParameters.length; i++) {
|
||||
if (i > 0) {
|
||||
writePunctuation(writer, SyntaxKind.CommaToken);
|
||||
writeSpace(writer);
|
||||
}
|
||||
var p = signature.parameters[i];
|
||||
if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) {
|
||||
writePunctuation(writer, SyntaxKind.DotDotDotToken);
|
||||
}
|
||||
writeSymbol(p, writer);
|
||||
if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (<VariableDeclaration>p.valueDeclaration).initializer) {
|
||||
writePunctuation(writer, SyntaxKind.QuestionToken);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
writeSpace(writer);
|
||||
writeTypeParameter(typeParameters[i], writer, enclosingDeclaration, flags, typeStack);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.GreaterThanToken);
|
||||
}
|
||||
}
|
||||
|
||||
writeType(getTypeOfSymbol(p), /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
function writeTypeArguments(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
|
||||
if (typeParameters && typeParameters.length) {
|
||||
writePunctuation(writer, SyntaxKind.LessThanToken);
|
||||
for (var i = 0; i < typeParameters.length; i++) {
|
||||
if (i > 0) {
|
||||
writePunctuation(writer, SyntaxKind.CommaToken);
|
||||
writeSpace(writer);
|
||||
}
|
||||
writeType(mapper(typeParameters[i]), writer, enclosingDeclaration, TypeFormatFlags.WriteArrowStyleSignature);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.GreaterThanToken);
|
||||
}
|
||||
}
|
||||
|
||||
writePunctuation(writer, SyntaxKind.CloseParenToken);
|
||||
if (arrowStyle) {
|
||||
function writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) {
|
||||
var rootSymbol = getRootSymbol(symbol);
|
||||
if (rootSymbol.flags & SymbolFlags.Class || rootSymbol.flags & SymbolFlags.Interface) {
|
||||
writeTypeParameters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags);
|
||||
}
|
||||
}
|
||||
|
||||
function writeSignature(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
|
||||
if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) {
|
||||
// Instantiated signature, write type arguments instead
|
||||
writeTypeArguments(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
|
||||
}
|
||||
else {
|
||||
writeTypeParameters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.OpenParenToken);
|
||||
for (var i = 0; i < signature.parameters.length; i++) {
|
||||
if (i > 0) {
|
||||
writePunctuation(writer, SyntaxKind.CommaToken);
|
||||
writeSpace(writer);
|
||||
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
|
||||
}
|
||||
else {
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
var p = signature.parameters[i];
|
||||
if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) {
|
||||
writePunctuation(writer, SyntaxKind.DotDotDotToken);
|
||||
}
|
||||
writeSymbol(p, writer);
|
||||
if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (<VariableDeclaration>p.valueDeclaration).initializer) {
|
||||
writePunctuation(writer, SyntaxKind.QuestionToken);
|
||||
}
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
writeSpace(writer);
|
||||
|
||||
writeType(getReturnTypeOfSignature(signature), /*allowFunctionOrConstructorTypeLiteral*/ true);
|
||||
writeType(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack);
|
||||
}
|
||||
|
||||
writePunctuation(writer, SyntaxKind.CloseParenToken);
|
||||
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
|
||||
writeSpace(writer);
|
||||
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
|
||||
}
|
||||
else {
|
||||
writePunctuation(writer, SyntaxKind.ColonToken);
|
||||
}
|
||||
writeSpace(writer);
|
||||
|
||||
writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack);
|
||||
}
|
||||
|
||||
function isDeclarationVisible(node: Declaration): boolean {
|
||||
@@ -3894,9 +3873,21 @@ module ts {
|
||||
var func = <FunctionDeclaration>parameter.parent;
|
||||
if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) {
|
||||
if (isContextSensitiveExpression(func)) {
|
||||
var signature = getContextualSignature(func);
|
||||
if (signature) {
|
||||
return getTypeAtPosition(signature, indexOf(func.parameters, parameter));
|
||||
var contextualSignature = getContextualSignature(func);
|
||||
if (contextualSignature) {
|
||||
|
||||
var funcHasRestParameters = hasRestParameters(func);
|
||||
var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
|
||||
var indexOfParameter = indexOf(func.parameters, parameter);
|
||||
if (indexOfParameter < len) {
|
||||
return getTypeAtPosition(contextualSignature, indexOfParameter);
|
||||
}
|
||||
|
||||
// If last parameter is contextually rest parameter get its type
|
||||
if (indexOfParameter === (func.parameters.length - 1) &&
|
||||
funcHasRestParameters && contextualSignature.hasRestParameter && func.parameters.length >= contextualSignature.parameters.length) {
|
||||
return getTypeOfSymbol(contextualSignature.parameters[contextualSignature.parameters.length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4529,8 +4520,21 @@ module ts {
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
|
||||
return resolveErrorCall(node);
|
||||
}
|
||||
|
||||
// No signature was applicable. We have already reported the errors for the invalid signature.
|
||||
// If this is a type resolution session, e.g. Language Service, try to get better information that anySignature.
|
||||
// Pick the first candidate that matches the arity. This way we can get a contextual type for cases like:
|
||||
// declare function f(a: { xa: number; xb: number; });
|
||||
// f({ |
|
||||
if (!fullTypeCheck) {
|
||||
for (var i = 0, n = candidates.length; i < n; i++) {
|
||||
if (signatureHasCorrectArity(node, candidates[i])) {
|
||||
return candidates[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resolveErrorCall(node);
|
||||
|
||||
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
|
||||
@@ -7151,6 +7155,22 @@ module ts {
|
||||
return mapToArray(symbols);
|
||||
}
|
||||
|
||||
function isTypeDeclarationName(name: Node): boolean {
|
||||
return name.kind == SyntaxKind.Identifier &&
|
||||
isTypeDeclaration(name.parent) &&
|
||||
(<Declaration>name.parent).name === name;
|
||||
}
|
||||
|
||||
function isTypeDeclaration(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// True if the given identifier is part of a type reference
|
||||
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
|
||||
var node: Node = entityName;
|
||||
@@ -7229,6 +7249,78 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTypeNode(node: Node): boolean {
|
||||
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.AnyKeyword:
|
||||
case SyntaxKind.NumberKeyword:
|
||||
case SyntaxKind.StringKeyword:
|
||||
case SyntaxKind.BooleanKeyword:
|
||||
return true;
|
||||
case SyntaxKind.VoidKeyword:
|
||||
return node.parent.kind !== SyntaxKind.PrefixOperator;
|
||||
case SyntaxKind.StringLiteral:
|
||||
// Specialized signatures can have string literals as their parameters' type names
|
||||
return node.parent.kind === SyntaxKind.Parameter;
|
||||
|
||||
// Identifiers and qualified names may be type nodes, depending on their context. Climb
|
||||
// above them to find the lowest container
|
||||
case SyntaxKind.Identifier:
|
||||
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
|
||||
if (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
}
|
||||
// fall through
|
||||
case SyntaxKind.QualifiedName:
|
||||
// At this point, node is either a qualified name or an identifier
|
||||
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName, "'node' was expected to be a qualified name or identifier in 'isTypeNode'.");
|
||||
|
||||
var parent = node.parent;
|
||||
if (parent.kind === SyntaxKind.TypeQuery) {
|
||||
return false;
|
||||
}
|
||||
// Do not recursively call isTypeNode on the parent. In the example:
|
||||
//
|
||||
// var a: A.B.C;
|
||||
//
|
||||
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
|
||||
// A.B.C is a type node.
|
||||
if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) {
|
||||
return true;
|
||||
}
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
return node === (<TypeParameterDeclaration>parent).constraint;
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return node === (<VariableDeclaration>parent).type;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.Method:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return node === (<FunctionDeclaration>parent).type;
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
return node === (<SignatureDeclaration>parent).type;
|
||||
case SyntaxKind.TypeAssertion:
|
||||
return node === (<TypeAssertion>parent).type;
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
return (<CallExpression>parent).typeArguments && (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
@@ -7595,34 +7687,17 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Create a single instance that we can wrap the underlying emitter TextWriter with. That
|
||||
// way we don't have to allocate a new wrapper every time writeTypeAtLocation and
|
||||
// writeReturnTypeOfSignatureDeclaration are called.
|
||||
var emitSymbolWriter = {
|
||||
writer: <TextWriter>undefined,
|
||||
|
||||
writeKind: function (text: string) { this.writer.write(text) },
|
||||
writeSymbol: function (text: string) { this.writer.write(text) },
|
||||
writeLine: function () { this.writer.writeLine() },
|
||||
increaseIndent: function () { this.writer.increaseIndent() },
|
||||
decreaseIndent: function () { this.writer.decreaseIndent() },
|
||||
clear: function () { },
|
||||
trackSymbol: function (symbol: Symbol, declaration: Node, meaning: SymbolFlags) { this.writer.trackSymbol(symbol, declaration, meaning) }
|
||||
};
|
||||
|
||||
function writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter) {
|
||||
function writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
|
||||
// Get type of the symbol if this is the valid symbol otherwise get type at location
|
||||
var symbol = getSymbolOfNode(location);
|
||||
var type = symbol && !(symbol.flags & SymbolFlags.TypeLiteral) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location);
|
||||
|
||||
emitSymbolWriter.writer = writer;
|
||||
writeType(type, emitSymbolWriter, enclosingDeclaration, flags);
|
||||
writeType(type, writer, enclosingDeclaration, flags);
|
||||
}
|
||||
|
||||
function writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter) {
|
||||
function writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) {
|
||||
var signature = getSignatureFromDeclaration(signatureDeclaration);
|
||||
emitSymbolWriter.writer = writer;
|
||||
writeType(getReturnTypeOfSignature(signature), emitSymbolWriter, enclosingDeclaration, flags);
|
||||
writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
|
||||
}
|
||||
|
||||
function invokeEmitter(targetSourceFile?: SourceFile) {
|
||||
@@ -7680,49 +7755,4 @@ module ts {
|
||||
|
||||
return checker;
|
||||
}
|
||||
|
||||
export function spacePart() {
|
||||
return new SymbolDisplayPart(" ", SymbolDisplayPartKind.space, undefined);
|
||||
}
|
||||
|
||||
export function keywordPart(kind: SyntaxKind) {
|
||||
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.keyword, undefined);
|
||||
}
|
||||
|
||||
export function punctuationPart(kind: SyntaxKind) {
|
||||
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation, undefined);
|
||||
}
|
||||
|
||||
export function operatorPart(kind: SyntaxKind) {
|
||||
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.operator, undefined);
|
||||
}
|
||||
|
||||
export function textPart(text: string) {
|
||||
return new SymbolDisplayPart(text, SymbolDisplayPartKind.text, undefined);
|
||||
}
|
||||
|
||||
export function symbolPart(text: string, symbol: Symbol) {
|
||||
return new SymbolDisplayPart(text, displayPartKind(symbol), symbol)
|
||||
}
|
||||
|
||||
function displayPartKind(symbol: Symbol): SymbolDisplayPartKind {
|
||||
var flags = symbol.flags;
|
||||
|
||||
if (flags & SymbolFlags.Variable) {
|
||||
return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === SyntaxKind.Parameter
|
||||
? SymbolDisplayPartKind.parameterName
|
||||
: SymbolDisplayPartKind.localName;
|
||||
}
|
||||
else if (flags & SymbolFlags.Property) { 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; }
|
||||
else if (flags & SymbolFlags.Interface) { return SymbolDisplayPartKind.interfaceName; }
|
||||
else if (flags & SymbolFlags.Enum) { return SymbolDisplayPartKind.enumName; }
|
||||
else if (flags & SymbolFlags.Module) { return SymbolDisplayPartKind.moduleName; }
|
||||
else if (flags & SymbolFlags.Method) { return SymbolDisplayPartKind.methodName; }
|
||||
else if (flags & SymbolFlags.TypeParameter) { return SymbolDisplayPartKind.typeParameterName; }
|
||||
|
||||
return SymbolDisplayPartKind.text;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -4,7 +4,9 @@
|
||||
/// <reference path="parser.ts"/>
|
||||
|
||||
module ts {
|
||||
interface EmitTextWriter extends TextWriter {
|
||||
interface EmitTextWriter extends SymbolWriter {
|
||||
write(s: string): void;
|
||||
getText(): string;
|
||||
rawWrite(s: string): void;
|
||||
writeLiteral(s: string): void;
|
||||
getTextPos(): number;
|
||||
@@ -14,7 +16,7 @@ module ts {
|
||||
}
|
||||
|
||||
var indentStrings: string[] = ["", " "];
|
||||
function getIndentString(level: number) {
|
||||
export function getIndentString(level: number) {
|
||||
if (indentStrings[level] === undefined) {
|
||||
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
|
||||
}
|
||||
@@ -147,9 +149,17 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function writeKind(text: string, kind: SymbolDisplayPartKind) {
|
||||
write(text);
|
||||
}
|
||||
function writeSymbol(text: string, symbol: Symbol) {
|
||||
write(text);
|
||||
}
|
||||
return {
|
||||
write: write,
|
||||
trackSymbol: trackSymbol,
|
||||
writeKind: writeKind,
|
||||
writeSymbol: writeSymbol,
|
||||
rawWrite: rawWrite,
|
||||
writeLiteral: writeLiteral,
|
||||
writeLine: writeLine,
|
||||
@@ -160,6 +170,7 @@ module ts {
|
||||
getLine: () => lineCount + 1,
|
||||
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
|
||||
getText: () => output,
|
||||
clear: () => { }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -391,100 +391,6 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this function only works when given a node with valid parent pointers.
|
||||
*/
|
||||
export function isTypeNode(node: Node): boolean {
|
||||
if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.AnyKeyword:
|
||||
case SyntaxKind.NumberKeyword:
|
||||
case SyntaxKind.StringKeyword:
|
||||
case SyntaxKind.BooleanKeyword:
|
||||
return true;
|
||||
case SyntaxKind.VoidKeyword:
|
||||
return node.parent.kind !== SyntaxKind.PrefixOperator;
|
||||
case SyntaxKind.StringLiteral:
|
||||
// Specialized signatures can have string literals as their parameters' type names
|
||||
return node.parent.kind === SyntaxKind.Parameter;
|
||||
// Identifiers and qualified names may be type nodes, depending on their context. Climb
|
||||
// above them to find the lowest container
|
||||
case SyntaxKind.Identifier:
|
||||
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
|
||||
if (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
}
|
||||
// Fall through
|
||||
case SyntaxKind.QualifiedName:
|
||||
// At this point, node is either a qualified name or an identifier
|
||||
var parent = node.parent;
|
||||
if (parent.kind === SyntaxKind.TypeQuery) {
|
||||
return false;
|
||||
}
|
||||
// Do not recursively call isTypeNode on the parent. In the example:
|
||||
//
|
||||
// var a: A.B.C;
|
||||
//
|
||||
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
|
||||
// A.B.C is a type node.
|
||||
if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) {
|
||||
return true;
|
||||
}
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
return node === (<TypeParameterDeclaration>parent).constraint;
|
||||
case SyntaxKind.Property:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return node === (<VariableDeclaration>parent).type;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.Method:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return node === (<FunctionDeclaration>parent).type;
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
return node === (<SignatureDeclaration>parent).type;
|
||||
case SyntaxKind.TypeAssertion:
|
||||
return node === (<TypeAssertion>parent).type;
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
return (<CallExpression>parent).typeArguments && (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this function only works when given a node with valid parent pointers.
|
||||
*
|
||||
* returns true if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
|
||||
*/
|
||||
export function isTypeDeclarationName(name: Node): boolean {
|
||||
return name.kind == SyntaxKind.Identifier &&
|
||||
isTypeDeclaration(name.parent) &&
|
||||
(<Declaration>name.parent).name === name;
|
||||
}
|
||||
|
||||
|
||||
export function isTypeDeclaration(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function getContainingFunction(node: Node): SignatureDeclaration {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
|
||||
+35
-33
@@ -643,14 +643,19 @@ module ts {
|
||||
getTypeOfNode(node: Node): Type;
|
||||
getApparentType(type: Type): ApparentType;
|
||||
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
|
||||
writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
|
||||
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
|
||||
typeToDisplayParts(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[];
|
||||
symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[];
|
||||
writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
|
||||
getFullyQualifiedName(symbol: Symbol): string;
|
||||
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
|
||||
getRootSymbol(symbol: Symbol): Symbol;
|
||||
getContextualType(node: Node): Type;
|
||||
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
|
||||
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
|
||||
writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
|
||||
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
|
||||
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
|
||||
isImplementationOfOverload(node: FunctionDeclaration): boolean;
|
||||
|
||||
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
|
||||
// computed value.
|
||||
@@ -660,20 +665,36 @@ module ts {
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
}
|
||||
|
||||
export interface TextWriter {
|
||||
write(s: string): void;
|
||||
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
|
||||
export interface SymbolWriter {
|
||||
writeKind(text: string, kind: SymbolDisplayPartKind): void;
|
||||
writeSymbol(text: string, symbol: Symbol): void;
|
||||
writeLine(): void;
|
||||
increaseIndent(): void;
|
||||
decreaseIndent(): void;
|
||||
getText(): string;
|
||||
clear(): void;
|
||||
|
||||
// Called when the symbol writer encounters a symbol to write. Currently only used by the
|
||||
// declaration emitter to help determine if it should patch up the final declaration file
|
||||
// with import statements it previously saw (but chose not to emit).
|
||||
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
export enum SymbolFormatFlags {
|
||||
None = 0x00000000,
|
||||
WriteTypeParametersOrArguments = 0x00000001, // Write symbols's type argument if it is instantiated symbol
|
||||
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
|
||||
// var a: C<number>;
|
||||
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
|
||||
}
|
||||
|
||||
export enum SymbolAccessibility {
|
||||
@@ -701,8 +722,8 @@ module ts {
|
||||
hasSemanticErrors(): boolean;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isImplementationOfOverload(node: FunctionDeclaration): boolean;
|
||||
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
|
||||
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
|
||||
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
|
||||
|
||||
@@ -743,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,
|
||||
@@ -1190,24 +1213,6 @@ module ts {
|
||||
verticalTab = 0x0B, // \v
|
||||
}
|
||||
|
||||
export class SymbolDisplayPart {
|
||||
constructor(public text: string,
|
||||
public kind: SymbolDisplayPartKind,
|
||||
public symbol: Symbol) {
|
||||
}
|
||||
|
||||
public toJSON() {
|
||||
return {
|
||||
text: this.text,
|
||||
kind: SymbolDisplayPartKind[this.kind]
|
||||
};
|
||||
}
|
||||
|
||||
public static toString(parts: SymbolDisplayPart[]) {
|
||||
return parts.map(p => p.text).join("");
|
||||
}
|
||||
}
|
||||
|
||||
export enum SymbolDisplayPartKind {
|
||||
aliasName,
|
||||
className,
|
||||
@@ -1215,20 +1220,17 @@ module ts {
|
||||
fieldName,
|
||||
interfaceName,
|
||||
keyword,
|
||||
labelName,
|
||||
lineBreak,
|
||||
numericLiteral,
|
||||
stringLiteral,
|
||||
localName,
|
||||
methodName,
|
||||
moduleName,
|
||||
namespaceName,
|
||||
operator,
|
||||
parameterName,
|
||||
propertyName,
|
||||
punctuation,
|
||||
space,
|
||||
anonymousTypeIndicator,
|
||||
text,
|
||||
typeParameterName,
|
||||
enumMemberName,
|
||||
|
||||
+47
-65
@@ -189,6 +189,9 @@ module FourSlash {
|
||||
}
|
||||
|
||||
export var currentTestState: TestState = null;
|
||||
function assertionMessage(msg: string) {
|
||||
return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n";
|
||||
}
|
||||
|
||||
export class TestCancellationToken implements ts.CancellationToken {
|
||||
// 0 - cancelled
|
||||
@@ -527,17 +530,17 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyMemberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
|
||||
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
|
||||
this.scenarioActions.push('<ShowCompletionList />');
|
||||
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
|
||||
|
||||
if (type || docComment || fullSymbolName || kind) {
|
||||
if (text || documentation || kind) {
|
||||
this.taoInvalidReason = 'verifyMemberListContains only supports the "symbol" parameter';
|
||||
}
|
||||
|
||||
var members = this.getMemberListAtCaret();
|
||||
if (members) {
|
||||
this.assertItemInCompletionList(members.entries, symbol, type, docComment, fullSymbolName, kind);
|
||||
this.assertItemInCompletionList(members.entries, symbol, text, documentation, kind);
|
||||
}
|
||||
else {
|
||||
this.raiseError("Expected a member list, but none was provided");
|
||||
@@ -636,9 +639,9 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyCompletionListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
|
||||
public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
|
||||
var completions = this.getCompletionListAtCaret();
|
||||
this.assertItemInCompletionList(completions.entries, symbol, type, docComment, fullSymbolName, kind);
|
||||
this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind);
|
||||
}
|
||||
|
||||
public verifyCompletionListDoesNotContain(symbol: string) {
|
||||
@@ -651,23 +654,19 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyCompletionEntryDetails(entryName: string, type: string, docComment?: string, fullSymbolName?: string, kind?: string) {
|
||||
public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) {
|
||||
this.taoInvalidReason = 'verifyCompletionEntryDetails NYI';
|
||||
|
||||
var details = this.getCompletionEntryDetails(entryName);
|
||||
|
||||
assert.equal(details.type, type);
|
||||
assert.equal(ts.displayPartsToString(details.displayParts), expectedText, assertionMessage("completion entry details text"));
|
||||
|
||||
if (docComment != undefined) {
|
||||
assert.equal(details.docComment, docComment);
|
||||
}
|
||||
|
||||
if (fullSymbolName !== undefined) {
|
||||
assert.equal(details.fullSymbolName, fullSymbolName);
|
||||
if (expectedDocumentation !== undefined) {
|
||||
assert.equal(ts.displayPartsToString(details.documentation), expectedDocumentation, assertionMessage("completion entry documentation"));
|
||||
}
|
||||
|
||||
if (kind !== undefined) {
|
||||
assert.equal(details.kind, kind);
|
||||
assert.equal(details.kind, kind, assertionMessage("completion entry kind"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,45 +765,31 @@ module FourSlash {
|
||||
return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue;
|
||||
}
|
||||
|
||||
public verifyQuickInfo(negative: boolean, expectedTypeName?: string, docComment?: string, symbolName?: string, kind?: string) {
|
||||
[expectedTypeName, docComment, symbolName, kind].forEach(str => {
|
||||
public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) {
|
||||
[expectedText, expectedDocumentation].forEach(str => {
|
||||
if (str) {
|
||||
this.scenarioActions.push('<ShowQuickInfo />');
|
||||
this.scenarioActions.push('<VerifyQuickInfoTextContains IgnoreSpacing="true" Text="' + escapeXmlAttributeValue(str) + '" ' + (negative ? 'ExpectsFailure="true"' : '') + ' />');
|
||||
}
|
||||
});
|
||||
|
||||
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
var actualQuickInfoMemberName = actualQuickInfo ? actualQuickInfo.memberName.toString() : "";
|
||||
var actualQuickInfoDocComment = actualQuickInfo ? actualQuickInfo.docComment : "";
|
||||
var actualQuickInfoSymbolName = actualQuickInfo ? actualQuickInfo.fullSymbolName : "";
|
||||
var actualQuickInfoKind = actualQuickInfo ? actualQuickInfo.kind : "";
|
||||
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
var actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
|
||||
var actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";
|
||||
|
||||
if (negative) {
|
||||
if (expectedTypeName !== undefined) {
|
||||
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, this.messageAtLastKnownMarker("quick info member name"));
|
||||
if (expectedText !== undefined) {
|
||||
assert.notEqual(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
|
||||
}
|
||||
if (docComment != undefined) {
|
||||
assert.notEqual(actualQuickInfoDocComment, docComment, this.messageAtLastKnownMarker("quick info doc comment"));
|
||||
}
|
||||
if (symbolName !== undefined) {
|
||||
assert.notEqual(actualQuickInfoSymbolName, symbolName, this.messageAtLastKnownMarker("quick info symbol name"));
|
||||
}
|
||||
if (kind !== undefined) {
|
||||
assert.notEqual(actualQuickInfoKind, kind, this.messageAtLastKnownMarker("quick info kind"));
|
||||
if (expectedDocumentation != undefined) {
|
||||
assert.notEqual(actualQuickInfoDocumentation, expectedDocumentation, this.messageAtLastKnownMarker("quick info doc comment"));
|
||||
}
|
||||
} else {
|
||||
if (expectedTypeName !== undefined) {
|
||||
assert.equal(actualQuickInfoMemberName, expectedTypeName, this.messageAtLastKnownMarker("quick info member"));
|
||||
if (expectedText !== undefined) {
|
||||
assert.equal(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
|
||||
}
|
||||
if (docComment != undefined) {
|
||||
assert.equal(actualQuickInfoDocComment, docComment, this.messageAtLastKnownMarker("quick info doc"));
|
||||
}
|
||||
if (symbolName !== undefined) {
|
||||
assert.equal(actualQuickInfoSymbolName, symbolName, this.messageAtLastKnownMarker("quick info symbol name"));
|
||||
}
|
||||
if (kind !== undefined) {
|
||||
assert.equal(actualQuickInfoKind, kind, this.messageAtLastKnownMarker("quick info kind"));
|
||||
if (expectedDocumentation != undefined) {
|
||||
assert.equal(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -844,7 +829,7 @@ module FourSlash {
|
||||
public verifyQuickInfoExists(negative: boolean) {
|
||||
this.taoInvalidReason = 'verifyQuickInfoExists NYI';
|
||||
|
||||
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
if (negative) {
|
||||
if (actualQuickInfo) {
|
||||
this.raiseError('verifyQuickInfoExists failed. Expected quick info NOT to exist');
|
||||
@@ -862,9 +847,9 @@ module FourSlash {
|
||||
|
||||
var help = this.getActiveSignatureHelpItem();
|
||||
assert.equal(
|
||||
ts.SymbolDisplayPart.toString(help.prefixDisplayParts) +
|
||||
help.parameters.map(p => ts.SymbolDisplayPart.toString(p.displayParts)).join(ts.SymbolDisplayPart.toString(help.separatorDisplayParts)) +
|
||||
ts.SymbolDisplayPart.toString(help.suffixDisplayParts), expected);
|
||||
ts.displayPartsToString(help.prefixDisplayParts) +
|
||||
help.parameters.map(p => ts.displayPartsToString(p.displayParts)).join(ts.displayPartsToString(help.separatorDisplayParts)) +
|
||||
ts.displayPartsToString(help.suffixDisplayParts), expected);
|
||||
}
|
||||
|
||||
public verifyCurrentParameterIsVariable(isVariable: boolean) {
|
||||
@@ -888,7 +873,7 @@ module FourSlash {
|
||||
|
||||
var activeSignature = this.getActiveSignatureHelpItem();
|
||||
var activeParameter = this.getActiveParameter();
|
||||
assert.equal(ts.SymbolDisplayPart.toString(activeParameter.displayParts), parameter);
|
||||
assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter);
|
||||
}
|
||||
|
||||
public verifyCurrentParameterHelpDocComment(docComment: string) {
|
||||
@@ -896,7 +881,7 @@ module FourSlash {
|
||||
|
||||
var activeParameter = this.getActiveParameter();
|
||||
var activeParameterDocComment = activeParameter.documentation;
|
||||
assert.equal(activeParameterDocComment, docComment);
|
||||
assert.equal(ts.displayPartsToString(activeParameterDocComment), docComment, assertionMessage("current parameter Help DocComment"));
|
||||
}
|
||||
|
||||
public verifyCurrentSignatureHelpParameterCount(expectedCount: number) {
|
||||
@@ -915,7 +900,7 @@ module FourSlash {
|
||||
this.taoInvalidReason = 'verifyCurrentSignatureHelpDocComment NYI';
|
||||
|
||||
var actualDocComment = this.getActiveSignatureHelpItem().documentation;
|
||||
assert.equal(actualDocComment, docComment);
|
||||
assert.equal(ts.displayPartsToString(actualDocComment), docComment, assertionMessage("current signature help doc comment"));
|
||||
}
|
||||
|
||||
public verifySignatureHelpCount(expected: number) {
|
||||
@@ -1084,7 +1069,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
public printCurrentQuickInfo() {
|
||||
var quickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
var quickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
|
||||
Harness.IO.log(JSON.stringify(quickInfo));
|
||||
}
|
||||
|
||||
@@ -1755,7 +1740,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
for (i = 0; i < positions.length; i++) {
|
||||
var nameOf = (type: ts.TypeInfo) => type ? type.fullSymbolName : '(none)';
|
||||
var nameOf = (type: ts.QuickInfo) => type ? ts.displayPartsToString(type.displayParts) : '(none)';
|
||||
|
||||
var pullName: string, refName: string;
|
||||
var anyFailed = false;
|
||||
@@ -1763,7 +1748,7 @@ module FourSlash {
|
||||
var errMsg = '';
|
||||
|
||||
try {
|
||||
var pullType = this.languageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
|
||||
var pullType = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
|
||||
pullName = nameOf(pullType);
|
||||
} catch (err1) {
|
||||
errMsg = 'Failed to get pull type check. Exception: ' + err1 + '\r\n';
|
||||
@@ -1773,7 +1758,7 @@ module FourSlash {
|
||||
}
|
||||
|
||||
try {
|
||||
var referenceType = referenceLanguageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
|
||||
var referenceType = referenceLanguageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
|
||||
refName = nameOf(referenceType);
|
||||
} catch (err2) {
|
||||
errMsg = 'Failed to get full type check. Exception: ' + err2 + '\r\n';
|
||||
@@ -2025,33 +2010,30 @@ module FourSlash {
|
||||
return result;
|
||||
}
|
||||
|
||||
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
|
||||
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) {
|
||||
this.scenarioActions.push('<ShowCompletionList />');
|
||||
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + name + '"/>');
|
||||
|
||||
if (type || docComment || fullSymbolName || kind) {
|
||||
if (text || documentation || kind) {
|
||||
this.taoInvalidReason = 'assertItemInCompletionList only supports the "name" parameter';
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
if (item.name == name) {
|
||||
if (docComment != undefined || type !== undefined || fullSymbolName !== undefined) {
|
||||
if (item.name === name) {
|
||||
if (documentation != undefined || text !== undefined) {
|
||||
var details = this.getCompletionEntryDetails(item.name);
|
||||
|
||||
if (docComment != undefined) {
|
||||
assert.equal(details.docComment, docComment);
|
||||
if (documentation !== undefined) {
|
||||
assert.equal(ts.displayPartsToString(details.documentation), documentation, assertionMessage("completion item documentation"));
|
||||
}
|
||||
if (type !== undefined) {
|
||||
assert.equal(details.type, type);
|
||||
}
|
||||
if (fullSymbolName !== undefined) {
|
||||
assert.equal(details.fullSymbolName, fullSymbolName);
|
||||
if (text !== undefined) {
|
||||
assert.equal(ts.displayPartsToString(details.displayParts), text, assertionMessage("completion item detail text"));
|
||||
}
|
||||
}
|
||||
|
||||
if (kind !== undefined) {
|
||||
assert.equal(item.kind, kind);
|
||||
assert.equal(item.kind, kind, assertionMessage("completion item kind"));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -2060,7 +2042,7 @@ module FourSlash {
|
||||
|
||||
var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n");
|
||||
|
||||
this.raiseError('Expected "' + JSON.stringify({ name: name, type: type, docComment: docComment, fullSymbolName: fullSymbolName, kind: kind }) + '" to be in list [' + itemsString + ']');
|
||||
this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']');
|
||||
}
|
||||
|
||||
private findFile(indexOrName: any) {
|
||||
|
||||
@@ -86,7 +86,7 @@ class TypeWriterWalker {
|
||||
column: lineAndCharacter.character,
|
||||
syntaxKind: ts.SyntaxKind[node.kind],
|
||||
sourceText: sourceText,
|
||||
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation)
|
||||
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.WriteOwnNameForAnyLike)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
/////<reference path='base64.ts' />
|
||||
/////<reference path='sourceMapping.ts' />
|
||||
/////<reference path='emitter.ts' />
|
||||
/////<reference path='types.ts' />
|
||||
/////<reference path='pathUtils.ts' />
|
||||
/////<reference path='referenceResolution.ts' />
|
||||
/////<reference path='precompile.ts' />
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class MemberName {
|
||||
public prefix: string = "";
|
||||
public suffix: string = "";
|
||||
|
||||
public isString() { return false; }
|
||||
public isArray() { return false; }
|
||||
public isMarker() { return !this.isString() && !this.isArray(); }
|
||||
|
||||
public toString(): string {
|
||||
return MemberName.memberNameToString(this);
|
||||
}
|
||||
|
||||
static memberNameToString(memberName: MemberName, markerInfo?: number[], markerBaseLength: number = 0): string {
|
||||
var result = memberName.prefix;
|
||||
|
||||
if (memberName.isString()) {
|
||||
result += (<MemberNameString>memberName).text;
|
||||
}
|
||||
else if (memberName.isArray()) {
|
||||
var ar = <MemberNameArray>memberName;
|
||||
for (var index = 0; index < ar.entries.length; index++) {
|
||||
if (ar.entries[index].isMarker()) {
|
||||
if (markerInfo) {
|
||||
markerInfo.push(markerBaseLength + result.length);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
result += MemberName.memberNameToString(ar.entries[index], markerInfo, markerBaseLength + result.length);
|
||||
result += ar.delim;
|
||||
}
|
||||
}
|
||||
|
||||
result += memberName.suffix;
|
||||
return result;
|
||||
}
|
||||
|
||||
static create(text: string): MemberName;
|
||||
static create(entry: MemberName, prefix: string, suffix: string): MemberName;
|
||||
static create(arg1: any, arg2?: any, arg3?: any): MemberName {
|
||||
if (typeof arg1 === "string") {
|
||||
return new MemberNameString(arg1);
|
||||
}
|
||||
else {
|
||||
var result = new MemberNameArray();
|
||||
if (arg2)
|
||||
result.prefix = arg2;
|
||||
if (arg3)
|
||||
result.suffix = arg3;
|
||||
result.entries.push(arg1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MemberNameString extends MemberName {
|
||||
constructor(public text: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
public isString() { return true; }
|
||||
}
|
||||
|
||||
export class MemberNameArray extends MemberName {
|
||||
public delim: string = "";
|
||||
public entries: MemberName[] = [];
|
||||
|
||||
public isArray() { return true; }
|
||||
|
||||
public add(entry: MemberName) {
|
||||
this.entries.push(entry);
|
||||
}
|
||||
|
||||
public addAll(entries: MemberName[]) {
|
||||
for (var i = 0 ; i < entries.length; i++) {
|
||||
this.entries.push(entries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
+957
-420
File diff suppressed because it is too large
Load Diff
@@ -85,9 +85,6 @@ module ts {
|
||||
|
||||
getQuickInfoAtPosition(fileName: string, position: number): string;
|
||||
|
||||
// Obsolete. Use getQuickInfoAtPosition instead.
|
||||
getTypeAtPosition(fileName: string, position: number): string;
|
||||
|
||||
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string;
|
||||
getBreakpointStatementAtPosition(fileName: string, position: number): string;
|
||||
|
||||
@@ -579,15 +576,6 @@ module ts {
|
||||
}
|
||||
|
||||
|
||||
public getTypeAtPosition(fileName: string, position: number): string {
|
||||
return this.forwardJSONCall(
|
||||
"getTypeAtPosition('" + fileName + "', " + position + ")",
|
||||
() => {
|
||||
var typeInfo = this.languageService.getTypeAtPosition(fileName, position);
|
||||
return typeInfo;
|
||||
});
|
||||
}
|
||||
|
||||
/// NAMEORDOTTEDNAMESPAN
|
||||
|
||||
/**
|
||||
|
||||
@@ -306,12 +306,12 @@ module ts.SignatureHelp {
|
||||
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
|
||||
displayParts.push(spacePart());
|
||||
|
||||
var typeParts = typeInfoResolver.typeToDisplayParts(typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList);
|
||||
var typeParts = typeToDisplayParts(typeInfoResolver, typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList);
|
||||
displayParts.push.apply(displayParts, typeParts);
|
||||
|
||||
return {
|
||||
name: p.name,
|
||||
documentation: getSymbolDocumentationDisplayParts(p),
|
||||
documentation: p.getDocumentationComment(),
|
||||
displayParts: displayParts,
|
||||
isOptional: isOptional
|
||||
};
|
||||
@@ -320,7 +320,7 @@ module ts.SignatureHelp {
|
||||
var callTargetNode = (<CallExpression>argumentListOrTypeArgumentList.parent).func;
|
||||
var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode);
|
||||
|
||||
var prefixParts = callTargetSymbol ? typeInfoResolver.symbolToDisplayParts(callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : [];
|
||||
var prefixParts = callTargetSymbol ? symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : [];
|
||||
|
||||
var separatorParts = [punctuationPart(SyntaxKind.CommaToken), spacePart()];
|
||||
|
||||
@@ -346,7 +346,7 @@ module ts.SignatureHelp {
|
||||
suffixParts.push(punctuationPart(SyntaxKind.ColonToken));
|
||||
suffixParts.push(spacePart());
|
||||
|
||||
var typeParts = typeInfoResolver.typeToDisplayParts(candidateSignature.getReturnType(), argumentListOrTypeArgumentList);
|
||||
var typeParts = typeToDisplayParts(typeInfoResolver, candidateSignature.getReturnType(), argumentListOrTypeArgumentList);
|
||||
suffixParts.push.apply(suffixParts, typeParts);
|
||||
|
||||
return {
|
||||
@@ -355,7 +355,7 @@ module ts.SignatureHelp {
|
||||
suffixDisplayParts: suffixParts,
|
||||
separatorDisplayParts: separatorParts,
|
||||
parameters: parameterHelpItems,
|
||||
documentation: <SymbolDisplayPart[]>null
|
||||
documentation: candidateSignature.getDocumentationComment()
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user