fix(ddc): type fixes necessary to bring DDC severe count to 0

This commit is contained in:
Yegor Jbanov
2016-01-21 18:13:58 -08:00
committed by Yegor
parent 9c96b8affc
commit 4282297c24
13 changed files with 82 additions and 59 deletions

View File

@ -21,7 +21,7 @@ class ObservableListDiff extends DefaultIterableDiffer {
} }
} }
dynamic diff(ObservableList collection) { DefaultIterableDiffer diff(ObservableList collection) {
if (collection is! ObservableList) { if (collection is! ObservableList) {
throw "Cannot change the type of a collection"; throw "Cannot change the type of a collection";
} }

View File

@ -513,5 +513,5 @@ export class ApplicationRef_ extends ApplicationRef {
this._platform._applicationDisposed(this); this._platform._applicationDisposed(this);
} }
get componentTypes(): any[] { return this._rootComponentTypes; } get componentTypes(): Type[] { return this._rootComponentTypes; }
} }

View File

@ -22,7 +22,7 @@ import {IterableDiffer, IterableDifferFactory} from '../differs/iterable_differs
@CONST() @CONST()
export class DefaultIterableDifferFactory implements IterableDifferFactory { export class DefaultIterableDifferFactory implements IterableDifferFactory {
supports(obj: Object): boolean { return isListLikeIterable(obj); } 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 { export class DefaultIterableDiffer implements IterableDiffer {

View File

@ -9,7 +9,7 @@ import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2
* respond to changes in an iterable by effecting equivalent changes in the DOM. * respond to changes in an iterable by effecting equivalent changes in the DOM.
*/ */
export interface IterableDiffer { export interface IterableDiffer {
diff(object: Object): any; diff(object: any): any;
onDestroy(); onDestroy();
} }
@ -17,7 +17,7 @@ export interface IterableDiffer {
* Provides a factory for {@link IterableDiffer}. * Provides a factory for {@link IterableDiffer}.
*/ */
export interface IterableDifferFactory { export interface IterableDifferFactory {
supports(objects: Object): boolean; supports(objects: any): boolean;
create(cdRef: ChangeDetectorRef): IterableDiffer; 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)); var factory = this.factories.find(f => f.supports(iterable));
if (isPresent(factory)) { if (isPresent(factory)) {
return factory; return factory;

View File

@ -8,7 +8,7 @@ import {Provider, SkipSelfMetadata, OptionalMetadata, Injectable} from 'angular2
* A differ that tracks changes made to an object over time. * A differ that tracks changes made to an object over time.
*/ */
export interface KeyValueDiffer { export interface KeyValueDiffer {
diff(object: Object); diff(object: any);
onDestroy(); onDestroy();
} }
@ -16,7 +16,7 @@ export interface KeyValueDiffer {
* Provides a factory for {@link KeyValueDiffer}. * Provides a factory for {@link KeyValueDiffer}.
*/ */
export interface KeyValueDifferFactory { export interface KeyValueDifferFactory {
supports(objects: Object): boolean; supports(objects: any): boolean;
create(cdRef: ChangeDetectorRef): KeyValueDiffer; create(cdRef: ChangeDetectorRef): KeyValueDiffer;
} }

View File

@ -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 == 0) return this.provider0;
if (index == 1) return this.provider1; if (index == 1) return this.provider1;
if (index == 2) return this.provider2; 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) { if (index < 0 || index >= this.providers.length) {
throw new OutOfBoundsError(index); throw new OutOfBoundsError(index);
} }
@ -210,7 +210,9 @@ export class ProtoInjector {
new ProtoInjectorInlineStrategy(this, bwv); new ProtoInjectorInlineStrategy(this, bwv);
} }
getProviderAtIndex(index: number): any { return this._strategy.getProviderAtIndex(index); } getProviderAtIndex(index: number): ResolvedProvider {
return this._strategy.getProviderAtIndex(index);
}
} }

View File

@ -250,7 +250,7 @@ export class AppView implements ChangeDispatcher {
return this.appElements[directive.elementIndex].getDirectiveAtIndex(directive.directiveIndex); return this.appElements[directive.elementIndex].getDirectiveAtIndex(directive.directiveIndex);
} }
getDetectorFor(directive: DirectiveIndex): any { getDetectorFor(directive: DirectiveIndex): ChangeDetector {
var componentView = this.appElements[directive.elementIndex].componentView; var componentView = this.appElements[directive.elementIndex].componentView;
return isPresent(componentView) ? componentView.changeDetector : null; return isPresent(componentView) ? componentView.changeDetector : null;
} }

View File

@ -133,13 +133,13 @@ export class ViewContainerRef_ extends ViewContainerRef {
// TODO(rado): profile and decide whether bounds checks should be added // TODO(rado): profile and decide whether bounds checks should be added
// to the methods below. // to the methods below.
createEmbeddedView(templateRef: TemplateRef_, index: number = -1): EmbeddedViewRef { createEmbeddedView(templateRef: TemplateRef, index: number = -1): EmbeddedViewRef {
if (index == -1) index = this.length; if (index == -1) index = this.length;
var vm = this._element.parentView.viewManager; var vm = this._element.parentView.viewManager;
return vm.createEmbeddedViewInContainer(this._element.ref, index, templateRef); return vm.createEmbeddedViewInContainer(this._element.ref, index, templateRef);
} }
createHostView(hostViewFactoryRef: HostViewFactoryRef_, index: number = -1, createHostView(hostViewFactoryRef: HostViewFactoryRef, index: number = -1,
dynamicallyCreatedProviders: ResolvedProvider[] = null, dynamicallyCreatedProviders: ResolvedProvider[] = null,
projectableNodes: any[][] = null): HostViewRef { projectableNodes: any[][] = null): HostViewRef {
if (index == -1) index = this.length; if (index == -1) index = this.length;
@ -149,14 +149,14 @@ export class ViewContainerRef_ extends ViewContainerRef {
} }
// TODO(i): refactor insert+remove into move // 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; if (index == -1) index = this.length;
var vm = this._element.parentView.viewManager; var vm = this._element.parentView.viewManager;
return vm.attachViewInContainer(this._element.ref, index, viewRef); return vm.attachViewInContainer(this._element.ref, index, viewRef);
} }
indexOf(viewRef: ViewRef_): number { indexOf(viewRef: ViewRef): number {
return ListWrapper.indexOf(this._element.nestedViews, viewRef.internalView); return ListWrapper.indexOf(this._element.nestedViews, (<ViewRef_>viewRef).internalView);
} }
// TODO(i): rename to destroy // TODO(i): rename to destroy

View File

@ -17,6 +17,7 @@ import {
HostViewFactoryRef_, HostViewFactoryRef_,
EmbeddedViewRef, EmbeddedViewRef,
HostViewRef, HostViewRef,
ViewRef,
ViewRef_ ViewRef_
} from './view_ref'; } from './view_ref';
import {ViewContainerRef} from './view_container_ref'; import {ViewContainerRef} from './view_container_ref';
@ -189,20 +190,20 @@ export class AppViewManager_ extends AppViewManager {
super(); super();
} }
getViewContainer(location: ElementRef_): ViewContainerRef { getViewContainer(location: ElementRef): ViewContainerRef {
return location.internalElement.getViewContainerRef(); return (<ElementRef_>location).internalElement.getViewContainerRef();
} }
getHostElement(hostViewRef: ViewRef_): ElementRef { getHostElement(hostViewRef: ViewRef): ElementRef {
var hostView = hostViewRef.internalView; var hostView = (<ViewRef_>hostViewRef).internalView;
if (hostView.proto.type !== ViewType.HOST) { if (hostView.proto.type !== ViewType.HOST) {
throw new BaseException('This operation is only allowed on host views'); throw new BaseException('This operation is only allowed on host views');
} }
return hostView.appElements[0].ref; return hostView.appElements[0].ref;
} }
getNamedElementInComponentView(hostLocation: ElementRef_, variableName: string): ElementRef { getNamedElementInComponentView(hostLocation: ElementRef, variableName: string): ElementRef {
var appEl = hostLocation.internalElement; var appEl = (<ElementRef_>hostLocation).internalElement;
var componentView = appEl.componentView; var componentView = appEl.componentView;
if (isBlank(componentView)) { if (isBlank(componentView)) {
throw new BaseException(`There is no component directive at element ${hostLocation}`); 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}`); throw new BaseException(`Could not find variable ${variableName}`);
} }
getComponent(hostLocation: ElementRef_): any { getComponent(hostLocation: ElementRef): any {
return hostLocation.internalElement.getComponent(); return (<ElementRef_>hostLocation).internalElement.getComponent();
} }
/** @internal */ /** @internal */
_createRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#createRootHostView()'); _createRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#createRootHostView()');
createRootHostView(hostViewFactoryRef: HostViewFactoryRef_, overrideSelector: string, createRootHostView(hostViewFactoryRef: HostViewFactoryRef, overrideSelector: string,
injector: Injector, projectableNodes: any[][] = null): HostViewRef { injector: Injector, projectableNodes: any[][] = null): HostViewRef {
var s = this._createRootHostViewScope(); var s = this._createRootHostViewScope();
var hostViewFactory = hostViewFactoryRef.internalHostViewFactory; var hostViewFactory = (<HostViewFactoryRef_>hostViewFactoryRef).internalHostViewFactory;
var selector = isPresent(overrideSelector) ? overrideSelector : hostViewFactory.selector; var selector = isPresent(overrideSelector) ? overrideSelector : hostViewFactory.selector;
var view = hostViewFactory.viewFactory(this._renderer, this, null, projectableNodes, selector, var view = hostViewFactory.viewFactory(this._renderer, this, null, projectableNodes, selector,
null, injector); null, injector);
@ -236,9 +237,9 @@ export class AppViewManager_ extends AppViewManager {
/** @internal */ /** @internal */
_destroyRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#destroyRootHostView()'); _destroyRootHostViewScope: WtfScopeFn = wtfCreateScope('AppViewManager#destroyRootHostView()');
destroyRootHostView(hostViewRef: ViewRef_) { destroyRootHostView(hostViewRef: ViewRef) {
var s = this._destroyRootHostViewScope(); var s = this._destroyRootHostViewScope();
var hostView = hostViewRef.internalView; var hostView = (<ViewRef_>hostViewRef).internalView;
hostView.renderer.detachView(flattenNestedViewRenderNodes(hostView.rootNodesOrAppElements)); hostView.renderer.detachView(flattenNestedViewRenderNodes(hostView.rootNodesOrAppElements));
hostView.destroy(); hostView.destroy();
wtfLeave(s); wtfLeave(s);
@ -248,14 +249,14 @@ export class AppViewManager_ extends AppViewManager {
_createEmbeddedViewInContainerScope: WtfScopeFn = _createEmbeddedViewInContainerScope: WtfScopeFn =
wtfCreateScope('AppViewManager#createEmbeddedViewInContainer()'); wtfCreateScope('AppViewManager#createEmbeddedViewInContainer()');
createEmbeddedViewInContainer(viewContainerLocation: ElementRef_, index: number, createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number,
templateRef: TemplateRef_): EmbeddedViewRef { templateRef: TemplateRef): EmbeddedViewRef {
var s = this._createEmbeddedViewInContainerScope(); var s = this._createEmbeddedViewInContainerScope();
var contextEl = templateRef.elementRef.internalElement; var contextEl = (<TemplateRef_>templateRef).elementRef.internalElement;
var view: AppView = var view: AppView =
contextEl.embeddedViewFactory(contextEl.parentView.renderer, this, contextEl, contextEl.embeddedViewFactory(contextEl.parentView.renderer, this, contextEl,
contextEl.parentView.projectableNodes, null, null, null); contextEl.parentView.projectableNodes, null, null, null);
this._attachViewToContainer(view, viewContainerLocation.internalElement, index); this._attachViewToContainer(view, (<ElementRef_>viewContainerLocation).internalElement, index);
return wtfLeave(s, view.ref); return wtfLeave(s, view.ref);
} }
@ -263,27 +264,29 @@ export class AppViewManager_ extends AppViewManager {
_createHostViewInContainerScope: WtfScopeFn = _createHostViewInContainerScope: WtfScopeFn =
wtfCreateScope('AppViewManager#createHostViewInContainer()'); wtfCreateScope('AppViewManager#createHostViewInContainer()');
createHostViewInContainer(viewContainerLocation: ElementRef_, index: number, createHostViewInContainer(viewContainerLocation: ElementRef, index: number,
hostViewFactoryRef: HostViewFactoryRef_, hostViewFactoryRef: HostViewFactoryRef,
dynamicallyCreatedProviders: ResolvedProvider[], dynamicallyCreatedProviders: ResolvedProvider[],
projectableNodes: any[][]): HostViewRef { projectableNodes: any[][]): HostViewRef {
var s = this._createHostViewInContainerScope(); var s = this._createHostViewInContainerScope();
// TODO(tbosch): This should be specifiable via an additional argument! // TODO(tbosch): This should be specifiable via an additional argument!
var contextEl = viewContainerLocation.internalElement; var viewContainerLocation_ = <ElementRef_>viewContainerLocation;
var hostViewFactory = hostViewFactoryRef.internalHostViewFactory; var contextEl = viewContainerLocation_.internalElement;
var hostViewFactory = (<HostViewFactoryRef_>hostViewFactoryRef).internalHostViewFactory;
var view = hostViewFactory.viewFactory( var view = hostViewFactory.viewFactory(
contextEl.parentView.renderer, contextEl.parentView.viewManager, contextEl, contextEl.parentView.renderer, contextEl.parentView.viewManager, contextEl,
projectableNodes, null, dynamicallyCreatedProviders, null); projectableNodes, null, dynamicallyCreatedProviders, null);
this._attachViewToContainer(view, viewContainerLocation.internalElement, index); this._attachViewToContainer(view, viewContainerLocation_.internalElement, index);
return wtfLeave(s, view.ref); return wtfLeave(s, view.ref);
} }
/** @internal */ /** @internal */
_destroyViewInContainerScope = wtfCreateScope('AppViewMananger#destroyViewInContainer()'); _destroyViewInContainerScope = wtfCreateScope('AppViewMananger#destroyViewInContainer()');
destroyViewInContainer(viewContainerLocation: ElementRef_, index: number) { destroyViewInContainer(viewContainerLocation: ElementRef, index: number) {
var s = this._destroyViewInContainerScope(); var s = this._destroyViewInContainerScope();
var view = this._detachViewInContainer(viewContainerLocation.internalElement, index); var view =
this._detachViewInContainer((<ElementRef_>viewContainerLocation).internalElement, index);
view.destroy(); view.destroy();
wtfLeave(s); wtfLeave(s);
} }
@ -292,20 +295,23 @@ export class AppViewManager_ extends AppViewManager {
_attachViewInContainerScope = wtfCreateScope('AppViewMananger#attachViewInContainer()'); _attachViewInContainerScope = wtfCreateScope('AppViewMananger#attachViewInContainer()');
// TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer // TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer
attachViewInContainer(viewContainerLocation: ElementRef_, index: number, attachViewInContainer(viewContainerLocation: ElementRef, index: number,
viewRef: ViewRef_): EmbeddedViewRef { viewRef: ViewRef): EmbeddedViewRef {
var viewRef_ = <ViewRef_>viewRef;
var s = this._attachViewInContainerScope(); var s = this._attachViewInContainerScope();
this._attachViewToContainer(viewRef.internalView, viewContainerLocation.internalElement, index); this._attachViewToContainer(viewRef_.internalView,
return wtfLeave(s, viewRef); (<ElementRef_>viewContainerLocation).internalElement, index);
return wtfLeave(s, viewRef_);
} }
/** @internal */ /** @internal */
_detachViewInContainerScope = wtfCreateScope('AppViewMananger#detachViewInContainer()'); _detachViewInContainerScope = wtfCreateScope('AppViewMananger#detachViewInContainer()');
// TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer // TODO(i): refactor detachViewInContainer+attachViewInContainer to moveViewInContainer
detachViewInContainer(viewContainerLocation: ElementRef_, index: number): EmbeddedViewRef { detachViewInContainer(viewContainerLocation: ElementRef, index: number): EmbeddedViewRef {
var s = this._detachViewInContainerScope(); var s = this._detachViewInContainerScope();
var view = this._detachViewInContainer(viewContainerLocation.internalElement, index); var view =
this._detachViewInContainer((<ElementRef_>viewContainerLocation).internalElement, index);
return wtfLeave(s, view.ref); return wtfLeave(s, view.ref);
} }

View File

@ -23,7 +23,7 @@ class NoReflectionCapabilities implements PlatformReflectionCapabilities {
} }
@override @override
List parameters(dynamic type) { List<List> parameters(dynamic type) {
throw "Cannot find reflection information on ${stringify(type)}"; throw "Cannot find reflection information on ${stringify(type)}";
} }
@ -33,7 +33,7 @@ class NoReflectionCapabilities implements PlatformReflectionCapabilities {
} }
@override @override
Map propMetadata(dynamic type) { Map<String, List> propMetadata(dynamic type) {
throw "Cannot find reflection information on ${stringify(type)}"; throw "Cannot find reflection information on ${stringify(type)}";
} }

View File

@ -73,16 +73,16 @@ class ObservableWrapper {
} }
class EventEmitter<T> extends Stream<T> { class EventEmitter<T> extends Stream<T> {
StreamController<dynamic> _controller; StreamController<T> _controller;
/// Creates an instance of [EventEmitter], which depending on [isAsync], /// Creates an instance of [EventEmitter], which depending on [isAsync],
/// delivers events synchronously or asynchronously. /// delivers events synchronously or asynchronously.
EventEmitter([bool isAsync = true]) { EventEmitter([bool isAsync = true]) {
_controller = new StreamController.broadcast(sync: !isAsync); _controller = new StreamController<T>.broadcast(sync: !isAsync);
} }
StreamSubscription listen(void onData(dynamic line), StreamSubscription<T> listen(void onData(T event),
{void onError(Error error), void onDone(), bool cancelOnError}) { {Function onError, void onDone(), bool cancelOnError}) {
return _controller.stream.listen(onData, return _controller.stream.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError); onError: onError, onDone: onDone, cancelOnError: cancelOnError);
} }
@ -106,14 +106,14 @@ class EventEmitter<T> extends Stream<T> {
//todo(robwormald): maybe fix in ts2dart? //todo(robwormald): maybe fix in ts2dart?
class Subject<T> extends Stream<T> { class Subject<T> extends Stream<T> {
StreamController<dynamic> _controller; StreamController<T> _controller;
Subject([bool isAsync = true]) { Subject([bool isAsync = true]) {
_controller = new StreamController.broadcast(sync: !isAsync); _controller = new StreamController<T>.broadcast(sync: !isAsync);
} }
StreamSubscription listen(void onData(dynamic line), StreamSubscription<T> listen(void onData(T data),
{void onError(Error error), void onDone(), bool cancelOnError}) { {Function onError, void onDone(), bool cancelOnError}) {
return _controller.stream.listen(onData, return _controller.stream.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError); onError: onError, onDone: onDone, cancelOnError: cancelOnError);
} }

View File

@ -27,7 +27,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
return isPresent(KeyEventsPlugin.parseEventName(eventName)); 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 parsedEvent = KeyEventsPlugin.parseEventName(eventName);
var outsideHandler = KeyEventsPlugin.eventCallback( var outsideHandler = KeyEventsPlugin.eventCallback(
@ -90,8 +90,8 @@ export class KeyEventsPlugin extends EventManagerPlugin {
return fullKey; return fullKey;
} }
static eventCallback(element: HTMLElement, fullKey: any, handler: (e: Event) => any, static eventCallback(element: HTMLElement, fullKey: any, handler: Function,
zone: NgZone): (event: KeyboardEvent) => void { zone: NgZone): Function {
return (event) => { return (event) => {
if (StringWrapper.equals(KeyEventsPlugin.getEventFullKey(event), fullKey)) { if (StringWrapper.equals(KeyEventsPlugin.getEventFullKey(event), fullKey)) {
zone.run(() => handler(event)); zone.run(() => handler(event));

View File

@ -60,3 +60,18 @@ then
else else
echo "Warning count ok" echo "Warning count ok"
fi 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'