Skip to content

Commit 048e67c

Browse files
committed
Merge branch 'master' into watchImprovements
2 parents e568976 + d2ec45f commit 048e67c

94 files changed

Lines changed: 1386 additions & 888 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/compiler/binder.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,8 @@ namespace ts {
416416
}
417417
}
418418
else {
419-
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
420-
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
421-
// on it. There are 2 main reasons:
419+
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue flag,
420+
// and an associated export symbol with all the correct flags set on it. There are 2 main reasons:
422421
//
423422
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
424423
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
@@ -438,10 +437,7 @@ namespace ts {
438437
(node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier &&
439438
((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace;
440439
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
441-
const exportKind =
442-
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
443-
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
444-
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
440+
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
445441
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
446442
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
447443
node.localSymbol = local;
@@ -2288,7 +2284,7 @@ namespace ts {
22882284
// When we create a property via 'exports.foo = bar', the 'exports.foo' property access
22892285
// expression is the declaration
22902286
setCommonJsModuleIndicator(node);
2291-
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.Export, SymbolFlags.None);
2287+
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None);
22922288
}
22932289

22942290
function isExportsOrModuleExportsOrAlias(node: Node): boolean {
@@ -2329,7 +2325,7 @@ namespace ts {
23292325

23302326
// 'module.exports = expr' assignment
23312327
setCommonJsModuleIndicator(node);
2332-
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.Export | SymbolFlags.ValueModule, SymbolFlags.None);
2328+
declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule, SymbolFlags.None);
23332329
}
23342330

23352331
function bindThisPropertyAssignment(node: BinaryExpression) {

src/compiler/checker.ts

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace ts {
105105
paramType: Diagnostics.KIND,
106106
showInSimplifiedHelpView: true,
107107
category: Diagnostics.Basic_Options,
108-
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_ESNext,
108+
description: Diagnostics.Specify_module_code_generation_Colon_none_commonjs_amd_system_umd_es2015_or_ESNext,
109109
},
110110
{
111111
name: "lib",
@@ -2162,7 +2162,7 @@ namespace ts {
21622162
* @param extensionPriority The priority of the extension.
21632163
* @param context The expansion context.
21642164
*/
2165-
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
2165+
function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<string>, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
21662166
const extensionPriority = getExtensionPriority(file, extensions);
21672167
const adjustedExtensionPriority = adjustExtensionPriority(extensionPriority, extensions);
21682168
for (let i = ExtensionPriority.Highest; i < adjustedExtensionPriority; i++) {
@@ -2184,7 +2184,7 @@ namespace ts {
21842184
* @param extensionPriority The priority of the extension.
21852185
* @param context The expansion context.
21862186
*/
2187-
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: string[], keyMapper: (value: string) => string) {
2187+
function removeWildcardFilesWithLowerPriorityExtension(file: string, wildcardFiles: Map<string>, extensions: ReadonlyArray<string>, keyMapper: (value: string) => string) {
21882188
const extensionPriority = getExtensionPriority(file, extensions);
21892189
const nextExtensionPriority = getNextLowestExtensionPriority(extensionPriority, extensions);
21902190
for (let i = nextExtensionPriority; i < extensions.length; i++) {

0 commit comments

Comments
 (0)