refactor(compiler): improve types, misc

This commit is contained in:
Victor Berchet
2016-10-07 17:36:08 -07:00
committed by Tobias Bosch
parent 79e1c7b807
commit bdcf46f82e
26 changed files with 115 additions and 119 deletions

View File

@ -15,7 +15,7 @@ import {CompileMetadataResolver} from '../../src/metadata_resolver';
export function main() {
describe('RuntimeAnimationCompiler', () => {
var resolver: any /** TODO #9100 */;
var resolver: CompileMetadataResolver;
beforeEach(
inject([CompileMetadataResolver], (res: CompileMetadataResolver) => { resolver = res; }));

View File

@ -28,9 +28,9 @@ export function main() {
(keyframe: AnimationKeyframeAst): {[key: string]: string | number} =>
combineStyles(keyframe.styles);
var collectStepStyles = (step: AnimationStepAst): Array<{[key: string]: string | number}> => {
var collectStepStyles = (step: AnimationStepAst): {[key: string]: string | number}[] => {
var keyframes = step.keyframes;
var styles: any[] /** TODO #9100 */ = [];
var styles: {[key: string]: string | number}[] = [];
if (step.startingStyles.styles.length > 0) {
styles.push(combineStyles(step.startingStyles));
}
@ -38,7 +38,7 @@ export function main() {
return styles;
};
var resolver: any /** TODO #9100 */;
var resolver: CompileMetadataResolver;
beforeEach(
inject([CompileMetadataResolver], (res: CompileMetadataResolver) => { resolver = res; }));

View File

@ -275,7 +275,7 @@ export function main() {
it('should throw an error if a selector is being parsed while in the wrong mode', () => {
var cssCode = '.class > tag';
var capturedMessage: any /** TODO #9100 */;
var capturedMessage: string;
try {
tokenize(cssCode, false, CssLexerMode.STYLE_BLOCK);
} catch (e) {
@ -298,7 +298,7 @@ export function main() {
describe('Attribute Mode', () => {
it('should consider attribute selectors as valid input and throw when an invalid modifier is used',
() => {
function tokenizeAttr(modifier: any /** TODO #9100 */) {
function tokenizeAttr(modifier: string) {
var cssCode = 'value' + modifier + '=\'something\'';
return tokenize(cssCode, false, CssLexerMode.ATTRIBUTE_SELECTOR);
}

View File

@ -7,8 +7,8 @@
*/
import {hasLifecycleHook} from '@angular/compiler/src/lifecycle_reflector';
import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks';
import {describe, expect, it} from '@angular/core/testing/testing_internal';
import {SimpleChanges} from '@angular/core';
import {LifecycleHooks as Hooks} from '@angular/core/src/metadata/lifecycle_hooks';
export function main() {
describe('Create Directive', () => {
@ -16,92 +16,81 @@ export function main() {
describe('ngOnChanges', () => {
it('should be true when the directive has the ngOnChanges method', () => {
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
.toBe(true);
expect(hasLifecycleHook(Hooks.OnChanges, DirectiveWithOnChangesMethod)).toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveNoHooks)).toBe(false);
});
it('should be false otherwise',
() => { expect(hasLifecycleHook(Hooks.OnChanges, DirectiveNoHooks)).toBe(false); });
});
describe('ngOnDestroy', () => {
it('should be true when the directive has the ngOnDestroy method', () => {
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
.toBe(true);
expect(hasLifecycleHook(Hooks.OnDestroy, DirectiveWithOnDestroyMethod)).toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveNoHooks)).toBe(false);
});
it('should be false otherwise',
() => { expect(hasLifecycleHook(Hooks.OnDestroy, DirectiveNoHooks)).toBe(false); });
});
describe('ngOnInit', () => {
it('should be true when the directive has the ngOnInit method', () => {
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
});
it('should be true when the directive has the ngOnInit method',
() => { expect(hasLifecycleHook(Hooks.OnInit, DirectiveWithOnInitMethod)).toBe(true); });
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveNoHooks)).toBe(false);
});
it('should be false otherwise',
() => { expect(hasLifecycleHook(Hooks.OnInit, DirectiveNoHooks)).toBe(false); });
});
describe('ngDoCheck', () => {
it('should be true when the directive has the ngDoCheck method', () => {
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
expect(hasLifecycleHook(Hooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveNoHooks)).toBe(false);
});
it('should be false otherwise',
() => { expect(hasLifecycleHook(Hooks.DoCheck, DirectiveNoHooks)).toBe(false); });
});
describe('ngAfterContentInit', () => {
it('should be true when the directive has the ngAfterContentInit method', () => {
expect(hasLifecycleHook(
LifecycleHooks.AfterContentInit, DirectiveWithAfterContentInitMethod))
expect(hasLifecycleHook(Hooks.AfterContentInit, DirectiveWithAfterContentInitMethod))
.toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
expect(hasLifecycleHook(Hooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
});
});
describe('ngAfterContentChecked', () => {
it('should be true when the directive has the ngAfterContentChecked method', () => {
expect(hasLifecycleHook(
LifecycleHooks.AfterContentChecked, DirectiveWithAfterContentCheckedMethod))
expect(
hasLifecycleHook(Hooks.AfterContentChecked, DirectiveWithAfterContentCheckedMethod))
.toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked, DirectiveNoHooks))
.toBe(false);
expect(hasLifecycleHook(Hooks.AfterContentChecked, DirectiveNoHooks)).toBe(false);
});
});
describe('ngAfterViewInit', () => {
it('should be true when the directive has the ngAfterViewInit method', () => {
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
expect(hasLifecycleHook(Hooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
.toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveNoHooks)).toBe(false);
});
it('should be false otherwise',
() => { expect(hasLifecycleHook(Hooks.AfterViewInit, DirectiveNoHooks)).toBe(false); });
});
describe('ngAfterViewChecked', () => {
it('should be true when the directive has the ngAfterViewChecked method', () => {
expect(hasLifecycleHook(
LifecycleHooks.AfterViewChecked, DirectiveWithAfterViewCheckedMethod))
expect(hasLifecycleHook(Hooks.AfterViewChecked, DirectiveWithAfterViewCheckedMethod))
.toBe(true);
});
it('should be false otherwise', () => {
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
expect(hasLifecycleHook(Hooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
});
});
});
@ -111,7 +100,7 @@ export function main() {
class DirectiveNoHooks {}
class DirectiveWithOnChangesMethod {
ngOnChanges(_: any /** TODO #9100 */) {}
ngOnChanges(_: SimpleChanges) {}
}
class DirectiveWithOnInitMethod {

View File

@ -43,7 +43,7 @@ export function main() {
describe('output emitter', () => {
outputDefs.forEach((outputDef) => {
describe(`${outputDef['name']}`, () => {
var expressions: any /** TODO #9100 */;
var expressions: {[k: string]: any};
beforeEach(() => { expressions = outputDef['getExpressions']()(); });
it('should support literals', () => {
@ -109,13 +109,16 @@ export function main() {
});
describe('operators', () => {
var ops: any /** TODO #9100 */;
var aObj: any /** TODO #9100 */, bObj: any /** TODO #9100 */;
var ops: {[k: string]: Function};
var aObj: any;
var bObj: any;
beforeEach(() => {
ops = expressions['operators'];
aObj = new Object();
bObj = new Object();
aObj = {};
bObj = {};
});
it('should support ==', () => {
expect(ops['=='](aObj, aObj)).toBe(true);
expect(ops['=='](aObj, bObj)).toBe(false);

View File

@ -53,7 +53,7 @@ export function main() {
it('should return an error from the definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var url = '/foo';
var response: any /** TODO #9100 */ = null;
var response: string = null;
resourceLoader.when(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
@ -71,7 +71,7 @@ export function main() {
it('should return an error from the expectations',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var url = '/foo';
var response: any /** TODO #9100 */ = null;
var response: string = null;
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();

View File

@ -11,7 +11,7 @@ import {UrlResolver} from '@angular/compiler/src/url_resolver';
export function main() {
describe('extractStyleUrls', () => {
var urlResolver: any /** TODO #9100 */;
var urlResolver: UrlResolver;
beforeEach(() => { urlResolver = new UrlResolver(); });

View File

@ -1146,7 +1146,7 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
});
describe('content projection', () => {
var compCounter: any /** TODO #9100 */;
var compCounter: number;
beforeEach(() => { compCounter = 0; });
function createComp(