Skip to content

Commit afea2dc

Browse files
author
Andy Hanson
committed
Merge branch 'master' into undefinedzilla
2 parents a369a80 + 8c2ed97 commit afea2dc

File tree

185 files changed

+3598
-2342
lines changed

Some content is hidden

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

185 files changed

+3598
-2342
lines changed

src/compiler/binder.ts

Lines changed: 75 additions & 88 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 273 additions & 159 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 33 additions & 9 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.
@@ -713,15 +722,30 @@ namespace ts {
713722
return false;
714723
}
715724

716-
export function concatenate<T>(array1: T[], array2: T[] | undefined): T[];
717-
export function concatenate<T>(array1: T[] | undefined, array2: T[]): T[];
718-
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[] | undefined;
719-
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T>): ReadonlyArray<T>;
720-
export function concatenate<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T>;
721-
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T> | undefined;
722-
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T> | undefined {
723-
if (!array2 || !array2.length) return array1;
724-
if (!array1 || !array1.length) return array2;
725+
/** Calls the callback with (start, afterEnd) index pairs for each range where 'pred' is true. */
726+
export function getRangesWhere<T>(arr: ReadonlyArray<T>, pred: (t: T) => boolean, cb: (start: number, afterEnd: number) => void): void {
727+
let start: number | undefined;
728+
for (let i = 0; i < arr.length; i++) {
729+
if (pred(arr[i])) {
730+
start = start === undefined ? i : start;
731+
}
732+
else {
733+
if (start !== undefined) {
734+
cb(start, i);
735+
start = undefined;
736+
}
737+
}
738+
}
739+
if (start !== undefined) cb(start, arr.length);
740+
}
741+
742+
export function concatenate<T>(array1: T[], array2: T[]): T[];
743+
export function concatenate<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>): ReadonlyArray<T>;
744+
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[];
745+
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T>;
746+
export function concatenate<T>(array1: T[], array2: T[]): T[] {
747+
if (!some(array2)) return array1;
748+
if (!some(array1)) return array2;
725749
return [...array1, ...array2];
726750
}
727751

src/compiler/parser.ts

Lines changed: 119 additions & 43 deletions
Large diffs are not rendered by default.

src/compiler/scanner.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,13 +1931,11 @@ namespace ts {
19311931
}
19321932

19331933
function scanJSDocToken(): JsDocSyntaxKind {
1934+
startPos = tokenPos = pos;
19341935
if (pos >= end) {
19351936
return token = SyntaxKind.EndOfFileToken;
19361937
}
19371938

1938-
startPos = pos;
1939-
tokenPos = pos;
1940-
19411939
const ch = text.charCodeAt(pos);
19421940
pos++;
19431941
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[] | undefined): 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
}
@@ -1326,4 +1336,4 @@ namespace ts {
13261336
}
13271337
return false;
13281338
}
1329-
}
1339+
}

src/compiler/types.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,11 @@ namespace ts {
413413
JSDocVariadicType,
414414
JSDocComment,
415415
JSDocTypeLiteral,
416+
JSDocSignature,
416417
JSDocTag,
417418
JSDocAugmentsTag,
418419
JSDocClassTag,
420+
JSDocCallbackTag,
419421
JSDocParameterTag,
420422
JSDocReturnTag,
421423
JSDocTypeTag,
@@ -2053,7 +2055,7 @@ namespace ts {
20532055

20542056
export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode;
20552057

2056-
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag;
2058+
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature;
20572059

20582060
export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer {
20592061
kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression;
@@ -2387,6 +2389,21 @@ namespace ts {
23872389
typeExpression?: JSDocTypeExpression | JSDocTypeLiteral;
23882390
}
23892391

2392+
export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration {
2393+
parent: JSDoc;
2394+
kind: SyntaxKind.JSDocCallbackTag;
2395+
fullName?: JSDocNamespaceDeclaration | Identifier;
2396+
name?: Identifier;
2397+
typeExpression: JSDocSignature;
2398+
}
2399+
2400+
export interface JSDocSignature extends JSDocType, Declaration {
2401+
kind: SyntaxKind.JSDocSignature;
2402+
typeParameters?: ReadonlyArray<JSDocTemplateTag>;
2403+
parameters: ReadonlyArray<JSDocParameterTag>;
2404+
type: JSDocReturnTag | undefined;
2405+
}
2406+
23902407
export interface JSDocPropertyLikeTag extends JSDocTag, Declaration {
23912408
parent: JSDoc;
23922409
name: EntityName;
@@ -3079,7 +3096,7 @@ namespace ts {
30793096
WriteArrayAsGenericType = 1 << 1, // Write Array<T> instead T[]
30803097
GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced
30813098
UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible
3082-
// empty space
3099+
ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a<x>.b<y>` instead
30833100
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
30843101
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
30853102
UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol
@@ -3678,6 +3695,8 @@ namespace ts {
36783695
ContainsAnyFunctionType = 1 << 26, // Type is or contains the anyFunctionType
36793696
NonPrimitive = 1 << 27, // intrinsic object type
36803697
/* @internal */
3698+
UnionOfUnitTypes = 1 << 28, // Type is union of unit types
3699+
/* @internal */
36813700
GenericMappedType = 1 << 29, // Flag used by maybeTypeOfKind
36823701

36833702
/* @internal */
@@ -3715,6 +3734,8 @@ namespace ts {
37153734
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
37163735
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
37173736
/* @internal */
3737+
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
3738+
/* @internal */
37183739
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
37193740
/* @internal */
37203741
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | ContainsAnyFunctionType,
@@ -4035,7 +4056,7 @@ namespace ts {
40354056
}
40364057

40374058
export interface Signature {
4038-
declaration?: SignatureDeclaration; // Originating declaration
4059+
declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration
40394060
typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic)
40404061
parameters: Symbol[]; // Parameters
40414062
/* @internal */
@@ -5247,6 +5268,13 @@ namespace ts {
52475268
isAtStartOfLine(): boolean;
52485269
}
52495270

5271+
/* @internal */
5272+
export interface ModuleNameResolverHost {
5273+
getCanonicalFileName(f: string): string;
5274+
getCommonSourceDirectory(): string;
5275+
getCurrentDirectory(): string;
5276+
}
5277+
52505278
/** @deprecated See comment on SymbolWriter */
52515279
// Note: this has non-deprecated internal uses.
52525280
export interface SymbolTracker {
@@ -5257,6 +5285,10 @@ namespace ts {
52575285
reportInaccessibleThisError?(): void;
52585286
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
52595287
reportInaccessibleUniqueSymbolError?(): void;
5288+
/* @internal */
5289+
moduleResolverHost?: ModuleNameResolverHost;
5290+
/* @internal */
5291+
trackReferencedAmbientModule?(decl: ModuleDeclaration): void;
52605292
}
52615293

52625294
export interface TextSpan {

0 commit comments

Comments
 (0)