Skip to content

Commit e4c380a

Browse files
committed
Merge branch 'master' into documentRegistery
2 parents 81ca650 + 440291e commit e4c380a

File tree

195 files changed

+3698
-2083
lines changed

Some content is hidden

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

195 files changed

+3698
-2083
lines changed

lib/lib.es2018.regexp.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ interface RegExpExecArray {
2828
groups?: {
2929
[key: string]: string
3030
}
31-
}
31+
}
32+
33+
interface RegExp {
34+
/** Returns a Boolean value indicating the state of the dotAll flag (s) used with a regular expression. Default is false. Read-only. */
35+
readonly dotAll: boolean;
36+
}

src/compiler/checker.ts

Lines changed: 211 additions & 130 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ namespace ts {
320320
return -1;
321321
}
322322

323+
export function findLastIndex<T>(array: ReadonlyArray<T>, predicate: (element: T, index: number) => boolean, startIndex?: number): number {
324+
for (let i = startIndex === undefined ? array.length - 1 : startIndex; i >= 0; i--) {
325+
if (predicate(array[i], i)) {
326+
return i;
327+
}
328+
}
329+
return -1;
330+
}
331+
323332
/**
324333
* Returns the first truthy result of `callback`, or else fails.
325334
* This is like `forEach`, but never returns undefined.
@@ -696,6 +705,23 @@ namespace ts {
696705
return false;
697706
}
698707

708+
/** Calls the callback with (start, afterEnd) index pairs for each range where 'pred' is true. */
709+
export function getRangesWhere<T>(arr: ReadonlyArray<T>, pred: (t: T) => boolean, cb: (start: number, afterEnd: number) => void): void {
710+
let start: number | undefined;
711+
for (let i = 0; i < arr.length; i++) {
712+
if (pred(arr[i])) {
713+
start = start === undefined ? i : start;
714+
}
715+
else {
716+
if (start !== undefined) {
717+
cb(start, i);
718+
start = undefined;
719+
}
720+
}
721+
}
722+
if (start !== undefined) cb(start, arr.length);
723+
}
724+
699725
export function concatenate<T>(array1: T[], array2: T[]): T[];
700726
export function concatenate<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>): ReadonlyArray<T>;
701727
export function concatenate<T>(array1: T[], array2: T[]): T[] {

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4258,8 +4258,16 @@
42584258
"category": "Message",
42594259
"code": 95051
42604260
},
4261-
"Add missing typeof": {
4261+
"Add missing 'typeof'": {
42624262
"category": "Message",
42634263
"code": 95052
4264+
},
4265+
"Remove unused label": {
4266+
"category": "Message",
4267+
"code": 95053
4268+
},
4269+
"Remove all unused labels": {
4270+
"category": "Message",
4271+
"code": 95054
42644272
}
42654273
}

src/compiler/parser.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6481,7 +6481,25 @@ namespace ts {
64816481
return finishNode(result, end);
64826482
}
64836483

6484+
function isNextNonwhitespaceTokenEndOfFile(): boolean {
6485+
// We must use infinite lookahead, as there could be any number of newlines :(
6486+
while (true) {
6487+
nextJSDocToken();
6488+
if (token() === SyntaxKind.EndOfFileToken) {
6489+
return true;
6490+
}
6491+
if (!(token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia)) {
6492+
return false;
6493+
}
6494+
}
6495+
}
6496+
64846497
function skipWhitespace(): void {
6498+
if (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) {
6499+
if (lookAhead(isNextNonwhitespaceTokenEndOfFile)) {
6500+
return; // Don't skip whitespace prior to EoF (or end of comment) - that shouldn't be included in any node's range
6501+
}
6502+
}
64856503
while (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) {
64866504
nextJSDocToken();
64876505
}
@@ -6802,6 +6820,7 @@ namespace ts {
68026820
typedefTag.comment = parseTagComments(indent);
68036821

68046822
typedefTag.typeExpression = typeExpression;
6823+
let end: number;
68056824
if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.type)) {
68066825
let child: JSDocTypeTag | JSDocPropertyTag | false;
68076826
let jsdocTypeLiteral: JSDocTypeLiteral;
@@ -6830,10 +6849,12 @@ namespace ts {
68306849
typedefTag.typeExpression = childTypeTag && childTypeTag.typeExpression && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ?
68316850
childTypeTag.typeExpression :
68326851
finishNode(jsdocTypeLiteral);
6852+
end = typedefTag.typeExpression.end;
68336853
}
68346854
}
68356855

6836-
return finishNode(typedefTag);
6856+
// Only include the characters between the name end and the next token if a comment was actually parsed out - otherwise it's just whitespace
6857+
return finishNode(typedefTag, end || typedefTag.comment !== undefined ? scanner.getStartPos() : (typedefTag.fullName || typedefTag.typeExpression || typedefTag.tagName).end);
68376858
}
68386859

68396860
function parseJSDocTypeNameWithNamespace(nested?: boolean) {
@@ -7075,7 +7096,7 @@ namespace ts {
70757096
const pos = scanner.getTokenPos();
70767097
const end = scanner.getTextPos();
70777098
const result = <Identifier>createNode(SyntaxKind.Identifier, pos);
7078-
result.escapedText = escapeLeadingUnderscores(content.substring(pos, end));
7099+
result.escapedText = escapeLeadingUnderscores(scanner.getTokenText());
70797100
finishNode(result, end);
70807101

70817102
nextJSDocToken();

src/compiler/resolutionCache.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ts {
66
finishRecordingFilesWithChangedResolutions(): Path[];
77

88
resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined): ResolvedModuleFull[];
9+
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations;
910
resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
1011

1112
invalidateResolutionOfFile(filePath: Path): void;
@@ -73,7 +74,7 @@ namespace ts {
7374
export const maxNumberOfFilesToIterateForInvalidation = 256;
7475

7576
type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
76-
(resolution: T) => R;
77+
(resolution: T) => R | undefined;
7778

7879
export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootDirForResolution: string, logChangesWhenResolvingModule: boolean): ResolutionCache {
7980
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
@@ -124,6 +125,7 @@ namespace ts {
124125
startCachingPerDirectoryResolution: clearPerDirectoryResolutions,
125126
finishCachingPerDirectoryResolution,
126127
resolveModuleNames,
128+
getResolvedModuleWithFailedLookupLocationsFromCache,
127129
resolveTypeReferenceDirectives,
128130
removeResolutionsOfFile,
129131
invalidateResolutionOfFile,
@@ -320,7 +322,7 @@ namespace ts {
320322
}
321323

322324
function resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[] {
323-
return resolveNamesWithLocalCache(
325+
return resolveNamesWithLocalCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolvedTypeReferenceDirective>(
324326
typeDirectiveNames, containingFile,
325327
resolvedTypeReferenceDirectives, perDirectoryResolvedTypeReferenceDirectives,
326328
resolveTypeReferenceDirective, getResolvedTypeReferenceDirective,
@@ -329,14 +331,19 @@ namespace ts {
329331
}
330332

331333
function resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined): ResolvedModuleFull[] {
332-
return resolveNamesWithLocalCache(
334+
return resolveNamesWithLocalCache<ResolvedModuleWithFailedLookupLocations, ResolvedModuleFull>(
333335
moduleNames, containingFile,
334336
resolvedModuleNames, perDirectoryResolvedModuleNames,
335337
resolveModuleName, getResolvedModule,
336338
reusedNames, logChangesWhenResolvingModule
337339
);
338340
}
339341

342+
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined {
343+
const cache = resolvedModuleNames.get(resolutionHost.toPath(containingFile));
344+
return cache && cache.get(moduleName);
345+
}
346+
340347
function isNodeModulesDirectory(dirPath: Path) {
341348
return endsWith(dirPath, "/node_modules");
342349
}

src/compiler/scanner.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,13 +1928,11 @@ namespace ts {
19281928
}
19291929

19301930
function scanJSDocToken(): JsDocSyntaxKind {
1931+
startPos = tokenPos = pos;
19311932
if (pos >= end) {
19321933
return token = SyntaxKind.EndOfFileToken;
19331934
}
19341935

1935-
startPos = pos;
1936-
tokenPos = pos;
1937-
19381936
const ch = text.charCodeAt(pos);
19391937
pos++;
19401938
switch (ch) {

src/compiler/transformers/declarations.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@ namespace ts {
3737
let lateStatementReplacementMap: Map<VisitResult<LateVisibilityPaintedStatement>>;
3838
let suppressNewDiagnosticContexts: boolean;
3939

40+
const host = context.getEmitHost();
4041
const symbolTracker: SymbolTracker = {
4142
trackSymbol,
4243
reportInaccessibleThisError,
4344
reportInaccessibleUniqueSymbolError,
44-
reportPrivateInBaseOfClassExpression
45+
reportPrivateInBaseOfClassExpression,
46+
moduleResolverHost: host,
47+
trackReferencedAmbientModule,
4548
};
4649
let errorNameNode: DeclarationName | undefined;
4750

4851
let currentSourceFile: SourceFile;
52+
let refs: Map<SourceFile>;
4953
const resolver = context.getEmitResolver();
5054
const options = context.getCompilerOptions();
5155
const newLine = getNewLineCharacter(options);
5256
const { noResolve, stripInternal } = options;
53-
const host = context.getEmitHost();
5457
return transformRoot;
5558

5659
function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: string[]): void {
@@ -63,6 +66,11 @@ namespace ts {
6366
}
6467
}
6568

69+
function trackReferencedAmbientModule(node: ModuleDeclaration) {
70+
const container = getSourceFileOfNode(node);
71+
refs.set("" + getOriginalNodeId(container), container);
72+
}
73+
6674
function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
6775
if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) {
6876
// Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info
@@ -197,13 +205,13 @@ namespace ts {
197205
lateMarkedStatements = undefined;
198206
lateStatementReplacementMap = createMap();
199207
necessaryTypeRefernces = undefined;
200-
const refs = collectReferences(currentSourceFile, createMap());
208+
refs = collectReferences(currentSourceFile, createMap());
201209
const references: FileReference[] = [];
202210
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath));
203211
const referenceVisitor = mapReferencesIntoArray(references, outputFilePath);
204-
refs.forEach(referenceVisitor);
205212
const statements = visitNodes(node.statements, visitDeclarationStatements);
206213
let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
214+
refs.forEach(referenceVisitor);
207215
const emittedImports = filter(combinedStatements, isAnyImportSyntax);
208216
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
209217
combinedStatements = setTextRange(createNodeArray([...combinedStatements, createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined)]), combinedStatements);
@@ -217,16 +225,18 @@ namespace ts {
217225

218226
function getFileReferenceForTypeName(typeName: string): FileReference | undefined {
219227
// Elide type references for which we have imports
220-
for (const importStatement of emittedImports) {
221-
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
222-
const expr = importStatement.moduleReference.expression;
223-
if (isStringLiteralLike(expr) && expr.text === typeName) {
228+
if (emittedImports) {
229+
for (const importStatement of emittedImports) {
230+
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
231+
const expr = importStatement.moduleReference.expression;
232+
if (isStringLiteralLike(expr) && expr.text === typeName) {
233+
return undefined;
234+
}
235+
}
236+
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
224237
return undefined;
225238
}
226239
}
227-
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
228-
return undefined;
229-
}
230240
}
231241
return { fileName: typeName, pos: -1, end: -1 };
232242
}
@@ -1325,4 +1335,4 @@ namespace ts {
13251335
}
13261336
return false;
13271337
}
1328-
}
1338+
}

src/compiler/types.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,7 @@ namespace ts {
30933093
WriteArrayAsGenericType = 1 << 1, // Write Array<T> instead T[]
30943094
GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced
30953095
UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible
3096-
// empty space
3096+
ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a<x>.b<y>` instead
30973097
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
30983098
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
30993099
UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol
@@ -3692,6 +3692,8 @@ namespace ts {
36923692
ContainsAnyFunctionType = 1 << 26, // Type is or contains the anyFunctionType
36933693
NonPrimitive = 1 << 27, // intrinsic object type
36943694
/* @internal */
3695+
UnionOfUnitTypes = 1 << 28, // Type is union of unit types
3696+
/* @internal */
36953697
GenericMappedType = 1 << 29, // Flag used by maybeTypeOfKind
36963698

36973699
/* @internal */
@@ -3729,6 +3731,8 @@ namespace ts {
37293731
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
37303732
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
37313733
/* @internal */
3734+
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
3735+
/* @internal */
37323736
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
37333737
/* @internal */
37343738
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | ContainsAnyFunctionType,
@@ -5258,6 +5262,13 @@ namespace ts {
52585262
isAtStartOfLine(): boolean;
52595263
}
52605264

5265+
/* @internal */
5266+
export interface ModuleNameResolverHost {
5267+
getCanonicalFileName(f: string): string;
5268+
getCommonSourceDirectory(): string;
5269+
getCurrentDirectory(): string;
5270+
}
5271+
52615272
/** @deprecated See comment on SymbolWriter */
52625273
// Note: this has non-deprecated internal uses.
52635274
export interface SymbolTracker {
@@ -5268,6 +5279,10 @@ namespace ts {
52685279
reportInaccessibleThisError?(): void;
52695280
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
52705281
reportInaccessibleUniqueSymbolError?(): void;
5282+
/* @internal */
5283+
moduleResolverHost?: ModuleNameResolverHost;
5284+
/* @internal */
5285+
trackReferencedAmbientModule?(decl: ModuleDeclaration): void;
52715286
}
52725287

52735288
export interface TextSpan {

0 commit comments

Comments
 (0)