X Tutup
Skip to content

Commit f3d7418

Browse files
committed
fix: add types for ts2dart's façade handling.
... in many, many places.
1 parent c4ecbf0 commit f3d7418

34 files changed

+259
-213
lines changed

modules/angular2/src/change_detection/dynamic_change_detector.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {isPresent, isBlank, BaseException, FunctionWrapper} from 'angular2/src/facade/lang';
22
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
3+
import {Locals} from 'angular2/src/change_detection/parser/locals';
34

45
import {AbstractChangeDetector} from './abstract_change_detector';
56
import {BindingRecord} from './binding_record';
@@ -12,7 +13,7 @@ import {ProtoRecord, RecordType} from './proto_record';
1213
import {ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError} from './exceptions';
1314

1415
export class DynamicChangeDetector extends AbstractChangeDetector {
15-
locals: any = null;
16+
locals: Locals = null;
1617
values: List<any>;
1718
changes: List<any>;
1819
pipes: List<any>;
@@ -36,7 +37,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
3637
ListWrapper.fill(this.changes, false);
3738
}
3839

39-
hydrate(context: any, locals: any, directives: any) {
40+
hydrate(context: any, locals: Locals, directives: any) {
4041
this.mode = ChangeDetectionUtil.changeDetectionMode(this.changeControlStrategy);
4142
this.values[0] = context;
4243
this.locals = locals;

modules/angular2/src/change_detection/parser/ast.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import {isBlank, isPresent, FunctionWrapper, BaseException} from "angular2/src/facade/lang";
22
import {List, Map, ListWrapper, StringMapWrapper} from "angular2/src/facade/collection";
3+
import {Locals} from "./locals";
34

45
export class AST {
5-
eval(context, locals) { throw new BaseException("Not supported"); }
6+
eval(context, locals: Locals) { throw new BaseException("Not supported"); }
67

78
get isAssignable(): boolean { return false; }
89

9-
assign(context, locals, value) { throw new BaseException("Not supported"); }
10+
assign(context, locals: Locals, value) { throw new BaseException("Not supported"); }
1011

1112
visit(visitor: AstVisitor): any { return null; }
1213

1314
toString(): string { return "AST"; }
1415
}
1516

1617
export class EmptyExpr extends AST {
17-
eval(context, locals) { return null; }
18+
eval(context, locals: Locals) { return null; }
1819

1920
visit(visitor: AstVisitor) {
2021
// do nothing
2122
}
2223
}
2324

2425
export class ImplicitReceiver extends AST {
25-
eval(context, locals) { return context; }
26+
eval(context, locals: Locals) { return context; }
2627

2728
visit(visitor: AstVisitor) { return visitor.visitImplicitReceiver(this); }
2829
}
@@ -33,7 +34,7 @@ export class ImplicitReceiver extends AST {
3334
export class Chain extends AST {
3435
constructor(public expressions: List<any>) { super(); }
3536

36-
eval(context, locals) {
37+
eval(context, locals: Locals) {
3738
var result;
3839
for (var i = 0; i < this.expressions.length; i++) {
3940
var last = this.expressions[i].eval(context, locals);
@@ -48,7 +49,7 @@ export class Chain extends AST {
4849
export class Conditional extends AST {
4950
constructor(public condition: AST, public trueExp: AST, public falseExp: AST) { super(); }
5051

51-
eval(context, locals) {
52+
eval(context, locals: Locals) {
5253
if (this.condition.eval(context, locals)) {
5354
return this.trueExp.eval(context, locals);
5455
} else {
@@ -65,7 +66,7 @@ export class AccessMember extends AST {
6566
super();
6667
}
6768

68-
eval(context, locals) {
69+
eval(context, locals: Locals) {
6970
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
7071
locals.contains(this.name)) {
7172
return locals.get(this.name);
@@ -77,7 +78,7 @@ export class AccessMember extends AST {
7778

7879
get isAssignable(): boolean { return true; }
7980

80-
assign(context, locals, value) {
81+
assign(context, locals: Locals, value) {
8182
var evaluatedContext = this.receiver.eval(context, locals);
8283

8384
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
@@ -97,7 +98,7 @@ export class SafeAccessMember extends AST {
9798
super();
9899
}
99100

100-
eval(context, locals) {
101+
eval(context, locals: Locals) {
101102
var evaluatedReceiver = this.receiver.eval(context, locals);
102103
return isBlank(evaluatedReceiver) ? null : this.getter(evaluatedReceiver);
103104
}
@@ -108,15 +109,15 @@ export class SafeAccessMember extends AST {
108109
export class KeyedAccess extends AST {
109110
constructor(public obj: AST, public key: AST) { super(); }
110111

111-
eval(context, locals) {
112+
eval(context, locals: Locals) {
112113
var obj: any = this.obj.eval(context, locals);
113114
var key: any = this.key.eval(context, locals);
114115
return obj[key];
115116
}
116117

117118
get isAssignable(): boolean { return true; }
118119

119-
assign(context, locals, value) {
120+
assign(context, locals: Locals, value) {
120121
var obj: any = this.obj.eval(context, locals);
121122
var key: any = this.key.eval(context, locals);
122123
obj[key] = value;
@@ -138,15 +139,15 @@ export class Pipe extends AST {
138139
export class LiteralPrimitive extends AST {
139140
constructor(public value) { super(); }
140141

141-
eval(context, locals) { return this.value; }
142+
eval(context, locals: Locals) { return this.value; }
142143

143144
visit(visitor: AstVisitor) { return visitor.visitLiteralPrimitive(this); }
144145
}
145146

146147
export class LiteralArray extends AST {
147148
constructor(public expressions: List<any>) { super(); }
148149

149-
eval(context, locals) {
150+
eval(context, locals: Locals) {
150151
return ListWrapper.map(this.expressions, (e) => e.eval(context, locals));
151152
}
152153

@@ -156,7 +157,7 @@ export class LiteralArray extends AST {
156157
export class LiteralMap extends AST {
157158
constructor(public keys: List<any>, public values: List<any>) { super(); }
158159

159-
eval(context, locals) {
160+
eval(context, locals: Locals) {
160161
var res = StringMapWrapper.create();
161162
for (var i = 0; i < this.keys.length; ++i) {
162163
StringMapWrapper.set(res, this.keys[i], this.values[i].eval(context, locals));
@@ -178,7 +179,7 @@ export class Interpolation extends AST {
178179
export class Binary extends AST {
179180
constructor(public operation: string, public left: AST, public right: AST) { super(); }
180181

181-
eval(context, locals) {
182+
eval(context, locals: Locals) {
182183
var left: any = this.left.eval(context, locals);
183184
switch (this.operation) {
184185
case '&&':
@@ -229,15 +230,15 @@ export class Binary extends AST {
229230
export class PrefixNot extends AST {
230231
constructor(public expression: AST) { super(); }
231232

232-
eval(context, locals) { return !this.expression.eval(context, locals); }
233+
eval(context, locals: Locals) { return !this.expression.eval(context, locals); }
233234

234235
visit(visitor: AstVisitor) { return visitor.visitPrefixNot(this); }
235236
}
236237

237238
export class Assignment extends AST {
238239
constructor(public target: AST, public value: AST) { super(); }
239240

240-
eval(context, locals) {
241+
eval(context, locals: Locals) {
241242
return this.target.assign(context, locals, this.value.eval(context, locals));
242243
}
243244

@@ -250,7 +251,7 @@ export class MethodCall extends AST {
250251
super();
251252
}
252253

253-
eval(context, locals) {
254+
eval(context, locals: Locals) {
254255
var evaluatedArgs = evalList(context, locals, this.args);
255256
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
256257
locals.contains(this.name)) {
@@ -271,7 +272,7 @@ export class SafeMethodCall extends AST {
271272
super();
272273
}
273274

274-
eval(context, locals) {
275+
eval(context, locals: Locals) {
275276
var evaluatedReceiver = this.receiver.eval(context, locals);
276277
if (isBlank(evaluatedReceiver)) return null;
277278
var evaluatedArgs = evalList(context, locals, this.args);
@@ -284,7 +285,7 @@ export class SafeMethodCall extends AST {
284285
export class FunctionCall extends AST {
285286
constructor(public target: AST, public args: List<any>) { super(); }
286287

287-
eval(context, locals) {
288+
eval(context, locals: Locals) {
288289
var obj: any = this.target.eval(context, locals);
289290
if (!(obj instanceof Function)) {
290291
throw new BaseException(`${obj} is not a function`);
@@ -298,11 +299,11 @@ export class FunctionCall extends AST {
298299
export class ASTWithSource extends AST {
299300
constructor(public ast: AST, public source: string, public location: string) { super(); }
300301

301-
eval(context, locals) { return this.ast.eval(context, locals); }
302+
eval(context, locals: Locals) { return this.ast.eval(context, locals); }
302303

303304
get isAssignable(): boolean { return this.ast.isAssignable; }
304305

305-
assign(context, locals, value) { return this.ast.assign(context, locals, value); }
306+
assign(context, locals: Locals, value) { return this.ast.assign(context, locals, value); }
306307

307308
visit(visitor: AstVisitor) { return this.ast.visit(visitor); }
308309

@@ -413,7 +414,7 @@ var _evalListCache = [
413414
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
414415
];
415416

416-
function evalList(context, locals, exps: List<any>) {
417+
function evalList(context, locals: Locals, exps: List<any>) {
417418
var length = exps.length;
418419
if (length > 10) {
419420
throw new BaseException("Cannot have more than 10 argument");

modules/angular2/src/change_detection/pipes/iterable_changes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class _DuplicateItemRecordList {
609609
}
610610

611611
class _DuplicateMap {
612-
map: Map<any, any>;
612+
map: Map<any, _DuplicateItemRecordList>;
613613
constructor() { this.map = MapWrapper.create(); }
614614

615615
put(record: CollectionChangeRecord) {

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class TreeNode<T extends TreeNode<any>> {
150150
get parent() { return this._parent; }
151151

152152
// TODO(rado): replace with a function call, does too much work for a getter.
153-
get children() {
153+
get children(): TreeNode<any>[] {
154154
var res = [];
155155
var child = this._head;
156156
while (child != null) {

modules/angular2/src/forms/directives/ng_model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {NgControl} from './ng_control';
99
import {Control} from '../model';
1010
import {setUpControl} from './shared';
1111

12-
const formControlBinding =
13-
CONST_EXPR(new Binding(NgControl, {toAlias: forwardRef(() => NgModel)}));
12+
const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRef(() => NgModel)}));
1413

1514
/**
1615
* Binds a domain model to the form.

modules/angular2/src/render/dom/events/hammer_gestures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../../../typings/hammerjs/hammerjs"/>
1+
/// <reference path="../../../../typings/hammerjs/hammerjs.d.ts"/>
22

33
import {HammerGesturesPluginCommon} from './hammer_common';
44
import {isPresent, BaseException} from 'angular2/src/facade/lang';

modules/angular2/src/router/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export class Router {
9090
*/
9191
config(config: any): Promise<any> {
9292
if (config instanceof List) {
93-
config.forEach(
94-
(configObject) => { this._registry.config(this.hostComponent, configObject); });
93+
(<List<any>>config)
94+
.forEach((configObject) => { this._registry.config(this.hostComponent, configObject); });
9595
} else {
9696
this._registry.config(this.hostComponent, config);
9797
}

modules/angular2/src/test_lib/test_bed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class ViewProxy {
128128
this._view.changeDetector.checkNoChanges();
129129
}
130130

131-
querySelector(selector) { return queryView(this._view, selector); }
131+
querySelector(selector): any { return queryView(this._view, selector); }
132132

133133
destroy() { this._componentRef.dispose(); }
134134

modules/angular2/src/test_lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function viewRootNodes(view): List</*node*/ any> {
2323
return resolveInternalDomView(view.render).rootNodes;
2424
}
2525

26-
export function queryView(view, selector: string) {
26+
export function queryView(view, selector: string): any {
2727
var rootNodes = viewRootNodes(view);
2828
for (var i = 0; i < rootNodes.length; ++i) {
2929
var res = DOM.querySelector(rootNodes[i], selector);

modules/angular2/test/change_detection/parser/locals_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {MapWrapper} from 'angular2/src/facade/collection';
66

77
export function main() {
88
describe('Locals', () => {
9-
var locals;
9+
var locals: Locals;
1010
beforeEach(() => {
1111
locals = new Locals(null, MapWrapper.createFromPairs([['key', 'value'], ['nullKey', null]]));
1212
});

0 commit comments

Comments
 (0)
X Tutup