From 44891996b592cbbeafb3a6f45a27d8d943895bab Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 26 Jun 2015 11:10:52 -0700 Subject: [PATCH] fix(build): add missing return types now enforced by linter --- .../change_detection_jit_generator.ts | 8 +- .../change_detection/change_detection_util.ts | 70 +++++----- .../dynamic_change_detector.ts | 2 +- .../src/change_detection/parser/ast.ts | 126 ++++++++++-------- .../src/change_detection/parser/locals.ts | 4 +- .../src/change_detection/parser/parser.ts | 41 +++--- .../src/change_detection/pipes/null_pipe.ts | 4 +- .../change_detection/proto_change_detector.ts | 34 ++--- .../angular2/src/core/annotations_impl/di.ts | 4 +- modules/angular2/src/core/application.ts | 2 +- .../src/core/compiler/base_query_list.ts | 6 +- .../src/core/compiler/element_binder.ts | 4 +- .../src/core/compiler/element_injector.ts | 22 +-- .../src/core/compiler/proto_view_factory.ts | 8 +- .../angular2/src/core/compiler/query_list.ts | 4 +- modules/angular2/src/core/compiler/view.ts | 4 +- .../src/core/compiler/view_container_ref.ts | 4 +- .../src/core/testability/get_testability.ts | 2 +- .../src/core/testability/testability.ts | 2 +- modules/angular2/src/core/zone/ng_zone.ts | 4 +- modules/angular2/src/debug/debug_element.ts | 12 +- modules/angular2/src/di/binding.ts | 4 +- modules/angular2/src/directives/ng_for.ts | 6 +- modules/angular2/src/dom/browser_adapter.ts | 58 ++++---- modules/angular2/src/dom/dom_adapter.ts | 64 +++++---- .../src/dom/generic_browser_adapter.ts | 8 +- modules/angular2/src/dom/parse5_adapter.ts | 98 +++++++------- modules/angular2/src/facade/async.ts | 10 +- modules/angular2/src/facade/collection.dart | 2 + modules/angular2/src/facade/collection.ts | 44 +++--- modules/angular2/src/facade/lang.ts | 32 +++-- .../angular2/src/forms/directives/ng_form.ts | 2 +- .../src/forms/directives/ng_form_model.ts | 2 +- .../angular2/src/forms/directives/shared.ts | 2 +- modules/angular2/src/forms/model.ts | 4 +- .../src/http/backends/mock_backend.ts | 2 +- modules/angular2/src/http/headers.ts | 8 +- modules/angular2/src/http/http.ts | 27 ++-- modules/angular2/src/mock/location_mock.ts | 4 +- modules/angular2/src/mock/ng_zone_mock.ts | 4 +- modules/angular2/src/render/api.ts | 2 +- .../render/dom/compiler/compile_control.ts | 5 +- .../render/dom/compiler/compile_element.ts | 4 +- .../src/render/dom/compiler/selector.ts | 4 +- .../render/dom/compiler/style_url_resolver.ts | 2 +- .../angular2/src/render/dom/dom_renderer.ts | 2 +- .../src/render/dom/events/event_manager.ts | 4 +- .../src/render/dom/events/key_events.ts | 24 ++-- .../emulated_unscoped_shadow_dom_strategy.ts | 2 +- .../shadow_dom/native_shadow_dom_strategy.ts | 2 +- .../src/render/dom/shadow_dom/util.ts | 6 +- modules/angular2/src/render/dom/util.ts | 4 +- .../src/render/dom/view/proto_view_builder.ts | 15 ++- modules/angular2/src/render/dom/view/view.ts | 2 +- .../src/render/dom/view/view_container.ts | 2 +- .../angular2/src/router/path_recognizer.ts | 8 +- modules/angular2/src/router/route_registry.ts | 2 +- modules/angular2/src/util/decorators.ts | 6 +- .../test/core/compiler/compiler_spec.ts | 5 +- .../compiler/dynamic_component_loader_spec.ts | 13 +- .../dom/dom_renderer_integration_spec.ts | 5 +- 61 files changed, 467 insertions(+), 400 deletions(-) diff --git a/modules/angular2/src/change_detection/change_detection_jit_generator.ts b/modules/angular2/src/change_detection/change_detection_jit_generator.ts index 2b87dcb68a..4b805cbcb7 100644 --- a/modules/angular2/src/change_detection/change_detection_jit_generator.ts +++ b/modules/angular2/src/change_detection/change_detection_jit_generator.ts @@ -138,9 +138,9 @@ export class ChangeDetectorJITGenerator { .map((d) => this._genGetDetector(d.directiveIndex)); } - _genGetDirective(d: DirectiveIndex) { return `this.directive_${d.name}`; } + _genGetDirective(d: DirectiveIndex): string { return `this.directive_${d.name}`; } - _genGetDetector(d: DirectiveIndex) { return `this.detector_${d.name}`; } + _genGetDetector(d: DirectiveIndex): string { return `this.detector_${d.name}`; } _getNonNullPipeNames(): List { var pipes = []; @@ -152,7 +152,7 @@ export class ChangeDetectorJITGenerator { return pipes; } - _genFieldDefinitions() { + _genFieldDefinitions(): string { var fields = []; fields = fields.concat(this._fieldNames); fields = fields.concat(this._getNonNullPipeNames()); @@ -226,7 +226,7 @@ export class ChangeDetectorJITGenerator { return `${rec}${this._maybeGenLastInDirective(r)}`; } - _genDirectiveLifecycle(r: ProtoRecord) { + _genDirectiveLifecycle(r: ProtoRecord): string { if (r.name === "onCheck") { return this._genOnCheck(r); } else if (r.name === "onInit") { diff --git a/modules/angular2/src/change_detection/change_detection_util.ts b/modules/angular2/src/change_detection/change_detection_util.ts index 413feac6f5..1e252a8c1e 100644 --- a/modules/angular2/src/change_detection/change_detection_util.ts +++ b/modules/angular2/src/change_detection/change_detection_util.ts @@ -35,7 +35,7 @@ var _simpleChanges = [ new SimpleChange(null, null) ]; -function _simpleChange(previousValue, currentValue) { +function _simpleChange(previousValue, currentValue): SimpleChange { var index = _simpleChangesIndex++ % 20; var s = _simpleChanges[index]; s.previousValue = previousValue; @@ -44,41 +44,43 @@ function _simpleChange(previousValue, currentValue) { } export class ChangeDetectionUtil { - static uninitialized() { return uninitialized; } + static uninitialized(): Object { return uninitialized; } - static arrayFn0() { return []; } - static arrayFn1(a1) { return [a1]; } - static arrayFn2(a1, a2) { return [a1, a2]; } - static arrayFn3(a1, a2, a3) { return [a1, a2, a3]; } - static arrayFn4(a1, a2, a3, a4) { return [a1, a2, a3, a4]; } - static arrayFn5(a1, a2, a3, a4, a5) { return [a1, a2, a3, a4, a5]; } - static arrayFn6(a1, a2, a3, a4, a5, a6) { return [a1, a2, a3, a4, a5, a6]; } - static arrayFn7(a1, a2, a3, a4, a5, a6, a7) { return [a1, a2, a3, a4, a5, a6, a7]; } - static arrayFn8(a1, a2, a3, a4, a5, a6, a7, a8) { return [a1, a2, a3, a4, a5, a6, a7, a8]; } - static arrayFn9(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + static arrayFn0(): any[] { return []; } + static arrayFn1(a1): any[] { return [a1]; } + static arrayFn2(a1, a2): any[] { return [a1, a2]; } + static arrayFn3(a1, a2, a3): any[] { return [a1, a2, a3]; } + static arrayFn4(a1, a2, a3, a4): any[] { return [a1, a2, a3, a4]; } + static arrayFn5(a1, a2, a3, a4, a5): any[] { return [a1, a2, a3, a4, a5]; } + static arrayFn6(a1, a2, a3, a4, a5, a6): any[] { return [a1, a2, a3, a4, a5, a6]; } + static arrayFn7(a1, a2, a3, a4, a5, a6, a7): any[] { return [a1, a2, a3, a4, a5, a6, a7]; } + static arrayFn8(a1, a2, a3, a4, a5, a6, a7, a8): any[] { + return [a1, a2, a3, a4, a5, a6, a7, a8]; + } + static arrayFn9(a1, a2, a3, a4, a5, a6, a7, a8, a9): any[] { return [a1, a2, a3, a4, a5, a6, a7, a8, a9]; } - static operation_negate(value) { return !value; } - static operation_add(left, right) { return left + right; } - static operation_subtract(left, right) { return left - right; } - static operation_multiply(left, right) { return left * right; } - static operation_divide(left, right) { return left / right; } - static operation_remainder(left, right) { return left % right; } - static operation_equals(left, right) { return left == right; } - static operation_not_equals(left, right) { return left != right; } - static operation_identical(left, right) { return left === right; } - static operation_not_identical(left, right) { return left !== right; } - static operation_less_then(left, right) { return left < right; } - static operation_greater_then(left, right) { return left > right; } - static operation_less_or_equals_then(left, right) { return left <= right; } - static operation_greater_or_equals_then(left, right) { return left >= right; } - static operation_logical_and(left, right) { return left && right; } - static operation_logical_or(left, right) { return left || right; } - static cond(cond, trueVal, falseVal) { return cond ? trueVal : falseVal; } + static operation_negate(value): any { return !value; } + static operation_add(left, right): any { return left + right; } + static operation_subtract(left, right): any { return left - right; } + static operation_multiply(left, right): any { return left * right; } + static operation_divide(left, right): any { return left / right; } + static operation_remainder(left, right): any { return left % right; } + static operation_equals(left, right): any { return left == right; } + static operation_not_equals(left, right): any { return left != right; } + static operation_identical(left, right): any { return left === right; } + static operation_not_identical(left, right): any { return left !== right; } + static operation_less_then(left, right): any { return left < right; } + static operation_greater_then(left, right): any { return left > right; } + static operation_less_or_equals_then(left, right): any { return left <= right; } + static operation_greater_or_equals_then(left, right): any { return left >= right; } + static operation_logical_and(left, right): any { return left && right; } + static operation_logical_or(left, right): any { return left || right; } + static cond(cond, trueVal, falseVal): any { return cond ? trueVal : falseVal; } - static mapFn(keys: List) { - function buildMap(values) { + static mapFn(keys: List): any { + function buildMap(values): StringMap { var res = StringMapWrapper.create(); for (var i = 0; i < keys.length; ++i) { StringMapWrapper.set(res, keys[i], values[i]); @@ -113,7 +115,7 @@ export class ChangeDetectionUtil { } } - static keyedAccess(obj, args) { return obj[args[0]]; } + static keyedAccess(obj, args): any { return obj[args[0]]; } static unwrapValue(value: any): any { if (value instanceof WrappedValue) { @@ -129,7 +131,7 @@ export class ChangeDetectionUtil { static throwDehydrated() { throw new DehydratedException(); } - static changeDetectionMode(strategy: string) { + static changeDetectionMode(strategy: string): string { return strategy == ON_PUSH ? CHECK_ONCE : CHECK_ALWAYS; } @@ -137,7 +139,7 @@ export class ChangeDetectionUtil { return _simpleChange(previousValue, currentValue); } - static addChange(changes, propertyName: string, change) { + static addChange(changes, propertyName: string, change): Map { if (isBlank(changes)) { changes = {}; } diff --git a/modules/angular2/src/change_detection/dynamic_change_detector.ts b/modules/angular2/src/change_detection/dynamic_change_detector.ts index 3fd7ff5722..3e3b288c42 100644 --- a/modules/angular2/src/change_detection/dynamic_change_detector.ts +++ b/modules/angular2/src/change_detection/dynamic_change_detector.ts @@ -318,7 +318,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } } -function isSame(a, b) { +function isSame(a, b): boolean { if (a === b) return true; if (a instanceof String && b instanceof String && a == b) return true; if ((a !== a) && (b !== b)) return true; diff --git a/modules/angular2/src/change_detection/parser/ast.ts b/modules/angular2/src/change_detection/parser/ast.ts index 91c75bed4a..0f02849367 100644 --- a/modules/angular2/src/change_detection/parser/ast.ts +++ b/modules/angular2/src/change_detection/parser/ast.ts @@ -15,7 +15,7 @@ export class AST { } export class EmptyExpr extends AST { - eval(context, locals: Locals) { return null; } + eval(context, locals: Locals): any { return null; } visit(visitor: AstVisitor) { // do nothing @@ -23,9 +23,9 @@ export class EmptyExpr extends AST { } export class ImplicitReceiver extends AST { - eval(context, locals: Locals) { return context; } + eval(context, locals: Locals): any { return context; } - visit(visitor: AstVisitor) { return visitor.visitImplicitReceiver(this); } + visit(visitor: AstVisitor): any { return visitor.visitImplicitReceiver(this); } } /** @@ -34,7 +34,7 @@ export class ImplicitReceiver extends AST { export class Chain extends AST { constructor(public expressions: List) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var result; for (var i = 0; i < this.expressions.length; i++) { var last = this.expressions[i].eval(context, locals); @@ -43,13 +43,13 @@ export class Chain extends AST { return result; } - visit(visitor: AstVisitor) { return visitor.visitChain(this); } + visit(visitor: AstVisitor): any { return visitor.visitChain(this); } } export class Conditional extends AST { constructor(public condition: AST, public trueExp: AST, public falseExp: AST) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { if (this.condition.eval(context, locals)) { return this.trueExp.eval(context, locals); } else { @@ -57,7 +57,7 @@ export class Conditional extends AST { } } - visit(visitor: AstVisitor) { return visitor.visitConditional(this); } + visit(visitor: AstVisitor): any { return visitor.visitConditional(this); } } export class If extends AST { @@ -71,7 +71,7 @@ export class If extends AST { } } - visit(visitor: AstVisitor) { return visitor.visitIf(this); } + visit(visitor: AstVisitor): any { return visitor.visitIf(this); } } export class AccessMember extends AST { @@ -80,7 +80,7 @@ export class AccessMember extends AST { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { if (this.receiver instanceof ImplicitReceiver && isPresent(locals) && locals.contains(this.name)) { return locals.get(this.name); @@ -92,7 +92,7 @@ export class AccessMember extends AST { get isAssignable(): boolean { return true; } - assign(context, locals: Locals, value) { + assign(context, locals: Locals, value): any { var evaluatedContext = this.receiver.eval(context, locals); if (this.receiver instanceof ImplicitReceiver && isPresent(locals) && @@ -103,7 +103,7 @@ export class AccessMember extends AST { } } - visit(visitor: AstVisitor) { return visitor.visitAccessMember(this); } + visit(visitor: AstVisitor): any { return visitor.visitAccessMember(this); } } export class SafeAccessMember extends AST { @@ -112,18 +112,18 @@ export class SafeAccessMember extends AST { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var evaluatedReceiver = this.receiver.eval(context, locals); return isBlank(evaluatedReceiver) ? null : this.getter(evaluatedReceiver); } - visit(visitor: AstVisitor) { return visitor.visitSafeAccessMember(this); } + visit(visitor: AstVisitor): any { return visitor.visitSafeAccessMember(this); } } export class KeyedAccess extends AST { constructor(public obj: AST, public key: AST) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var obj: any = this.obj.eval(context, locals); var key: any = this.key.eval(context, locals); return obj[key]; @@ -131,44 +131,44 @@ export class KeyedAccess extends AST { get isAssignable(): boolean { return true; } - assign(context, locals: Locals, value) { + assign(context, locals: Locals, value): any { var obj: any = this.obj.eval(context, locals); var key: any = this.key.eval(context, locals); obj[key] = value; return value; } - visit(visitor: AstVisitor) { return visitor.visitKeyedAccess(this); } + visit(visitor: AstVisitor): any { return visitor.visitKeyedAccess(this); } } export class BindingPipe extends AST { constructor(public exp: AST, public name: string, public args: List) { super(); } - visit(visitor: AstVisitor) { return visitor.visitPipe(this); } + visit(visitor: AstVisitor): any { return visitor.visitPipe(this); } } export class LiteralPrimitive extends AST { constructor(public value) { super(); } - eval(context, locals: Locals) { return this.value; } + eval(context, locals: Locals): any { return this.value; } - visit(visitor: AstVisitor) { return visitor.visitLiteralPrimitive(this); } + visit(visitor: AstVisitor): any { return visitor.visitLiteralPrimitive(this); } } export class LiteralArray extends AST { constructor(public expressions: List) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { return ListWrapper.map(this.expressions, (e) => e.eval(context, locals)); } - visit(visitor: AstVisitor) { return visitor.visitLiteralArray(this); } + visit(visitor: AstVisitor): any { return visitor.visitLiteralArray(this); } } export class LiteralMap extends AST { constructor(public keys: List, public values: List) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var res = StringMapWrapper.create(); for (var i = 0; i < this.keys.length; ++i) { StringMapWrapper.set(res, this.keys[i], this.values[i].eval(context, locals)); @@ -176,13 +176,15 @@ export class LiteralMap extends AST { return res; } - visit(visitor: AstVisitor) { return visitor.visitLiteralMap(this); } + visit(visitor: AstVisitor): any { return visitor.visitLiteralMap(this); } } export class Interpolation extends AST { constructor(public strings: List, public expressions: List) { super(); } - eval(context, locals) { throw new BaseException("evaluating an Interpolation is not supported"); } + eval(context, locals): any { + throw new BaseException("evaluating an Interpolation is not supported"); + } visit(visitor: AstVisitor) { visitor.visitInterpolation(this); } } @@ -190,7 +192,7 @@ export class Interpolation extends AST { export class Binary extends AST { constructor(public operation: string, public left: AST, public right: AST) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var left: any = this.left.eval(context, locals); switch (this.operation) { case '&&': @@ -235,25 +237,25 @@ export class Binary extends AST { throw 'Internal error [$operation] not handled'; } - visit(visitor: AstVisitor) { return visitor.visitBinary(this); } + visit(visitor: AstVisitor): any { return visitor.visitBinary(this); } } export class PrefixNot extends AST { constructor(public expression: AST) { super(); } - eval(context, locals: Locals) { return !this.expression.eval(context, locals); } + eval(context, locals: Locals): any { return !this.expression.eval(context, locals); } - visit(visitor: AstVisitor) { return visitor.visitPrefixNot(this); } + visit(visitor: AstVisitor): any { return visitor.visitPrefixNot(this); } } export class Assignment extends AST { constructor(public target: AST, public value: AST) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { return this.target.assign(context, locals, this.value.eval(context, locals)); } - visit(visitor: AstVisitor) { return visitor.visitAssignment(this); } + visit(visitor: AstVisitor): any { return visitor.visitAssignment(this); } } export class MethodCall extends AST { @@ -262,7 +264,7 @@ export class MethodCall extends AST { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var evaluatedArgs = evalList(context, locals, this.args); if (this.receiver instanceof ImplicitReceiver && isPresent(locals) && locals.contains(this.name)) { @@ -274,7 +276,7 @@ export class MethodCall extends AST { } } - visit(visitor: AstVisitor) { return visitor.visitMethodCall(this); } + visit(visitor: AstVisitor): any { return visitor.visitMethodCall(this); } } export class SafeMethodCall extends AST { @@ -283,20 +285,20 @@ export class SafeMethodCall extends AST { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var evaluatedReceiver = this.receiver.eval(context, locals); if (isBlank(evaluatedReceiver)) return null; var evaluatedArgs = evalList(context, locals, this.args); return this.fn(evaluatedReceiver, evaluatedArgs); } - visit(visitor: AstVisitor) { return visitor.visitSafeMethodCall(this); } + visit(visitor: AstVisitor): any { return visitor.visitSafeMethodCall(this); } } export class FunctionCall extends AST { constructor(public target: AST, public args: List) { super(); } - eval(context, locals: Locals) { + eval(context, locals: Locals): any { var obj: any = this.target.eval(context, locals); if (!(obj instanceof Function)) { throw new BaseException(`${obj} is not a function`); @@ -304,19 +306,19 @@ export class FunctionCall extends AST { return FunctionWrapper.apply(obj, evalList(context, locals, this.args)); } - visit(visitor: AstVisitor) { return visitor.visitFunctionCall(this); } + visit(visitor: AstVisitor): any { return visitor.visitFunctionCall(this); } } export class ASTWithSource extends AST { constructor(public ast: AST, public source: string, public location: string) { super(); } - eval(context, locals: Locals) { return this.ast.eval(context, locals); } + eval(context, locals: Locals): any { return this.ast.eval(context, locals); } get isAssignable(): boolean { return this.ast.isAssignable; } - assign(context, locals: Locals, value) { return this.ast.assign(context, locals, value); } + assign(context, locals: Locals, value): any { return this.ast.assign(context, locals, value); } - visit(visitor: AstVisitor) { return this.ast.visit(visitor); } + visit(visitor: AstVisitor): any { return this.ast.visit(visitor); } toString(): string { return `${this.source} in ${this.location}`; } } @@ -348,58 +350,64 @@ export interface AstVisitor { } export class AstTransformer implements AstVisitor { - visitImplicitReceiver(ast: ImplicitReceiver) { return ast; } + visitImplicitReceiver(ast: ImplicitReceiver): ImplicitReceiver { return ast; } - visitInterpolation(ast: Interpolation) { + visitInterpolation(ast: Interpolation): Interpolation { return new Interpolation(ast.strings, this.visitAll(ast.expressions)); } - visitLiteralPrimitive(ast: LiteralPrimitive) { return new LiteralPrimitive(ast.value); } + visitLiteralPrimitive(ast: LiteralPrimitive): LiteralPrimitive { + return new LiteralPrimitive(ast.value); + } - visitAccessMember(ast: AccessMember) { + visitAccessMember(ast: AccessMember): AccessMember { return new AccessMember(ast.receiver.visit(this), ast.name, ast.getter, ast.setter); } - visitSafeAccessMember(ast: SafeAccessMember) { + visitSafeAccessMember(ast: SafeAccessMember): SafeAccessMember { return new SafeAccessMember(ast.receiver.visit(this), ast.name, ast.getter, ast.setter); } - visitMethodCall(ast: MethodCall) { + visitMethodCall(ast: MethodCall): MethodCall { return new MethodCall(ast.receiver.visit(this), ast.name, ast.fn, this.visitAll(ast.args)); } - visitSafeMethodCall(ast: SafeMethodCall) { + visitSafeMethodCall(ast: SafeMethodCall): SafeMethodCall { return new SafeMethodCall(ast.receiver.visit(this), ast.name, ast.fn, this.visitAll(ast.args)); } - visitFunctionCall(ast: FunctionCall) { + visitFunctionCall(ast: FunctionCall): FunctionCall { return new FunctionCall(ast.target.visit(this), this.visitAll(ast.args)); } - visitLiteralArray(ast: LiteralArray) { return new LiteralArray(this.visitAll(ast.expressions)); } + visitLiteralArray(ast: LiteralArray): LiteralArray { + return new LiteralArray(this.visitAll(ast.expressions)); + } - visitLiteralMap(ast: LiteralMap) { return new LiteralMap(ast.keys, this.visitAll(ast.values)); } + visitLiteralMap(ast: LiteralMap): LiteralMap { + return new LiteralMap(ast.keys, this.visitAll(ast.values)); + } - visitBinary(ast: Binary) { + visitBinary(ast: Binary): Binary { return new Binary(ast.operation, ast.left.visit(this), ast.right.visit(this)); } - visitPrefixNot(ast: PrefixNot) { return new PrefixNot(ast.expression.visit(this)); } + visitPrefixNot(ast: PrefixNot): PrefixNot { return new PrefixNot(ast.expression.visit(this)); } - visitConditional(ast: Conditional) { + visitConditional(ast: Conditional): Conditional { return new Conditional(ast.condition.visit(this), ast.trueExp.visit(this), ast.falseExp.visit(this)); } - visitPipe(ast: BindingPipe) { + visitPipe(ast: BindingPipe): BindingPipe { return new BindingPipe(ast.exp.visit(this), ast.name, this.visitAll(ast.args)); } - visitKeyedAccess(ast: KeyedAccess) { + visitKeyedAccess(ast: KeyedAccess): KeyedAccess { return new KeyedAccess(ast.obj.visit(this), ast.key.visit(this)); } - visitAll(asts: List) { + visitAll(asts: List): List { var res = ListWrapper.createFixedSize(asts.length); for (var i = 0; i < asts.length; ++i) { res[i] = asts[i].visit(this); @@ -407,13 +415,13 @@ export class AstTransformer implements AstVisitor { return res; } - visitChain(ast: Chain) { return new Chain(this.visitAll(ast.expressions)); } + visitChain(ast: Chain): Chain { return new Chain(this.visitAll(ast.expressions)); } - visitAssignment(ast: Assignment) { + visitAssignment(ast: Assignment): Assignment { return new Assignment(ast.target.visit(this), ast.value.visit(this)); } - visitIf(ast: If) { + visitIf(ast: If): If { let falseExp = isPresent(ast.falseExp) ? ast.falseExp.visit(this) : null; return new If(ast.condition.visit(this), ast.trueExp.visit(this), falseExp); } @@ -433,7 +441,7 @@ var _evalListCache = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]; -function evalList(context, locals: Locals, exps: List) { +function evalList(context, locals: Locals, exps: List): any[] { var length = exps.length; if (length > 10) { throw new BaseException("Cannot have more than 10 argument"); diff --git a/modules/angular2/src/change_detection/parser/locals.ts b/modules/angular2/src/change_detection/parser/locals.ts index d7f9ac0a11..5042991d85 100644 --- a/modules/angular2/src/change_detection/parser/locals.ts +++ b/modules/angular2/src/change_detection/parser/locals.ts @@ -16,7 +16,7 @@ export class Locals { return false; } - get(name: string) { + get(name: string): any { if (this.current.has(name)) { return this.current.get(name); } @@ -41,4 +41,4 @@ export class Locals { } clearValues(): void { MapWrapper.clearValues(this.current); } -} \ No newline at end of file +} diff --git a/modules/angular2/src/change_detection/parser/parser.ts b/modules/angular2/src/change_detection/parser/parser.ts index 7fbe05adcc..f7049ab52f 100644 --- a/modules/angular2/src/change_detection/parser/parser.ts +++ b/modules/angular2/src/change_detection/parser/parser.ts @@ -217,7 +217,7 @@ class _ParseAST { return ast; } - parsePipe() { + parsePipe(): AST { var result = this.parseExpression(); if (this.optionalOperator("|")) { if (this.parseAction) { @@ -237,7 +237,7 @@ class _ParseAST { return result; } - parseExpression() { + parseExpression(): AST { var start = this.inputIndex; var result = this.parseConditional(); @@ -259,7 +259,7 @@ class _ParseAST { return result; } - parseConditional() { + parseConditional(): AST { var start = this.inputIndex; var result = this.parseLogicalOr(); @@ -277,7 +277,7 @@ class _ParseAST { } } - parseLogicalOr() { + parseLogicalOr(): AST { // '||' var result = this.parseLogicalAnd(); while (this.optionalOperator('||')) { @@ -286,7 +286,7 @@ class _ParseAST { return result; } - parseLogicalAnd() { + parseLogicalAnd(): AST { // '&&' var result = this.parseEquality(); while (this.optionalOperator('&&')) { @@ -295,7 +295,7 @@ class _ParseAST { return result; } - parseEquality() { + parseEquality(): AST { // '==','!=','===','!==' var result = this.parseRelational(); while (true) { @@ -313,7 +313,7 @@ class _ParseAST { } } - parseRelational() { + parseRelational(): AST { // '<', '>', '<=', '>=' var result = this.parseAdditive(); while (true) { @@ -331,7 +331,7 @@ class _ParseAST { } } - parseAdditive() { + parseAdditive(): AST { // '+', '-' var result = this.parseMultiplicative(); while (true) { @@ -345,7 +345,7 @@ class _ParseAST { } } - parseMultiplicative() { + parseMultiplicative(): AST { // '*', '%', '/' var result = this.parsePrefix(); while (true) { @@ -361,7 +361,7 @@ class _ParseAST { } } - parsePrefix() { + parsePrefix(): AST { if (this.optionalOperator('+')) { return this.parsePrefix(); } else if (this.optionalOperator('-')) { @@ -398,12 +398,11 @@ class _ParseAST { } } - parsePrimary() { + parsePrimary(): AST { if (this.optionalCharacter($LPAREN)) { let result = this.parsePipe(); this.expectCharacter($RPAREN); - return result - + return result; } else if (this.next.isKeywordNull() || this.next.isKeywordUndefined()) { this.advance(); return new LiteralPrimitive(null); @@ -427,7 +426,7 @@ class _ParseAST { this.advance(); elseExp = this.parseExpressionOrBlock(); } - return new If(condition, ifExp, elseExp) + return new If(condition, ifExp, elseExp); } else if (this.optionalCharacter($LBRACKET)) { var elements = this.parseExpressionList($RBRACKET); @@ -456,6 +455,8 @@ class _ParseAST { } else { this.error(`Unexpected token ${this.next}`); } + // error() throws, so we don't reach here. + throw new BaseException("Fell through all cases in parsePrimary"); } parseExpressionList(terminator: int): List { @@ -468,7 +469,7 @@ class _ParseAST { return result; } - parseLiteralMap() { + parseLiteralMap(): LiteralMap { var keys = []; var values = []; this.expectCharacter($LBRACE); @@ -502,7 +503,7 @@ class _ParseAST { } } - parseCallArguments() { + parseCallArguments(): BindingPipe[] { if (this.next.isCharacter($RPAREN)) return []; var positionals = []; do { @@ -545,7 +546,7 @@ class _ParseAST { /** * An identifier, a keyword, a string with an optional `-` inbetween. */ - expectTemplateBindingKey() { + expectTemplateBindingKey(): string { var result = ''; var operatorFound = false; do { @@ -559,7 +560,7 @@ class _ParseAST { return result.toString(); } - parseTemplateBindings() { + parseTemplateBindings(): any[] { var bindings = []; var prefix = null; while (this.index < this.tokens.length) { @@ -607,7 +608,7 @@ class _ParseAST { } class SimpleExpressionChecker implements AstVisitor { - static check(ast: AST) { + static check(ast: AST): boolean { var s = new SimpleExpressionChecker(); ast.visit(s); return s.simple; @@ -645,7 +646,7 @@ class SimpleExpressionChecker implements AstVisitor { visitKeyedAccess(ast: KeyedAccess) { this.simple = false; } - visitAll(asts: List) { + visitAll(asts: List): List { var res = ListWrapper.createFixedSize(asts.length); for (var i = 0; i < asts.length; ++i) { res[i] = asts[i].visit(this); diff --git a/modules/angular2/src/change_detection/pipes/null_pipe.ts b/modules/angular2/src/change_detection/pipes/null_pipe.ts index a0e95db44e..4037368d96 100644 --- a/modules/angular2/src/change_detection/pipes/null_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/null_pipe.ts @@ -19,9 +19,9 @@ export class NullPipe extends BasePipe { static supportsObj(obj): boolean { return isBlank(obj); } - supports(obj) { return NullPipe.supportsObj(obj); } + supports(obj): boolean { return NullPipe.supportsObj(obj); } - transform(value) { + transform(value): WrappedValue { if (!this.called) { this.called = true; return WrappedValue.wrap(null); diff --git a/modules/angular2/src/change_detection/proto_change_detector.ts b/modules/angular2/src/change_detection/proto_change_detector.ts index 03811f6d89..9e2d4ef7d2 100644 --- a/modules/angular2/src/change_detection/proto_change_detector.ts +++ b/modules/angular2/src/change_detection/proto_change_detector.ts @@ -43,7 +43,7 @@ export class DynamicProtoChangeDetector implements ProtoChangeDetector { this._records = this._createRecords(definition); } - instantiate(dispatcher: any) { + instantiate(dispatcher: any): ChangeDetector { return new DynamicChangeDetector(this.definition.id, this.definition.strategy, dispatcher, this._pipeRegistry, this._records, this.definition.directiveRecords); @@ -95,19 +95,19 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { b.ast.visit(c); } - visitImplicitReceiver(ast: ImplicitReceiver) { return this._bindingRecord.implicitReceiver; } + visitImplicitReceiver(ast: ImplicitReceiver): any { return this._bindingRecord.implicitReceiver; } - visitInterpolation(ast: Interpolation) { + visitInterpolation(ast: Interpolation): number { var args = this._visitAll(ast.expressions); return this._addRecord(RecordType.INTERPOLATE, "interpolate", _interpolationFn(ast.strings), args, ast.strings, 0); } - visitLiteralPrimitive(ast: LiteralPrimitive) { + visitLiteralPrimitive(ast: LiteralPrimitive): number { return this._addRecord(RecordType.CONST, "literal", ast.value, [], null, 0); } - visitAccessMember(ast: AccessMember) { + visitAccessMember(ast: AccessMember): number { var receiver = ast.receiver.visit(this); if (isPresent(this._variableNames) && ListWrapper.contains(this._variableNames, ast.name) && ast.receiver instanceof @@ -118,12 +118,12 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { } } - visitSafeAccessMember(ast: SafeAccessMember) { + visitSafeAccessMember(ast: SafeAccessMember): number { var receiver = ast.receiver.visit(this); return this._addRecord(RecordType.SAFE_PROPERTY, ast.name, ast.getter, [], null, receiver); } - visitMethodCall(ast: MethodCall) { + visitMethodCall(ast: MethodCall): number { var receiver = ast.receiver.visit(this); var args = this._visitAll(ast.args); if (isPresent(this._variableNames) && ListWrapper.contains(this._variableNames, ast.name)) { @@ -134,44 +134,44 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { } } - visitSafeMethodCall(ast: SafeMethodCall) { + visitSafeMethodCall(ast: SafeMethodCall): number { var receiver = ast.receiver.visit(this); var args = this._visitAll(ast.args); return this._addRecord(RecordType.SAFE_INVOKE_METHOD, ast.name, ast.fn, args, null, receiver); } - visitFunctionCall(ast: FunctionCall) { + visitFunctionCall(ast: FunctionCall): number { var target = ast.target.visit(this); var args = this._visitAll(ast.args); return this._addRecord(RecordType.INVOKE_CLOSURE, "closure", null, args, null, target); } - visitLiteralArray(ast: LiteralArray) { + visitLiteralArray(ast: LiteralArray): number { var primitiveName = `arrayFn${ast.expressions.length}`; return this._addRecord(RecordType.PRIMITIVE_OP, primitiveName, _arrayFn(ast.expressions.length), this._visitAll(ast.expressions), null, 0); } - visitLiteralMap(ast: LiteralMap) { + visitLiteralMap(ast: LiteralMap): number { return this._addRecord(RecordType.PRIMITIVE_OP, _mapPrimitiveName(ast.keys), ChangeDetectionUtil.mapFn(ast.keys), this._visitAll(ast.values), null, 0); } - visitBinary(ast: Binary) { + visitBinary(ast: Binary): number { var left = ast.left.visit(this); var right = ast.right.visit(this); return this._addRecord(RecordType.PRIMITIVE_OP, _operationToPrimitiveName(ast.operation), _operationToFunction(ast.operation), [left, right], null, 0); } - visitPrefixNot(ast: PrefixNot) { + visitPrefixNot(ast: PrefixNot): number { var exp = ast.expression.visit(this); return this._addRecord(RecordType.PRIMITIVE_OP, "operation_negate", ChangeDetectionUtil.operation_negate, [exp], null, 0); } - visitConditional(ast: Conditional) { + visitConditional(ast: Conditional): number { var c = ast.condition.visit(this); var t = ast.trueExp.visit(this); var f = ast.falseExp.visit(this); @@ -179,12 +179,12 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { null, 0); } - visitPipe(ast: BindingPipe) { + visitPipe(ast: BindingPipe): number { var value = ast.exp.visit(this); return this._addRecord(RecordType.PIPE, ast.name, ast.name, [], null, value); } - visitKeyedAccess(ast: KeyedAccess) { + visitKeyedAccess(ast: KeyedAccess): number { var obj = ast.obj.visit(this); var key = ast.key.visit(this); return this._addRecord(RecordType.KEYED_ACCESS, "keyedAccess", ChangeDetectionUtil.keyedAccess, @@ -328,7 +328,7 @@ function _operationToFunction(operation: string): Function { } } -function s(v) { +function s(v): string { return isPresent(v) ? `${v}` : ''; } diff --git a/modules/angular2/src/core/annotations_impl/di.ts b/modules/angular2/src/core/annotations_impl/di.ts index d6733e8b13..78ed67384a 100644 --- a/modules/angular2/src/core/annotations_impl/di.ts +++ b/modules/angular2/src/core/annotations_impl/di.ts @@ -42,7 +42,7 @@ export class Attribute extends DependencyAnnotation { // account. return this; } - toString() { return `@Attribute(${stringify(this.attributeName)})`; } + toString(): string { return `@Attribute(${stringify(this.attributeName)})`; } } /** @@ -67,5 +67,5 @@ export class Query extends DependencyAnnotation { get varBindings(): List { return StringWrapper.split(this.selector, new RegExp(",")); } - toString() { return `@Query(${stringify(this.selector)})`; } + toString(): string { return `@Query(${stringify(this.selector)})`; } } diff --git a/modules/angular2/src/core/application.ts b/modules/angular2/src/core/application.ts index 7d09cf0c2c..1672cb7aa8 100644 --- a/modules/angular2/src/core/application.ts +++ b/modules/angular2/src/core/application.ts @@ -326,7 +326,7 @@ export class ApplicationRef { dispose() { // TODO: We also need to clean up the Zone, ... here! - return this._hostComponent.dispose(); + this._hostComponent.dispose(); } get injector() { return this._injector; } diff --git a/modules/angular2/src/core/compiler/base_query_list.ts b/modules/angular2/src/core/compiler/base_query_list.ts index b23ea565ab..1768f9ca09 100644 --- a/modules/angular2/src/core/compiler/base_query_list.ts +++ b/modules/angular2/src/core/compiler/base_query_list.ts @@ -14,7 +14,7 @@ export class BaseQueryList { protected _callbacks = []; protected _dirty = false; - [Symbol.iterator]() { return this._results[Symbol.iterator](); } + [Symbol.iterator](): any { return this._results[Symbol.iterator](); } reset(newList) { this._results = newList; @@ -33,9 +33,9 @@ export class BaseQueryList { } } - onChange(callback) { this._callbacks.push(callback); } + onChange(callback): void { this._callbacks.push(callback); } - removeCallback(callback) { ListWrapper.remove(this._callbacks, callback); } + removeCallback(callback): void { ListWrapper.remove(this._callbacks, callback); } get length() { return this._results.length; } get first() { return ListWrapper.first(this._results); } diff --git a/modules/angular2/src/core/compiler/element_binder.ts b/modules/angular2/src/core/compiler/element_binder.ts index ac9e3ee4a2..adca11aa3d 100644 --- a/modules/angular2/src/core/compiler/element_binder.ts +++ b/modules/angular2/src/core/compiler/element_binder.ts @@ -19,11 +19,11 @@ export class ElementBinder { } } - hasStaticComponent() { + hasStaticComponent(): boolean { return isPresent(this.componentDirective) && isPresent(this.nestedProtoView); } - hasEmbeddedProtoView() { + hasEmbeddedProtoView(): boolean { return !isPresent(this.componentDirective) && isPresent(this.nestedProtoView); } } diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 3528d9fa9f..8771509085 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -190,11 +190,13 @@ export class DirectiveDependency extends Dependency { } static _attributeName(properties): string { - var p = ListWrapper.find(properties, (p) => p instanceof Attribute); + var p = ListWrapper.find(properties, (p) => p instanceof Attribute); return isPresent(p) ? p.attributeName : null; } - static _query(properties) { return ListWrapper.find(properties, (p) => p instanceof Query); } + static _query(properties): Query { + return ListWrapper.find(properties, (p) => p instanceof Query); + } } export class DirectiveBinding extends ResolvedBinding { @@ -292,7 +294,7 @@ export class PreBuiltObjects { export class EventEmitterAccessor { constructor(public eventName: string, public getter: Function) {} - subscribe(view: viewModule.AppView, boundElementIndex: number, directive: Object) { + subscribe(view: viewModule.AppView, boundElementIndex: number, directive: Object): Object { var eventEmitter = this.getter(directive); return ObservableWrapper.subscribe( eventEmitter, @@ -303,7 +305,7 @@ export class EventEmitterAccessor { export class HostActionAccessor { constructor(public methodName: string, public getter: Function) {} - subscribe(view: viewModule.AppView, boundElementIndex: number, directive: Object) { + subscribe(view: viewModule.AppView, boundElementIndex: number, directive: Object): Object { var eventEmitter = this.getter(directive); return ObservableWrapper.subscribe( eventEmitter, @@ -314,9 +316,9 @@ export class HostActionAccessor { export class BindingData { constructor(public binding: ResolvedBinding, public visibility: number) {} - getKeyId() { return this.binding.key.id; } + getKeyId(): number { return this.binding.key.id; } - createEventEmitterAccessors() { + createEventEmitterAccessors(): List { if (!(this.binding instanceof DirectiveBinding)) return []; var db = this.binding; return ListWrapper.map(db.eventEmitters, eventConfig => { @@ -331,11 +333,11 @@ export class BindingData { // short format: 'name' when fieldName and eventName are the same fieldName = eventName = eventConfig; } - return new EventEmitterAccessor(eventName, reflector.getter(fieldName)) + return new EventEmitterAccessor(eventName, reflector.getter(fieldName)); }); } - createHostActionAccessors() { + createHostActionAccessors(): HostActionAccessor[] { if (!(this.binding instanceof DirectiveBinding)) return []; var res = []; var db = this.binding; @@ -355,7 +357,7 @@ export class ProtoElementInjector { static create(parent: ProtoElementInjector, index: number, bindings: List, firstBindingIsComponent: boolean, distanceToParent: number, - directiveVariableBindings: Map) { + directiveVariableBindings: Map): ProtoElementInjector { var bd = []; ProtoElementInjector._createDirectiveBindingData(bindings, bd, firstBindingIsComponent); @@ -808,7 +810,7 @@ export class ElementInjector extends TreeNode { } } - getDirectiveAtIndex(index: number) { return this._injector.getObjAtIndex(index); } + getDirectiveAtIndex(index: number): any { return this._injector.getObjAtIndex(index); } hasInstances(): boolean { return this._proto.hasBindings && this.hydrated; } diff --git a/modules/angular2/src/core/compiler/proto_view_factory.ts b/modules/angular2/src/core/compiler/proto_view_factory.ts index d67f73c2b8..84a2c71f49 100644 --- a/modules/angular2/src/core/compiler/proto_view_factory.ts +++ b/modules/angular2/src/core/compiler/proto_view_factory.ts @@ -286,12 +286,14 @@ function _collectNestedProtoViewsVariableNames( return nestedPvVariableNames; } -function _createVariableNames(parentVariableNames, renderProtoView): List { - var res = isBlank(parentVariableNames) ? [] : ListWrapper.clone(parentVariableNames); +function _createVariableNames(parentVariableNames: List, renderProtoView): List { + var res = + isBlank(parentVariableNames) ? >[] : ListWrapper.clone(parentVariableNames); MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => { res.push(mappedName); }); ListWrapper.forEach(renderProtoView.elementBinders, binder => { - MapWrapper.forEach(binder.variableBindings, (mappedName, varName) => { res.push(mappedName); }); + MapWrapper.forEach(binder.variableBindings, + (mappedName: string, varName: string) => { res.push(mappedName); }); }); return res; } diff --git a/modules/angular2/src/core/compiler/query_list.ts b/modules/angular2/src/core/compiler/query_list.ts index 9d0152c9cd..fe1b5b09b4 100644 --- a/modules/angular2/src/core/compiler/query_list.ts +++ b/modules/angular2/src/core/compiler/query_list.ts @@ -78,9 +78,9 @@ import {BaseQueryList} from './base_query_list'; export class QueryList extends BaseQueryList { /** */ - onChange(callback) { return super.onChange(callback); } + onChange(callback) { super.onChange(callback); } /** */ - removeCallback(callback) { return super.removeCallback(callback); } + removeCallback(callback) { super.removeCallback(callback); } } diff --git a/modules/angular2/src/core/compiler/view.ts b/modules/angular2/src/core/compiler/view.ts index d3f6030aea..0f5ce541b6 100644 --- a/modules/angular2/src/core/compiler/view.ts +++ b/modules/angular2/src/core/compiler/view.ts @@ -134,12 +134,12 @@ export class AppView implements ChangeDispatcher, EventDispatcher { } } - getDirectiveFor(directive: DirectiveIndex) { + getDirectiveFor(directive: DirectiveIndex): any { var elementInjector = this.elementInjectors[directive.elementIndex]; return elementInjector.getDirectiveAtIndex(directive.directiveIndex); } - getDetectorFor(directive: DirectiveIndex) { + getDetectorFor(directive: DirectiveIndex): any { var childView = this.componentChildViews[directive.elementIndex]; return isPresent(childView) ? childView.changeDetector : null; } diff --git a/modules/angular2/src/core/compiler/view_container_ref.ts b/modules/angular2/src/core/compiler/view_container_ref.ts index f3c56f486e..419c46c5e5 100644 --- a/modules/angular2/src/core/compiler/view_container_ref.ts +++ b/modules/angular2/src/core/compiler/view_container_ref.ts @@ -42,7 +42,9 @@ export class ViewContainerRef { return this.viewManager.attachViewInContainer(this.element, atIndex, viewRef); } - indexOf(viewRef: ViewRef) { return ListWrapper.indexOf(this._getViews(), internalView(viewRef)); } + indexOf(viewRef: ViewRef): number { + return ListWrapper.indexOf(this._getViews(), internalView(viewRef)); + } remove(atIndex: number = -1): void { if (atIndex == -1) atIndex = this.length - 1; diff --git a/modules/angular2/src/core/testability/get_testability.ts b/modules/angular2/src/core/testability/get_testability.ts index 58d4fd2c37..beded01be8 100644 --- a/modules/angular2/src/core/testability/get_testability.ts +++ b/modules/angular2/src/core/testability/get_testability.ts @@ -8,7 +8,7 @@ class PublicTestability { whenStable(callback: Function) { this._testability.whenStable(callback); } - findBindings(using, binding: string, exactMatch: boolean) { + findBindings(using, binding: string, exactMatch: boolean): List { return this._testability.findBindings(using, binding, exactMatch); } } diff --git a/modules/angular2/src/core/testability/testability.ts b/modules/angular2/src/core/testability/testability.ts index ff12895d97..5e4921c8de 100644 --- a/modules/angular2/src/core/testability/testability.ts +++ b/modules/angular2/src/core/testability/testability.ts @@ -20,7 +20,7 @@ export class Testability { this._callbacks = []; } - increaseCount(delta: number = 1) { + increaseCount(delta: number = 1): number { this._pendingCount += delta; if (this._pendingCount < 0) { throw new BaseException('pending async requests below zero'); diff --git a/modules/angular2/src/core/zone/ng_zone.ts b/modules/angular2/src/core/zone/ng_zone.ts index 8d2e1d6300..304a7d7fb0 100644 --- a/modules/angular2/src/core/zone/ng_zone.ts +++ b/modules/angular2/src/core/zone/ng_zone.ts @@ -103,7 +103,7 @@ export class NgZone { * }); * ``` */ - run(fn) { + run(fn): any { if (this._disabled) { return fn(); } else { @@ -127,7 +127,7 @@ export class NgZone { * }); * ``` */ - runOutsideAngular(fn) { + runOutsideAngular(fn): any { if (this._disabled) { return fn(); } else { diff --git a/modules/angular2/src/debug/debug_element.ts b/modules/angular2/src/debug/debug_element.ts index 2fc03aab38..f61d8e8219 100644 --- a/modules/angular2/src/debug/debug_element.ts +++ b/modules/angular2/src/debug/debug_element.ts @@ -1,5 +1,5 @@ import {Type, isPresent, BaseException, isBlank} from 'angular2/src/facade/lang'; -import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; +import {List, ListWrapper, MapWrapper, Predicate} from 'angular2/src/facade/collection'; import {DOM} from 'angular2/src/dom/dom_adapter'; @@ -90,7 +90,7 @@ export class DebugElement { getLocal(name: string): any { return this._parentView.locals.get(name); } /** - * Return the first descendant TestElememt matching the given predicate + * Return the first descendant TestElement matching the given predicate * and scope. * * @param {Function: boolean} predicate @@ -98,7 +98,7 @@ export class DebugElement { * * @return {DebugElement} */ - query(predicate: Function, scope = Scope.all): DebugElement { + query(predicate: Predicate, scope = Scope.all): DebugElement { var results = this.queryAll(predicate, scope); return results.length > 0 ? results[0] : null; } @@ -112,7 +112,7 @@ export class DebugElement { * * @return {List} */ - queryAll(predicate: Function, scope = Scope.all): List { + queryAll(predicate: Predicate, scope = Scope.all): List { var elementsInScope = scope(this); return ListWrapper.filter(elementsInScope, predicate); @@ -191,10 +191,10 @@ export class Scope { export class By { static all(): Function { return (debugElement) => true; } - static css(selector: string): Function { + static css(selector: string): Predicate { return (debugElement) => { return DOM.elementMatches(debugElement.nativeElement, selector); }; } - static directive(type: Type): Function { + static directive(type: Type): Predicate { return (debugElement) => { return debugElement.hasDirective(type); }; } } diff --git a/modules/angular2/src/di/binding.ts b/modules/angular2/src/di/binding.ts index 733e398f22..dee1a9ca28 100644 --- a/modules/angular2/src/di/binding.ts +++ b/modules/angular2/src/di/binding.ts @@ -29,7 +29,9 @@ export class Dependency { constructor(public key: Key, public optional: boolean, public visibility: Visibility, public properties: List) {} - static fromKey(key: Key) { return new Dependency(key, false, _defaulVisiblity(key.token), []); } + static fromKey(key: Key): Dependency { + return new Dependency(key, false, _defaulVisiblity(key.token), []); + } } const _EMPTY_LIST = CONST_EXPR([]); diff --git a/modules/angular2/src/directives/ng_for.ts b/modules/angular2/src/directives/ng_for.ts index a25b97645e..8378b838ca 100644 --- a/modules/angular2/src/directives/ng_for.ts +++ b/modules/angular2/src/directives/ng_for.ts @@ -91,7 +91,8 @@ export class NgFor { view.setLocal('index', record.currentIndex); } - static bulkRemove(tuples, viewContainer) { + static bulkRemove(tuples: List, + viewContainer: ViewContainerRef): List { tuples.sort((a, b) => a.record.previousIndex - b.record.previousIndex); var movedTuples = []; for (var i = tuples.length - 1; i >= 0; i--) { @@ -107,7 +108,8 @@ export class NgFor { return movedTuples; } - static bulkInsert(tuples, viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef) { + static bulkInsert(tuples: List, viewContainer: ViewContainerRef, + protoViewRef: ProtoViewRef): List { tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex); for (var i = 0; i < tuples.length; i++) { var tuple = tuples[i]; diff --git a/modules/angular2/src/dom/browser_adapter.ts b/modules/angular2/src/dom/browser_adapter.ts index ee0b7ccc29..e7ee492ffb 100644 --- a/modules/angular2/src/dom/browser_adapter.ts +++ b/modules/angular2/src/dom/browser_adapter.ts @@ -50,7 +50,7 @@ var _chromeNumKeyPadMap = { export class BrowserDomAdapter extends GenericBrowserDomAdapter { static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); } - hasProperty(element, name: string) { return name in element; } + hasProperty(element, name: string): boolean { return name in element; } setProperty(el: /*element*/ any, name: string, value: any) { el[name] = value; } getProperty(el: /*element*/ any, name: string): any { return el[name]; } invoke(el: /*element*/ any, methodName: string, args: List): any { @@ -87,8 +87,8 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { evt.preventDefault(); evt.returnValue = false; } - getInnerHTML(el) { return el.innerHTML; } - getOuterHTML(el) { return el.outerHTML; } + getInnerHTML(el): string { return el.innerHTML; } + getOuterHTML(el): string { return el.outerHTML; } nodeName(node: Node): string { return node.nodeName; } nodeValue(node: Node): string { return node.nodeValue; } type(node: HTMLInputElement): string { return node.type; } @@ -101,7 +101,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { } firstChild(el): Node { return el.firstChild; } nextSibling(el): Node { return el.nextSibling; } - parentElement(el) { return el.parentElement; } + parentElement(el): Node { return el.parentElement; } childNodes(el): List { return el.childNodes; } childNodesAsList(el): List { var childNodes = el.childNodes; @@ -119,7 +119,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { appendChild(el, node) { el.appendChild(node); } removeChild(el, node) { el.removeChild(node); } replaceChild(el: Node, newChild, oldChild) { el.replaceChild(newChild, oldChild); } - remove(el) { + remove(el): Node { var parent = el.parentNode; parent.removeChild(el); return el; @@ -130,12 +130,12 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { } insertAfter(el, node) { el.parentNode.insertBefore(node, el.nextSibling); } setInnerHTML(el, value) { el.innerHTML = value; } - getText(el) { return el.textContent; } + getText(el): string { return el.textContent; } // TODO(vicb): removed Element type because it does not support StyleElement setText(el, value: string) { el.textContent = value; } - getValue(el) { return el.value; } + getValue(el): string { return el.value; } setValue(el, value: string) { el.value = value; } - getChecked(el) { return el.checked; } + getChecked(el): boolean { return el.checked; } setChecked(el, value: boolean) { el.checked = value; } createTemplate(html): HTMLElement { var t = document.createElement('template'); @@ -157,22 +157,26 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { createShadowRoot(el: HTMLElement): DocumentFragment { return (el).createShadowRoot(); } getShadowRoot(el: HTMLElement): DocumentFragment { return (el).shadowRoot; } getHost(el: HTMLElement): HTMLElement { return (el).host; } - clone(node: Node) { return node.cloneNode(true); } - getElementsByClassName(element, name: string) { return element.getElementsByClassName(name); } - getElementsByTagName(element, name: string) { return element.getElementsByTagName(name); } + clone(node: Node): Node { return node.cloneNode(true); } + getElementsByClassName(element, name: string): List { + return element.getElementsByClassName(name); + } + getElementsByTagName(element, name: string): List { + return element.getElementsByTagName(name); + } classList(element): List { return >Array.prototype.slice.call(element.classList, 0); } addClass(element, classname: string) { element.classList.add(classname); } removeClass(element, classname: string) { element.classList.remove(classname); } - hasClass(element, classname: string) { return element.classList.contains(classname); } + hasClass(element, classname: string): boolean { return element.classList.contains(classname); } setStyle(element, stylename: string, stylevalue: string) { element.style[stylename] = stylevalue; } removeStyle(element, stylename: string) { element.style[stylename] = null; } - getStyle(element, stylename: string) { return element.style[stylename]; } + getStyle(element, stylename: string): string { return element.style[stylename]; } tagName(element): string { return element.tagName; } - attributeMap(element) { + attributeMap(element): Map { var res = new Map(); var elAttrs = element.attributes; for (var i = 0; i < elAttrs.length; i++) { @@ -181,14 +185,16 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { } return res; } - hasAttribute(element, attribute: string) { return element.hasAttribute(attribute); } - getAttribute(element, attribute: string) { return element.getAttribute(attribute); } + hasAttribute(element, attribute: string): boolean { return element.hasAttribute(attribute); } + getAttribute(element, attribute: string): string { return element.getAttribute(attribute); } setAttribute(element, name: string, value: string) { element.setAttribute(name, value); } - removeAttribute(element, attribute: string) { return element.removeAttribute(attribute); } - templateAwareRoot(el) { return this.isTemplateElement(el) ? this.content(el) : el; } - createHtmlDocument() { return document.implementation.createHTMLDocument('fakeTitle'); } - defaultDoc() { return document; } - getBoundingClientRect(el) { + removeAttribute(element, attribute: string) { element.removeAttribute(attribute); } + templateAwareRoot(el): any { return this.isTemplateElement(el) ? this.content(el) : el; } + createHtmlDocument(): HTMLDocument { + return document.implementation.createHTMLDocument('fakeTitle'); + } + defaultDoc(): HTMLDocument { return document; } + getBoundingClientRect(el): any { try { return el.getBoundingClientRect(); } catch (e) { @@ -209,7 +215,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { isElementNode(node: Node): boolean { return node.nodeType === Node.ELEMENT_NODE; } hasShadowRoot(node): boolean { return node instanceof HTMLElement && isPresent(node.shadowRoot); } isShadowRoot(node): boolean { return node instanceof DocumentFragment; } - importIntoDoc(node: Node) { + importIntoDoc(node: Node): any { var toImport = node; if (this.isTemplateElement(node)) { toImport = this.content(node); @@ -256,9 +262,9 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { return document.body; } } - getHistory() { return window.history; } - getLocation() { return window.location; } - getBaseHref() { return relativePath(document.baseURI); } + getHistory(): History { return window.history; } + getLocation(): Location { return window.location; } + getBaseHref(): string { return relativePath(document.baseURI); } getUserAgent(): string { return window.navigator.userAgent; } setData(element, name: string, value: string) { element.dataset[name] = value; } getData(element, name: string): string { return element.dataset[name]; } @@ -268,7 +274,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { // based on urlUtils.js in AngularJS 1 var urlParsingNode = null; -function relativePath(url) { +function relativePath(url): string { if (isBlank(urlParsingNode)) { urlParsingNode = document.createElement("a"); } diff --git a/modules/angular2/src/dom/dom_adapter.ts b/modules/angular2/src/dom/dom_adapter.ts index 74804d818c..35105a0e30 100644 --- a/modules/angular2/src/dom/dom_adapter.ts +++ b/modules/angular2/src/dom/dom_adapter.ts @@ -17,9 +17,11 @@ function _abstract() { */ export class DomAdapter { hasProperty(element, name: string): boolean { throw _abstract(); } - setProperty(el: /*element*/ any, name: string, value: any) { throw _abstract(); } - getProperty(el: /*element*/ any, name: string): any { throw _abstract(); } - invoke(el: /*element*/ any, methodName: string, args: List): any { throw _abstract(); } + setProperty(el: /*(#2770) Element*/ any, name: string, value: any) { throw _abstract(); } + getProperty(el: /*(#2770) Element*/ any, name: string): any { throw _abstract(); } + invoke(el: /*(#2770) Element*/ any, methodName: string, args: List): any { + throw _abstract(); + } logError(error) { throw _abstract(); } @@ -45,45 +47,53 @@ export class DomAdapter { nodeValue(node): string { throw _abstract(); } type(node): string { throw _abstract(); } content(node): any { throw _abstract(); } - firstChild(el): any { throw _abstract(); } - nextSibling(el): any { throw _abstract(); } - parentElement(el): any { throw _abstract(); } - childNodes(el): List { throw _abstract(); } - childNodesAsList(el): List { throw _abstract(); } + firstChild(el): /*(#2770) Node*/ any { throw _abstract(); } + nextSibling(el): /*(#2770) Node*/ any { throw _abstract(); } + parentElement(el): /*(#2770) Node*/ any { throw _abstract(); } + childNodes(el): List { throw _abstract(); } + childNodesAsList(el): List { throw _abstract(); } clearNodes(el) { throw _abstract(); } appendChild(el, node) { throw _abstract(); } removeChild(el, node) { throw _abstract(); } replaceChild(el, newNode, oldNode) { throw _abstract(); } - remove(el) { throw _abstract(); } + remove(el): /*(#2770) Node*/ any { throw _abstract(); } insertBefore(el, node) { throw _abstract(); } insertAllBefore(el, nodes) { throw _abstract(); } insertAfter(el, node) { throw _abstract(); } setInnerHTML(el, value) { throw _abstract(); } - getText(el): any { throw _abstract(); } + getText(el): string { throw _abstract(); } setText(el, value: string) { throw _abstract(); } - getValue(el): any { throw _abstract(); } + getValue(el): string { throw _abstract(); } setValue(el, value: string) { throw _abstract(); } - getChecked(el): any { throw _abstract(); } + getChecked(el): boolean { throw _abstract(); } setChecked(el, value: boolean) { throw _abstract(); } - createTemplate(html): any { throw _abstract(); } - createElement(tagName, doc = null): any { throw _abstract(); } - createTextNode(text: string, doc = null): any { throw _abstract(); } - createScriptTag(attrName: string, attrValue: string, doc = null): any { throw _abstract(); } - createStyleElement(css: string, doc = null): any { throw _abstract(); } + createTemplate(html): /*(#2770) HTMLElement*/ any { throw _abstract(); } + createElement(tagName, doc = null): /*(#2770) HTMLElement*/ any { throw _abstract(); } + createTextNode(text: string, doc = null): /*(#2770) Text*/ any { throw _abstract(); } + createScriptTag(attrName: string, attrValue: string, doc = null): /*(#2770) HTMLElement*/ any { + throw _abstract(); + } + createStyleElement(css: string, doc = null): /*(#2770) HTMLStyleElement*/ any { + throw _abstract(); + } createShadowRoot(el): any { throw _abstract(); } getShadowRoot(el): any { throw _abstract(); } getHost(el): any { throw _abstract(); } - getDistributedNodes(el): List { throw _abstract(); } - clone(node): any { throw _abstract(); } - getElementsByClassName(element, name: string): List { throw _abstract(); } - getElementsByTagName(element, name: string): List { throw _abstract(); } + getDistributedNodes(el): List { throw _abstract(); } + clone(node: /*(#2770) Node*/ any): /*(#2770) Node*/ any { throw _abstract(); } + getElementsByClassName(element, name: string): List { + throw _abstract(); + } + getElementsByTagName(element, name: string): List { + throw _abstract(); + } classList(element): List { throw _abstract(); } addClass(element, classname: string) { throw _abstract(); } removeClass(element, classname: string) { throw _abstract(); } - hasClass(element, classname: string) { throw _abstract(); } + hasClass(element, classname: string): boolean { throw _abstract(); } setStyle(element, stylename: string, stylevalue: string) { throw _abstract(); } removeStyle(element, stylename: string) { throw _abstract(); } - getStyle(element, stylename: string) { throw _abstract(); } + getStyle(element, stylename: string): string { throw _abstract(); } tagName(element): string { throw _abstract(); } attributeMap(element): Map { throw _abstract(); } hasAttribute(element, attribute: string): boolean { throw _abstract(); } @@ -91,8 +101,8 @@ export class DomAdapter { setAttribute(element, name: string, value: string) { throw _abstract(); } removeAttribute(element, attribute: string) { throw _abstract(); } templateAwareRoot(el) { throw _abstract(); } - createHtmlDocument() { throw _abstract(); } - defaultDoc(): any { throw _abstract(); } + createHtmlDocument(): /*(#2770) HTMLDocument*/ any { throw _abstract(); } + defaultDoc(): /*(#2770) HTMLDocument*/ any { throw _abstract(); } getBoundingClientRect(el) { throw _abstract(); } getTitle(): string { throw _abstract(); } setTitle(newTitle: string) { throw _abstract(); } @@ -115,8 +125,8 @@ export class DomAdapter { supportsDOMEvents(): boolean { throw _abstract(); } supportsNativeShadowDOM(): boolean { throw _abstract(); } getGlobalEventTarget(target: string): any { throw _abstract(); } - getHistory(): any { throw _abstract(); } - getLocation(): any { throw _abstract(); } + getHistory(): /*(#2770) History*/ any { throw _abstract(); } + getLocation(): /*(#2770) Location*/ any { throw _abstract(); } getBaseHref(): string { throw _abstract(); } getUserAgent(): string { throw _abstract(); } setData(element, name: string, value: string) { throw _abstract(); } diff --git a/modules/angular2/src/dom/generic_browser_adapter.ts b/modules/angular2/src/dom/generic_browser_adapter.ts index db2a797bb5..1f78217c1f 100644 --- a/modules/angular2/src/dom/generic_browser_adapter.ts +++ b/modules/angular2/src/dom/generic_browser_adapter.ts @@ -6,7 +6,7 @@ import {DomAdapter} from './dom_adapter'; * Provides DOM operations in any browser environment. */ export class GenericBrowserDomAdapter extends DomAdapter { - getDistributedNodes(el) { return el.getDistributedNodes(); } + getDistributedNodes(el): List { return el.getDistributedNodes(); } resolveAndSetHref(el, baseUrl: string, href: string) { el.href = href == null ? baseUrl : baseUrl + '/../' + href; } @@ -19,7 +19,7 @@ export class GenericBrowserDomAdapter extends DomAdapter { // with an @import // https://bugzilla.mozilla.org/show_bug.cgi?id=625013 try { - var rawRules = style.sheet.cssRules; + var rawRules = (style.sheet).cssRules; rules = ListWrapper.createFixedSize(rawRules.length); for (var i = 0; i < rawRules.length; i++) { rules[i] = rawRules[i]; @@ -34,5 +34,7 @@ export class GenericBrowserDomAdapter extends DomAdapter { return rules; } supportsDOMEvents(): boolean { return true; } - supportsNativeShadowDOM(): boolean { return isFunction(this.defaultDoc().body.createShadowRoot); } + supportsNativeShadowDOM(): boolean { + return isFunction((this.defaultDoc().body).createShadowRoot); + } } diff --git a/modules/angular2/src/dom/parse5_adapter.ts b/modules/angular2/src/dom/parse5_adapter.ts index 3920e5c113..7fdc66578a 100644 --- a/modules/angular2/src/dom/parse5_adapter.ts +++ b/modules/angular2/src/dom/parse5_adapter.ts @@ -26,7 +26,9 @@ function _notImplemented(methodName) { export class Parse5DomAdapter extends DomAdapter { static makeCurrent() { setRootDomAdapter(new Parse5DomAdapter()); } - hasProperty(element, name: string) { return _HTMLElementPropertyList.indexOf(name) > -1; } + hasProperty(element, name: string): boolean { + return _HTMLElementPropertyList.indexOf(name) > -1; + } // TODO(tbosch): don't even call this method when we run the tests on server side // by not using the DomRenderer in tests. Keeping this for now to make tests happy... setProperty(el: /*element*/ any, name: string, value: any) { @@ -45,8 +47,8 @@ export class Parse5DomAdapter extends DomAdapter { get attrToPropMap() { return _attrToPropMap; } query(selector) { throw _notImplemented('query'); } - querySelector(el, selector: string) { return this.querySelectorAll(el, selector)[0]; } - querySelectorAll(el, selector: string) { + querySelector(el, selector: string): any { return this.querySelectorAll(el, selector)[0]; } + querySelectorAll(el, selector: string): List { var res = []; var _recursive = (result, node, selector, matcher) => { var cNodes = node.childNodes; @@ -130,18 +132,18 @@ export class Parse5DomAdapter extends DomAdapter { this.dispatchEvent(el._window, evt); } } - createMouseEvent(eventType) { return this.createEvent(eventType); } - createEvent(eventType) { - var evt = { + createMouseEvent(eventType): Event { return this.createEvent(eventType); } + createEvent(eventType: string): Event { + var evt = { type: eventType, defaultPrevented: false, - preventDefault: () => { evt.defaultPrevented = true } + preventDefault: () => { evt.defaultPrevented = true; } }; return evt; } preventDefault(evt) { evt.returnValue = false; } - getInnerHTML(el) { return serializer.serialize(this.templateAwareRoot(el)); } - getOuterHTML(el) { + getInnerHTML(el): string { return serializer.serialize(this.templateAwareRoot(el)); } + getOuterHTML(el): string { serializer.html = ''; serializer._serializeElement(el); return serializer.html; @@ -149,11 +151,11 @@ export class Parse5DomAdapter extends DomAdapter { nodeName(node): string { return node.tagName; } nodeValue(node): string { return node.nodeValue; } type(node: any): string { throw _notImplemented('type'); } - content(node) { return node.childNodes[0]; } - firstChild(el) { return el.firstChild; } - nextSibling(el) { return el.nextSibling; } - parentElement(el) { return el.parent; } - childNodes(el) { return el.childNodes; } + content(node): string { return node.childNodes[0]; } + firstChild(el): Node { return el.firstChild; } + nextSibling(el): Node { return el.nextSibling; } + parentElement(el): Node { return el.parent; } + childNodes(el): Node[] { return el.childNodes; } childNodesAsList(el): List { var childNodes = el.childNodes; var res = ListWrapper.createFixedSize(childNodes.length); @@ -176,7 +178,7 @@ export class Parse5DomAdapter extends DomAdapter { this.remove(node); } } - remove(el) { + remove(el): HTMLElement { var parent = el.parent; if (parent) { var index = parent.childNodes.indexOf(el); @@ -216,7 +218,7 @@ export class Parse5DomAdapter extends DomAdapter { treeAdapter.appendChild(el, content.childNodes[i]); } } - getText(el) { + getText(el): string { if (this.isTextNode(el)) { return el.data; } else if (isBlank(el.childNodes) || el.childNodes.length == 0) { @@ -237,40 +239,40 @@ export class Parse5DomAdapter extends DomAdapter { if (value !== '') treeAdapter.insertText(el, value); } } - getValue(el) { return el.value; } + getValue(el): string { return el.value; } setValue(el, value: string) { el.value = value; } - getChecked(el) { return el.checked; } + getChecked(el): boolean { return el.checked; } setChecked(el, value: boolean) { el.checked = value; } - createTemplate(html) { + createTemplate(html): HTMLElement { var template = treeAdapter.createElement("template", 'http://www.w3.org/1999/xhtml', []); var content = parser.parseFragment(html); treeAdapter.appendChild(template, content); return template; } - createElement(tagName) { + createElement(tagName): HTMLElement { return treeAdapter.createElement(tagName, 'http://www.w3.org/1999/xhtml', []); } - createTextNode(text: string) { throw _notImplemented('createTextNode'); } - createScriptTag(attrName: string, attrValue: string) { + createTextNode(text: string): Text { throw _notImplemented('createTextNode'); } + createScriptTag(attrName: string, attrValue: string): HTMLElement { return treeAdapter.createElement("script", 'http://www.w3.org/1999/xhtml', [{name: attrName, value: attrValue}]); } - createStyleElement(css: string) { + createStyleElement(css: string): HTMLStyleElement { var style = this.createElement('style'); this.setText(style, css); - return style; + return style; } - createShadowRoot(el) { + createShadowRoot(el): HTMLElement { el.shadowRoot = treeAdapter.createDocumentFragment(); el.shadowRoot.parent = el; return el.shadowRoot; } - getShadowRoot(el) { return el.shadowRoot; } - getHost(el) { return el.host; } - getDistributedNodes(el: any): List { throw _notImplemented('getDistributedNodes'); } - clone(node) { + getShadowRoot(el): Element { return el.shadowRoot; } + getHost(el): string { return el.host; } + getDistributedNodes(el: any): List { throw _notImplemented('getDistributedNodes'); } + clone(node: Node): Node { // e.g. document fragment - if (node.type === 'root') { + if ((node).type === 'root') { var serialized = serializer.serialize(node); var newParser = new parse5.Parser(parse5.TreeAdapters.htmlparser2); return newParser.parseFragment(serialized); @@ -282,10 +284,10 @@ export class Parse5DomAdapter extends DomAdapter { return newParser.parseFragment(serialized).childNodes[0]; } } - getElementsByClassName(element, name: string) { + getElementsByClassName(element, name: string): List { return this.querySelectorAll(element, "." + name); } - getElementsByTagName(element: any, name: string): List { + getElementsByTagName(element: any, name: string): List { throw _notImplemented('getElementsByTagName'); } classList(element): List { @@ -312,7 +314,7 @@ export class Parse5DomAdapter extends DomAdapter { element.attribs["class"] = element.className = ListWrapper.join(classList, " "); } } - hasClass(element, classname: string) { + hasClass(element, classname: string): boolean { return ListWrapper.contains(this.classList(element), classname); } _readStyleAttribute(element) { @@ -346,12 +348,12 @@ export class Parse5DomAdapter extends DomAdapter { this._writeStyleAttribute(element, styleMap); } removeStyle(element, stylename: string) { this.setStyle(element, stylename, null); } - getStyle(element, stylename: string) { + getStyle(element, stylename: string): string { var styleMap = this._readStyleAttribute(element); return styleMap.hasOwnProperty(stylename) ? styleMap[stylename] : ""; } tagName(element): string { return element.tagName == "style" ? "STYLE" : element.tagName; } - attributeMap(element) { + attributeMap(element): Map { var res = new Map(); var elAttrs = treeAdapter.getAttrList(element); for (var i = 0; i < elAttrs.length; i++) { @@ -360,10 +362,10 @@ export class Parse5DomAdapter extends DomAdapter { } return res; } - hasAttribute(element, attribute: string) { + hasAttribute(element, attribute: string): boolean { return element.attribs && element.attribs.hasOwnProperty(attribute); } - getAttribute(element, attribute: string) { + getAttribute(element, attribute: string): string { return element.attribs && element.attribs.hasOwnProperty(attribute) ? element.attribs[attribute] : null; @@ -378,8 +380,8 @@ export class Parse5DomAdapter extends DomAdapter { StringMapWrapper.delete(element.attribs, attribute); } } - templateAwareRoot(el) { return this.isTemplateElement(el) ? this.content(el) : el; } - createHtmlDocument() { + templateAwareRoot(el): any { return this.isTemplateElement(el) ? this.content(el) : el; } + createHtmlDocument(): Document { var newDoc = treeAdapter.createDocument(); newDoc.title = "fake title"; var head = treeAdapter.createElement("head", null, []); @@ -391,14 +393,14 @@ export class Parse5DomAdapter extends DomAdapter { StringMapWrapper.set(newDoc, "_window", StringMapWrapper.create()); return newDoc; } - defaultDoc() { + defaultDoc(): Document { if (defDoc === null) { defDoc = this.createHtmlDocument(); } return defDoc; } - getBoundingClientRect(el) { return {left: 0, top: 0, width: 0, height: 0}; } - getTitle() { return this.defaultDoc().title || ""; } + getBoundingClientRect(el): any { return {left: 0, top: 0, width: 0, height: 0}; } + getTitle(): string { return this.defaultDoc().title || ""; } setTitle(newTitle: string) { this.defaultDoc().title = newTitle; } isTemplateElement(el: any): boolean { return this.isElementNode(el) && this.tagName(el) === "template"; @@ -408,7 +410,7 @@ export class Parse5DomAdapter extends DomAdapter { isElementNode(node): boolean { return node ? treeAdapter.isElementNode(node) : false; } hasShadowRoot(node): boolean { return isPresent(node.shadowRoot); } isShadowRoot(node): boolean { return this.getShadowRoot(node) == node; } - importIntoDoc(node) { return this.clone(node); } + importIntoDoc(node): any { return this.clone(node); } isPageRule(rule): boolean { return rule.type === 6; // CSSRule.PAGE_RULE } @@ -476,18 +478,18 @@ export class Parse5DomAdapter extends DomAdapter { } supportsDOMEvents(): boolean { return false; } supportsNativeShadowDOM(): boolean { return false; } - getGlobalEventTarget(target: string) { + getGlobalEventTarget(target: string): any { if (target == "window") { - return this.defaultDoc()._window; + return (this.defaultDoc())._window; } else if (target == "document") { return this.defaultDoc(); } else if (target == "body") { return this.defaultDoc().body; } } - getHistory() { throw 'not implemented'; } - getLocation() { throw 'not implemented'; } - getUserAgent() { return "Fake user agent"; } + getHistory(): History { throw 'not implemented'; } + getLocation(): Location { throw 'not implemented'; } + getUserAgent(): string { return "Fake user agent"; } getData(el, name: string): string { return this.getAttribute(el, 'data-' + name); } setData(el, name: string, value: string) { this.setAttribute(el, 'data-' + name, value); } // TODO(tbosch): move this into a separate environment class once we have it diff --git a/modules/angular2/src/facade/async.ts b/modules/angular2/src/facade/async.ts index c8a80a9d2c..8061162e52 100644 --- a/modules/angular2/src/facade/async.ts +++ b/modules/angular2/src/facade/async.ts @@ -7,6 +7,12 @@ import * as Rx from 'rx'; export var Promise = (global).Promise; +export interface PromiseCompleter { + promise: Promise; + resolve: (value?: R | Thenable) => void; + reject: (error?: any, stackTrace?: string) => void; +} + export class PromiseWrapper { static resolve(obj): Promise { return Promise.resolve(obj); } @@ -38,7 +44,7 @@ export class PromiseWrapper { }); } - static completer() { + static completer(): PromiseCompleter { var resolve; var reject; @@ -103,7 +109,7 @@ export class EventEmitter extends Observable { } } - observer(generator) { + observer(generator): Rx.IDisposable { return this._subject.observeOn(this._immediateScheduler) .subscribe((value) => { setTimeout(() => generator.next(value)); }, (error) => generator.throw ? generator.throw(error) : null, diff --git a/modules/angular2/src/facade/collection.dart b/modules/angular2/src/facade/collection.dart index a46c84b6b2..ec451e1ebb 100644 --- a/modules/angular2/src/facade/collection.dart +++ b/modules/angular2/src/facade/collection.dart @@ -90,6 +90,8 @@ class StringMapWrapper { } } +typedef bool Predicate(T item); + class ListWrapper { static List clone(Iterable l) => new List.from(l); static List createFixedSize(int size) => new List(size); diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index d0cf91b711..46f22de58d 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -65,10 +65,10 @@ export class MapWrapper { } static createFromPairs(pairs: List): Map { return createMapFromPairs(pairs); } static forEach(m: Map, fn: /*(V, K) => void*/ Function) { m.forEach(fn); } - static size(m: Map) { return m.size; } + static size(m: Map): number { return m.size; } static delete(m: Map, k: K) { m.delete(k); } static clearValues(m: Map) { _clearValues(m); } - static iterable(m) { return m; } + static iterable(m: T): T { return m; } static keys(m: Map): List { return (Array).from(m.keys()); } static values(m: Map): List { return (Array).from(m.values()); } } @@ -83,13 +83,15 @@ export class StringMapWrapper { // http://jsperf.com/ng2-object-create-null return {}; } - static contains(map: StringMap, key: string) { return map.hasOwnProperty(key); } + static contains(map: StringMap, key: string): boolean { + return map.hasOwnProperty(key); + } static get(map: StringMap, key: string): V { return map.hasOwnProperty(key) ? map[key] : undefined; } static set(map: StringMap, key: string, value: V) { map[key] = value; } static keys(map: StringMap): List { return Object.keys(map); } - static isEmpty(map: StringMap) { + static isEmpty(map: StringMap): boolean { for (var prop in map) { return false; } @@ -139,57 +141,59 @@ export class StringMapWrapper { } } +export interface Predicate { (value: T, index?: number, array?: T[]): boolean; } + export class ListWrapper { // JS has no way to express a staticly fixed size list, but dart does so we // keep both methods. static createFixedSize(size): List { return new List(size); } static createGrowableSize(size): List { return new List(size); } - static get(m, k) { return m[k]; } + static get(m, k): any { return m[k]; } static set(m, k, v) { m[k] = v; } - static clone(array: List) { return array.slice(0); } - static map(array, fn) { return array.map(fn); } + static clone(array: List): T[] { return array.slice(0); } + static map(array, fn): any { return array.map(fn); } static forEach(array: List, fn: Function) { for (var i = 0; i < array.length; i++) { fn(array[i]); } } - static first(array) { + static first(array: List): T { if (!array) return null; return array[0]; } - static last(array) { + static last(array: List): T { if (!array || array.length == 0) return null; return array[array.length - 1]; } - static find(list: List, pred: Function) { + static find(list: List, pred: Predicate): T { for (var i = 0; i < list.length; ++i) { if (pred(list[i])) return list[i]; } return null; } - static indexOf(array: List, value, startIndex = 0) { + static indexOf(array: List, value, startIndex = 0): number { return array.indexOf(value, startIndex); } static reduce(list: List, fn: (accumValue: E, currentValue: T, currentIndex: number, array: T[]) => E, - init: E) { + init: E): E { return list.reduce(fn, init); } - static filter(array, pred: Function) { return array.filter(pred); } - static any(list: List, pred: Function) { + static filter(array: List, pred: Predicate): T[] { return array.filter(pred); } + static any(list: List, pred: Function): boolean { for (var i = 0; i < list.length; ++i) { if (pred(list[i])) return true; } return false; } - static contains(list: List, el) { return list.indexOf(el) !== -1; } - static reversed(array) { + static contains(list: List, el): boolean { return list.indexOf(el) !== -1; } + static reversed(array: List): T[] { var a = ListWrapper.clone(array); return a.reverse(); } - static concat(a, b) { return a.concat(b); } + static concat(a, b): List { return a.concat(b); } static insert(list, index: int, value) { list.splice(index, 0, value); } - static removeAt(list, index: int) { + static removeAt(list: List, index: int): T { var res = list[index]; list.splice(index, 1); return res; @@ -210,8 +214,8 @@ export class ListWrapper { return false; } static clear(list) { list.splice(0, list.length); } - static join(list, s) { return list.join(s); } - static isEmpty(list) { return list.length == 0; } + static join(list, s: string): string { return list.join(s); } + static isEmpty(list): boolean { return list.length == 0; } static fill(list: List, value, start: int = 0, end: int = null) { list.fill(value, start, end === null ? undefined : end); } diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index 84c7b939ff..597ad5945b 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -37,18 +37,18 @@ export function CONST_EXPR(expr: T): T { return expr; } -export function CONST() { +export function CONST():(target: T) => T { return (target) => target; } -export function ABSTRACT() { +export function ABSTRACT():(target: T) => T { return (t) => t; } // Note: This is only a marker annotation needed for ts2dart. // This is written so that is can be used as a Traceur annotation // or a Typescript decorator. -export function IMPLEMENTS(_) { +export function IMPLEMENTS(_):(target: T) => T { return (t) => t; } @@ -152,7 +152,7 @@ export class NumberParseError extends BaseException { constructor(public message: string) { super(); } - toString() { return this.message; } + toString(): string { return this.message; } } @@ -211,7 +211,11 @@ export class RegExpWrapper { return regExp.exec(input); } static test(regExp: RegExp, input: string): boolean { return regExp.test(input); } - static matcher(regExp, input) { + static matcher(regExp, input): { + re: RegExp; + input: string + } + { // Reset regex state for the case // someone did not loop over all matches // last time. @@ -221,11 +225,11 @@ export class RegExpWrapper { } export class RegExpMatcherWrapper { - static next(matcher) { return matcher.re.exec(matcher.input); } + static next(matcher): string { return matcher.re.exec(matcher.input); } } export class FunctionWrapper { - static apply(fn: Function, posArgs) { return fn.apply(null, posArgs); } + static apply(fn: Function, posArgs): any { return fn.apply(null, posArgs); } } // JS has NaN !== NaN @@ -235,11 +239,11 @@ export function looseIdentical(a, b): boolean { // JS considers NaN is the same as NaN for map Key (while NaN !== NaN otherwise) // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map -export function getMapKey(value) { +export function getMapKey(value): any { return value; } -export function normalizeBlank(obj) { +export function normalizeBlank(obj): any { return isBlank(obj) ? null : obj; } @@ -261,7 +265,7 @@ export function print(obj) { // Can't be all uppercase as our transpiler would think it is a special directive... export class Json { - static parse(s: string) { return _global.JSON.parse(s); } + static parse(s: string): Object { return _global.JSON.parse(s); } static stringify(data): string { // Dart doesn't take 3 arguments return _global.JSON.stringify(data, null, 2); @@ -269,8 +273,8 @@ export class Json { } export class DateWrapper { - static fromMillis(ms) { return new Date(ms); } - static toMillis(date: Date) { return date.getTime(); } - static now() { return new Date(); } - static toJson(date) { return date.toJSON(); } + static fromMillis(ms): Date { return new Date(ms); } + static toMillis(date: Date): number { return date.getTime(); } + static now(): Date { return new Date(); } + static toJson(date): string { return date.toJSON(); } } diff --git a/modules/angular2/src/forms/directives/ng_form.ts b/modules/angular2/src/forms/directives/ng_form.ts index 1eb3dd7497..bcda35118b 100644 --- a/modules/angular2/src/forms/directives/ng_form.ts +++ b/modules/angular2/src/forms/directives/ng_form.ts @@ -123,7 +123,7 @@ export class NgForm extends ControlContainer implements Form { }); } - onSubmit() { + onSubmit(): boolean { ObservableWrapper.callNext(this.ngSubmit, null); return false; } diff --git a/modules/angular2/src/forms/directives/ng_form_model.ts b/modules/angular2/src/forms/directives/ng_form_model.ts index 3e85423212..8b1e21f466 100644 --- a/modules/angular2/src/forms/directives/ng_form_model.ts +++ b/modules/angular2/src/forms/directives/ng_form_model.ts @@ -124,7 +124,7 @@ export class NgFormModel extends ControlContainer implements Form { c.updateValue(value); } - onSubmit() { + onSubmit(): boolean { ObservableWrapper.callNext(this.ngSubmit, null); return false; } diff --git a/modules/angular2/src/forms/directives/shared.ts b/modules/angular2/src/forms/directives/shared.ts index eda1bbfa2a..cf5f4932a5 100644 --- a/modules/angular2/src/forms/directives/shared.ts +++ b/modules/angular2/src/forms/directives/shared.ts @@ -9,7 +9,7 @@ import {Validators} from '../validators'; import {Renderer, ElementRef, QueryList} from 'angular2/angular2'; -export function controlPath(name, parent: ControlContainer) { +export function controlPath(name: string, parent: ControlContainer): string[] { var p = ListWrapper.clone(parent.path); p.push(name); return p; diff --git a/modules/angular2/src/forms/model.ts b/modules/angular2/src/forms/model.ts index fd00fbad5c..06a952a82f 100644 --- a/modules/angular2/src/forms/model.ts +++ b/modules/angular2/src/forms/model.ts @@ -122,7 +122,7 @@ export class AbstractControl { find(path: List| string): AbstractControl { return _find(this, path); } - getError(errorCode: string, path: List = null) { + getError(errorCode: string, path: List = null): any { var c = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this; if (isPresent(c) && isPresent(c._errors)) { return StringMapWrapper.get(c._errors, errorCode); @@ -131,7 +131,7 @@ export class AbstractControl { } } - hasError(errorCode: string, path: List = null) { + hasError(errorCode: string, path: List = null): boolean { return isPresent(this.getError(errorCode, path)); } diff --git a/modules/angular2/src/http/backends/mock_backend.ts b/modules/angular2/src/http/backends/mock_backend.ts index 0902ff897f..24ad7b8e80 100644 --- a/modules/angular2/src/http/backends/mock_backend.ts +++ b/modules/angular2/src/http/backends/mock_backend.ts @@ -229,7 +229,7 @@ export class MockBackend implements ConnectionBackend { * observable of this `MockBackend` instance. This method will usually only be used by tests * against the framework itself, not by end-users. */ - createConnection(req: Request) { + createConnection(req: Request): Connection { if (!req || !(req instanceof Request)) { throw new Error(`createConnection requires an instance of Request, got ${req}`); } diff --git a/modules/angular2/src/http/headers.ts b/modules/angular2/src/http/headers.ts index 46b0bc1969..592f5465ed 100644 --- a/modules/angular2/src/http/headers.ts +++ b/modules/angular2/src/http/headers.ts @@ -49,13 +49,13 @@ export class Headers { delete (name: string): void { MapWrapper.delete(this._headersMap, name); } - forEach(fn: Function) { return MapWrapper.forEach(this._headersMap, fn); } + forEach(fn: Function) { MapWrapper.forEach(this._headersMap, fn); } get(header: string): string { return ListWrapper.first(this._headersMap.get(header)); } - has(header: string) { return this._headersMap.has(header); } + has(header: string): boolean { return this._headersMap.has(header); } - keys() { return MapWrapper.keys(this._headersMap); } + keys(): List { return MapWrapper.keys(this._headersMap); } // TODO: this implementation seems wrong. create list then check if it's iterable? set(header: string, value: string | List): void { @@ -69,7 +69,7 @@ export class Headers { this._headersMap.set(header, list); } - values() { return MapWrapper.values(this._headersMap); } + values(): List> { return MapWrapper.values(this._headersMap); } getAll(header: string): Array { return this._headersMap.get(header) || []; } diff --git a/modules/angular2/src/http/http.ts b/modules/angular2/src/http/http.ts index 5731ee7020..0677b719f2 100644 --- a/modules/angular2/src/http/http.ts +++ b/modules/angular2/src/http/http.ts @@ -1,7 +1,7 @@ /// import {Injectable} from 'angular2/src/di/decorators'; -import {IRequestOptions, Connection} from './interfaces'; +import {IRequestOptions, Connection, IHttp} from './interfaces'; import {Request} from './static_request'; import {Response} from './static_response'; import {XHRBackend} from './backends/xhr_backend'; @@ -10,15 +10,15 @@ import {RequestMethods} from './enums'; import {URLSearchParams} from './url_search_params'; import * as Rx from 'rx'; -function httpRequest(backend: XHRBackend, request: Request) { +function httpRequest(backend: XHRBackend, request: Request): Rx.Observable { return >(Observable.create(observer => { var connection: Connection = backend.createConnection(request); var internalSubscription = connection.response.subscribe(observer); return () => { internalSubscription.dispose(); connection.dispose(); - } - })) + }; + })); } /** @@ -91,7 +91,7 @@ export class Http { /** * Performs a request with `get` http method. */ - get(url: string, options?: IRequestOptions) { + get(url: string, options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options) .merge({method: RequestMethods.GET}))); } @@ -99,7 +99,8 @@ export class Http { /** * Performs a request with `post` http method. */ - post(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) { + post(url: string, body: URLSearchParams | FormData | Blob | string, + options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options) @@ -109,7 +110,8 @@ export class Http { /** * Performs a request with `put` http method. */ - put(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) { + put(url: string, body: URLSearchParams | FormData | Blob | string, + options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options) .merge({body: body, method: RequestMethods.PUT}))); @@ -118,7 +120,7 @@ export class Http { /** * Performs a request with `delete` http method. */ - delete (url: string, options?: IRequestOptions) { + delete (url: string, options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options).merge( {method: RequestMethods.DELETE}))); } @@ -126,7 +128,8 @@ export class Http { /** * Performs a request with `patch` http method. */ - patch(url: string, body: URLSearchParams | FormData | Blob | string, options?: IRequestOptions) { + patch(url: string, body: URLSearchParams | FormData | Blob | string, + options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options) .merge({body: body, method: RequestMethods.PATCH}))); @@ -135,7 +138,7 @@ export class Http { /** * Performs a request with `head` http method. */ - head(url: string, options?: IRequestOptions) { + head(url: string, options?: IRequestOptions): Rx.Observable { return httpRequest(this._backend, new Request(url, this._defaultOptions.merge(options) .merge({method: RequestMethods.HEAD}))); } @@ -171,12 +174,12 @@ if (Rx.hasOwnProperty('default')) { * } * ``` **/ -export function HttpFactory(backend: XHRBackend, defaultOptions: BaseRequestOptions) { +export function HttpFactory(backend: XHRBackend, defaultOptions: BaseRequestOptions): IHttp { return function(url: string | Request, options?: IRequestOptions) { if (typeof url === 'string') { return httpRequest(backend, new Request(url, defaultOptions.merge(options))); } else if (url instanceof Request) { return httpRequest(backend, url); } - } + }; } diff --git a/modules/angular2/src/mock/location_mock.ts b/modules/angular2/src/mock/location_mock.ts index fddceab5df..868c61f349 100644 --- a/modules/angular2/src/mock/location_mock.ts +++ b/modules/angular2/src/mock/location_mock.ts @@ -30,7 +30,7 @@ export class SpyLocation extends SpyObject { simulateUrlPop(pathname: string) { ObservableWrapper.callNext(this._subject, {'url': pathname}); } - normalizeAbsolutely(url) { return this._baseHref + url; } + normalizeAbsolutely(url): string { return this._baseHref + url; } go(url: string) { url = this.normalizeAbsolutely(url); @@ -53,5 +53,5 @@ export class SpyLocation extends SpyObject { ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn); } - noSuchMethod(m) { return super.noSuchMethod(m); } + noSuchMethod(m) { super.noSuchMethod(m); } } diff --git a/modules/angular2/src/mock/ng_zone_mock.ts b/modules/angular2/src/mock/ng_zone_mock.ts index c2ddbf42b7..64b53a39d1 100644 --- a/modules/angular2/src/mock/ng_zone_mock.ts +++ b/modules/angular2/src/mock/ng_zone_mock.ts @@ -3,7 +3,7 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone'; export class MockNgZone extends NgZone { constructor() { super({enableLongStackTrace: false}); } - run(fn) { return fn(); } + run(fn): any { return fn(); } - runOutsideAngular(fn) { return fn(); } + runOutsideAngular(fn): any { return fn(); } } diff --git a/modules/angular2/src/render/api.ts b/modules/angular2/src/render/api.ts index 6de107424e..d72a81af9e 100644 --- a/modules/angular2/src/render/api.ts +++ b/modules/angular2/src/render/api.ts @@ -217,7 +217,7 @@ export class DirectiveMetadata { callOnAllChangesDone?: boolean, changeDetection?: string, exportAs?: string - }) { + }): DirectiveMetadata { let hostListeners = new Map(); let hostProperties = new Map(); let hostAttributes = new Map(); diff --git a/modules/angular2/src/render/dom/compiler/compile_control.ts b/modules/angular2/src/render/dom/compiler/compile_control.ts index 1a06502fba..ebb3e06b4e 100644 --- a/modules/angular2/src/render/dom/compiler/compile_control.ts +++ b/modules/angular2/src/render/dom/compiler/compile_control.ts @@ -11,13 +11,14 @@ export class CompileControl { _currentStepIndex: number = 0; _parent: CompileElement = null; _results: any[] = null; - _additionalChildren: any[] = null; + _additionalChildren: CompileElement[] = null; _ignoreCurrentElement: boolean; constructor(public _steps: List) {} // only public so that it can be used by compile_pipeline - internalProcess(results: any[], startStepIndex, parent: CompileElement, current: CompileElement) { + internalProcess(results: any[], startStepIndex, parent: CompileElement, + current: CompileElement): CompileElement[] { this._results = results; var previousStepIndex = this._currentStepIndex; var previousParent = this._parent; diff --git a/modules/angular2/src/render/dom/compiler/compile_element.ts b/modules/angular2/src/render/dom/compiler/compile_element.ts index 1d64db7b16..2333a85734 100644 --- a/modules/angular2/src/render/dom/compiler/compile_element.ts +++ b/modules/angular2/src/render/dom/compiler/compile_element.ts @@ -33,11 +33,11 @@ export class CompileElement { } } - isBound() { + isBound(): boolean { return isPresent(this.inheritedElementBinder) && this.distanceToInheritedBinder === 0; } - bindElement() { + bindElement(): ElementBinderBuilder { if (!this.isBound()) { var parentBinder = this.inheritedElementBinder; this.inheritedElementBinder = diff --git a/modules/angular2/src/render/dom/compiler/selector.ts b/modules/angular2/src/render/dom/compiler/selector.ts index 45e261fe19..de342039b8 100644 --- a/modules/angular2/src/render/dom/compiler/selector.ts +++ b/modules/angular2/src/render/dom/compiler/selector.ts @@ -135,7 +135,7 @@ export class CssSelector { * are contained in a given CssSelector. */ export class SelectorMatcher { - static createNotMatcher(notSelectors: List) { + static createNotMatcher(notSelectors: List): SelectorMatcher { var notMatcher = new SelectorMatcher(); notMatcher.addSelectables(notSelectors, null); return notMatcher; @@ -353,7 +353,7 @@ class SelectorContext { this.notSelectors = selector.notSelectors; } - finalize(cssSelector: CssSelector, callback /*: (CssSelector, any) => void*/) { + finalize(cssSelector: CssSelector, callback /*: (CssSelector, any) => void*/): boolean { var result = true; if (this.notSelectors.length > 0 && (isBlank(this.listContext) || !this.listContext.alreadyMatched)) { diff --git a/modules/angular2/src/render/dom/compiler/style_url_resolver.ts b/modules/angular2/src/render/dom/compiler/style_url_resolver.ts index 6660fd3b48..27bf82d37a 100644 --- a/modules/angular2/src/render/dom/compiler/style_url_resolver.ts +++ b/modules/angular2/src/render/dom/compiler/style_url_resolver.ts @@ -12,7 +12,7 @@ import {UrlResolver} from 'angular2/src/services/url_resolver'; export class StyleUrlResolver { constructor(public _resolver: UrlResolver) {} - resolveUrls(cssText: string, baseUrl: string) { + resolveUrls(cssText: string, baseUrl: string): string { cssText = this._replaceUrls(cssText, _cssUrlRe, baseUrl); cssText = this._replaceUrls(cssText, _cssImportRe, baseUrl); return cssText; diff --git a/modules/angular2/src/render/dom/dom_renderer.ts b/modules/angular2/src/render/dom/dom_renderer.ts index 272dd9729d..dd93bad85f 100644 --- a/modules/angular2/src/render/dom/dom_renderer.ts +++ b/modules/angular2/src/render/dom/dom_renderer.ts @@ -53,7 +53,7 @@ export class DomRenderer extends Renderer { // noop for now } - getNativeElementSync(location: RenderElementRef) { + getNativeElementSync(location: RenderElementRef): any { return resolveInternalDomView(location.renderView) .boundElements[location.boundElementIndex] .element; diff --git a/modules/angular2/src/render/dom/events/event_manager.ts b/modules/angular2/src/render/dom/events/event_manager.ts index 5e5097fbf5..39b4b1f129 100644 --- a/modules/angular2/src/render/dom/events/event_manager.ts +++ b/modules/angular2/src/render/dom/events/event_manager.ts @@ -90,7 +90,7 @@ export class DomEventsPlugin extends EventManagerPlugin { DomEventsPlugin.sameElementCallback(element, handler, zone); } - static sameElementCallback(element, handler, zone) { + static sameElementCallback(element, handler, zone): (event: Event) => void { return (event) => { if (event.target === element) { zone.run(() => handler(event)); @@ -98,7 +98,7 @@ export class DomEventsPlugin extends EventManagerPlugin { }; } - static bubbleCallback(element, handler, zone) { + static bubbleCallback(element, handler, zone): (event: Event) => void { return (event) => zone.run(() => handler(event)); } } diff --git a/modules/angular2/src/render/dom/events/key_events.ts b/modules/angular2/src/render/dom/events/key_events.ts index a6412fe332..e1628e7f26 100644 --- a/modules/angular2/src/render/dom/events/key_events.ts +++ b/modules/angular2/src/render/dom/events/key_events.ts @@ -11,13 +11,12 @@ import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {EventManagerPlugin} from './event_manager'; var modifierKeys = ['alt', 'control', 'meta', 'shift']; -var modifierKeyGetters: StringMap = - { - 'alt': (event) => event.altKey, - 'control': (event) => event.ctrlKey, - 'meta': (event) => event.metaKey, - 'shift': (event) => event.shiftKey - } +var modifierKeyGetters: StringMap = { + 'alt': (event) => event.altKey, + 'control': (event) => event.ctrlKey, + 'meta': (event) => event.metaKey, + 'shift': (event) => event.shiftKey +}; export class KeyEventsPlugin extends EventManagerPlugin { constructor() { super(); } @@ -38,7 +37,7 @@ export class KeyEventsPlugin extends EventManagerPlugin { }); } - static parseEventName(eventName: string) /* {'domEventName': string, 'fullKey': string} */ { + static parseEventName(eventName: string): StringMap { var parts = eventName.toLowerCase().split('.'); var domEventName = ListWrapper.removeAt(parts, 0); @@ -63,8 +62,10 @@ export class KeyEventsPlugin extends EventManagerPlugin { // returning null instead of throwing to let another plugin process the event return null; } - - return {'domEventName': domEventName, 'fullKey': fullKey}; + var result = StringMapWrapper.create(); + StringMapWrapper.set(result, 'domEventName', domEventName); + StringMapWrapper.set(result, 'fullKey', fullKey); + return result; } static getEventFullKey(event): string { @@ -88,7 +89,8 @@ export class KeyEventsPlugin extends EventManagerPlugin { return fullKey; } - static eventCallback(element, shouldSupportBubble, fullKey, handler, zone) { + static eventCallback(element, shouldSupportBubble, fullKey, handler, + zone): (event: Event) => void { return (event) => { var correctElement = shouldSupportBubble || event.target === element; if (correctElement && StringWrapper.equals(KeyEventsPlugin.getEventFullKey(event), fullKey)) { diff --git a/modules/angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy.ts b/modules/angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy.ts index f9b69b2718..349497d734 100644 --- a/modules/angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy.ts +++ b/modules/angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy.ts @@ -20,7 +20,7 @@ export class EmulatedUnscopedShadowDomStrategy extends ShadowDomStrategy { hasNativeContentElement(): boolean { return false; } - prepareShadowRoot(el) { return el; } + prepareShadowRoot(el): /*(#2770) Node*/ any { return el; } constructLightDom(lightDomView: viewModule.DomView, el): LightDom { return new LightDom(lightDomView, el); diff --git a/modules/angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy.ts b/modules/angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy.ts index 67c36ad965..7bee6c54c8 100644 --- a/modules/angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy.ts +++ b/modules/angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy.ts @@ -10,5 +10,5 @@ import {ShadowDomStrategy} from './shadow_dom_strategy'; */ @Injectable() export class NativeShadowDomStrategy extends ShadowDomStrategy { - prepareShadowRoot(el) { return DOM.createShadowRoot(el); } + prepareShadowRoot(el): /*(#2770) Node*/ any { return DOM.createShadowRoot(el); } } diff --git a/modules/angular2/src/render/dom/shadow_dom/util.ts b/modules/angular2/src/render/dom/shadow_dom/util.ts index 1250b0f117..98a18f6820 100644 --- a/modules/angular2/src/render/dom/shadow_dom/util.ts +++ b/modules/angular2/src/render/dom/shadow_dom/util.ts @@ -10,7 +10,7 @@ var _nextComponentUID: int = 0; var _sharedStyleTexts: Map = new Map(); var _lastInsertedStyleEl; -export function getComponentId(componentStringId: string) { +export function getComponentId(componentStringId: string): number { var id = _componentUIDs.get(componentStringId); if (isBlank(id)) { id = _nextComponentUID++; @@ -43,12 +43,12 @@ export function insertStyleElement(host, styleEl) { } // Return the attribute to be added to the component -export function getHostAttribute(id: int) { +export function getHostAttribute(id: int): string { return `_nghost-${id}`; } // Returns the attribute to be added on every single element nodes in the component -export function getContentAttribute(id: int) { +export function getContentAttribute(id: int): string { return `_ngcontent-${id}`; } diff --git a/modules/angular2/src/render/dom/util.ts b/modules/angular2/src/render/dom/util.ts index adc6077da0..2676d53eb4 100644 --- a/modules/angular2/src/render/dom/util.ts +++ b/modules/angular2/src/render/dom/util.ts @@ -8,12 +8,12 @@ export const EVENT_TARGET_SEPARATOR = ':'; var CAMEL_CASE_REGEXP = RegExpWrapper.create('([A-Z])'); var DASH_CASE_REGEXP = RegExpWrapper.create('-([a-z])'); -export function camelCaseToDashCase(input: string) { +export function camelCaseToDashCase(input: string): string { return StringWrapper.replaceAllMapped(input, CAMEL_CASE_REGEXP, (m) => { return '-' + m[1].toLowerCase(); }); } -export function dashCaseToCamelCase(input: string) { +export function dashCaseToCamelCase(input: string): string { return StringWrapper.replaceAllMapped(input, DASH_CASE_REGEXP, (m) => { return m[1].toUpperCase(); }); } diff --git a/modules/angular2/src/render/dom/view/proto_view_builder.ts b/modules/angular2/src/render/dom/view/proto_view_builder.ts index b5b6b4409f..04cc4d4912 100644 --- a/modules/angular2/src/render/dom/view/proto_view_builder.ts +++ b/modules/angular2/src/render/dom/view/proto_view_builder.ts @@ -293,7 +293,7 @@ export class EventBuilder extends AstTransformer { return result; } - visitAccessMember(ast: AccessMember) { + visitAccessMember(ast: AccessMember): AccessMember { var isEventAccess = false; var current: AST = ast; while (!isEventAccess && (current instanceof AccessMember)) { @@ -313,11 +313,11 @@ export class EventBuilder extends AstTransformer { } } - buildEventLocals() { return this.locals; } + buildEventLocals(): List { return this.locals; } - buildLocalEvents() { return this.localEvents; } + buildLocalEvents(): List { return this.localEvents; } - buildGlobalEvents() { return this.globalEvents; } + buildGlobalEvents(): List { return this.globalEvents; } merge(eventBuilder: EventBuilder) { this._merge(this.localEvents, eventBuilder.localEvents); @@ -343,9 +343,10 @@ const ATTRIBUTE_PREFIX = 'attr'; const CLASS_PREFIX = 'class'; const STYLE_PREFIX = 'style'; -function buildElementPropertyBindings(protoElement: /*element*/ any, isNgComponent: boolean, - bindingsInTemplate: Map, - directiveTempaltePropertyNames: Set) { +function buildElementPropertyBindings( + protoElement: /*element*/ any, isNgComponent: boolean, + bindingsInTemplate: Map, + directiveTempaltePropertyNames: Set): List { var propertyBindings = []; MapWrapper.forEach(bindingsInTemplate, (ast, propertyNameInTemplate) => { var propertyBinding = createElementPropertyBinding(ast, propertyNameInTemplate); diff --git a/modules/angular2/src/render/dom/view/view.ts b/modules/angular2/src/render/dom/view/view.ts index 7703dea628..2d86354f40 100644 --- a/modules/angular2/src/render/dom/view/view.ts +++ b/modules/angular2/src/render/dom/view/view.ts @@ -9,7 +9,7 @@ import {DomElement} from './element'; import {RenderViewRef, EventDispatcher} from '../../api'; import {camelCaseToDashCase} from '../util'; -export function resolveInternalDomView(viewRef: RenderViewRef) { +export function resolveInternalDomView(viewRef: RenderViewRef): DomView { return (viewRef)._view; } diff --git a/modules/angular2/src/render/dom/view/view_container.ts b/modules/angular2/src/render/dom/view/view_container.ts index 7b41b54148..c73c3d9ecd 100644 --- a/modules/angular2/src/render/dom/view/view_container.ts +++ b/modules/angular2/src/render/dom/view/view_container.ts @@ -6,7 +6,7 @@ export class DomViewContainer { // The order in this list matches the DOM order. views: List = []; - contentTagContainers() { return this.views; } + contentTagContainers(): List { return this.views; } nodes(): List { var r = []; diff --git a/modules/angular2/src/router/path_recognizer.ts b/modules/angular2/src/router/path_recognizer.ts index c8a20ec132..5a651182f2 100644 --- a/modules/angular2/src/router/path_recognizer.ts +++ b/modules/angular2/src/router/path_recognizer.ts @@ -72,7 +72,7 @@ class StarSegment { var paramMatcher = RegExpWrapper.create("^:([^\/]+)$"); var wildcardMatcher = RegExpWrapper.create("^\\*([^\/]+)$"); -function parsePathString(route: string) { +function parsePathString(route: string): StringMap { // normalize route as not starting with a "/". Recognition will // also normalize. if (StringWrapper.startsWith(route, "/")) { @@ -117,8 +117,10 @@ function parsePathString(route: string) { specificity += 100 * (100 - i); } } - - return {segments: results, specificity}; + var result = StringMapWrapper.create(); + StringMapWrapper.set(result, 'segments', results); + StringMapWrapper.set(result, 'specificity', specificity); + return result; } function splitBySlash(url: string): List { diff --git a/modules/angular2/src/router/route_registry.ts b/modules/angular2/src/router/route_registry.ts index 2205815f56..a2229e558e 100644 --- a/modules/angular2/src/router/route_registry.ts +++ b/modules/angular2/src/router/route_registry.ts @@ -106,7 +106,7 @@ export class RouteRegistry { ListWrapper.map(possibleMatches, (candidate) => this._completeRouteMatch(candidate)); return PromiseWrapper.all(matchPromises) - .then((solutions) => { + .then((solutions: List) => { // remove nulls var fullSolutions = ListWrapper.filter(solutions, (solution) => isPresent(solution)); diff --git a/modules/angular2/src/util/decorators.ts b/modules/angular2/src/util/decorators.ts index d2f01aca1f..577fc5ff05 100644 --- a/modules/angular2/src/util/decorators.ts +++ b/modules/angular2/src/util/decorators.ts @@ -11,7 +11,7 @@ export interface TypeDecorator { Class(obj: ClassDefinition): Type; } -function extractAnnotation(annotation: any) { +function extractAnnotation(annotation: any): any { if (isFunction(annotation) && annotation.hasOwnProperty('annotation')) { // it is a decorator, extract annotation annotation = annotation.annotation; @@ -121,7 +121,7 @@ export function makeDecorator(annotationCls, chainFn: (fn: Function) => void = n } export function makeParamDecorator(annotationCls): any { - function ParamDecoratorFactory(...args) { + function ParamDecoratorFactory(...args): any { var annotationInstance = Object.create(annotationCls.prototype); annotationCls.apply(annotationInstance, args); if (this instanceof annotationCls) { @@ -131,7 +131,7 @@ export function makeParamDecorator(annotationCls): any { return ParamDecorator; } - function ParamDecorator(cls, unusedKey, index) { + function ParamDecorator(cls, unusedKey, index): any { var parameters: Array> = Reflect.getMetadata('parameters', cls); parameters = parameters || []; diff --git a/modules/angular2/test/core/compiler/compiler_spec.ts b/modules/angular2/test/core/compiler/compiler_spec.ts index c5c93b61cd..629a7688b3 100644 --- a/modules/angular2/test/core/compiler/compiler_spec.ts +++ b/modules/angular2/test/core/compiler/compiler_spec.ts @@ -58,8 +58,9 @@ export function main() { rootProtoView = createRootProtoView(directiveResolver, MainComponent); }); - function createCompiler(renderCompileResults: List, - protoViewFactoryResults: List>) { + function createCompiler( + renderCompileResults: List>, + protoViewFactoryResults: List>) { var urlResolver = new UrlResolver(); renderCompileRequests = []; renderCompiler.spy('compile').andCallFake((view) => { diff --git a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts index c50be62362..7c59f690ba 100644 --- a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts +++ b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts @@ -115,10 +115,9 @@ export function main() { tc.detectChanges(); var newlyInsertedElement = DOM.childNodes(tc.nativeElement)[1]; - expect(newlyInsertedElement.id) - .toEqual("new value") - - async.done(); + expect((newlyInsertedElement).id) + .toEqual("new value"); + async.done(); }); }); })); @@ -211,10 +210,10 @@ export function main() { tc.detectChanges(); var newlyInsertedElement = DOM.nextSibling(tc.nativeElement); - expect(newlyInsertedElement.id) - .toEqual("new value") + expect((newlyInsertedElement).id) + .toEqual("new value"); - async.done(); + async.done(); }); }); })); diff --git a/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts b/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts index a44022f501..934d757f81 100644 --- a/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts +++ b/modules/angular2/test/render/dom/dom_renderer_integration_spec.ts @@ -107,10 +107,11 @@ export function main() { var el = DOM.childNodes(tb.rootEl)[0]; tb.renderer.setElementProperty(elRef(cmpView.viewRef, 0), 'value', 'hello'); - expect(el.value).toEqual('hello'); + expect((el).value).toEqual('hello'); tb.renderer.setElementClass(elRef(cmpView.viewRef, 0), 'a', true); - expect(DOM.childNodes(tb.rootEl)[0].value).toEqual('hello'); + expect((DOM.childNodes(tb.rootEl)[0]).value) + .toEqual('hello'); tb.renderer.setElementClass(elRef(cmpView.viewRef, 0), 'a', false); expect(DOM.hasClass(el, 'a')).toBe(false);