This commit is contained in:
Andy Hanson 2017-06-26 12:19:16 -07:00
parent b32704ce25
commit e7d13f8303
5 changed files with 28 additions and 19 deletions

View file

@ -22226,12 +22226,6 @@ namespace ts {
}
switch (location.kind) {
case SyntaxKind.SourceFile:
if (!isExternalOrCommonJsModule(<SourceFile>location)) {
break;
}
break;
//falls through -- not!
case SyntaxKind.ModuleDeclaration:
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
break;
@ -22283,8 +22277,7 @@ namespace ts {
* @param meaning meaning of symbol to filter by before adding to symbol table
*/
function copySymbol(symbol: Symbol, meaning: SymbolFlags): void {
//We copy the local symbol, not the export symbol.
if (symbol.flags & meaning || symbol.exportSymbol && symbol.exportSymbol.flags & meaning) {
if (getCombinedLocalAndExportSymbolFlags(symbol) & meaning) {
const id = symbol.name;
// We will copy all symbol regardless of its reserved name because
// symbolsToArray will check whether the key is a reserved name and

View file

@ -3549,6 +3549,11 @@ namespace ts {
}
return previous[previous.length - 1];
}
/** See comment on `declareModuleMember` in `binder.ts`. */
export function getCombinedLocalAndExportSymbolFlags(symbol: Symbol): SymbolFlags {
return symbol.exportSymbol ? symbol.exportSymbol.flags | symbol.flags : symbol.flags;
}
}
namespace ts {

View file

@ -608,7 +608,7 @@ namespace ts.Completions {
// Extract module or enum members
const exportedSymbols = typeChecker.getExportsOfModule(symbol);
const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess(<PropertyAccessExpression>(node.parent), symbol.name);
const isValidTypeAccess = (symbol: Symbol) => symbolCanbeReferencedAtTypeLocation(symbol);
const isValidTypeAccess = (symbol: Symbol) => symbolCanBeReferencedAtTypeLocation(symbol);
const isValidAccess = isRhsOfImportDeclaration ?
// Any kind is allowed when dotting off namespace in internal import equals declaration
(symbol: Symbol) => isValidTypeAccess(symbol) || isValidValueAccess(symbol) :
@ -768,12 +768,12 @@ namespace ts.Completions {
(!isContextTokenValueLocation(contextToken) &&
(isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)))) {
// Its a type, but you can reach it by namespace.type as well
return symbolCanbeReferencedAtTypeLocation(symbol);
return symbolCanBeReferencedAtTypeLocation(symbol);
}
}
// expressions are value space (which includes the value namespaces)
return !!(symbol.flags & SymbolFlags.Value || symbol.exportSymbol && symbol.exportSymbol.flags & SymbolFlags.Value);
return getCombinedLocalAndExportSymbolFlags(symbol) & SymbolFlags.Value;
});
}
@ -803,8 +803,8 @@ namespace ts.Completions {
}
}
function symbolCanbeReferencedAtTypeLocation(symbol: Symbol): boolean { //CanBe
symbol = symbol.exportSymbol || symbol; //fn
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol): boolean {
symbol = symbol.exportSymbol || symbol;
// This is an alias, follow what it aliases
if (symbol && symbol.flags & SymbolFlags.Alias) {
@ -819,7 +819,7 @@ namespace ts.Completions {
const exportedSymbols = typeChecker.getExportsOfModule(symbol);
// If the exported symbols contains type,
// symbol can be referenced at locations where type is allowed
return forEach(exportedSymbols, symbolCanbeReferencedAtTypeLocation);
return forEach(exportedSymbols, symbolCanBeReferencedAtTypeLocation);
}
}

View file

@ -2,7 +2,7 @@
namespace ts.SymbolDisplay {
// TODO(drosen): use contextual SemanticMeaning.
export function getSymbolKind(typeChecker: TypeChecker, symbol: Symbol, location: Node): ScriptElementKind {
const { flags } = symbol.exportSymbol || symbol; //helper fn
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
if (flags & SymbolFlags.Class) {
return getDeclarationOfKind(symbol, SyntaxKind.ClassExpression) ?
@ -34,7 +34,7 @@ namespace ts.SymbolDisplay {
if (location.kind === SyntaxKind.ThisKeyword && isExpression(location)) {
return ScriptElementKind.parameterElement;
}
const { flags } = symbol.exportSymbol || symbol; //helper fn
const flags = getCombinedLocalAndExportSymbolFlags(symbol);
if (flags & SymbolFlags.Variable) {
if (isFirstDeclarationOfSymbolParameter(symbol)) {
return ScriptElementKind.parameterElement;
@ -96,8 +96,7 @@ namespace ts.SymbolDisplay {
const displayParts: SymbolDisplayPart[] = [];
let documentation: SymbolDisplayPart[];
let tags: JSDocTagInfo[];
//Use *all* flags, to get all meanings.
const symbolFlags = symbol.exportSymbol ? symbol.exportSymbol.flags | symbol.flags : symbol.flags; //helper fn
const symbolFlags = ts.getCombinedLocalAndExportSymbolFlags(symbol);
let symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location);
let hasAddedSymbolInfo: boolean;
const isThisExpression = location.kind === SyntaxKind.ThisKeyword && isExpression(location);
@ -111,7 +110,6 @@ namespace ts.SymbolDisplay {
}
let signature: Signature;
//! If I change 'getTypeOfSymbol' in checker.ts to use symbol.exportSymbol there will be compiler crashes
type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol.exportSymbol || symbol, location);
if (type) {
if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {

View file

@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />
// @Filename: /a.ts
////import * as self from "./a";
////
////declare module "a" {
//// export const a: number;
////}
////
/////**/
goTo.marker();
verify.not.completionListContains("a");