Skip to content

Commit de18da2

Browse files
committed
feat(build): require parameter types
Fixes angular#2833
1 parent 6d76066 commit de18da2

File tree

81 files changed

+379
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+379
-290
lines changed

gulpfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,19 @@ gulp.task('enforce-format', function() {
275275
});
276276

277277
gulp.task('lint', ['build.tools'], function() {
278+
// Built-in rules are at
278279
// https://github.com/palantir/tslint#supported-rules
279280
var tslintConfig = {
280281
"rules": {
281282
"semicolon": true,
282-
"requireReturnType": true
283+
"requireReturnType": true,
284+
"requireParameterType": true
283285
}
284286
};
285287

286288
return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/test_lib/**'])
287289
.pipe(tslint({configuration: tslintConfig, rulesDirectory: 'dist/tools/tslint'}))
288-
.pipe(tslint.report('prose'));
290+
.pipe(tslint.report('prose', {emitError: true}));
289291
});
290292

291293
// ------------

modules/angular2/src/change_detection/change_detection_util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function _simpleChange(previousValue, currentValue): SimpleChange {
4545
return s;
4646
}
4747

48+
/* tslint:disable:requireParameterType */
4849
export class ChangeDetectionUtil {
4950
static uninitialized(): Object { return uninitialized; }
5051

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ import {List, Map, ListWrapper, StringMapWrapper} from "angular2/src/facade/coll
33
import {Locals} from "./locals";
44

55
export class AST {
6-
eval(context, locals: Locals) { throw new BaseException("Not supported"); }
6+
eval(context: any, locals: Locals): any { throw new BaseException("Not supported"); }
77

88
get isAssignable(): boolean { return false; }
99

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

1212
visit(visitor: AstVisitor): any { return null; }
1313

1414
toString(): string { return "AST"; }
1515
}
1616

1717
export class EmptyExpr extends AST {
18-
eval(context, locals: Locals): any { return null; }
18+
eval(context: any, locals: Locals): any { return null; }
1919

2020
visit(visitor: AstVisitor) {
2121
// do nothing
2222
}
2323
}
2424

2525
export class ImplicitReceiver extends AST {
26-
eval(context, locals: Locals): any { return context; }
26+
eval(context: any, locals: Locals): any { return context; }
2727

2828
visit(visitor: AstVisitor): any { return visitor.visitImplicitReceiver(this); }
2929
}
@@ -34,7 +34,7 @@ export class ImplicitReceiver extends AST {
3434
export class Chain extends AST {
3535
constructor(public expressions: List<any>) { super(); }
3636

37-
eval(context, locals: Locals): any {
37+
eval(context: any, locals: Locals): any {
3838
var result;
3939
for (var i = 0; i < this.expressions.length; i++) {
4040
var last = this.expressions[i].eval(context, locals);
@@ -49,7 +49,7 @@ export class Chain extends AST {
4949
export class Conditional extends AST {
5050
constructor(public condition: AST, public trueExp: AST, public falseExp: AST) { super(); }
5151

52-
eval(context, locals: Locals): any {
52+
eval(context: any, locals: Locals): any {
5353
if (this.condition.eval(context, locals)) {
5454
return this.trueExp.eval(context, locals);
5555
} else {
@@ -63,7 +63,7 @@ export class Conditional extends AST {
6363
export class If extends AST {
6464
constructor(public condition: AST, public trueExp: AST, public falseExp?: AST) { super(); }
6565

66-
eval(context, locals) {
66+
eval(context: any, locals: Locals) {
6767
if (this.condition.eval(context, locals)) {
6868
this.trueExp.eval(context, locals);
6969
} else if (isPresent(this.falseExp)) {
@@ -80,7 +80,7 @@ export class AccessMember extends AST {
8080
super();
8181
}
8282

83-
eval(context, locals: Locals): any {
83+
eval(context: any, locals: Locals): any {
8484
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
8585
locals.contains(this.name)) {
8686
return locals.get(this.name);
@@ -92,7 +92,7 @@ export class AccessMember extends AST {
9292

9393
get isAssignable(): boolean { return true; }
9494

95-
assign(context, locals: Locals, value): any {
95+
assign(context: any, locals: Locals, value: any): any {
9696
var evaluatedContext = this.receiver.eval(context, locals);
9797

9898
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
@@ -112,7 +112,7 @@ export class SafeAccessMember extends AST {
112112
super();
113113
}
114114

115-
eval(context, locals: Locals): any {
115+
eval(context: any, locals: Locals): any {
116116
var evaluatedReceiver = this.receiver.eval(context, locals);
117117
return isBlank(evaluatedReceiver) ? null : this.getter(evaluatedReceiver);
118118
}
@@ -123,15 +123,15 @@ export class SafeAccessMember extends AST {
123123
export class KeyedAccess extends AST {
124124
constructor(public obj: AST, public key: AST) { super(); }
125125

126-
eval(context, locals: Locals): any {
126+
eval(context: any, locals: Locals): any {
127127
var obj: any = this.obj.eval(context, locals);
128128
var key: any = this.key.eval(context, locals);
129129
return obj[key];
130130
}
131131

132132
get isAssignable(): boolean { return true; }
133133

134-
assign(context, locals: Locals, value): any {
134+
assign(context: any, locals: Locals, value: any): any {
135135
var obj: any = this.obj.eval(context, locals);
136136
var key: any = this.key.eval(context, locals);
137137
obj[key] = value;
@@ -150,15 +150,15 @@ export class BindingPipe extends AST {
150150
export class LiteralPrimitive extends AST {
151151
constructor(public value) { super(); }
152152

153-
eval(context, locals: Locals): any { return this.value; }
153+
eval(context: any, locals: Locals): any { return this.value; }
154154

155155
visit(visitor: AstVisitor): any { return visitor.visitLiteralPrimitive(this); }
156156
}
157157

158158
export class LiteralArray extends AST {
159159
constructor(public expressions: List<any>) { super(); }
160160

161-
eval(context, locals: Locals): any {
161+
eval(context: any, locals: Locals): any {
162162
return ListWrapper.map(this.expressions, (e) => e.eval(context, locals));
163163
}
164164

@@ -168,7 +168,7 @@ export class LiteralArray extends AST {
168168
export class LiteralMap extends AST {
169169
constructor(public keys: List<any>, public values: List<any>) { super(); }
170170

171-
eval(context, locals: Locals): any {
171+
eval(context: any, locals: Locals): any {
172172
var res = StringMapWrapper.create();
173173
for (var i = 0; i < this.keys.length; ++i) {
174174
StringMapWrapper.set(res, this.keys[i], this.values[i].eval(context, locals));
@@ -182,7 +182,7 @@ export class LiteralMap extends AST {
182182
export class Interpolation extends AST {
183183
constructor(public strings: List<any>, public expressions: List<any>) { super(); }
184184

185-
eval(context, locals): any {
185+
eval(context: any, locals: Locals): any {
186186
throw new BaseException("evaluating an Interpolation is not supported");
187187
}
188188

@@ -192,7 +192,7 @@ export class Interpolation extends AST {
192192
export class Binary extends AST {
193193
constructor(public operation: string, public left: AST, public right: AST) { super(); }
194194

195-
eval(context, locals: Locals): any {
195+
eval(context: any, locals: Locals): any {
196196
var left: any = this.left.eval(context, locals);
197197
switch (this.operation) {
198198
case '&&':
@@ -243,15 +243,15 @@ export class Binary extends AST {
243243
export class PrefixNot extends AST {
244244
constructor(public expression: AST) { super(); }
245245

246-
eval(context, locals: Locals): any { return !this.expression.eval(context, locals); }
246+
eval(context: any, locals: Locals): any { return !this.expression.eval(context, locals); }
247247

248248
visit(visitor: AstVisitor): any { return visitor.visitPrefixNot(this); }
249249
}
250250

251251
export class Assignment extends AST {
252-
constructor(public target: AST, public value: AST) { super(); }
252+
constructor(public target: AST, public value: any) { super(); }
253253

254-
eval(context, locals: Locals): any {
254+
eval(context: any, locals: Locals): any {
255255
return this.target.assign(context, locals, this.value.eval(context, locals));
256256
}
257257

@@ -264,7 +264,7 @@ export class MethodCall extends AST {
264264
super();
265265
}
266266

267-
eval(context, locals: Locals): any {
267+
eval(context: any, locals: Locals): any {
268268
var evaluatedArgs = evalList(context, locals, this.args);
269269
if (this.receiver instanceof ImplicitReceiver && isPresent(locals) &&
270270
locals.contains(this.name)) {
@@ -285,7 +285,7 @@ export class SafeMethodCall extends AST {
285285
super();
286286
}
287287

288-
eval(context, locals: Locals): any {
288+
eval(context: any, locals: Locals): any {
289289
var evaluatedReceiver = this.receiver.eval(context, locals);
290290
if (isBlank(evaluatedReceiver)) return null;
291291
var evaluatedArgs = evalList(context, locals, this.args);
@@ -298,7 +298,7 @@ export class SafeMethodCall extends AST {
298298
export class FunctionCall extends AST {
299299
constructor(public target: AST, public args: List<any>) { super(); }
300300

301-
eval(context, locals: Locals): any {
301+
eval(context: any, locals: Locals): any {
302302
var obj: any = this.target.eval(context, locals);
303303
if (!(obj instanceof Function)) {
304304
throw new BaseException(`${obj} is not a function`);
@@ -312,11 +312,13 @@ export class FunctionCall extends AST {
312312
export class ASTWithSource extends AST {
313313
constructor(public ast: AST, public source: string, public location: string) { super(); }
314314

315-
eval(context, locals: Locals): any { return this.ast.eval(context, locals); }
315+
eval(context: any, locals: Locals): any { return this.ast.eval(context, locals); }
316316

317317
get isAssignable(): boolean { return this.ast.isAssignable; }
318318

319-
assign(context, locals: Locals, value): any { return this.ast.assign(context, locals, value); }
319+
assign(context: any, locals: Locals, value: any): any {
320+
return this.ast.assign(context, locals, value);
321+
}
320322

321323
visit(visitor: AstVisitor): any { return this.ast.visit(visitor); }
322324

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Locals {
2828
throw new BaseException(`Cannot find '${name}'`);
2929
}
3030

31-
set(name: string, value): void {
31+
set(name: string, value: any): void {
3232
// TODO(rado): consider removing this check if we can guarantee this is not
3333
// exposed to the public API.
3434
// TODO: vsavkin maybe it should check only the local map

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class _ParseAST {
479479
return new LiteralMap(keys, values);
480480
}
481481

482-
parseAccessMemberOrMethodCall(receiver, isSafe: boolean = false): AST {
482+
parseAccessMemberOrMethodCall(receiver: AST, isSafe: boolean = false): AST {
483483
let id = this.expectIdentifierOrKeyword();
484484

485485
if (this.optionalCharacter($LPAREN)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class DatePipe extends BasePipe implements PipeFactory {
8383
};
8484

8585

86-
transform(value, args: List<any>): string {
86+
transform(value: any, args: List<any>): string {
8787
var pattern: string = isPresent(args) && args.length > 0 ? args[0] : 'mediumDate';
8888
if (isNumber(value)) {
8989
value = DateWrapper.fromMillis(value);
@@ -94,7 +94,7 @@ export class DatePipe extends BasePipe implements PipeFactory {
9494
return DateFormatter.format(value, defaultLocale, pattern);
9595
}
9696

97-
supports(obj): boolean { return isDate(obj) || isNumber(obj); }
97+
supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
9898

9999
create(cdRef: ChangeDetectorRef): Pipe { return this; }
100100
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {ChangeDetectorRef} from '../change_detector_ref';
2020

2121
@CONST()
2222
export class IterableChangesFactory implements PipeFactory {
23-
supports(obj): boolean { return IterableChanges.supportsObj(obj); }
23+
supports(obj: any): boolean { return IterableChanges.supportsObj(obj); }
2424

2525
create(cdRef: ChangeDetectorRef): Pipe { return new IterableChanges(); }
2626
}
@@ -44,9 +44,9 @@ export class IterableChanges extends BasePipe {
4444

4545
constructor() { super(); }
4646

47-
static supportsObj(obj): boolean { return isListLikeIterable(obj); }
47+
static supportsObj(obj: Object): boolean { return isListLikeIterable(obj); }
4848

49-
supports(obj): boolean { return IterableChanges.supportsObj(obj); }
49+
supports(obj: Object): boolean { return IterableChanges.supportsObj(obj); }
5050

5151
get collection() { return this._collection; }
5252

@@ -87,7 +87,7 @@ export class IterableChanges extends BasePipe {
8787
}
8888
}
8989

90-
transform(collection, args: List<any> = null): any {
90+
transform(collection: any, args: List<any> = null): any {
9191
if (this.check(collection)) {
9292
return WrappedValue.wrap(this);
9393
} else {
@@ -96,7 +96,7 @@ export class IterableChanges extends BasePipe {
9696
}
9797

9898
// todo(vicb): optim for UnmodifiableListView (frozen arrays)
99-
check(collection): boolean {
99+
check(collection: any): boolean {
100100
this._reset();
101101

102102
var record: CollectionChangeRecord = this._itHead;
@@ -524,7 +524,7 @@ class _DuplicateItemRecordList {
524524

525525
// Returns a CollectionChangeRecord having CollectionChangeRecord.item == item and
526526
// CollectionChangeRecord.currentIndex >= afterIndex
527-
get(item, afterIndex: int): CollectionChangeRecord {
527+
get(item: any, afterIndex: int): CollectionChangeRecord {
528528
var record: CollectionChangeRecord;
529529
for (record = this._head; record !== null; record = record._nextDup) {
530530
if ((afterIndex === null || afterIndex < record.currentIndex) &&
@@ -588,7 +588,7 @@ class _DuplicateMap {
588588
* Use case: `[a, b, c, a, a]` if we are at index `3` which is the second `a` then asking if we
589589
* have any more `a`s needs to return the last `a` not the first or second.
590590
*/
591-
get(value, afterIndex = null): CollectionChangeRecord {
591+
get(value: any, afterIndex: int = null): CollectionChangeRecord {
592592
var key = getMapKey(value);
593593

594594
var recordList = this.map.get(key);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {ChangeDetectorRef} from '../change_detector_ref';
2727
*/
2828
@CONST()
2929
export class JsonPipe extends BasePipe implements PipeFactory {
30-
transform(value, args: List<any> = null): string { return Json.stringify(value); }
30+
transform(value: any, args: List<any> = null): string { return Json.stringify(value); }
3131

3232
create(cdRef: ChangeDetectorRef): Pipe { return this; }
3333
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {WrappedValue, BasePipe, Pipe, PipeFactory} from './pipe';
55

66
@CONST()
77
export class KeyValueChangesFactory implements PipeFactory {
8-
supports(obj): boolean { return KeyValueChanges.supportsObj(obj); }
8+
supports(obj: any): boolean { return KeyValueChanges.supportsObj(obj); }
99

1010
create(cdRef: ChangeDetectorRef): Pipe { return new KeyValueChanges(); }
1111
}
@@ -21,11 +21,11 @@ export class KeyValueChanges extends BasePipe {
2121
private _removalsHead: KVChangeRecord = null;
2222
private _removalsTail: KVChangeRecord = null;
2323

24-
static supportsObj(obj): boolean { return obj instanceof Map || isJsObject(obj); }
24+
static supportsObj(obj: any): boolean { return obj instanceof Map || isJsObject(obj); }
2525

26-
supports(obj): boolean { return KeyValueChanges.supportsObj(obj); }
26+
supports(obj: any): boolean { return KeyValueChanges.supportsObj(obj); }
2727

28-
transform(map, args: List<any> = null): any {
28+
transform(map: Map<any, any>, args: List<any> = null): any {
2929
if (this.check(map)) {
3030
return WrappedValue.wrap(this);
3131
} else {
@@ -73,7 +73,7 @@ export class KeyValueChanges extends BasePipe {
7373
}
7474
}
7575

76-
check(map): boolean {
76+
check(map: Map<any, any>): boolean {
7777
this._reset();
7878
var records = this._records;
7979
var oldSeqRecord: KVChangeRecord = this._mapHead;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ import {ChangeDetectorRef} from '../change_detector_ref';
5151
* {{ 'abcdefghij' | limitTo: -100 }} // output is 'abcdefghij'
5252
*/
5353
export class LimitToPipe implements Pipe {
54-
static supportsObj(obj): boolean { return isString(obj) || isArray(obj); }
54+
static supportsObj(obj: any): boolean { return isString(obj) || isArray(obj); }
5555

56-
supports(obj): boolean { return LimitToPipe.supportsObj(obj); }
56+
supports(obj: any): boolean { return LimitToPipe.supportsObj(obj); }
5757

58-
transform(value, args: List<any> = null): any {
58+
transform(value: any, args: List<any> = null): any {
5959
if (isBlank(args) || args.length == 0) {
6060
throw new BaseException('limitTo pipe requires one argument');
6161
}
@@ -76,7 +76,7 @@ export class LimitToPipe implements Pipe {
7676

7777
@CONST()
7878
export class LimitToPipeFactory implements PipeFactory {
79-
supports(obj): boolean { return LimitToPipe.supportsObj(obj); }
79+
supports(obj: any): boolean { return LimitToPipe.supportsObj(obj); }
8080

8181
create(cdRef: ChangeDetectorRef): Pipe { return new LimitToPipe(); }
8282
}

0 commit comments

Comments
 (0)