@@ -2010,7 +2010,7 @@ namespace ts {
20102010 }
20112011
20122012 function getAccessibleSymbolChainFromSymbolTableWorker(symbols: SymbolTable, visitedSymbolTables: SymbolTable[]): Symbol[] {
2013- if (contains(visitedSymbolTables, symbols)) {
2013+ if (contains<SymbolTable> (visitedSymbolTables, symbols)) {
20142014 return undefined;
20152015 }
20162016 visitedSymbolTables.push(symbols);
@@ -2285,21 +2285,15 @@ namespace ts {
22852285 }
22862286
22872287 function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string {
2288- const writer = getSingleLineStringWriter();
2289- getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
2290- const result = writer.string();
2291- releaseStringWriter(writer);
2292-
2293- return result;
2288+ return usingSingleLineStringWriter(writer => {
2289+ getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
2290+ });
22942291 }
22952292
22962293 function signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string {
2297- const writer = getSingleLineStringWriter();
2298- getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, kind);
2299- const result = writer.string();
2300- releaseStringWriter(writer);
2301-
2302- return result;
2294+ return usingSingleLineStringWriter(writer => {
2295+ getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, kind);
2296+ });
23032297 }
23042298
23052299 function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
@@ -2996,12 +2990,9 @@ namespace ts {
29962990 }
29972991
29982992 function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Declaration, flags?: TypeFormatFlags): string {
2999- const writer = getSingleLineStringWriter();
3000- getSymbolDisplayBuilder().buildTypePredicateDisplay(typePredicate, writer, enclosingDeclaration, flags);
3001- const result = writer.string();
3002- releaseStringWriter(writer);
3003-
3004- return result;
2993+ return usingSingleLineStringWriter(writer => {
2994+ getSymbolDisplayBuilder().buildTypePredicateDisplay(typePredicate, writer, enclosingDeclaration, flags);
2995+ });
30052996 }
30062997
30072998 function formatUnionTypes(types: Type[]): Type[] {
@@ -4239,7 +4230,7 @@ namespace ts {
42394230 return addOptionality(declaredType, /*optional*/ declaration.questionToken && includeOptionality);
42404231 }
42414232
4242- if ((noImplicitAny || declaration.flags & NodeFlags.JavaScriptFile ) &&
4233+ if ((noImplicitAny || isInJavaScriptFile( declaration) ) &&
42434234 declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
42444235 !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !isInAmbientContext(declaration)) {
42454236 // If --noImplicitAny is on or the declaration is in a Javascript file,
@@ -4493,7 +4484,7 @@ namespace ts {
44934484 if (declaration.kind === SyntaxKind.ExportAssignment) {
44944485 return links.type = checkExpression((<ExportAssignment>declaration).expression);
44954486 }
4496- if (declaration.flags & NodeFlags.JavaScriptFile && declaration.kind === SyntaxKind.JSDocPropertyTag && (<JSDocPropertyTag>declaration).typeExpression) {
4487+ if (isInJavaScriptFile( declaration) && declaration.kind === SyntaxKind.JSDocPropertyTag && (<JSDocPropertyTag>declaration).typeExpression) {
44974488 return links.type = getTypeFromTypeNode((<JSDocPropertyTag>declaration).typeExpression.type);
44984489 }
44994490 // Handle variable, parameter or property
@@ -4552,7 +4543,7 @@ namespace ts {
45524543 const getter = getDeclarationOfKind<AccessorDeclaration>(symbol, SyntaxKind.GetAccessor);
45534544 const setter = getDeclarationOfKind<AccessorDeclaration>(symbol, SyntaxKind.SetAccessor);
45544545
4555- if (getter && getter.flags & NodeFlags.JavaScriptFile ) {
4546+ if (getter && isInJavaScriptFile( getter) ) {
45564547 const jsDocType = getTypeForDeclarationFromJSDocComment(getter);
45574548 if (jsDocType) {
45584549 return links.type = jsDocType;
@@ -6206,7 +6197,7 @@ namespace ts {
62066197 }
62076198
62086199 function isJSDocOptionalParameter(node: ParameterDeclaration) {
6209- if (node.flags & NodeFlags.JavaScriptFile ) {
6200+ if (isInJavaScriptFile( node) ) {
62106201 if (node.type && node.type.kind === SyntaxKind.JSDocOptionalType) {
62116202 return true;
62126203 }
@@ -6892,6 +6883,7 @@ namespace ts {
68926883 case "Null":
68936884 return nullType;
68946885 case "Object":
6886+ case "object":
68956887 return anyType;
68966888 case "Function":
68976889 case "function":
@@ -11065,8 +11057,14 @@ namespace ts {
1106511057 if (!links.switchTypes) {
1106611058 // If all case clauses specify expressions that have unit types, we return an array
1106711059 // of those unit types. Otherwise we return an empty array.
11068- const types = map(switchStatement.caseBlock.clauses, getTypeOfSwitchClause);
11069- links.switchTypes = !contains(types, undefined) ? types : emptyArray;
11060+ links.switchTypes = [];
11061+ for (const clause of switchStatement.caseBlock.clauses) {
11062+ const type = getTypeOfSwitchClause(clause);
11063+ if (type === undefined) {
11064+ return links.switchTypes = emptyArray;
11065+ }
11066+ links.switchTypes.push(type);
11067+ }
1107011068 }
1107111069 return links.switchTypes;
1107211070 }
@@ -11875,6 +11873,8 @@ namespace ts {
1187511873 }
1187611874
1187711875 function getTypeOfSymbolAtLocation(symbol: Symbol, location: Node) {
11876+ symbol = symbol.exportSymbol || symbol;
11877+
1187811878 // If we have an identifier or a property access at the given location, if the location is
1187911879 // an dotted name expression, and if the location is not an assignment target, obtain the type
1188011880 // of the expression (which will reflect control flow analysis). If the expression indeed
@@ -18800,7 +18800,7 @@ namespace ts {
1880018800 // local symbol is undefined => this declaration is non-exported.
1880118801 // however symbol might contain other declarations that are exported
1880218802 symbol = getSymbolOfNode(node);
18803- if (!( symbol.flags & SymbolFlags.Export) ) {
18803+ if (!symbol.exportSymbol ) {
1880418804 // this is a pure local symbol (all declarations are non-exported) - no need to check anything
1880518805 return;
1880618806 }
@@ -18811,11 +18811,9 @@ namespace ts {
1881118811 return;
1881218812 }
1881318813
18814- // we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
18815- // to denote disjoint declarationSpaces (without making new enum type).
18816- let exportedDeclarationSpaces = SymbolFlags.None;
18817- let nonExportedDeclarationSpaces = SymbolFlags.None;
18818- let defaultExportedDeclarationSpaces = SymbolFlags.None;
18814+ let exportedDeclarationSpaces = DeclarationSpaces.None;
18815+ let nonExportedDeclarationSpaces = DeclarationSpaces.None;
18816+ let defaultExportedDeclarationSpaces = DeclarationSpaces.None;
1881918817 for (const d of symbol.declarations) {
1882018818 const declarationSpaces = getDeclarationSpaces(d);
1882118819 const effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, ModifierFlags.Export | ModifierFlags.Default);
@@ -18855,24 +18853,36 @@ namespace ts {
1885518853 }
1885618854 }
1885718855
18858- function getDeclarationSpaces(d: Declaration): SymbolFlags {
18856+ const enum DeclarationSpaces {
18857+ None = 0,
18858+ ExportValue = 1 << 0,
18859+ ExportType = 1 << 1,
18860+ ExportNamespace = 1 << 2,
18861+ }
18862+ function getDeclarationSpaces(d: Declaration): DeclarationSpaces {
1885918863 switch (d.kind) {
1886018864 case SyntaxKind.InterfaceDeclaration:
18861- return SymbolFlags.ExportType;
18865+ case SyntaxKind.TypeAliasDeclaration:
18866+ return DeclarationSpaces.ExportType;
1886218867 case SyntaxKind.ModuleDeclaration:
1886318868 return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
18864- ? SymbolFlags .ExportNamespace | SymbolFlags .ExportValue
18865- : SymbolFlags .ExportNamespace;
18869+ ? DeclarationSpaces .ExportNamespace | DeclarationSpaces .ExportValue
18870+ : DeclarationSpaces .ExportNamespace;
1886618871 case SyntaxKind.ClassDeclaration:
1886718872 case SyntaxKind.EnumDeclaration:
18868- return SymbolFlags .ExportType | SymbolFlags .ExportValue;
18873+ return DeclarationSpaces .ExportType | DeclarationSpaces .ExportValue;
1886918874 case SyntaxKind.ImportEqualsDeclaration:
18870- let result: SymbolFlags = 0 ;
18875+ let result = DeclarationSpaces.None ;
1887118876 const target = resolveAlias(getSymbolOfNode(d));
1887218877 forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
1887318878 return result;
18879+ case SyntaxKind.VariableDeclaration:
18880+ case SyntaxKind.BindingElement:
18881+ case SyntaxKind.FunctionDeclaration:
18882+ case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591
18883+ return DeclarationSpaces.ExportValue;
1887418884 default:
18875- return SymbolFlags.ExportValue ;
18885+ Debug.fail((ts as any).SyntaxKind[d.kind]) ;
1887618886 }
1887718887 }
1887818888 }
@@ -20909,7 +20919,7 @@ namespace ts {
2090920919 }
2091020920 }
2091120921
20912- function areTypeParametersIdentical(declarations: ( ClassDeclaration | InterfaceDeclaration)[] , typeParameters: TypeParameter[]) {
20922+ function areTypeParametersIdentical(declarations: ReadonlyArray< ClassDeclaration | InterfaceDeclaration> , typeParameters: TypeParameter[]) {
2091320923 const maxTypeArgumentCount = length(typeParameters);
2091420924 const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
2091520925
@@ -22281,11 +22291,6 @@ namespace ts {
2228122291 }
2228222292
2228322293 switch (location.kind) {
22284- case SyntaxKind.SourceFile:
22285- if (!isExternalOrCommonJsModule(<SourceFile>location)) {
22286- break;
22287- }
22288- // falls through
2228922294 case SyntaxKind.ModuleDeclaration:
2229022295 copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
2229122296 break;
@@ -22337,7 +22342,7 @@ namespace ts {
2233722342 * @param meaning meaning of symbol to filter by before adding to symbol table
2233822343 */
2233922344 function copySymbol(symbol: Symbol, meaning: SymbolFlags): void {
22340- if (symbol.flags & meaning) {
22345+ if (getCombinedLocalAndExportSymbolFlags( symbol) & meaning) {
2234122346 const id = symbol.name;
2234222347 // We will copy all symbol regardless of its reserved name because
2234322348 // symbolsToArray will check whether the key is a reserved name and
0 commit comments