From 4282297c2449b1e3f5f652a853b6ab2581e1675d Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Thu, 21 Jan 2016 18:13:58 -0800 Subject: [PATCH] fix(ddc): type fixes necessary to bring DDC severe count to 0 --- .../directives/observable_list_diff.dart | 2 +- modules/angular2/src/core/application_ref.ts | 2 +- .../differs/default_iterable_differ.ts | 2 +- .../differs/iterable_differs.ts | 6 +- .../differs/keyvalue_differs.ts | 4 +- modules/angular2/src/core/di/injector.ts | 8 ++- modules/angular2/src/core/linker/view.ts | 2 +- .../src/core/linker/view_container_ref.ts | 10 +-- .../angular2/src/core/linker/view_manager.ts | 64 ++++++++++--------- .../src/core/reflection/reflection.dart | 4 +- modules/angular2/src/facade/async.dart | 16 ++--- .../src/platform/dom/events/key_events.ts | 6 +- scripts/ci/build_dart_experimental.sh | 15 +++++ 13 files changed, 82 insertions(+), 59 deletions(-) diff --git a/modules/angular2/src/common/directives/observable_list_diff.dart b/modules/angular2/src/common/directives/observable_list_diff.dart index cca7057fac..034dd66375 100644 --- a/modules/angular2/src/common/directives/observable_list_diff.dart +++ b/modules/angular2/src/common/directives/observable_list_diff.dart @@ -21,7 +21,7 @@ class ObservableListDiff extends DefaultIterableDiffer { } } - dynamic diff(ObservableList collection) { + DefaultIterableDiffer diff(ObservableList collection) { if (collection is! ObservableList) { throw "Cannot change the type of a collection"; } diff --git a/modules/angular2/src/core/application_ref.ts b/modules/angular2/src/core/application_ref.ts index 3dd2e35da3..345c862a18 100644 --- a/modules/angular2/src/core/application_ref.ts +++ b/modules/angular2/src/core/application_ref.ts @@ -513,5 +513,5 @@ export class ApplicationRef_ extends ApplicationRef { this._platform._applicationDisposed(this); } - get componentTypes(): any[] { return this._rootComponentTypes; } + get componentTypes(): Type[] { return this._rootComponentTypes; } } diff --git a/modules/angular2/src/core/change_detection/differs/default_iterable_differ.ts b/modules/angular2/src/core/change_detection/differs/default_iterable_differ.ts index 424577ea52..366c117c60 100644 --- a/modules/angular2/src/core/change_detection/differs/default_iterable_differ.ts +++ b/modules/angular2/src/core/change_detection/differs/default_iterable_differ.ts @@ -22,7 +22,7 @@ import {IterableDiffer, IterableDifferFactory} from '../differs/iterable_differs @CONST() export class DefaultIterableDifferFactory implements IterableDifferFactory { supports(obj: Object): boolean { return isListLikeIterable(obj); } - create(cdRef: ChangeDetectorRef): any { return new DefaultIterableDiffer(); } + create(cdRef: ChangeDetectorRef): DefaultIterableDiffer { return new DefaultIterableDiffer(); } } export class DefaultIterableDiffer implements IterableDiffer { diff --git a/modules/angular2/src/core/change_detection/differs/iterable_differs.ts b/modules/angular2/src/core/change_detection/differs/iterable_differs.ts index 076ac40e58..e9a173fe4d 100644 --- a/modules/angular2/src/core/change_detection/differs/iterable_differs.ts +++ b/modules/angular2/src/core/change_detection/differs/iterable_differs.ts @@ -9,7 +9,7 @@ import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2 * respond to changes in an iterable by effecting equivalent changes in the DOM. */ export interface IterableDiffer { - diff(object: Object): any; + diff(object: any): any; onDestroy(); } @@ -17,7 +17,7 @@ export interface IterableDiffer { * Provides a factory for {@link IterableDiffer}. */ export interface IterableDifferFactory { - supports(objects: Object): boolean; + supports(objects: any): boolean; create(cdRef: ChangeDetectorRef): IterableDiffer; } @@ -74,7 +74,7 @@ export class IterableDiffers { }); } - find(iterable: Object): IterableDifferFactory { + find(iterable: any): IterableDifferFactory { var factory = this.factories.find(f => f.supports(iterable)); if (isPresent(factory)) { return factory; diff --git a/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts b/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts index 83430ca4eb..68105a5727 100644 --- a/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts +++ b/modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts @@ -8,7 +8,7 @@ import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2 * A differ that tracks changes made to an object over time. */ export interface KeyValueDiffer { - diff(object: Object); + diff(object: any); onDestroy(); } @@ -16,7 +16,7 @@ export interface KeyValueDiffer { * Provides a factory for {@link KeyValueDiffer}. */ export interface KeyValueDifferFactory { - supports(objects: Object): boolean; + supports(objects: any): boolean; create(cdRef: ChangeDetectorRef): KeyValueDiffer; } diff --git a/modules/angular2/src/core/di/injector.ts b/modules/angular2/src/core/di/injector.ts index 4d499cc8a6..4f846c9923 100644 --- a/modules/angular2/src/core/di/injector.ts +++ b/modules/angular2/src/core/di/injector.ts @@ -143,7 +143,7 @@ export class ProtoInjectorInlineStrategy implements ProtoInjectorStrategy { } } - getProviderAtIndex(index: number): any { + getProviderAtIndex(index: number): ResolvedProvider { if (index == 0) return this.provider0; if (index == 1) return this.provider1; if (index == 2) return this.provider2; @@ -181,7 +181,7 @@ export class ProtoInjectorDynamicStrategy implements ProtoInjectorStrategy { } } - getProviderAtIndex(index: number): any { + getProviderAtIndex(index: number): ResolvedProvider { if (index < 0 || index >= this.providers.length) { throw new OutOfBoundsError(index); } @@ -210,7 +210,9 @@ export class ProtoInjector { new ProtoInjectorInlineStrategy(this, bwv); } - getProviderAtIndex(index: number): any { return this._strategy.getProviderAtIndex(index); } + getProviderAtIndex(index: number): ResolvedProvider { + return this._strategy.getProviderAtIndex(index); + } } diff --git a/modules/angular2/src/core/linker/view.ts b/modules/angular2/src/core/linker/view.ts index f91fb09b5c..6c15032613 100644 --- a/modules/angular2/src/core/linker/view.ts +++ b/modules/angular2/src/core/linker/view.ts @@ -250,7 +250,7 @@ export class AppView implements ChangeDispatcher { return this.appElements[directive.elementIndex].getDirectiveAtIndex(directive.directiveIndex); } - getDetectorFor(directive: DirectiveIndex): any { + getDetectorFor(directive: DirectiveIndex): ChangeDetector { var componentView = this.appElements[directive.elementIndex].componentView; return isPresent(componentView) ? componentView.changeDetector : null; } diff --git a/modules/angular2/src/core/linker/view_container_ref.ts b/modules/angular2/src/core/linker/view_container_ref.ts index b8561ed108..0c2b8438b1 100644 --- a/modules/angular2/src/core/linker/view_container_ref.ts +++ b/modules/angular2/src/core/linker/view_container_ref.ts @@ -133,13 +133,13 @@ export class ViewContainerRef_ extends ViewContainerRef { // TODO(rado): profile and decide whether bounds checks should be added // to the methods below. - createEmbeddedView(templateRef: TemplateRef_, index: number = -1): EmbeddedViewRef { + createEmbeddedView(templateRef: TemplateRef, index: number = -1): EmbeddedViewRef { if (index == -1) index = this.length; var vm = this._element.parentView.viewManager; return vm.createEmbeddedViewInContainer(this._element.ref, index, templateRef); } - createHostView(hostViewFactoryRef: HostViewFactoryRef_, index: number = -1, + createHostView(hostViewFactoryRef: HostViewFactoryRef, index: number = -1, dynamicallyCreatedProviders: ResolvedProvider[] = null, projectableNodes: any[][] = null): HostViewRef { if (index == -1) index = this.length; @@ -149,14 +149,14 @@ export class ViewContainerRef_ extends ViewContainerRef { } // TODO(i): refactor insert+remove into move - insert(viewRef: ViewRef_, index: number = -1): EmbeddedViewRef { + insert(viewRef: ViewRef, index: number = -1): EmbeddedViewRef { if (index == -1) index = this.length; var vm = this._element.parentView.viewManager; return vm.attachViewInContainer(this._element.ref, index, viewRef); } - indexOf(viewRef: ViewRef_): number { - return ListWrapper.indexOf(this._element.nestedViews, viewRef.internalView); + indexOf(viewRef: ViewRef): number { + return ListWrapper.indexOf(this._element.nestedViews, (viewRef).internalView); } // TODO(i): rename to destroy diff --git a/modules/angular2/src/core/linker/view_manager.ts b/modules/angular2/src/core/linker/view_manager.ts index 57a0a82da8..d2efabaeab 100644 --- a/modules/angular2/src/core/linker/view_manager.ts +++ b/modules/angular2/src/core/linker/view_manager.ts @@ -17,6 +17,7 @@ import { HostViewFactoryRef_, EmbeddedViewRef, HostViewRef, + ViewRef, ViewRef_ } from './view_ref'; import {ViewContainerRef} from './view_container_ref'; @@ -189,20 +190,20 @@ export class AppViewManager_ extends AppViewManager { super(); } - getViewContainer(location: ElementRef_): ViewContainerRef { - return location.internalElement.getViewContainerRef(); + getViewContainer(location: ElementRef): ViewContainerRef { + return (location).internalElement.getViewContainerRef(); } - getHostElement(hostViewRef: ViewRef_): ElementRef { - var hostView = hostViewRef.internalView; + getHostElement(hostViewRef: ViewRef): ElementRef { + var hostView = (hostViewRef).internalView; if (hostView.proto.type !== ViewType.HOST) { throw new BaseException('This operation is only allowed on host views'); } return hostView.appElements[0].ref; } - getNamedElementInComponentView(hostLocation: ElementRef_, variableName: string): ElementRef { - var appEl = hostLocation.internalElement; + getNamedElementInComponentView(hostLocation: ElementRef, variableName: string): ElementRef { + var appEl = (hostLocation).internalElement; var componentView = appEl.componentView; if (isBlank(componentView)) { throw new BaseException(`There is no component directive at element ${hostLocation}`); @@ -216,17 +217,17 @@ export class AppViewManager_ extends AppViewManager { throw new BaseException(`Could not find variable ${variableName}`); } - getComponent(hostLocation: ElementRef_): any { - return hostLocation.internalElement.getComponent(); + getComponent(hostLocation: ElementRef): any { + return (hostLocation).internalElement.getComponent(); } /** @internal */ _createRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#createRootHostView()'); - createRootHostView(hostViewFactoryRef: HostViewFactoryRef_, overrideSelector: string, + createRootHostView(hostViewFactoryRef: HostViewFactoryRef, overrideSelector: string, injector: Injector, projectableNodes: any[][] = null): HostViewRef { var s = this._createRootHostViewScope(); - var hostViewFactory = hostViewFactoryRef.internalHostViewFactory; + var hostViewFactory = (hostViewFactoryRef).internalHostViewFactory; var selector = isPresent(overrideSelector) ? overrideSelector : hostViewFactory.selector; var view = hostViewFactory.viewFactory(this._renderer, this, null, projectableNodes, selector, null, injector); @@ -236,9 +237,9 @@ export class AppViewManager_ extends AppViewManager { /** @internal */ _destroyRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#destroyRootHostView()'); - destroyRootHostView(hostViewRef: ViewRef_) { + destroyRootHostView(hostViewRef: ViewRef) { var s = this._destroyRootHostViewScope(); - var hostView = hostViewRef.internalView; + var hostView = (hostViewRef).internalView; hostView.renderer.detachView(flattenNestedViewRenderNodes(hostView.rootNodesOrAppElements)); hostView.destroy(); wtfLeave(s); @@ -248,14 +249,14 @@ export class AppViewManager_ extends AppViewManager { _createEmbeddedViewInContainerScope: WtfScopeFn = wtfCreateScope('AppViewManager#createEmbeddedViewInContainer()'); - createEmbeddedViewInContainer(viewContainerLocation: ElementRef_, index: number, - templateRef: TemplateRef_): EmbeddedViewRef { + createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number, + templateRef: TemplateRef): EmbeddedViewRef { var s = this._createEmbeddedViewInContainerScope(); - var contextEl = templateRef.elementRef.internalElement; + var contextEl = (templateRef).elementRef.internalElement; var view: AppView = contextEl.embeddedViewFactory(contextEl.parentView.renderer, this, contextEl, contextEl.parentView.projectableNodes, null, null, null); - this._attachViewToContainer(view, viewContainerLocation.internalElement, index); + this._attachViewToContainer(view, (viewContainerLocation).internalElement, index); return wtfLeave(s, view.ref); } @@ -263,27 +264,29 @@ export class AppViewManager_ extends AppViewManager { _createHostViewInContainerScope: WtfScopeFn = wtfCreateScope('AppViewManager#createHostViewInContainer()'); - createHostViewInContainer(viewContainerLocation: ElementRef_, index: number, - hostViewFactoryRef: HostViewFactoryRef_, + createHostViewInContainer(viewContainerLocation: ElementRef, index: number, + hostViewFactoryRef: HostViewFactoryRef, dynamicallyCreatedProviders: ResolvedProvider[], projectableNodes: any[][]): HostViewRef { var s = this._createHostViewInContainerScope(); // TODO(tbosch): This should be specifiable via an additional argument! - var contextEl = viewContainerLocation.internalElement; - var hostViewFactory = hostViewFactoryRef.internalHostViewFactory; + var viewContainerLocation_ = viewContainerLocation; + var contextEl = viewContainerLocation_.internalElement; + var hostViewFactory = (hostViewFactoryRef).internalHostViewFactory; var view = hostViewFactory.viewFactory( contextEl.parentView.renderer, contextEl.parentView.viewManager, contextEl, projectableNodes, null, dynamicallyCreatedProviders, null); - this._attachViewToContainer(view, viewContainerLocation.internalElement, index); + this._attachViewToContainer(view, viewContainerLocation_.internalElement, index); return wtfLeave(s, view.ref); } /** @internal */ _destroyViewInContainerScope = wtfCreateScope('AppViewMananger#destroyViewInContainer()'); - destroyViewInContainer(viewContainerLocation: ElementRef_, index: number) { + destroyViewInContainer(viewContainerLocation: ElementRef, index: number) { var s = this._destroyViewInContainerScope(); - var view = this._detachViewInContainer(viewContainerLocation.internalElement, index); + var view = + this._detachViewInContainer((viewContainerLocation).internalElement, index); view.destroy(); wtfLeave(s); } @@ -292,20 +295,23 @@ export class AppViewManager_ extends AppViewManager { _attachViewInContainerScope = wtfCreateScope('AppViewMananger#attachViewInContainer()'); // TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer - attachViewInContainer(viewContainerLocation: ElementRef_, index: number, - viewRef: ViewRef_): EmbeddedViewRef { + attachViewInContainer(viewContainerLocation: ElementRef, index: number, + viewRef: ViewRef): EmbeddedViewRef { + var viewRef_ = viewRef; var s = this._attachViewInContainerScope(); - this._attachViewToContainer(viewRef.internalView, viewContainerLocation.internalElement, index); - return wtfLeave(s, viewRef); + this._attachViewToContainer(viewRef_.internalView, + (viewContainerLocation).internalElement, index); + return wtfLeave(s, viewRef_); } /** @internal */ _detachViewInContainerScope = wtfCreateScope('AppViewMananger#detachViewInContainer()'); // TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer - detachViewInContainer(viewContainerLocation: ElementRef_, index: number): EmbeddedViewRef { + detachViewInContainer(viewContainerLocation: ElementRef, index: number): EmbeddedViewRef { var s = this._detachViewInContainerScope(); - var view = this._detachViewInContainer(viewContainerLocation.internalElement, index); + var view = + this._detachViewInContainer((viewContainerLocation).internalElement, index); return wtfLeave(s, view.ref); } diff --git a/modules/angular2/src/core/reflection/reflection.dart b/modules/angular2/src/core/reflection/reflection.dart index 25d470fbd9..f110cc8b6e 100644 --- a/modules/angular2/src/core/reflection/reflection.dart +++ b/modules/angular2/src/core/reflection/reflection.dart @@ -23,7 +23,7 @@ class NoReflectionCapabilities implements PlatformReflectionCapabilities { } @override - List parameters(dynamic type) { + List parameters(dynamic type) { throw "Cannot find reflection information on ${stringify(type)}"; } @@ -33,7 +33,7 @@ class NoReflectionCapabilities implements PlatformReflectionCapabilities { } @override - Map propMetadata(dynamic type) { + Map propMetadata(dynamic type) { throw "Cannot find reflection information on ${stringify(type)}"; } diff --git a/modules/angular2/src/facade/async.dart b/modules/angular2/src/facade/async.dart index 5f8a196b5f..b34d47a13a 100644 --- a/modules/angular2/src/facade/async.dart +++ b/modules/angular2/src/facade/async.dart @@ -73,16 +73,16 @@ class ObservableWrapper { } class EventEmitter extends Stream { - StreamController _controller; + StreamController _controller; /// Creates an instance of [EventEmitter], which depending on [isAsync], /// delivers events synchronously or asynchronously. EventEmitter([bool isAsync = true]) { - _controller = new StreamController.broadcast(sync: !isAsync); + _controller = new StreamController.broadcast(sync: !isAsync); } - StreamSubscription listen(void onData(dynamic line), - {void onError(Error error), void onDone(), bool cancelOnError}) { + StreamSubscription listen(void onData(T event), + {Function onError, void onDone(), bool cancelOnError}) { return _controller.stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); } @@ -106,14 +106,14 @@ class EventEmitter extends Stream { //todo(robwormald): maybe fix in ts2dart? class Subject extends Stream { - StreamController _controller; + StreamController _controller; Subject([bool isAsync = true]) { - _controller = new StreamController.broadcast(sync: !isAsync); + _controller = new StreamController.broadcast(sync: !isAsync); } - StreamSubscription listen(void onData(dynamic line), - {void onError(Error error), void onDone(), bool cancelOnError}) { + StreamSubscription listen(void onData(T data), + {Function onError, void onDone(), bool cancelOnError}) { return _controller.stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); } diff --git a/modules/angular2/src/platform/dom/events/key_events.ts b/modules/angular2/src/platform/dom/events/key_events.ts index 9c625dc278..68c258ed6f 100644 --- a/modules/angular2/src/platform/dom/events/key_events.ts +++ b/modules/angular2/src/platform/dom/events/key_events.ts @@ -27,7 +27,7 @@ export class KeyEventsPlugin extends EventManagerPlugin { return isPresent(KeyEventsPlugin.parseEventName(eventName)); } - addEventListener(element: HTMLElement, eventName: string, handler: (Event: any) => any) { + addEventListener(element: HTMLElement, eventName: string, handler: Function) { var parsedEvent = KeyEventsPlugin.parseEventName(eventName); var outsideHandler = KeyEventsPlugin.eventCallback( @@ -90,8 +90,8 @@ export class KeyEventsPlugin extends EventManagerPlugin { return fullKey; } - static eventCallback(element: HTMLElement, fullKey: any, handler: (e: Event) => any, - zone: NgZone): (event: KeyboardEvent) => void { + static eventCallback(element: HTMLElement, fullKey: any, handler: Function, + zone: NgZone): Function { return (event) => { if (StringWrapper.equals(KeyEventsPlugin.getEventFullKey(event), fullKey)) { zone.run(() => handler(event)); diff --git a/scripts/ci/build_dart_experimental.sh b/scripts/ci/build_dart_experimental.sh index d4a1bd9046..6481fb8d73 100755 --- a/scripts/ci/build_dart_experimental.sh +++ b/scripts/ci/build_dart_experimental.sh @@ -60,3 +60,18 @@ then else echo "Warning count ok" fi + +function countWarnings { + local GREP_PATTERN=$1 + local COUNT=`cat $LOG_FILE | grep -E '$GREP_PATTERN' | wc -l | sed -e 's/^[[:space:]]*//'` + echo $COUNT +} + +SEVERE_ANGULAR_COUNT=$(countWarnings '^severe.*package:angular2') +if [[ "$SEVERE_ANGULAR_COUNT" -gt "0" ]] +then + echo "Found severe errors in angular2 package" + exit 1 +fi + +echo 'Dart DDC build finished'