Skip to content

Commit

Permalink
Merge branch 'master' into undefinedzilla
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed May 18, 2018
2 parents a369a80 + 8c2ed97 commit afea2dc
Show file tree
Hide file tree
Showing 185 changed files with 3,598 additions and 2,342 deletions.
163 changes: 75 additions & 88 deletions src/compiler/binder.ts

Large diffs are not rendered by default.

432 changes: 273 additions & 159 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

42 changes: 33 additions & 9 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ namespace ts {
return -1;
}

export function findLastIndex<T>(array: ReadonlyArray<T>, predicate: (element: T, index: number) => boolean, startIndex?: number): number {
for (let i = startIndex === undefined ? array.length - 1 : startIndex; i >= 0; i--) {
if (predicate(array[i], i)) {
return i;
}
}
return -1;
}

/**
* Returns the first truthy result of `callback`, or else fails.
* This is like `forEach`, but never returns undefined.
Expand Down Expand Up @@ -713,15 +722,30 @@ namespace ts {
return false;
}

export function concatenate<T>(array1: T[], array2: T[] | undefined): T[];
export function concatenate<T>(array1: T[] | undefined, array2: T[]): T[];
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[] | undefined;
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T>): ReadonlyArray<T>;
export function concatenate<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T>;
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T> | undefined;
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T> | undefined {
if (!array2 || !array2.length) return array1;
if (!array1 || !array1.length) return array2;
/** Calls the callback with (start, afterEnd) index pairs for each range where 'pred' is true. */
export function getRangesWhere<T>(arr: ReadonlyArray<T>, pred: (t: T) => boolean, cb: (start: number, afterEnd: number) => void): void {
let start: number | undefined;
for (let i = 0; i < arr.length; i++) {
if (pred(arr[i])) {
start = start === undefined ? i : start;
}
else {
if (start !== undefined) {
cb(start, i);
start = undefined;
}
}
}
if (start !== undefined) cb(start, arr.length);
}

export function concatenate<T>(array1: T[], array2: T[]): T[];
export function concatenate<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>): ReadonlyArray<T>;
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[];
export function concatenate<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined): ReadonlyArray<T>;
export function concatenate<T>(array1: T[], array2: T[]): T[] {
if (!some(array2)) return array1;
if (!some(array1)) return array2;
return [...array1, ...array2];
}

Expand Down
162 changes: 119 additions & 43 deletions src/compiler/parser.ts

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1931,13 +1931,11 @@ namespace ts {
}

function scanJSDocToken(): JsDocSyntaxKind {
startPos = tokenPos = pos;
if (pos >= end) {
return token = SyntaxKind.EndOfFileToken;
}

startPos = pos;
tokenPos = pos;

const ch = text.charCodeAt(pos);
pos++;
switch (ch) {
Expand Down
34 changes: 22 additions & 12 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ namespace ts {
let lateStatementReplacementMap: Map<VisitResult<LateVisibilityPaintedStatement>>;
let suppressNewDiagnosticContexts: boolean;

const host = context.getEmitHost();
const symbolTracker: SymbolTracker = {
trackSymbol,
reportInaccessibleThisError,
reportInaccessibleUniqueSymbolError,
reportPrivateInBaseOfClassExpression
reportPrivateInBaseOfClassExpression,
moduleResolverHost: host,
trackReferencedAmbientModule,
};
let errorNameNode: DeclarationName | undefined;

let currentSourceFile: SourceFile;
let refs: Map<SourceFile>;
const resolver = context.getEmitResolver();
const options = context.getCompilerOptions();
const newLine = getNewLineCharacter(options);
const { noResolve, stripInternal } = options;
const host = context.getEmitHost();
return transformRoot;

function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: string[] | undefined): void {
Expand All @@ -63,6 +66,11 @@ namespace ts {
}
}

function trackReferencedAmbientModule(node: ModuleDeclaration) {
const container = getSourceFileOfNode(node);
refs.set("" + getOriginalNodeId(container), container);
}

function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) {
// Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info
Expand Down Expand Up @@ -197,13 +205,13 @@ namespace ts {
lateMarkedStatements = undefined;
lateStatementReplacementMap = createMap();
necessaryTypeRefernces = undefined;
const refs = collectReferences(currentSourceFile, createMap());
refs = collectReferences(currentSourceFile, createMap());
const references: FileReference[] = [];
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!));
const referenceVisitor = mapReferencesIntoArray(references, outputFilePath);
refs.forEach(referenceVisitor);
const statements = visitNodes(node.statements, visitDeclarationStatements);
let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements);
refs.forEach(referenceVisitor);
const emittedImports = filter(combinedStatements, isAnyImportSyntax);
if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) {
combinedStatements = setTextRange(createNodeArray([...combinedStatements, createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined)]), combinedStatements);
Expand All @@ -217,16 +225,18 @@ namespace ts {

function getFileReferenceForTypeName(typeName: string): FileReference | undefined {
// Elide type references for which we have imports
for (const importStatement of emittedImports) {
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
const expr = importStatement.moduleReference.expression;
if (isStringLiteralLike(expr) && expr.text === typeName) {
if (emittedImports) {
for (const importStatement of emittedImports) {
if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) {
const expr = importStatement.moduleReference.expression;
if (isStringLiteralLike(expr) && expr.text === typeName) {
return undefined;
}
}
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
return undefined;
}
}
else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) {
return undefined;
}
}
return { fileName: typeName, pos: -1, end: -1 };
}
Expand Down Expand Up @@ -1326,4 +1336,4 @@ namespace ts {
}
return false;
}
}
}
38 changes: 35 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ namespace ts {
JSDocVariadicType,
JSDocComment,
JSDocTypeLiteral,
JSDocSignature,
JSDocTag,
JSDocAugmentsTag,
JSDocClassTag,
JSDocCallbackTag,
JSDocParameterTag,
JSDocReturnTag,
JSDocTypeTag,
Expand Down Expand Up @@ -2053,7 +2055,7 @@ namespace ts {

export type ObjectTypeDeclaration = ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode;

export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag;
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag | JSDocTypedefTag | JSDocCallbackTag | JSDocSignature;

export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer {
kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression;
Expand Down Expand Up @@ -2387,6 +2389,21 @@ namespace ts {
typeExpression?: JSDocTypeExpression | JSDocTypeLiteral;
}

export interface JSDocCallbackTag extends JSDocTag, NamedDeclaration {
parent: JSDoc;
kind: SyntaxKind.JSDocCallbackTag;
fullName?: JSDocNamespaceDeclaration | Identifier;
name?: Identifier;
typeExpression: JSDocSignature;
}

export interface JSDocSignature extends JSDocType, Declaration {
kind: SyntaxKind.JSDocSignature;
typeParameters?: ReadonlyArray<JSDocTemplateTag>;
parameters: ReadonlyArray<JSDocParameterTag>;
type: JSDocReturnTag | undefined;
}

export interface JSDocPropertyLikeTag extends JSDocTag, Declaration {
parent: JSDoc;
name: EntityName;
Expand Down Expand Up @@ -3079,7 +3096,7 @@ namespace ts {
WriteArrayAsGenericType = 1 << 1, // Write Array<T> instead T[]
GenerateNamesForShadowedTypeParams = 1 << 2, // When a type parameter T is shadowing another T, generate a name for it so it can still be referenced
UseStructuralFallback = 1 << 3, // When an alias cannot be named by its symbol, rather than report an error, fallback to a structural printout if possible
// empty space
ForbidIndexedAccessSymbolReferences = 1 << 4, // Forbid references like `I["a"]["b"]` - print `typeof I.a<x>.b<y>` instead
WriteTypeArgumentsOfSignature = 1 << 5, // Write the type arguments instead of type parameters of the signature
UseFullyQualifiedType = 1 << 6, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
UseOnlyExternalAliasing = 1 << 7, // Only use external aliases for a symbol
Expand Down Expand Up @@ -3678,6 +3695,8 @@ namespace ts {
ContainsAnyFunctionType = 1 << 26, // Type is or contains the anyFunctionType
NonPrimitive = 1 << 27, // intrinsic object type
/* @internal */
UnionOfUnitTypes = 1 << 28, // Type is union of unit types
/* @internal */
GenericMappedType = 1 << 29, // Flag used by maybeTypeOfKind

/* @internal */
Expand Down Expand Up @@ -3715,6 +3734,8 @@ namespace ts {
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
/* @internal */
NotUnit = Any | String | Number | Boolean | Enum | ESSymbol | Void | Never | StructuredOrInstantiable,
/* @internal */
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
/* @internal */
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | ContainsAnyFunctionType,
Expand Down Expand Up @@ -4035,7 +4056,7 @@ namespace ts {
}

export interface Signature {
declaration?: SignatureDeclaration; // Originating declaration
declaration?: SignatureDeclaration | JSDocSignature; // Originating declaration
typeParameters?: TypeParameter[]; // Type parameters (undefined if non-generic)
parameters: Symbol[]; // Parameters
/* @internal */
Expand Down Expand Up @@ -5247,6 +5268,13 @@ namespace ts {
isAtStartOfLine(): boolean;
}

/* @internal */
export interface ModuleNameResolverHost {
getCanonicalFileName(f: string): string;
getCommonSourceDirectory(): string;
getCurrentDirectory(): string;
}

/** @deprecated See comment on SymbolWriter */
// Note: this has non-deprecated internal uses.
export interface SymbolTracker {
Expand All @@ -5257,6 +5285,10 @@ namespace ts {
reportInaccessibleThisError?(): void;
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
reportInaccessibleUniqueSymbolError?(): void;
/* @internal */
moduleResolverHost?: ModuleNameResolverHost;
/* @internal */
trackReferencedAmbientModule?(decl: ModuleDeclaration): void;
}

export interface TextSpan {
Expand Down
Loading

0 comments on commit afea2dc

Please sign in to comment.