diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 14fec7bb976..047850c3c30 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5045,42 +5045,29 @@ namespace ts { return t => t === source1 ? target1 : t === source2 ? target2 : t; } - function createTypeMapper(sources: Type[], targets: Type[]): TypeMapper { - switch (sources.length) { - case 1: return createUnaryTypeMapper(sources[0], targets[0]); - case 2: return createBinaryTypeMapper(sources[0], targets[0], sources[1], targets[1]); - } + function createArrayTypeMapper(sources: Type[], targets: Type[]): TypeMapper { return t => { for (let i = 0; i < sources.length; i++) { if (t === sources[i]) { - return targets[i]; + return targets ? targets[i] : anyType; } } return t; }; } - function createUnaryTypeEraser(source: Type): TypeMapper { - return t => t === source ? anyType : t; - } - - function createBinaryTypeEraser(source1: Type, source2: Type): TypeMapper { - return t => t === source1 || t === source2 ? anyType : t; + function createTypeMapper(sources: Type[], targets: Type[]): TypeMapper { + const count = sources.length; + const mapper: TypeMapper = + count == 1 ? createUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) : + count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) : + createArrayTypeMapper(sources, targets); + mapper.mappedTypes = sources; + return mapper; } function createTypeEraser(sources: Type[]): TypeMapper { - switch (sources.length) { - case 1: return createUnaryTypeEraser(sources[0]); - case 2: return createBinaryTypeEraser(sources[0], sources[1]); - } - return t => { - for (const source of sources) { - if (t === source) { - return anyType; - } - } - return t; - }; + return createTypeMapper(sources, undefined); } function getInferenceMapper(context: InferenceContext): TypeMapper { @@ -5095,6 +5082,7 @@ namespace ts { } return t; }; + mapper.mappedTypes = context.typeParameters; mapper.context = context; context.mapper = mapper; } @@ -5106,7 +5094,9 @@ namespace ts { } function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper { - return t => instantiateType(mapper1(t), mapper2); + const mapper: TypeMapper = t => instantiateType(mapper1(t), mapper2); + mapper.mappedTypes = mapper1.mappedTypes; + return mapper; } function cloneTypeParameter(typeParameter: TypeParameter): TypeParameter { @@ -5201,13 +5191,70 @@ namespace ts { return result; } + function isSymbolInScopeOfMappedTypeParameter(symbol: Symbol, mapper: TypeMapper) { + const mappedTypes = mapper.mappedTypes; + // Starting with the parent of the symbol's declaration, check if the mapper maps any of + // the type parameters introduced by enclosing declarations. We just pick the first + // declaration since multiple declarations will all have the same parent anyway. + let node = symbol.declarations[0].parent; + while (node) { + switch (node.kind) { + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.Constructor: + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + const declaration = node; + if (declaration.typeParameters) { + for (const d of declaration.typeParameters) { + if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(d.symbol))) { + return true; + } + } + } + if (isClassLike(node) || node.kind === SyntaxKind.InterfaceDeclaration) { + const thisType = getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node)).thisType; + if (thisType && contains(mappedTypes, thisType)) { + return true; + } + } + break; + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.SourceFile: + return false; + } + node = node.parent; + } + return false; + } + function instantiateType(type: Type, mapper: TypeMapper): Type { if (type && mapper !== identityMapper) { if (type.flags & TypeFlags.TypeParameter) { return mapper(type); } if (type.flags & TypeFlags.Anonymous) { - return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ? + // If the anonymous type originates in a declaration of a function, method, class, or + // interface, in an object type literal, or in an object literal expression, we may need + // to instantiate the type because it might reference a type parameter. We skip instantiation + // if none of the type parameters that are in scope in the type's declaration are mapped by + // the given mapper, however we can only do that analysis if the type isn't itself an + // instantiation. + return type.symbol && + type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && + (type.flags & TypeFlags.Instantiated || isSymbolInScopeOfMappedTypeParameter(type.symbol, mapper)) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & TypeFlags.Reference) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 10cae6e6ee3..282a658aa36 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1208,6 +1208,8 @@ namespace ts { block: Block; } + export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration; + export interface ClassLikeDeclaration extends Declaration { name?: Identifier; typeParameters?: NodeArray; @@ -2286,6 +2288,7 @@ namespace ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; + mappedTypes?: Type[]; // Types mapped by this mapper instantiations?: Type[]; // Cache of instantiations created using this type mapper. context?: InferenceContext; // The inference context this mapper was created from. // Only inference mappers have this set (in createInferenceMapper). diff --git a/tests/baselines/reference/bluebirdStaticThis.errors.txt b/tests/baselines/reference/bluebirdStaticThis.errors.txt new file mode 100644 index 00000000000..6e78a90db4b --- /dev/null +++ b/tests/baselines/reference/bluebirdStaticThis.errors.txt @@ -0,0 +1,164 @@ +tests/cases/compiler/bluebirdStaticThis.ts(5,15): error TS2420: Class 'Promise' incorrectly implements interface 'Thenable'. + Property 'then' is missing in type 'Promise'. +tests/cases/compiler/bluebirdStaticThis.ts(22,51): error TS2305: Module 'Promise' has no exported member 'Resolver'. +tests/cases/compiler/bluebirdStaticThis.ts(57,109): error TS2305: Module 'Promise' has no exported member 'Inspection'. +tests/cases/compiler/bluebirdStaticThis.ts(58,91): error TS2305: Module 'Promise' has no exported member 'Inspection'. +tests/cases/compiler/bluebirdStaticThis.ts(59,91): error TS2305: Module 'Promise' has no exported member 'Inspection'. +tests/cases/compiler/bluebirdStaticThis.ts(60,73): error TS2305: Module 'Promise' has no exported member 'Inspection'. + + +==== tests/cases/compiler/bluebirdStaticThis.ts (6 errors) ==== + // This version is reduced from the full d.ts by removing almost all the tests + // and all the comments. + // Then it adds explicit `this` arguments to the static members. + // Tests by: Bart van der Schoor + declare class Promise implements Promise.Thenable { + ~~~~~~~ +!!! error TS2420: Class 'Promise' incorrectly implements interface 'Thenable'. +!!! error TS2420: Property 'then' is missing in type 'Promise'. + constructor(callback: (resolve: (thenableOrResult: R | Promise.Thenable) => void, reject: (error: any) => void) => void); + static try(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static try(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static attempt(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static attempt(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static method(dit: typeof Promise, fn: Function): Function; + + static resolve(dit: typeof Promise): Promise; + static resolve(dit: typeof Promise, value: Promise.Thenable): Promise; + static resolve(dit: typeof Promise, value: R): Promise; + + static reject(dit: typeof Promise, reason: any): Promise; + static reject(dit: typeof Promise, reason: any): Promise; + + static defer(dit: typeof Promise): Promise.Resolver; + ~~~~~~~~ +!!! error TS2305: Module 'Promise' has no exported member 'Resolver'. + + static cast(dit: typeof Promise, value: Promise.Thenable): Promise; + static cast(dit: typeof Promise, value: R): Promise; + + static bind(dit: typeof Promise, thisArg: any): Promise; + + static is(dit: typeof Promise, value: any): boolean; + + static longStackTraces(dit: typeof Promise): void; + + static delay(dit: typeof Promise, value: Promise.Thenable, ms: number): Promise; + static delay(dit: typeof Promise, value: R, ms: number): Promise; + static delay(dit: typeof Promise, ms: number): Promise; + + static promisify(dit: typeof Promise, nodeFunction: Function, receiver?: any): Function; + + static promisifyAll(dit: typeof Promise, target: Object): Object; + + static coroutine(dit: typeof Promise, generatorFunction: Function): Function; + + static spawn(dit: typeof Promise, generatorFunction: Function): Promise; + + static noConflict(dit: typeof Promise): typeof Promise; + + static onPossiblyUnhandledRejection(dit: typeof Promise, handler: (reason: any) => any): void; + + static all(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static all(dit: typeof Promise, values: Promise.Thenable): Promise; + static all(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static all(dit: typeof Promise, values: R[]): Promise; + + static props(dit: typeof Promise, object: Promise): Promise; + static props(dit: typeof Promise, object: Object): Promise; + + static settle(dit: typeof Promise, values: Promise.Thenable[]>): Promise[]>; + ~~~~~~~~~~ +!!! error TS2305: Module 'Promise' has no exported member 'Inspection'. + static settle(dit: typeof Promise, values: Promise.Thenable): Promise[]>; + ~~~~~~~~~~ +!!! error TS2305: Module 'Promise' has no exported member 'Inspection'. + static settle(dit: typeof Promise, values: Promise.Thenable[]): Promise[]>; + ~~~~~~~~~~ +!!! error TS2305: Module 'Promise' has no exported member 'Inspection'. + static settle(dit: typeof Promise, values: R[]): Promise[]>; + ~~~~~~~~~~ +!!! error TS2305: Module 'Promise' has no exported member 'Inspection'. + + static any(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static any(dit: typeof Promise, values: Promise.Thenable): Promise; + static any(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static any(dit: typeof Promise, values: R[]): Promise; + + static race(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static race(dit: typeof Promise, values: Promise.Thenable): Promise; + static race(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static race(dit: typeof Promise, values: R[]): Promise; + + static some(dit: typeof Promise, values: Promise.Thenable[]>, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable[], count: number): Promise; + static some(dit: typeof Promise, values: R[], count: number): Promise; + + static join(dit: typeof Promise, ...values: Promise.Thenable[]): Promise; + static join(dit: typeof Promise, ...values: R[]): Promise; + + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + } + + declare module Promise { + export interface Thenable { + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; + } + + } + + declare module 'bluebird' { + export = Promise; + } + interface Foo { + a: number; + b: string; + } + var x: any; + var arr: any[]; + var foo: Foo; + var fooProm: Promise; + + fooProm = Promise.try(Promise, () => { + return foo; + }); + fooProm = Promise.try(Promise, () => { + return foo; + }, arr); + fooProm = Promise.try(Promise, () => { + return foo; + }, arr, x); \ No newline at end of file diff --git a/tests/baselines/reference/bluebirdStaticThis.js b/tests/baselines/reference/bluebirdStaticThis.js new file mode 100644 index 00000000000..301f32319a7 --- /dev/null +++ b/tests/baselines/reference/bluebirdStaticThis.js @@ -0,0 +1,157 @@ +//// [bluebirdStaticThis.ts] +// This version is reduced from the full d.ts by removing almost all the tests +// and all the comments. +// Then it adds explicit `this` arguments to the static members. +// Tests by: Bart van der Schoor +declare class Promise implements Promise.Thenable { + constructor(callback: (resolve: (thenableOrResult: R | Promise.Thenable) => void, reject: (error: any) => void) => void); + static try(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static try(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static attempt(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static attempt(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static method(dit: typeof Promise, fn: Function): Function; + + static resolve(dit: typeof Promise): Promise; + static resolve(dit: typeof Promise, value: Promise.Thenable): Promise; + static resolve(dit: typeof Promise, value: R): Promise; + + static reject(dit: typeof Promise, reason: any): Promise; + static reject(dit: typeof Promise, reason: any): Promise; + + static defer(dit: typeof Promise): Promise.Resolver; + + static cast(dit: typeof Promise, value: Promise.Thenable): Promise; + static cast(dit: typeof Promise, value: R): Promise; + + static bind(dit: typeof Promise, thisArg: any): Promise; + + static is(dit: typeof Promise, value: any): boolean; + + static longStackTraces(dit: typeof Promise): void; + + static delay(dit: typeof Promise, value: Promise.Thenable, ms: number): Promise; + static delay(dit: typeof Promise, value: R, ms: number): Promise; + static delay(dit: typeof Promise, ms: number): Promise; + + static promisify(dit: typeof Promise, nodeFunction: Function, receiver?: any): Function; + + static promisifyAll(dit: typeof Promise, target: Object): Object; + + static coroutine(dit: typeof Promise, generatorFunction: Function): Function; + + static spawn(dit: typeof Promise, generatorFunction: Function): Promise; + + static noConflict(dit: typeof Promise): typeof Promise; + + static onPossiblyUnhandledRejection(dit: typeof Promise, handler: (reason: any) => any): void; + + static all(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static all(dit: typeof Promise, values: Promise.Thenable): Promise; + static all(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static all(dit: typeof Promise, values: R[]): Promise; + + static props(dit: typeof Promise, object: Promise): Promise; + static props(dit: typeof Promise, object: Object): Promise; + + static settle(dit: typeof Promise, values: Promise.Thenable[]>): Promise[]>; + static settle(dit: typeof Promise, values: Promise.Thenable): Promise[]>; + static settle(dit: typeof Promise, values: Promise.Thenable[]): Promise[]>; + static settle(dit: typeof Promise, values: R[]): Promise[]>; + + static any(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static any(dit: typeof Promise, values: Promise.Thenable): Promise; + static any(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static any(dit: typeof Promise, values: R[]): Promise; + + static race(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static race(dit: typeof Promise, values: Promise.Thenable): Promise; + static race(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static race(dit: typeof Promise, values: R[]): Promise; + + static some(dit: typeof Promise, values: Promise.Thenable[]>, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable[], count: number): Promise; + static some(dit: typeof Promise, values: R[], count: number): Promise; + + static join(dit: typeof Promise, ...values: Promise.Thenable[]): Promise; + static join(dit: typeof Promise, ...values: R[]): Promise; + + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; +} + +declare module Promise { + export interface Thenable { + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; + } + +} + +declare module 'bluebird' { + export = Promise; +} +interface Foo { + a: number; + b: string; +} +var x: any; +var arr: any[]; +var foo: Foo; +var fooProm: Promise; + +fooProm = Promise.try(Promise, () => { + return foo; +}); +fooProm = Promise.try(Promise, () => { + return foo; +}, arr); +fooProm = Promise.try(Promise, () => { + return foo; +}, arr, x); + +//// [bluebirdStaticThis.js] +var x; +var arr; +var foo; +var fooProm; +fooProm = Promise.try(Promise, function () { + return foo; +}); +fooProm = Promise.try(Promise, function () { + return foo; +}, arr); +fooProm = Promise.try(Promise, function () { + return foo; +}, arr, x); diff --git a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.js b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.js new file mode 100644 index 00000000000..62a23d538c4 --- /dev/null +++ b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.js @@ -0,0 +1,295 @@ +//// [staticAnonymousTypeNotReferencingTypeParameter.ts] +// This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 +// this would cause the compiler to run out of memory. + +function outer(x: T) { + class Inner { + static y: T = x; + } + return Inner; +} +let y: number = outer(5).y; + +class ListWrapper2 { + static clone(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } + static reversed(dit: typeof ListWrapper2, array: T[]): T[] { + var a = ListWrapper2.clone(dit, array); + return a; + } +} +namespace tessst { + /** + * Iterates through 'array' by index and performs the callback on each element of array until the callback + * returns a truthy value, then returns that value. + * If no such value is found, the callback is applied to each element of array and undefined is returned. + */ + export function funkyFor(array: T[], callback: (element: T, index: number) => U): U { + if (array) { + for (let i = 0, len = array.length; i < len; i++) { + const result = callback(array[i], i); + if (result) { + return result; + } + } + } + return undefined; + } +} +interface Scanner { + scanRange(start: number, length: number, callback: () => T): T; +} +class ListWrapper { + // JS has no way to express a statically fixed size list, but dart does so we + // keep both methods. + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + static clone(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } + static forEachWithIndex(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { + for (var i = 0; i < array.length; i++) { + fn(array[i], i); + } + } + static first(dit: typeof ListWrapper, array: T[]): T { + if (!array) return null; + return array[0]; + } + static last(dit: typeof ListWrapper, array: T[]): T { + if (!array || array.length == 0) return null; + return array[array.length - 1]; + } + static indexOf(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { + return array.indexOf(value, startIndex); + } + static contains(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } + static reversed(dit: typeof ListWrapper, array: T[]): T[] { + var a = ListWrapper.clone(dit, array); + let scanner: Scanner; + scanner.scanRange(3, 5, () => { }); + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; + } + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } + static insert(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } + static removeAt(dit: typeof ListWrapper, list: T[], index: number): T { + var res = list[index]; + list.splice(index, 1); + return res; + } + static removeAll(dit: typeof ListWrapper, list: T[], items: T[]) { + for (var i = 0; i < items.length; ++i) { + var index = list.indexOf(items[i]); + list.splice(index, 1); + } + } + static remove(dit: typeof ListWrapper, list: T[], el: T): boolean { + var index = list.indexOf(el); + if (index > -1) { + list.splice(index, 1); + return true; + } + return false; + } + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { + list.fill(value, start, end === null ? list.length : end); + } + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; + } + static slice(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { + return l.slice(from, to === null ? undefined : to); + } + static splice(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } + static sort(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { + if (isPresent(compareFn)) { + l.sort(compareFn); + } else { + l.sort(); + } + } + static toString(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } + static toJSON(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } + + static maximum(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { + if (list.length == 0) { + return null; + } + var solution: T = null; + var maxValue = -Infinity; + for (var index = 0; index < list.length; index++) { + var candidate = list[index]; + if (isBlank(candidate)) { + continue; + } + var candidateValue = predicate(candidate); + if (candidateValue > maxValue) { + solution = candidate; + maxValue = candidateValue; + } + } + return solution; + } +} +let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); +declare function isBlank(x: any): boolean; +declare function isPresent(compareFn?: (a: T, b: T) => number): boolean; +interface Array { + fill(value: any, start: number, end: number): void; +} + +//// [staticAnonymousTypeNotReferencingTypeParameter.js] +// This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 +// this would cause the compiler to run out of memory. +function outer(x) { + var Inner = (function () { + function Inner() { + } + Inner.y = x; + return Inner; + }()); + return Inner; +} +var y = outer(5).y; +var ListWrapper2 = (function () { + function ListWrapper2() { + } + ListWrapper2.clone = function (dit, array) { return array.slice(0); }; + ListWrapper2.reversed = function (dit, array) { + var a = ListWrapper2.clone(dit, array); + return a; + }; + return ListWrapper2; +}()); +var tessst; +(function (tessst) { + /** + * Iterates through 'array' by index and performs the callback on each element of array until the callback + * returns a truthy value, then returns that value. + * If no such value is found, the callback is applied to each element of array and undefined is returned. + */ + function funkyFor(array, callback) { + if (array) { + for (var i = 0, len = array.length; i < len; i++) { + var result = callback(array[i], i); + if (result) { + return result; + } + } + } + return undefined; + } + tessst.funkyFor = funkyFor; +})(tessst || (tessst = {})); +var ListWrapper = (function () { + function ListWrapper() { + } + // JS has no way to express a statically fixed size list, but dart does so we + // keep both methods. + ListWrapper.createFixedSize = function (dit, size) { return new Array(size); }; + ListWrapper.createGrowableSize = function (dit, size) { return new Array(size); }; + ListWrapper.clone = function (dit, array) { return array.slice(0); }; + ListWrapper.forEachWithIndex = function (dit, array, fn) { + for (var i = 0; i < array.length; i++) { + fn(array[i], i); + } + }; + ListWrapper.first = function (dit, array) { + if (!array) + return null; + return array[0]; + }; + ListWrapper.last = function (dit, array) { + if (!array || array.length == 0) + return null; + return array[array.length - 1]; + }; + ListWrapper.indexOf = function (dit, array, value, startIndex) { + if (startIndex === void 0) { startIndex = 0; } + return array.indexOf(value, startIndex); + }; + ListWrapper.contains = function (dit, list, el) { return list.indexOf(el) !== -1; }; + ListWrapper.reversed = function (dit, array) { + var a = ListWrapper.clone(dit, array); + var scanner; + scanner.scanRange(3, 5, function () { }); + return tessst.funkyFor(array, function (t) { return t.toString(); }) ? a.reverse() : a; + }; + ListWrapper.concat = function (dit, a, b) { return a.concat(b); }; + ListWrapper.insert = function (dit, list, index, value) { list.splice(index, 0, value); }; + ListWrapper.removeAt = function (dit, list, index) { + var res = list[index]; + list.splice(index, 1); + return res; + }; + ListWrapper.removeAll = function (dit, list, items) { + for (var i = 0; i < items.length; ++i) { + var index = list.indexOf(items[i]); + list.splice(index, 1); + } + }; + ListWrapper.remove = function (dit, list, el) { + var index = list.indexOf(el); + if (index > -1) { + list.splice(index, 1); + return true; + } + return false; + }; + ListWrapper.clear = function (dit, list) { list.length = 0; }; + ListWrapper.isEmpty = function (dit, list) { return list.length == 0; }; + ListWrapper.fill = function (dit, list, value, start, end) { + if (start === void 0) { start = 0; } + if (end === void 0) { end = null; } + list.fill(value, start, end === null ? list.length : end); + }; + ListWrapper.equals = function (dit, a, b) { + if (a.length != b.length) + return false; + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) + return false; + } + return true; + }; + ListWrapper.slice = function (dit, l, from, to) { + if (from === void 0) { from = 0; } + if (to === void 0) { to = null; } + return l.slice(from, to === null ? undefined : to); + }; + ListWrapper.splice = function (dit, l, from, length) { return l.splice(from, length); }; + ListWrapper.sort = function (dit, l, compareFn) { + if (isPresent(compareFn)) { + l.sort(compareFn); + } + else { + l.sort(); + } + }; + ListWrapper.toString = function (dit, l) { return l.toString(); }; + ListWrapper.toJSON = function (dit, l) { return JSON.stringify(l); }; + ListWrapper.maximum = function (dit, list, predicate) { + if (list.length == 0) { + return null; + } + var solution = null; + var maxValue = -Infinity; + for (var index = 0; index < list.length; index++) { + var candidate = list[index]; + if (isBlank(candidate)) { + continue; + } + var candidateValue = predicate(candidate); + if (candidateValue > maxValue) { + solution = candidate; + maxValue = candidateValue; + } + } + return solution; + }; + return ListWrapper; +}()); +var cloned = ListWrapper.clone(ListWrapper, [1, 2, 3, 4]); diff --git a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.symbols b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.symbols new file mode 100644 index 00000000000..2d39eec74e6 --- /dev/null +++ b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.symbols @@ -0,0 +1,667 @@ +=== tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts === +// This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 +// this would cause the compiler to run out of memory. + +function outer(x: T) { +>outer : Symbol(outer, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 0, 0)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 15)) +>x : Symbol(x, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 18)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 15)) + + class Inner { +>Inner : Symbol(Inner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 25)) + + static y: T = x; +>y : Symbol(Inner.y, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 4, 15)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 15)) +>x : Symbol(x, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 18)) + } + return Inner; +>Inner : Symbol(Inner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 3, 25)) +} +let y: number = outer(5).y; +>y : Symbol(y, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 9, 3)) +>outer(5).y : Symbol(Inner.y, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 4, 15)) +>outer : Symbol(outer, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 0, 0)) +>y : Symbol(Inner.y, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 4, 15)) + +class ListWrapper2 { +>ListWrapper2 : Symbol(ListWrapper2, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 9, 27)) + + static clone(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } +>clone : Symbol(ListWrapper2.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 11, 20)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 15)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 18)) +>ListWrapper2 : Symbol(ListWrapper2, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 9, 27)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 15)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 15)) +>array.slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 43)) +>slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) + + static reversed(dit: typeof ListWrapper2, array: T[]): T[] { +>reversed : Symbol(ListWrapper2.reversed, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 12, 87)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 18)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 21)) +>ListWrapper2 : Symbol(ListWrapper2, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 9, 27)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 46)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 18)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 18)) + + var a = ListWrapper2.clone(dit, array); +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 14, 7)) +>ListWrapper2.clone : Symbol(ListWrapper2.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 11, 20)) +>ListWrapper2 : Symbol(ListWrapper2, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 9, 27)) +>clone : Symbol(ListWrapper2.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 11, 20)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 21)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 13, 46)) + + return a; +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 14, 7)) + } +} +namespace tessst { +>tessst : Symbol(tessst, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 17, 1)) + + /** + * Iterates through 'array' by index and performs the callback on each element of array until the callback + * returns a truthy value, then returns that value. + * If no such value is found, the callback is applied to each element of array and undefined is returned. + */ + export function funkyFor(array: T[], callback: (element: T, index: number) => U): U { +>funkyFor : Symbol(funkyFor, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 18, 18)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 29)) +>U : Symbol(U, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 31)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 35)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 29)) +>callback : Symbol(callback, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 46)) +>element : Symbol(element, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 58)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 29)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 69)) +>U : Symbol(U, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 31)) +>U : Symbol(U, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 31)) + + if (array) { +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 35)) + + for (let i = 0, len = array.length; i < len; i++) { +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 20)) +>len : Symbol(len, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 27)) +>array.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 35)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 20)) +>len : Symbol(len, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 27)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 20)) + + const result = callback(array[i], i); +>result : Symbol(result, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 27, 21)) +>callback : Symbol(callback, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 46)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 24, 35)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 20)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 26, 20)) + + if (result) { +>result : Symbol(result, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 27, 21)) + + return result; +>result : Symbol(result, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 27, 21)) + } + } + } + return undefined; +>undefined : Symbol(undefined) + } +} +interface Scanner { +>Scanner : Symbol(Scanner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 35, 1)) + + scanRange(start: number, length: number, callback: () => T): T; +>scanRange : Symbol(scanRange, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 36, 19)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 12)) +>start : Symbol(start, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 15)) +>length : Symbol(length, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 29)) +>callback : Symbol(callback, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 45)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 12)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 37, 12)) +} +class ListWrapper { +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) + + // JS has no way to express a statically fixed size list, but dart does so we + // keep both methods. + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } +>createFixedSize : Symbol(ListWrapper.createFixedSize, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 39, 19)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 42, 25)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>size : Symbol(size, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 42, 49)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 75)) +>size : Symbol(size, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 42, 49)) + + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } +>createGrowableSize : Symbol(ListWrapper.createGrowableSize, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 42, 98)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 28)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>size : Symbol(size, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 52)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 75)) +>size : Symbol(size, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 52)) + + static clone(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } +>clone : Symbol(ListWrapper.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 101)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 15)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 18)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 42)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 15)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 15)) +>array.slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 42)) +>slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) + + static forEachWithIndex(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { +>forEachWithIndex : Symbol(ListWrapper.forEachWithIndex, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 44, 86)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 26)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 29)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 53)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 26)) +>fn : Symbol(fn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 65)) +>t : Symbol(t, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 71)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 26)) +>n : Symbol(n, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 76)) + + for (var i = 0; i < array.length; i++) { +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 46, 12)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 46, 12)) +>array.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 53)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 46, 12)) + + fn(array[i], i); +>fn : Symbol(fn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 65)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 45, 53)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 46, 12)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 46, 12)) + } + } + static first(dit: typeof ListWrapper, array: T[]): T { +>first : Symbol(ListWrapper.first, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 49, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 15)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 18)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 42)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 15)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 15)) + + if (!array) return null; +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 42)) + + return array[0]; +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 50, 42)) + } + static last(dit: typeof ListWrapper, array: T[]): T { +>last : Symbol(ListWrapper.last, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 53, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 14)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 17)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 41)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 14)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 14)) + + if (!array || array.length == 0) return null; +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 41)) +>array.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 41)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + + return array[array.length - 1]; +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 41)) +>array.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 54, 41)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + } + static indexOf(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { +>indexOf : Symbol(ListWrapper.indexOf, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 57, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 17)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 20)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 44)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 17)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 56)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 17)) +>startIndex : Symbol(startIndex, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 66)) + + return array.indexOf(value, startIndex); +>array.indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 44)) +>indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 56)) +>startIndex : Symbol(startIndex, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 58, 66)) + } + static contains(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } +>contains : Symbol(ListWrapper.contains, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 60, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 18)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 21)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 45)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 18)) +>el : Symbol(el, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 56)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 18)) +>list.indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 45)) +>indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>el : Symbol(el, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 56)) + + static reversed(dit: typeof ListWrapper, array: T[]): T[] { +>reversed : Symbol(ListWrapper.reversed, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 61, 108)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 18)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 21)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 45)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 18)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 18)) + + var a = ListWrapper.clone(dit, array); +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 63, 7)) +>ListWrapper.clone : Symbol(ListWrapper.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 101)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>clone : Symbol(ListWrapper.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 101)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 21)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 45)) + + let scanner: Scanner; +>scanner : Symbol(scanner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 64, 7)) +>Scanner : Symbol(Scanner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 35, 1)) + + scanner.scanRange(3, 5, () => { }); +>scanner.scanRange : Symbol(Scanner.scanRange, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 36, 19)) +>scanner : Symbol(scanner, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 64, 7)) +>scanRange : Symbol(Scanner.scanRange, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 36, 19)) + + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; +>tessst.funkyFor : Symbol(tessst.funkyFor, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 18, 18)) +>tessst : Symbol(tessst, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 17, 1)) +>funkyFor : Symbol(tessst.funkyFor, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 18, 18)) +>array : Symbol(array, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 62, 45)) +>t : Symbol(t, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 66, 33)) +>t.toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) +>t : Symbol(t, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 66, 33)) +>toString : Symbol(Object.toString, Decl(lib.d.ts, --, --)) +>a.reverse : Symbol(Array.reverse, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 63, 7)) +>reverse : Symbol(Array.reverse, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 63, 7)) + } + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } +>concat : Symbol(ListWrapper.concat, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 67, 3)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 16)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 40)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 50)) +>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 40)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 50)) + + static insert(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } +>insert : Symbol(ListWrapper.insert, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 68, 91)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 16)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 19)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 16)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 54)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 69)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 16)) +>list.splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 43)) +>splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 54)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 69)) + + static removeAt(dit: typeof ListWrapper, list: T[], index: number): T { +>removeAt : Symbol(ListWrapper.removeAt, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 69, 113)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 18)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 21)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 45)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 18)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 56)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 18)) + + var res = list[index]; +>res : Symbol(res, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 71, 7)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 45)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 56)) + + list.splice(index, 1); +>list.splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 45)) +>splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 70, 56)) + + return res; +>res : Symbol(res, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 71, 7)) + } + static removeAll(dit: typeof ListWrapper, list: T[], items: T[]) { +>removeAll : Symbol(ListWrapper.removeAll, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 74, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 19)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 22)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 46)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 19)) +>items : Symbol(items, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 57)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 19)) + + for (var i = 0; i < items.length; ++i) { +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 76, 12)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 76, 12)) +>items.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>items : Symbol(items, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 57)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 76, 12)) + + var index = list.indexOf(items[i]); +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 77, 9)) +>list.indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 46)) +>indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>items : Symbol(items, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 57)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 76, 12)) + + list.splice(index, 1); +>list.splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 75, 46)) +>splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 77, 9)) + } + } + static remove(dit: typeof ListWrapper, list: T[], el: T): boolean { +>remove : Symbol(ListWrapper.remove, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 80, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 16)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 19)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 16)) +>el : Symbol(el, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 54)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 16)) + + var index = list.indexOf(el); +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 82, 7)) +>list.indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 43)) +>indexOf : Symbol(Array.indexOf, Decl(lib.d.ts, --, --)) +>el : Symbol(el, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 54)) + + if (index > -1) { +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 82, 7)) + + list.splice(index, 1); +>list.splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 81, 43)) +>splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 82, 7)) + + return true; + } + return false; + } + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } +>clear : Symbol(ListWrapper.clear, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 88, 3)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 89, 15)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 89, 39)) +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 89, 39)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } +>isEmpty : Symbol(ListWrapper.isEmpty, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 89, 73)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 90, 17)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 90, 41)) +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 90, 41)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { +>fill : Symbol(ListWrapper.fill, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 90, 92)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 14)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 38)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 51)) +>start : Symbol(start, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 63)) +>end : Symbol(end, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 82)) + + list.fill(value, start, end === null ? list.length : end); +>list.fill : Symbol(Array.fill, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 138, 20)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 38)) +>fill : Symbol(Array.fill, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 138, 20)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 51)) +>start : Symbol(start, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 63)) +>end : Symbol(end, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 82)) +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 38)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>end : Symbol(end, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 91, 82)) + } + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { +>equals : Symbol(ListWrapper.equals, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 93, 3)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 16)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 40)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 50)) + + if (a.length != b.length) return false; +>a.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 40)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>b.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 50)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + + for (var i = 0; i < a.length; ++i) { +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 96, 12)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 96, 12)) +>a.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 40)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 96, 12)) + + if (a[i] !== b[i]) return false; +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 40)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 96, 12)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 94, 50)) +>i : Symbol(i, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 96, 12)) + } + return true; + } + static slice(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { +>slice : Symbol(ListWrapper.slice, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 100, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 15)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 18)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 42)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 15)) +>from : Symbol(from, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 50)) +>to : Symbol(to, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 68)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 15)) + + return l.slice(from, to === null ? undefined : to); +>l.slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 42)) +>slice : Symbol(Array.slice, Decl(lib.d.ts, --, --)) +>from : Symbol(from, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 50)) +>to : Symbol(to, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 68)) +>undefined : Symbol(undefined) +>to : Symbol(to, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 101, 68)) + } + static splice(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } +>splice : Symbol(ListWrapper.splice, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 103, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 16)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 19)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 16)) +>from : Symbol(from, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 51)) +>length : Symbol(length, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 65)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 16)) +>l.splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 43)) +>splice : Symbol(Array.splice, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>from : Symbol(from, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 51)) +>length : Symbol(length, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 65)) + + static sort(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { +>sort : Symbol(ListWrapper.sort, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 104, 121)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 14)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 17)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 41)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 14)) +>compareFn : Symbol(compareFn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 49)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 63)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 14)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 68)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 14)) + + if (isPresent(compareFn)) { +>isPresent : Symbol(isPresent, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 136, 42)) +>compareFn : Symbol(compareFn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 49)) + + l.sort(compareFn); +>l.sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 41)) +>sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) +>compareFn : Symbol(compareFn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 49)) + + } else { + l.sort(); +>l.sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 105, 41)) +>sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) + } + } + static toString(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } +>toString : Symbol(ListWrapper.toString, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 111, 3)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 18)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 21)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 45)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 18)) +>l.toString : Symbol(Array.toString, Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 45)) +>toString : Symbol(Array.toString, Decl(lib.d.ts, --, --)) + + static toJSON(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } +>toJSON : Symbol(ListWrapper.toJSON, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 112, 86)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 16)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 19)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 16)) +>JSON.stringify : Symbol(JSON.stringify, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>JSON : Symbol(JSON, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>stringify : Symbol(JSON.stringify, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>l : Symbol(l, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 43)) + + static maximum(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { +>maximum : Symbol(ListWrapper.maximum, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 113, 89)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 17)) +>dit : Symbol(dit, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 20)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 44)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 17)) +>predicate : Symbol(predicate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 55)) +>t : Symbol(t, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 68)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 17)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 17)) + + if (list.length == 0) { +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 44)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) + + return null; + } + var solution: T = null; +>solution : Symbol(solution, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 119, 7)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 17)) + + var maxValue = -Infinity; +>maxValue : Symbol(maxValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 120, 7)) +>Infinity : Symbol(Infinity, Decl(lib.d.ts, --, --)) + + for (var index = 0; index < list.length; index++) { +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 121, 12)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 121, 12)) +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 44)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 121, 12)) + + var candidate = list[index]; +>candidate : Symbol(candidate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 122, 9)) +>list : Symbol(list, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 44)) +>index : Symbol(index, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 121, 12)) + + if (isBlank(candidate)) { +>isBlank : Symbol(isBlank, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 135, 55)) +>candidate : Symbol(candidate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 122, 9)) + + continue; + } + var candidateValue = predicate(candidate); +>candidateValue : Symbol(candidateValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 126, 9)) +>predicate : Symbol(predicate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 115, 55)) +>candidate : Symbol(candidate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 122, 9)) + + if (candidateValue > maxValue) { +>candidateValue : Symbol(candidateValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 126, 9)) +>maxValue : Symbol(maxValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 120, 7)) + + solution = candidate; +>solution : Symbol(solution, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 119, 7)) +>candidate : Symbol(candidate, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 122, 9)) + + maxValue = candidateValue; +>maxValue : Symbol(maxValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 120, 7)) +>candidateValue : Symbol(candidateValue, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 126, 9)) + } + } + return solution; +>solution : Symbol(solution, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 119, 7)) + } +} +let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); +>cloned : Symbol(cloned, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 135, 3)) +>ListWrapper.clone : Symbol(ListWrapper.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 101)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) +>clone : Symbol(ListWrapper.clone, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 43, 101)) +>ListWrapper : Symbol(ListWrapper, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 38, 1)) + +declare function isBlank(x: any): boolean; +>isBlank : Symbol(isBlank, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 135, 55)) +>x : Symbol(x, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 136, 25)) + +declare function isPresent(compareFn?: (a: T, b: T) => number): boolean; +>isPresent : Symbol(isPresent, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 136, 42)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 27)) +>compareFn : Symbol(compareFn, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 30)) +>a : Symbol(a, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 43)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 27)) +>b : Symbol(b, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 48)) +>T : Symbol(T, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 27)) + +interface Array { +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 137, 75)) +>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 138, 16)) + + fill(value: any, start: number, end: number): void; +>fill : Symbol(fill, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 138, 20)) +>value : Symbol(value, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 139, 6)) +>start : Symbol(start, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 139, 17)) +>end : Symbol(end, Decl(staticAnonymousTypeNotReferencingTypeParameter.ts, 139, 32)) +} diff --git a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types new file mode 100644 index 00000000000..90148bdbb19 --- /dev/null +++ b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types @@ -0,0 +1,787 @@ +=== tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts === +// This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 +// this would cause the compiler to run out of memory. + +function outer(x: T) { +>outer : (x: T) => typeof Inner +>T : T +>x : T +>T : T + + class Inner { +>Inner : Inner + + static y: T = x; +>y : T +>T : T +>x : T + } + return Inner; +>Inner : typeof Inner +} +let y: number = outer(5).y; +>y : number +>outer(5).y : number +>outer(5) : typeof Inner +>outer : (x: T) => typeof Inner +>5 : number +>y : number + +class ListWrapper2 { +>ListWrapper2 : ListWrapper2 + + static clone(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } +>clone : (dit: typeof ListWrapper2, array: T[]) => T[] +>T : T +>dit : typeof ListWrapper2 +>ListWrapper2 : typeof ListWrapper2 +>array : T[] +>T : T +>T : T +>array.slice(0) : T[] +>array.slice : (start?: number, end?: number) => T[] +>array : T[] +>slice : (start?: number, end?: number) => T[] +>0 : number + + static reversed(dit: typeof ListWrapper2, array: T[]): T[] { +>reversed : (dit: typeof ListWrapper2, array: T[]) => T[] +>T : T +>dit : typeof ListWrapper2 +>ListWrapper2 : typeof ListWrapper2 +>array : T[] +>T : T +>T : T + + var a = ListWrapper2.clone(dit, array); +>a : T[] +>ListWrapper2.clone(dit, array) : T[] +>ListWrapper2.clone : (dit: typeof ListWrapper2, array: T[]) => T[] +>ListWrapper2 : typeof ListWrapper2 +>clone : (dit: typeof ListWrapper2, array: T[]) => T[] +>dit : typeof ListWrapper2 +>array : T[] + + return a; +>a : T[] + } +} +namespace tessst { +>tessst : typeof tessst + + /** + * Iterates through 'array' by index and performs the callback on each element of array until the callback + * returns a truthy value, then returns that value. + * If no such value is found, the callback is applied to each element of array and undefined is returned. + */ + export function funkyFor(array: T[], callback: (element: T, index: number) => U): U { +>funkyFor : (array: T[], callback: (element: T, index: number) => U) => U +>T : T +>U : U +>array : T[] +>T : T +>callback : (element: T, index: number) => U +>element : T +>T : T +>index : number +>U : U +>U : U + + if (array) { +>array : T[] + + for (let i = 0, len = array.length; i < len; i++) { +>i : number +>0 : number +>len : number +>array.length : number +>array : T[] +>length : number +>i < len : boolean +>i : number +>len : number +>i++ : number +>i : number + + const result = callback(array[i], i); +>result : U +>callback(array[i], i) : U +>callback : (element: T, index: number) => U +>array[i] : T +>array : T[] +>i : number +>i : number + + if (result) { +>result : U + + return result; +>result : U + } + } + } + return undefined; +>undefined : undefined + } +} +interface Scanner { +>Scanner : Scanner + + scanRange(start: number, length: number, callback: () => T): T; +>scanRange : (start: number, length: number, callback: () => T) => T +>T : T +>start : number +>length : number +>callback : () => T +>T : T +>T : T +} +class ListWrapper { +>ListWrapper : ListWrapper + + // JS has no way to express a statically fixed size list, but dart does so we + // keep both methods. + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } +>createFixedSize : (dit: typeof ListWrapper, size: number) => any[] +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>size : number +>new Array(size) : any[] +>Array : ArrayConstructor +>size : number + + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } +>createGrowableSize : (dit: typeof ListWrapper, size: number) => any[] +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>size : number +>new Array(size) : any[] +>Array : ArrayConstructor +>size : number + + static clone(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } +>clone : (dit: typeof ListWrapper, array: T[]) => T[] +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>T : T +>array.slice(0) : T[] +>array.slice : (start?: number, end?: number) => T[] +>array : T[] +>slice : (start?: number, end?: number) => T[] +>0 : number + + static forEachWithIndex(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { +>forEachWithIndex : (dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) => void +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>fn : (t: T, n: number) => void +>t : T +>T : T +>n : number + + for (var i = 0; i < array.length; i++) { +>i : number +>0 : number +>i < array.length : boolean +>i : number +>array.length : number +>array : T[] +>length : number +>i++ : number +>i : number + + fn(array[i], i); +>fn(array[i], i) : void +>fn : (t: T, n: number) => void +>array[i] : T +>array : T[] +>i : number +>i : number + } + } + static first(dit: typeof ListWrapper, array: T[]): T { +>first : (dit: typeof ListWrapper, array: T[]) => T +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>T : T + + if (!array) return null; +>!array : boolean +>array : T[] +>null : null + + return array[0]; +>array[0] : T +>array : T[] +>0 : number + } + static last(dit: typeof ListWrapper, array: T[]): T { +>last : (dit: typeof ListWrapper, array: T[]) => T +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>T : T + + if (!array || array.length == 0) return null; +>!array || array.length == 0 : boolean +>!array : boolean +>array : T[] +>array.length == 0 : boolean +>array.length : number +>array : T[] +>length : number +>0 : number +>null : null + + return array[array.length - 1]; +>array[array.length - 1] : T +>array : T[] +>array.length - 1 : number +>array.length : number +>array : T[] +>length : number +>1 : number + } + static indexOf(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { +>indexOf : (dit: typeof ListWrapper, array: T[], value: T, startIndex?: number) => number +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>value : T +>T : T +>startIndex : number +>0 : number + + return array.indexOf(value, startIndex); +>array.indexOf(value, startIndex) : number +>array.indexOf : (searchElement: T, fromIndex?: number) => number +>array : T[] +>indexOf : (searchElement: T, fromIndex?: number) => number +>value : T +>startIndex : number + } + static contains(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } +>contains : (dit: typeof ListWrapper, list: T[], el: T) => boolean +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>el : T +>T : T +>list.indexOf(el) !== -1 : boolean +>list.indexOf(el) : number +>list.indexOf : (searchElement: T, fromIndex?: number) => number +>list : T[] +>indexOf : (searchElement: T, fromIndex?: number) => number +>el : T +>-1 : number +>1 : number + + static reversed(dit: typeof ListWrapper, array: T[]): T[] { +>reversed : (dit: typeof ListWrapper, array: T[]) => T[] +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>array : T[] +>T : T +>T : T + + var a = ListWrapper.clone(dit, array); +>a : T[] +>ListWrapper.clone(dit, array) : T[] +>ListWrapper.clone : (dit: typeof ListWrapper, array: T[]) => T[] +>ListWrapper : typeof ListWrapper +>clone : (dit: typeof ListWrapper, array: T[]) => T[] +>dit : typeof ListWrapper +>array : T[] + + let scanner: Scanner; +>scanner : Scanner +>Scanner : Scanner + + scanner.scanRange(3, 5, () => { }); +>scanner.scanRange(3, 5, () => { }) : void +>scanner.scanRange : (start: number, length: number, callback: () => T) => T +>scanner : Scanner +>scanRange : (start: number, length: number, callback: () => T) => T +>3 : number +>5 : number +>() => { } : () => void + + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; +>tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a : T[] +>tessst.funkyFor(array, t => t.toString()) : string +>tessst.funkyFor : (array: T[], callback: (element: T, index: number) => U) => U +>tessst : typeof tessst +>funkyFor : (array: T[], callback: (element: T, index: number) => U) => U +>array : T[] +>t => t.toString() : (t: T) => string +>t : T +>t.toString() : string +>t.toString : () => string +>t : T +>toString : () => string +>a.reverse() : T[] +>a.reverse : () => T[] +>a : T[] +>reverse : () => T[] +>a : T[] + } + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } +>concat : (dit: typeof ListWrapper, a: any[], b: any[]) => any[] +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>a : any[] +>b : any[] +>a.concat(b) : any[] +>a.concat : (...items: any[]) => any[] +>a : any[] +>concat : (...items: any[]) => any[] +>b : any[] + + static insert(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } +>insert : (dit: typeof ListWrapper, list: T[], index: number, value: T) => void +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>index : number +>value : T +>T : T +>list.splice(index, 0, value) : T[] +>list.splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>list : T[] +>splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>index : number +>0 : number +>value : T + + static removeAt(dit: typeof ListWrapper, list: T[], index: number): T { +>removeAt : (dit: typeof ListWrapper, list: T[], index: number) => T +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>index : number +>T : T + + var res = list[index]; +>res : T +>list[index] : T +>list : T[] +>index : number + + list.splice(index, 1); +>list.splice(index, 1) : T[] +>list.splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>list : T[] +>splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>index : number +>1 : number + + return res; +>res : T + } + static removeAll(dit: typeof ListWrapper, list: T[], items: T[]) { +>removeAll : (dit: typeof ListWrapper, list: T[], items: T[]) => void +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>items : T[] +>T : T + + for (var i = 0; i < items.length; ++i) { +>i : number +>0 : number +>i < items.length : boolean +>i : number +>items.length : number +>items : T[] +>length : number +>++i : number +>i : number + + var index = list.indexOf(items[i]); +>index : number +>list.indexOf(items[i]) : number +>list.indexOf : (searchElement: T, fromIndex?: number) => number +>list : T[] +>indexOf : (searchElement: T, fromIndex?: number) => number +>items[i] : T +>items : T[] +>i : number + + list.splice(index, 1); +>list.splice(index, 1) : T[] +>list.splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>list : T[] +>splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>index : number +>1 : number + } + } + static remove(dit: typeof ListWrapper, list: T[], el: T): boolean { +>remove : (dit: typeof ListWrapper, list: T[], el: T) => boolean +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>el : T +>T : T + + var index = list.indexOf(el); +>index : number +>list.indexOf(el) : number +>list.indexOf : (searchElement: T, fromIndex?: number) => number +>list : T[] +>indexOf : (searchElement: T, fromIndex?: number) => number +>el : T + + if (index > -1) { +>index > -1 : boolean +>index : number +>-1 : number +>1 : number + + list.splice(index, 1); +>list.splice(index, 1) : T[] +>list.splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>list : T[] +>splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>index : number +>1 : number + + return true; +>true : boolean + } + return false; +>false : boolean + } + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } +>clear : (dit: typeof ListWrapper, list: any[]) => void +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : any[] +>list.length = 0 : number +>list.length : number +>list : any[] +>length : number +>0 : number + + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } +>isEmpty : (dit: typeof ListWrapper, list: any[]) => boolean +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : any[] +>list.length == 0 : boolean +>list.length : number +>list : any[] +>length : number +>0 : number + + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { +>fill : (dit: typeof ListWrapper, list: any[], value: any, start?: number, end?: number) => void +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : any[] +>value : any +>start : number +>0 : number +>end : number +>null : null + + list.fill(value, start, end === null ? list.length : end); +>list.fill(value, start, end === null ? list.length : end) : void +>list.fill : (value: any, start: number, end: number) => void +>list : any[] +>fill : (value: any, start: number, end: number) => void +>value : any +>start : number +>end === null ? list.length : end : number +>end === null : boolean +>end : number +>null : null +>list.length : number +>list : any[] +>length : number +>end : number + } + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { +>equals : (dit: typeof ListWrapper, a: any[], b: any[]) => boolean +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>a : any[] +>b : any[] + + if (a.length != b.length) return false; +>a.length != b.length : boolean +>a.length : number +>a : any[] +>length : number +>b.length : number +>b : any[] +>length : number +>false : boolean + + for (var i = 0; i < a.length; ++i) { +>i : number +>0 : number +>i < a.length : boolean +>i : number +>a.length : number +>a : any[] +>length : number +>++i : number +>i : number + + if (a[i] !== b[i]) return false; +>a[i] !== b[i] : boolean +>a[i] : any +>a : any[] +>i : number +>b[i] : any +>b : any[] +>i : number +>false : boolean + } + return true; +>true : boolean + } + static slice(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { +>slice : (dit: typeof ListWrapper, l: T[], from?: number, to?: number) => T[] +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>l : T[] +>T : T +>from : number +>0 : number +>to : number +>null : null +>T : T + + return l.slice(from, to === null ? undefined : to); +>l.slice(from, to === null ? undefined : to) : T[] +>l.slice : (start?: number, end?: number) => T[] +>l : T[] +>slice : (start?: number, end?: number) => T[] +>from : number +>to === null ? undefined : to : number +>to === null : boolean +>to : number +>null : null +>undefined : undefined +>to : number + } + static splice(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } +>splice : (dit: typeof ListWrapper, l: T[], from: number, length: number) => T[] +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>l : T[] +>T : T +>from : number +>length : number +>T : T +>l.splice(from, length) : T[] +>l.splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>l : T[] +>splice : { (start: number): T[]; (start: number, deleteCount: number, ...items: T[]): T[]; } +>from : number +>length : number + + static sort(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { +>sort : (dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) => void +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>l : T[] +>T : T +>compareFn : (a: T, b: T) => number +>a : T +>T : T +>b : T +>T : T + + if (isPresent(compareFn)) { +>isPresent(compareFn) : boolean +>isPresent : (compareFn?: (a: T, b: T) => number) => boolean +>compareFn : (a: T, b: T) => number + + l.sort(compareFn); +>l.sort(compareFn) : T[] +>l.sort : (compareFn?: (a: T, b: T) => number) => T[] +>l : T[] +>sort : (compareFn?: (a: T, b: T) => number) => T[] +>compareFn : (a: T, b: T) => number + + } else { + l.sort(); +>l.sort() : T[] +>l.sort : (compareFn?: (a: T, b: T) => number) => T[] +>l : T[] +>sort : (compareFn?: (a: T, b: T) => number) => T[] + } + } + static toString(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } +>toString : (dit: typeof ListWrapper, l: T[]) => string +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>l : T[] +>T : T +>l.toString() : string +>l.toString : () => string +>l : T[] +>toString : () => string + + static toJSON(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } +>toJSON : (dit: typeof ListWrapper, l: T[]) => string +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>l : T[] +>T : T +>JSON.stringify(l) : string +>JSON.stringify : { (value: any): string; (value: any, replacer: (key: string, value: any) => any): string; (value: any, replacer: any[]): string; (value: any, replacer: (key: string, value: any) => any, space: string | number): string; (value: any, replacer: any[], space: string | number): string; } +>JSON : JSON +>stringify : { (value: any): string; (value: any, replacer: (key: string, value: any) => any): string; (value: any, replacer: any[]): string; (value: any, replacer: (key: string, value: any) => any, space: string | number): string; (value: any, replacer: any[], space: string | number): string; } +>l : T[] + + static maximum(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { +>maximum : (dit: typeof ListWrapper, list: T[], predicate: (t: T) => number) => T +>T : T +>dit : typeof ListWrapper +>ListWrapper : typeof ListWrapper +>list : T[] +>T : T +>predicate : (t: T) => number +>t : T +>T : T +>T : T + + if (list.length == 0) { +>list.length == 0 : boolean +>list.length : number +>list : T[] +>length : number +>0 : number + + return null; +>null : null + } + var solution: T = null; +>solution : T +>T : T +>null : null + + var maxValue = -Infinity; +>maxValue : number +>-Infinity : number +>Infinity : number + + for (var index = 0; index < list.length; index++) { +>index : number +>0 : number +>index < list.length : boolean +>index : number +>list.length : number +>list : T[] +>length : number +>index++ : number +>index : number + + var candidate = list[index]; +>candidate : T +>list[index] : T +>list : T[] +>index : number + + if (isBlank(candidate)) { +>isBlank(candidate) : boolean +>isBlank : (x: any) => boolean +>candidate : T + + continue; + } + var candidateValue = predicate(candidate); +>candidateValue : number +>predicate(candidate) : number +>predicate : (t: T) => number +>candidate : T + + if (candidateValue > maxValue) { +>candidateValue > maxValue : boolean +>candidateValue : number +>maxValue : number + + solution = candidate; +>solution = candidate : T +>solution : T +>candidate : T + + maxValue = candidateValue; +>maxValue = candidateValue : number +>maxValue : number +>candidateValue : number + } + } + return solution; +>solution : T + } +} +let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); +>cloned : number[] +>ListWrapper.clone(ListWrapper, [1,2,3,4]) : number[] +>ListWrapper.clone : (dit: typeof ListWrapper, array: T[]) => T[] +>ListWrapper : typeof ListWrapper +>clone : (dit: typeof ListWrapper, array: T[]) => T[] +>ListWrapper : typeof ListWrapper +>[1,2,3,4] : number[] +>1 : number +>2 : number +>3 : number +>4 : number + +declare function isBlank(x: any): boolean; +>isBlank : (x: any) => boolean +>x : any + +declare function isPresent(compareFn?: (a: T, b: T) => number): boolean; +>isPresent : (compareFn?: (a: T, b: T) => number) => boolean +>T : T +>compareFn : (a: T, b: T) => number +>a : T +>T : T +>b : T +>T : T + +interface Array { +>Array : T[] +>T : T + + fill(value: any, start: number, end: number): void; +>fill : (value: any, start: number, end: number) => void +>value : any +>start : number +>end : number +} diff --git a/tests/cases/compiler/bluebirdStaticThis.ts b/tests/cases/compiler/bluebirdStaticThis.ts new file mode 100644 index 00000000000..55b1d0022d8 --- /dev/null +++ b/tests/cases/compiler/bluebirdStaticThis.ts @@ -0,0 +1,141 @@ +// This version is reduced from the full d.ts by removing almost all the tests +// and all the comments. +// Then it adds explicit `this` arguments to the static members. +// Tests by: Bart van der Schoor +declare class Promise implements Promise.Thenable { + constructor(callback: (resolve: (thenableOrResult: R | Promise.Thenable) => void, reject: (error: any) => void) => void); + static try(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static try(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static attempt(dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; + static attempt(dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; + + static method(dit: typeof Promise, fn: Function): Function; + + static resolve(dit: typeof Promise): Promise; + static resolve(dit: typeof Promise, value: Promise.Thenable): Promise; + static resolve(dit: typeof Promise, value: R): Promise; + + static reject(dit: typeof Promise, reason: any): Promise; + static reject(dit: typeof Promise, reason: any): Promise; + + static defer(dit: typeof Promise): Promise.Resolver; + + static cast(dit: typeof Promise, value: Promise.Thenable): Promise; + static cast(dit: typeof Promise, value: R): Promise; + + static bind(dit: typeof Promise, thisArg: any): Promise; + + static is(dit: typeof Promise, value: any): boolean; + + static longStackTraces(dit: typeof Promise): void; + + static delay(dit: typeof Promise, value: Promise.Thenable, ms: number): Promise; + static delay(dit: typeof Promise, value: R, ms: number): Promise; + static delay(dit: typeof Promise, ms: number): Promise; + + static promisify(dit: typeof Promise, nodeFunction: Function, receiver?: any): Function; + + static promisifyAll(dit: typeof Promise, target: Object): Object; + + static coroutine(dit: typeof Promise, generatorFunction: Function): Function; + + static spawn(dit: typeof Promise, generatorFunction: Function): Promise; + + static noConflict(dit: typeof Promise): typeof Promise; + + static onPossiblyUnhandledRejection(dit: typeof Promise, handler: (reason: any) => any): void; + + static all(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static all(dit: typeof Promise, values: Promise.Thenable): Promise; + static all(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static all(dit: typeof Promise, values: R[]): Promise; + + static props(dit: typeof Promise, object: Promise): Promise; + static props(dit: typeof Promise, object: Object): Promise; + + static settle(dit: typeof Promise, values: Promise.Thenable[]>): Promise[]>; + static settle(dit: typeof Promise, values: Promise.Thenable): Promise[]>; + static settle(dit: typeof Promise, values: Promise.Thenable[]): Promise[]>; + static settle(dit: typeof Promise, values: R[]): Promise[]>; + + static any(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static any(dit: typeof Promise, values: Promise.Thenable): Promise; + static any(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static any(dit: typeof Promise, values: R[]): Promise; + + static race(dit: typeof Promise, values: Promise.Thenable[]>): Promise; + static race(dit: typeof Promise, values: Promise.Thenable): Promise; + static race(dit: typeof Promise, values: Promise.Thenable[]): Promise; + static race(dit: typeof Promise, values: R[]): Promise; + + static some(dit: typeof Promise, values: Promise.Thenable[]>, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable, count: number): Promise; + static some(dit: typeof Promise, values: Promise.Thenable[], count: number): Promise; + static some(dit: typeof Promise, values: R[], count: number): Promise; + + static join(dit: typeof Promise, ...values: Promise.Thenable[]): Promise; + static join(dit: typeof Promise, ...values: R[]): Promise; + + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[]>, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable, mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: Promise.Thenable[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static map(dit: typeof Promise, values: R[], mapper: (item: R, index: number, arrayLength: number) => U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[]>, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable, reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: Promise.Thenable[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => Promise.Thenable, initialValue?: U): Promise; + static reduce(dit: typeof Promise, values: R[], reducer: (total: U, current: R, index: number, arrayLength: number) => U, initialValue?: U): Promise; + + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[]>, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable, filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: Promise.Thenable[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => Promise.Thenable): Promise; + static filter(dit: typeof Promise, values: R[], filterer: (item: R, index: number, arrayLength: number) => boolean): Promise; +} + +declare module Promise { + export interface Thenable { + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; + } + +} + +declare module 'bluebird' { + export = Promise; +} +interface Foo { + a: number; + b: string; +} +var x: any; +var arr: any[]; +var foo: Foo; +var fooProm: Promise; + +fooProm = Promise.try(Promise, () => { + return foo; +}); +fooProm = Promise.try(Promise, () => { + return foo; +}, arr); +fooProm = Promise.try(Promise, () => { + return foo; +}, arr, x); \ No newline at end of file diff --git a/tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts b/tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts new file mode 100644 index 00000000000..3923e1d707f --- /dev/null +++ b/tests/cases/compiler/staticAnonymousTypeNotReferencingTypeParameter.ts @@ -0,0 +1,141 @@ +// This test case is a condensed version of Angular 2's ListWrapper. Prior to #7448 +// this would cause the compiler to run out of memory. + +function outer(x: T) { + class Inner { + static y: T = x; + } + return Inner; +} +let y: number = outer(5).y; + +class ListWrapper2 { + static clone(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } + static reversed(dit: typeof ListWrapper2, array: T[]): T[] { + var a = ListWrapper2.clone(dit, array); + return a; + } +} +namespace tessst { + /** + * Iterates through 'array' by index and performs the callback on each element of array until the callback + * returns a truthy value, then returns that value. + * If no such value is found, the callback is applied to each element of array and undefined is returned. + */ + export function funkyFor(array: T[], callback: (element: T, index: number) => U): U { + if (array) { + for (let i = 0, len = array.length; i < len; i++) { + const result = callback(array[i], i); + if (result) { + return result; + } + } + } + return undefined; + } +} +interface Scanner { + scanRange(start: number, length: number, callback: () => T): T; +} +class ListWrapper { + // JS has no way to express a statically fixed size list, but dart does so we + // keep both methods. + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } + static clone(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } + static forEachWithIndex(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { + for (var i = 0; i < array.length; i++) { + fn(array[i], i); + } + } + static first(dit: typeof ListWrapper, array: T[]): T { + if (!array) return null; + return array[0]; + } + static last(dit: typeof ListWrapper, array: T[]): T { + if (!array || array.length == 0) return null; + return array[array.length - 1]; + } + static indexOf(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { + return array.indexOf(value, startIndex); + } + static contains(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } + static reversed(dit: typeof ListWrapper, array: T[]): T[] { + var a = ListWrapper.clone(dit, array); + let scanner: Scanner; + scanner.scanRange(3, 5, () => { }); + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; + } + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } + static insert(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } + static removeAt(dit: typeof ListWrapper, list: T[], index: number): T { + var res = list[index]; + list.splice(index, 1); + return res; + } + static removeAll(dit: typeof ListWrapper, list: T[], items: T[]) { + for (var i = 0; i < items.length; ++i) { + var index = list.indexOf(items[i]); + list.splice(index, 1); + } + } + static remove(dit: typeof ListWrapper, list: T[], el: T): boolean { + var index = list.indexOf(el); + if (index > -1) { + list.splice(index, 1); + return true; + } + return false; + } + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { + list.fill(value, start, end === null ? list.length : end); + } + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } + return true; + } + static slice(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { + return l.slice(from, to === null ? undefined : to); + } + static splice(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } + static sort(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { + if (isPresent(compareFn)) { + l.sort(compareFn); + } else { + l.sort(); + } + } + static toString(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } + static toJSON(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } + + static maximum(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { + if (list.length == 0) { + return null; + } + var solution: T = null; + var maxValue = -Infinity; + for (var index = 0; index < list.length; index++) { + var candidate = list[index]; + if (isBlank(candidate)) { + continue; + } + var candidateValue = predicate(candidate); + if (candidateValue > maxValue) { + solution = candidate; + maxValue = candidateValue; + } + } + return solution; + } +} +let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); +declare function isBlank(x: any): boolean; +declare function isPresent(compareFn?: (a: T, b: T) => number): boolean; +interface Array { + fill(value: any, start: number, end: number): void; +} \ No newline at end of file