Skip to content

Commit e1b7652

Browse files
committed
Code review feedback - Show the type as any even inside the with block
1 parent 8c23171 commit e1b7652

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

src/compiler/checker.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,22 +967,22 @@ module ts {
967967
// Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
968968
// Meaning needs to be specified if the enclosing declaration is given
969969
function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void {
970-
var previouslyWrittenSymbol: Symbol;
970+
var parentSymbol: Symbol;
971971
function writeSymbolName(symbol: Symbol): void {
972-
if (previouslyWrittenSymbol) {
972+
if (parentSymbol) {
973973
// Write type arguments of instantiated class/interface here
974974
if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) {
975975
if (symbol.flags & SymbolFlags.Instantiated) {
976-
writeTypeArguments(getTypeParametersOfClassOrInterface(previouslyWrittenSymbol),
976+
writeTypeArguments(getTypeParametersOfClassOrInterface(parentSymbol),
977977
(<TransientSymbol>symbol).mapper, writer, enclosingDeclaration);
978978
}
979979
else {
980-
writeTypeParametersOfSymbol(previouslyWrittenSymbol, writer, enclosingDeclaration);
980+
writeTypeParametersOfSymbol(parentSymbol, writer, enclosingDeclaration);
981981
}
982982
}
983983
writePunctuation(writer, SyntaxKind.DotToken);
984984
}
985-
previouslyWrittenSymbol = symbol;
985+
parentSymbol = symbol;
986986
if (symbol.declarations && symbol.declarations.length > 0) {
987987
var declaration = symbol.declarations[0];
988988
if (declaration.name) {
@@ -1022,7 +1022,7 @@ module ts {
10221022
}
10231023
else {
10241024
// If we didn't find accessible symbol chain for this symbol, break if this is external module
1025-
if (!previouslyWrittenSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) {
1025+
if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) {
10261026
return;
10271027
}
10281028

@@ -6996,6 +6996,19 @@ module ts {
69966996
return findChildAtPosition(sourceFile);
69976997
}
69986998

6999+
function isInsideWithStatementBody(node: Node): boolean {
7000+
if (node) {
7001+
while (node.parent) {
7002+
if (node.parent.kind === SyntaxKind.WithStatement && (<WithStatement>node.parent).statement === node) {
7003+
return true;
7004+
}
7005+
node = node.parent;
7006+
}
7007+
}
7008+
7009+
return false;
7010+
}
7011+
69997012
function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]{
70007013
var symbols: SymbolTable = {};
70017014
var memberFlags: NodeFlags = 0;

src/compiler/parser.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,6 @@ module ts {
166166
}
167167
}
168168

169-
export function isInsideWithStatementBody(node: Node): boolean {
170-
if (node) {
171-
while (node.parent) {
172-
if (node.parent.kind === SyntaxKind.WithStatement && (<WithStatement>node.parent).statement === node) {
173-
return true;
174-
}
175-
node = node.parent;
176-
}
177-
}
178-
179-
return false;
180-
}
181-
182169
export var fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
183170

184171
// Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes

src/services/services.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,18 +2970,16 @@ module ts {
29702970
case SyntaxKind.QualifiedName:
29712971
case SyntaxKind.ThisKeyword:
29722972
case SyntaxKind.SuperKeyword:
2973-
// For the identifiers/this/usper etc get the type at position if not inside if statement
2974-
if (!isInsideWithStatementBody(node)) {
2975-
var type = typeInfoResolver.getTypeOfNode(node);
2976-
if (type) {
2977-
return {
2978-
kind: ScriptElementKind.unknown,
2979-
kindModifiers: ScriptElementKindModifier.none,
2980-
textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()),
2981-
displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)),
2982-
documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined
2983-
};
2984-
}
2973+
// For the identifiers/this/usper etc get the type at position
2974+
var type = typeInfoResolver.getTypeOfNode(node);
2975+
if (type) {
2976+
return {
2977+
kind: ScriptElementKind.unknown,
2978+
kindModifiers: ScriptElementKindModifier.none,
2979+
textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()),
2980+
displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)),
2981+
documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined
2982+
};
29852983
}
29862984
}
29872985

tests/cases/fourslash/quickInfoInWithBlock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88

99
goTo.marker('1');
10-
verify.not.quickInfoExists();
10+
verify.quickInfoIs("any");
1111

1212
goTo.marker('2');
13-
verify.not.quickInfoExists();
13+
verify.quickInfoIs("any");
1414

1515
goTo.marker('3');
16-
verify.not.quickInfoExists();
16+
verify.quickInfoIs("any");

0 commit comments

Comments
 (0)