chore: add more type annotations

This commit is contained in:
Kevin Moore 2015-04-19 14:47:02 -07:00
parent e23004df52
commit f7f06c5ad4
17 changed files with 80 additions and 81 deletions

View File

@ -6,7 +6,7 @@ export class AST {
throw new BaseException("Not supported");
}
get isAssignable() {
get isAssignable():boolean {
return false;
}
@ -113,7 +113,7 @@ export class AccessMember extends AST {
}
}
get isAssignable() {
get isAssignable():boolean {
return true;
}
@ -148,7 +148,7 @@ export class KeyedAccess extends AST {
return obj[key];
}
get isAssignable() {
get isAssignable():boolean {
return true;
}
@ -397,7 +397,7 @@ export class ASTWithSource extends AST {
return this.ast.eval(context, locals);
}
get isAssignable() {
get isAssignable():boolean {
return this.ast.isAssignable;
}

View File

@ -34,7 +34,7 @@ export class Locals {
throw new BaseException(`Cannot find '${name}'`);
}
set(name:string, value) {
set(name:string, value):void {
// TODO(rado): consider removing this check if we can guarantee this is not
// exposed to the public API.
// TODO: vsavkin maybe it should check only the local map
@ -45,7 +45,7 @@ export class Locals {
}
}
clearValues() {
clearValues():void {
MapWrapper.clearValues(this.current);
}
}

View File

@ -38,14 +38,14 @@ export class View {
*
* NOTE: either `templateURL` or `template` should be used, but not both.
*/
templateUrl:any; //string;
templateUrl:string;
/**
* Specifies an inline template for an angular component.
*
* NOTE: either `templateURL` or `template` should be used, but not both.
*/
template:any; //string;
template:string;
/**
* Specifies a list of directives that can be used within a template.
@ -69,7 +69,7 @@ export class View {
* }
* ```
*/
directives:any; //List<Type>;
directives:List<Type>;
/**
* Specify a custom renderer for this View.

View File

@ -1,7 +1,7 @@
import {OpaqueToken} from 'angular2/di';
export var appComponentRefToken = new OpaqueToken('ComponentRef');
export var appChangeDetectorToken = new OpaqueToken('AppChangeDetector');
export var appElementToken = new OpaqueToken('AppElement');
export var appComponentAnnotatedTypeToken = new OpaqueToken('AppComponentAnnotatedType');
export var appDocumentToken = new OpaqueToken('AppDocument');
export var appComponentRefToken:OpaqueToken = new OpaqueToken('ComponentRef');
export var appChangeDetectorToken:OpaqueToken = new OpaqueToken('AppChangeDetector');
export var appElementToken:OpaqueToken = new OpaqueToken('AppElement');
export var appComponentAnnotatedTypeToken:OpaqueToken = new OpaqueToken('AppComponentAnnotatedType');
export var appDocumentToken:OpaqueToken = new OpaqueToken('AppDocument');

View File

@ -26,7 +26,7 @@ export class CompilerCache {
this._cache = MapWrapper.create();
}
set(component:Type, protoView:AppProtoView) {
set(component:Type, protoView:AppProtoView):void {
MapWrapper.set(this._cache, component, protoView);
}
@ -35,7 +35,7 @@ export class CompilerCache {
return normalizeBlank(result);
}
clear() {
clear():void {
MapWrapper.clear(this._cache);
}
}
@ -73,7 +73,7 @@ export class Compiler {
this._protoViewFactory = protoViewFactory;
}
_bindDirective(directiveTypeOrBinding) {
_bindDirective(directiveTypeOrBinding):DirectiveBinding {
if (directiveTypeOrBinding instanceof DirectiveBinding) {
return directiveTypeOrBinding;
}
@ -190,7 +190,7 @@ export class Compiler {
}
}
_buildRenderTemplate(component, view, directives) {
_buildRenderTemplate(component, view, directives): renderApi.ViewDefinition {
var componentUrl = this._urlResolver.resolve(
this._appUrl, this._componentUrlMapper.getUrl(component)
);
@ -211,7 +211,7 @@ export class Compiler {
});
}
static buildRenderDirective(directiveBinding) {
static buildRenderDirective(directiveBinding):renderApi.DirectiveMetadata {
var ann = directiveBinding.annotation;
var renderType;
var compileChildren = true;
@ -254,7 +254,7 @@ export class Compiler {
return directives;
}
_flattenList(tree:List<any>, out:List<Type>) {
_flattenList(tree:List<any>, out:List<Type>):void {
for (var i = 0; i < tree.length; i++) {
var item = tree[i];
if (ListWrapper.isList(item)) {

View File

@ -123,7 +123,7 @@ export class DynamicComponentLoader {
}
/** Asserts that the type being dynamically instantiated is a Component. */
_assertTypeIsComponent(type:Type) {
_assertTypeIsComponent(type:Type):void {
var annotation = this._directiveMetadataReader.read(type).annotation;
if (!(annotation instanceof Component)) {
throw new BaseException(`Could not load '${stringify(type)}' because it is not a component.`);

View File

@ -59,7 +59,7 @@ class StaticKeys {
this.elementRefId = Key.get(ElementRef).id;
}
static instance() {
static instance():StaticKeys {
if (isBlank(_staticKeys)) _staticKeys = new StaticKeys();
return _staticKeys;
}
@ -77,17 +77,17 @@ export class TreeNode {
if (isPresent(parent)) parent.addChild(this);
}
_assertConsistency() {
_assertConsistency():void {
this._assertHeadBeforeTail();
this._assertTailReachable();
this._assertPresentInParentList();
}
_assertHeadBeforeTail() {
_assertHeadBeforeTail():void {
if (isBlank(this._tail) && isPresent(this._head)) throw new BaseException('null tail but non-null head');
}
_assertTailReachable() {
_assertTailReachable():void {
if (isBlank(this._tail)) return;
if (isPresent(this._tail._next)) throw new BaseException('node after tail');
var p = this._head;
@ -95,7 +95,7 @@ export class TreeNode {
if (isBlank(p) && isPresent(this._tail)) throw new BaseException('tail not reachable.')
}
_assertPresentInParentList() {
_assertPresentInParentList():void {
var p = this._parent;
if (isBlank(p)) {
return;
@ -108,7 +108,7 @@ export class TreeNode {
/**
* Adds a child to the parent node. The child MUST NOT be a part of a tree.
*/
addChild(child:TreeNode) {
addChild(child:TreeNode):void {
if (isPresent(this._tail)) {
this._tail._next = child;
this._tail = child;
@ -124,7 +124,7 @@ export class TreeNode {
* Adds a child to the parent node after a given sibling.
* The child MUST NOT be a part of a tree and the sibling must be present.
*/
addChildAfter(child:TreeNode, prevSibling:TreeNode) {
addChildAfter(child:TreeNode, prevSibling:TreeNode):void {
this._assertConsistency();
if (isBlank(prevSibling)) {
var prevHead = this._head;
@ -146,7 +146,7 @@ export class TreeNode {
/**
* Detaches a node from the parent's tree.
*/
remove() {
remove():void {
this._assertConsistency();
if (isBlank(this.parent)) return;
var nextSibling = this._next;
@ -209,7 +209,7 @@ export class DirectiveDependency extends Dependency {
this._verify();
}
_verify() {
_verify():void {
var count = 0;
if (isPresent(this.propSetterName)) count++;
if (isPresent(this.queryDirective)) count++;

View File

@ -28,7 +28,7 @@ export class NgElement {
return domViewRef.delegate.boundElements[this._boundElementIndex];
}
getAttribute(name:string) {
getAttribute(name:string):string {
return normalizeBlank(DOM.getAttribute(this.domElement, name));
}
}

View File

@ -75,7 +75,7 @@ export class AppView {
this.componentChildViews = componentChildViews;
}
getOrCreateViewContainer(boundElementIndex:number) {
getOrCreateViewContainer(boundElementIndex:number):ViewContainer {
var viewContainer = this.viewContainers[boundElementIndex];
if (isBlank(viewContainer)) {
viewContainer = new ViewContainer(this, this.proto.elementBinders[boundElementIndex].nestedProtoView, this.elementInjectors[boundElementIndex]);
@ -84,7 +84,7 @@ export class AppView {
return viewContainer;
}
setLocal(contextName: string, value) {
setLocal(contextName: string, value):void {
if (!this.hydrated()) throw new BaseException('Cannot set locals on dehydrated view.');
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
return;
@ -93,7 +93,7 @@ export class AppView {
this.locals.set(templateName, value);
}
hydrated() {
hydrated():boolean {
return isPresent(this.context);
}
@ -106,14 +106,14 @@ export class AppView {
* @param {*} eventObj
* @param {int} binderIndex
*/
triggerEventHandlers(eventName: string, eventObj, binderIndex: int) {
triggerEventHandlers(eventName: string, eventObj, binderIndex: int): void {
var locals = MapWrapper.create();
MapWrapper.set(locals, '$event', eventObj);
this.dispatchEvent(binderIndex, eventName, locals);
}
// dispatch to element injector or text nodes based on context
notifyOnBinding(b:BindingRecord, currentValue:any) {
notifyOnBinding(b:BindingRecord, currentValue:any): void {
if (b.isElement()) {
this.renderer.setElementProperty(
this.render, b.elementIndex, b.propertyName, currentValue
@ -199,7 +199,7 @@ export class AppProtoView {
//TODO: Tobias or Victor. Moving it into the constructor.
// this work should be done the constructor of AppProtoView once we separate
// AppProtoView and ProtoViewBuilder
getVariableBindings() {
getVariableBindings(): List {
if (isPresent(this._variableBindings)) {
return this._variableBindings;
}
@ -217,7 +217,7 @@ export class AppProtoView {
//TODO: Tobias or Victor. Moving it into the constructor.
// this work should be done the constructor of ProtoView once we separate
// AppProtoView and ProtoViewBuilder
getdirectiveRecords() {
getdirectiveRecords(): List {
if (isPresent(this._directiveRecords)) {
return this._directiveRecords;
}
@ -236,7 +236,7 @@ export class AppProtoView {
return this._directiveRecords;
}
bindVariable(contextName:string, templateName:string) {
bindVariable(contextName:string, templateName:string): void {
MapWrapper.set(this.variableBindings, contextName, templateName);
MapWrapper.set(this.protoLocals, templateName, null);
}
@ -252,7 +252,7 @@ export class AppProtoView {
/**
* Adds a text node binding for the last created ElementBinder via bindElement
*/
bindTextNode(expression:AST) {
bindTextNode(expression:AST):void {
var textNodeIndex = this.textNodesWithBindingCount++;
var b = BindingRecord.createForTextNode(expression, textNodeIndex);
ListWrapper.push(this.bindings, b);
@ -261,7 +261,7 @@ export class AppProtoView {
/**
* Adds an element property binding for the last created ElementBinder via bindElement
*/
bindElementProperty(expression:AST, setterName:string) {
bindElementProperty(expression:AST, setterName:string):void {
var elementIndex = this.elementBinders.length-1;
var b = BindingRecord.createForElement(expression, elementIndex, setterName);
ListWrapper.push(this.bindings, b);
@ -280,7 +280,7 @@ export class AppProtoView {
* @param {int} directiveIndex The directive index in the binder or -1 when the event is not bound
* to a directive
*/
bindEvent(eventBindings: List<renderApi.EventBinding>, directiveIndex: int = -1) {
bindEvent(eventBindings: List<renderApi.EventBinding>, directiveIndex: int = -1): void {
var elBinder = this.elementBinders[this.elementBinders.length - 1];
var events = elBinder.hostListeners;
if (isBlank(events)) {
@ -306,7 +306,7 @@ export class AppProtoView {
directiveIndex:number,
expression:AST,
setterName:string,
setter:SetterFn) {
setter:SetterFn): void {
var elementIndex = this.elementBinders.length-1;
var directiveRecord = this._getDirectiveRecord(elementIndex, directiveIndex);
@ -314,7 +314,7 @@ export class AppProtoView {
ListWrapper.push(this.bindings, b);
}
_getDirectiveRecord(elementInjectorIndex:number, directiveIndex:number) {
_getDirectiveRecord(elementInjectorIndex:number, directiveIndex:number): DirectiveRecord {
var id = elementInjectorIndex * 100 + directiveIndex;
var protoElementInjector = this.elementBinders[elementInjectorIndex].protoElementInjector;

View File

@ -27,17 +27,17 @@ export class ViewContainer {
this._views = [];
}
getRender() {
getRender():ViewContainerRef {
return new ViewContainerRef(this.parentView.render, this.elementInjector.getBoundElementIndex());
}
internalClearWithoutRender() {
internalClearWithoutRender():void {
for (var i = this._views.length - 1; i >= 0; i--) {
this._detachInjectors(i);
}
}
clear() {
clear():void {
for (var i = this._views.length - 1; i >= 0; i--) {
this.remove(i);
}
@ -47,22 +47,22 @@ export class ViewContainer {
return this._views[index];
}
get length() {
get length() /* :int */ {
return this._views.length;
}
_siblingInjectorToLinkAfter(index: number) {
_siblingInjectorToLinkAfter(index: number):eiModule.ElementInjector {
if (index == 0) return null;
return ListWrapper.last(this._views[index - 1].rootElementInjectors)
}
hydrated() {
hydrated():boolean {
return this.parentView.hydrated();
}
// TODO(rado): profile and decide whether bounds checks should be added
// to the methods below.
create(atIndex=-1, protoView:viewModule.AppProtoView = null, injector:Injector = null): viewModule.AppView {
create(atIndex:number=-1, protoView:viewModule.AppProtoView = null, injector:Injector = null): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length;
if (!this.hydrated()) throw new BaseException(
'Cannot create views on a dehydrated ViewContainer');
@ -77,7 +77,7 @@ export class ViewContainer {
return newView;
}
insert(view, atIndex=-1): viewModule.AppView {
insert(view:viewModule.AppView, atIndex:number=-1): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length;
this._insertInjectors(view, atIndex);
this.parentView.changeDetector.addChild(view.changeDetector);
@ -85,7 +85,7 @@ export class ViewContainer {
return view;
}
_insertInjectors(view, atIndex): viewModule.AppView {
_insertInjectors(view:viewModule.AppView, atIndex:number): viewModule.AppView {
ListWrapper.insert(this._views, atIndex, view);
this._linkElementInjectors(this._siblingInjectorToLinkAfter(atIndex), view);
@ -96,7 +96,7 @@ export class ViewContainer {
return ListWrapper.indexOf(this._views, view);
}
remove(atIndex=-1) {
remove(atIndex:number=-1):void {
if (atIndex == -1) atIndex = this._views.length - 1;
var view = this._views[atIndex];
// opposite order as in create
@ -110,7 +110,7 @@ export class ViewContainer {
* The method can be used together with insert to implement a view move, i.e.
* moving the dom nodes while the directives in the view stay intact.
*/
detach(atIndex=-1): viewModule.AppView {
detach(atIndex:number=-1): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length - 1;
var detachedView = this._detachInjectors(atIndex);
detachedView.changeDetector.remove();
@ -118,20 +118,20 @@ export class ViewContainer {
return detachedView;
}
_detachInjectors(atIndex): viewModule.AppView {
_detachInjectors(atIndex:number): viewModule.AppView {
var detachedView = this.get(atIndex);
ListWrapper.removeAt(this._views, atIndex);
this._unlinkElementInjectors(detachedView);
return detachedView;
}
_linkElementInjectors(sibling, view) {
_linkElementInjectors(sibling, view:viewModule.AppView):void {
for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) {
view.rootElementInjectors[i].linkAfter(this.elementInjector, sibling);
}
}
_unlinkElementInjectors(view) {
_unlinkElementInjectors(view:viewModule.AppView):void {
for (var i = 0; i < view.rootElementInjectors.length; ++i) {
view.rootElementInjectors[i].unlink();
}

View File

@ -1,7 +1,7 @@
import {ListWrapper, List} from 'angular2/src/facade/collection';
import {stringify} from 'angular2/src/facade/lang';
function findFirstClosedCycle(keys:List) {
function findFirstClosedCycle(keys:List):List {
var res = [];
for(var i = 0; i < keys.length; ++i) {
if (ListWrapper.contains(res, keys[i])) {
@ -14,7 +14,7 @@ function findFirstClosedCycle(keys:List) {
return res;
}
function constructResolvingPath(keys:List) {
function constructResolvingPath(keys:List):string {
if (keys.length > 1) {
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
@ -43,12 +43,12 @@ export class AbstractBindingError extends Error {
}
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
addKey(key) {
addKey(key):void {
ListWrapper.push(this.keys, key);
this.message = this.constructResolvingMessage(this.keys);
}
toString() {
toString():string {
return this.message;
}
}
@ -166,7 +166,7 @@ export class InvalidBindingError extends Error {
this.message = `Invalid binding ${binding}`;
}
toString() {
toString():string {
return this.message;
}
}
@ -187,7 +187,7 @@ export class NoAnnotationError extends Error {
` Make sure they all have valid type or annotations.`;
}
toString() {
toString():string {
return this.message;
}
}

View File

@ -97,7 +97,7 @@ export class Injector {
* bindings.
* @param `defaultBindings` Setting to true will auto-create bindings.
*/
static resolveAndCreate(bindings:List/*<ResolvedBinding|Binding|Type|List>*/, {defaultBindings=false}={}) {
static resolveAndCreate(bindings:List/*<ResolvedBinding|Binding|Type|List>*/, {defaultBindings=false}={}): Injector {
return new Injector(Injector.resolve(bindings), null, defaultBindings);
}
@ -108,7 +108,7 @@ export class Injector {
* @param `bindings` A sparse list of {@link ResolvedBinding}s. See `resolve` for the {@link Injector}.
* @param `defaultBindings` Setting to true will auto-create bindings.
*/
static fromResolvedBindings(bindings:List<ResolvedBinding>, {defaultBindings=false}={}) {
static fromResolvedBindings(bindings:List<ResolvedBinding>, {defaultBindings=false}={}): Injector {
return new Injector(bindings, null, defaultBindings);
}
@ -133,7 +133,6 @@ export class Injector {
* @returns an instance represented by the token. Throws if not found.
*/
get(token) {
return this._getByKey(Key.get(token), false, false, false);
}
@ -227,7 +226,7 @@ export class Injector {
return ListWrapper.get(this._instances, key.id);
}
_setInstance(key:Key, obj) {
_setInstance(key:Key, obj):void {
ListWrapper.set(this._instances, key.id, obj);
}
@ -243,11 +242,11 @@ export class Injector {
}
}
_markAsConstructing(key:Key) {
_markAsConstructing(key:Key):void {
this._setInstance(key, _constructing);
}
_clear(key:Key) {
_clear(key:Key):void {
this._setInstance(key, null);
}
}
@ -325,7 +324,7 @@ class _AsyncInjectorStrategy {
}
}
instantiate(key:Key) {
instantiate(key:Key) /* Promise?? */ {
var binding = this.injector._getBinding(key);
if (isBlank(binding)) return _notFound;
@ -395,7 +394,7 @@ function _createListOfBindings(flattenedBindings):List {
return bindings;
}
function _flattenBindings(bindings:List, res:Map) {
function _flattenBindings(bindings:List, res:Map):Map {
ListWrapper.forEach(bindings, function (b) {
if (b instanceof ResolvedBinding) {
MapWrapper.set(res, b.key.id, b);

View File

@ -10,7 +10,7 @@ export class OpaqueToken {
this._desc = `Token(${desc})`;
}
toString() {
toString():string {
return this._desc;
}
}

View File

@ -15,7 +15,7 @@ export class CSSClass {
this._domEl = ngEl.domElement;
}
_toggleClass(className, enabled) {
_toggleClass(className, enabled):void {
if (enabled) {
DOM.addClass(this._domEl, className);
} else {

View File

@ -40,7 +40,7 @@ export class If {
this.prevCondition = null;
}
set condition(newCondition) {
set condition(newCondition /* boolean */) {
if (newCondition && (isBlank(this.prevCondition) || !this.prevCondition)) {
this.prevCondition = true;
this.viewContainer.create();

View File

@ -65,7 +65,7 @@ export class Switch {
this._switchValue = value;
}
_onWhenValueChanged(oldWhen, newWhen, viewContainer: ViewContainer) {
_onWhenValueChanged(oldWhen, newWhen, viewContainer: ViewContainer):void {
this._deregisterViewContainer(oldWhen, viewContainer);
this._registerViewContainer(newWhen, viewContainer);
@ -88,7 +88,7 @@ export class Switch {
}
}
_emptyAllActiveViewContainers() {
_emptyAllActiveViewContainers():void {
var activeContainers = this._activeViewContainers;
for (var i = 0; i < activeContainers.length; i++) {
activeContainers[i].remove();
@ -96,7 +96,7 @@ export class Switch {
this._activeViewContainers = ListWrapper.create();
}
_activateViewContainers(containers: List<ViewContainer>) {
_activateViewContainers(containers: List<ViewContainer>):void {
// TODO(vicb): assert(this._activeViewContainers.length === 0);
if (isPresent(containers)) {
for (var i = 0; i < containers.length; i++) {
@ -106,7 +106,7 @@ export class Switch {
}
}
_registerViewContainer(value, container: ViewContainer) {
_registerViewContainer(value, container: ViewContainer): void {
var containers = MapWrapper.get(this._valueViewContainers, value);
if (isBlank(containers)) {
containers = ListWrapper.create();
@ -115,7 +115,7 @@ export class Switch {
ListWrapper.push(containers, container);
}
_deregisterViewContainer(value, container: ViewContainer) {
_deregisterViewContainer(value, container: ViewContainer):void {
// `_whenDefault` is used a marker for non-registered whens
if (value == _whenDefault) return;
var containers = MapWrapper.get(this._valueViewContainers, value);

View File

@ -195,7 +195,7 @@ export class DomAdapter {
attributeMap(element) {
throw _abstract();
}
getAttribute(element, attribute:string) {
getAttribute(element, attribute:string):string {
throw _abstract();
}
setAttribute(element, name:string, value:string) {