X Tutup
Skip to content

Commit 044625a

Browse files
mheveryvsavkin
authored andcommitted
chore: Make field declarations explicit
This used to be valid code: ``` class Foo { constructor() { this.bar = ‘string’; } } ``` This will now fail since ‘bar’ is not explicitly defined as a field. We now have to write: ``` class Foo { bar:string; // << REQUIRED constructor() { this.bar = ‘string’; } } ```
1 parent ab961b3 commit 044625a

Some content is hidden

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

69 files changed

+575
-507
lines changed

modules/benchmarks/src/compiler/compiler_benchmark.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {Lexer} from 'change_detection/parser/lexer';
1212
import {Compiler} from 'core/compiler/compiler';
1313
import {Reflector} from 'core/compiler/reflector';
1414

15-
import {Component} from 'core/annotations/component';
16-
import {Decorator} from 'core/annotations/decorator';
15+
import {Component} from 'core/annotations/annotations';
16+
import {Decorator} from 'core/annotations/annotations';
1717
import {TemplateConfig} from 'core/annotations/template_config';
1818

1919
var COUNT = 30;
@@ -64,6 +64,7 @@ function loadTemplate(templateId, repeatCount) {
6464

6565
// Caching reflector as reflection in Dart using Mirrors
6666
class CachingReflector extends Reflector {
67+
_cache: Map;
6768
constructor() {
6869
this._cache = MapWrapper.create();
6970
}

modules/change_detection/src/change_detector.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export * from './record';
66
export * from './record_range'
77

88
export class ChangeDetector {
9-
10-
@FIELD('final _rootRecordRange:RecordRange')
9+
_rootRecordRange:RecordRange;
1110
constructor(recordRange:RecordRange) {
1211
this._rootRecordRange = recordRange;
1312
}

modules/change_detection/src/collection_changes.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ import {
1313
} from 'facade/lang';
1414

1515
export class CollectionChanges {
16-
// todo(vicb) Add fields when supported
17-
/*
1816
_collection;
19-
int _length;
20-
DuplicateMap _linkedRecords;
21-
DuplicateMap _unlinkedRecords;
22-
CollectionChangeItem<V> _previousItHead;
23-
CollectionChangeItem<V> _itHead, _itTail;
24-
CollectionChangeItem<V> _additionsHead, _additionsTail;
25-
CollectionChangeItem<V> _movesHead, _movesTail;
26-
CollectionChangeItem<V> _removalsHead, _removalsTail;
27-
*/
17+
_length:int;
18+
_linkedRecords:_DuplicateMap;
19+
_unlinkedRecords:_DuplicateMap;
20+
_previousItHead:CollectionChangeRecord<V> ;
21+
_itHead:CollectionChangeRecord<V>;
22+
_itTail:CollectionChangeRecord<V> ;
23+
_additionsHead:CollectionChangeRecord<V>;
24+
_additionsTail:CollectionChangeRecord<V> ;
25+
_movesHead:CollectionChangeRecord<V>;
26+
_movesTail:CollectionChangeRecord<V> ;
27+
_removalsHead:CollectionChangeRecord<V>;
28+
_removalsTail:CollectionChangeRecord<V> ;
2829
constructor() {
2930
this._collection = null;
3031
this._length = null;
@@ -236,9 +237,9 @@ export class CollectionChanges {
236237
}
237238

238239
/**
239-
* Get rid of any excess [CollectionChangeItem]s from the previous collection
240+
* Get rid of any excess [CollectionChangeRecord]s from the previous collection
240241
*
241-
* - [record] The first excess [CollectionChangeItem].
242+
* - [record] The first excess [CollectionChangeRecord].
242243
*/
243244
_truncate(record:CollectionChangeRecord) {
244245
// Anything after that needs to be removed;
@@ -457,19 +458,16 @@ export class CollectionChanges {
457458
}
458459

459460
export class CollectionChangeRecord {
460-
// todo(vicb) add fields when supported
461-
/*
462-
int currentIndex;
463-
int previousIndex;
464-
V item;
465-
466-
CollectionChangeItem<V> _nextPrevious;
467-
CollectionChangeItem<V> _prev, _next;
468-
CollectionChangeItem<V> _prevDup, _nextDup;
469-
CollectionChangeItem<V> _prevRemoved, _nextRemoved;
470-
CollectionChangeItem<V> _nextAdded;
471-
CollectionChangeItem<V> _nextMoved;
472-
*/
461+
currentIndex:int;
462+
previousIndex:int;
463+
item;
464+
465+
_nextPrevious:CollectionChangeRecord;
466+
_prev:CollectionChangeRecord; _next:CollectionChangeRecord;
467+
_prevDup:CollectionChangeRecord; _nextDup:CollectionChangeRecord;
468+
_prevRemoved:CollectionChangeRecord; _nextRemoved:CollectionChangeRecord;
469+
_nextAdded:CollectionChangeRecord;
470+
_nextMoved:CollectionChangeRecord;
473471

474472
constructor(item) {
475473
this.currentIndex = null;
@@ -497,10 +495,8 @@ export class CollectionChangeRecord {
497495

498496
// A linked list of CollectionChangeRecords with the same CollectionChangeRecord.item
499497
class _DuplicateItemRecordList {
500-
/*
501-
todo(vicb): add fields when supported
502-
CollectionChangeRecord _head, _tail;
503-
*/
498+
_head:CollectionChangeRecord;
499+
_tail:CollectionChangeRecord;
504500

505501
constructor() {
506502
this._head = null;
@@ -542,15 +538,15 @@ class _DuplicateItemRecordList {
542538
}
543539

544540
/**
545-
* Remove one [CollectionChangeItem] from the list of duplicates.
541+
* Remove one [CollectionChangeRecord] from the list of duplicates.
546542
*
547543
* Returns whether the list of duplicates is empty.
548544
*/
549545
remove(record:CollectionChangeRecord):boolean {
550546
// todo(vicb)
551547
//assert(() {
552548
// // verify that the record being removed is in the list.
553-
// for (CollectionChangeItem cursor = _head; cursor != null; cursor = cursor._nextDup) {
549+
// for (CollectionChangeRecord cursor = _head; cursor != null; cursor = cursor._nextDup) {
554550
// if (identical(cursor, record)) return true;
555551
// }
556552
// return false;
@@ -573,7 +569,7 @@ class _DuplicateItemRecordList {
573569
}
574570

575571
class _DuplicateMap {
576-
// todo(vicb): add fields when supported
572+
map:Map;
577573
constructor() {
578574
this.map = MapWrapper.create();
579575
}
@@ -605,7 +601,7 @@ class _DuplicateMap {
605601
}
606602

607603
/**
608-
* Removes an [CollectionChangeItem] from the list of duplicates.
604+
* Removes an [CollectionChangeRecord] from the list of duplicates.
609605
*
610606
* The list of duplicates also is removed from the map if it gets empty.
611607
*/

modules/change_detection/src/map_changes.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ import {ListWrapper, MapWrapper} from 'facade/collection';
33
import {stringify, looseIdentical} from 'facade/lang';
44

55
export class MapChanges {
6-
// todo(vicb) add as fields when supported
7-
/*
8-
final _records = new HashMap<dynamic, MapKeyValue>();
9-
Map _map;
10-
11-
Map get map => _map;
12-
13-
MapKeyValue<K, V> _mapHead;
14-
MapKeyValue<K, V> _previousMapHead;
15-
MapKeyValue<K, V> _changesHead, _changesTail;
16-
MapKeyValue<K, V> _additionsHead, _additionsTail;
17-
MapKeyValue<K, V> _removalsHead, _removalsTail;
18-
*/
6+
_records:Map;
7+
_map:Map;
8+
9+
_mapHead:MapChangeRecord;
10+
_previousMapHead:MapChangeRecord;
11+
_changesHead:MapChangeRecord;
12+
_changesTail:MapChangeRecord;
13+
_additionsHead:MapChangeRecord;
14+
_additionsTail:MapChangeRecord;
15+
_removalsHead:MapChangeRecord;
16+
_removalsTail:MapChangeRecord;
1917

2018
constructor() {
2119
this._records = MapWrapper.create();
@@ -317,18 +315,16 @@ export class MapChanges {
317315
}
318316

319317
export class MapChangeRecord {
320-
// todo(vicb) add as fields
321-
//final K key;
322-
//V _previousValue, _currentValue;
323-
//
324-
//V get previousValue => _previousValue;
325-
//V get currentValue => _currentValue;
326-
//
327-
//MapKeyValue<K, V> _nextPrevious;
328-
//MapKeyValue<K, V> _next;
329-
//MapKeyValue<K, V> _nextAdded;
330-
//MapKeyValue<K, V> _nextRemoved, _prevRemoved;
331-
//MapKeyValue<K, V> _nextChanged;
318+
key;
319+
_previousValue;
320+
_currentValue;
321+
322+
_nextPrevious:MapChangeRecord;
323+
_next:MapChangeRecord;
324+
_nextAdded:MapChangeRecord;
325+
_nextRemoved:MapChangeRecord;
326+
_prevRemoved:MapChangeRecord;
327+
_nextChanged:MapChangeRecord;
332328

333329
constructor(key) {
334330
this.key = key;

modules/change_detection/src/parser/ast.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ImplicitReceiver extends AST {
3333
* Multiple expressions separated by a semicolon.
3434
*/
3535
export class Chain extends AST {
36-
@FIELD('final expressions:List')
36+
expressions:List;
3737
constructor(expressions:List) {
3838
this.expressions = expressions;
3939
}
@@ -53,9 +53,9 @@ export class Chain extends AST {
5353
}
5454

5555
export class Conditional extends AST {
56-
@FIELD('final condition:AST')
57-
@FIELD('final trueExp:AST')
58-
@FIELD('final falseExp:AST')
56+
condition:AST;
57+
trueExp:AST;
58+
falseExp:AST;
5959
constructor(condition:AST, trueExp:AST, falseExp:AST){
6060
this.condition = condition;
6161
this.trueExp = trueExp;
@@ -76,10 +76,10 @@ export class Conditional extends AST {
7676
}
7777

7878
export class AccessMember extends AST {
79-
@FIELD('final receiver:AST')
80-
@FIELD('final name:string')
81-
@FIELD('final getter:Function')
82-
@FIELD('final setter:Function')
79+
receiver:AST;
80+
name:string;
81+
getter:Function;
82+
setter:Function;
8383
constructor(receiver:AST, name:string, getter:Function, setter:Function) {
8484
this.receiver = receiver;
8585
this.name = name;
@@ -105,8 +105,8 @@ export class AccessMember extends AST {
105105
}
106106

107107
export class KeyedAccess extends AST {
108-
@FIELD('final obj:AST')
109-
@FIELD('final key:AST')
108+
obj:AST;
109+
key:AST;
110110
constructor(obj:AST, key:AST) {
111111
this.obj = obj;
112112
this.key = key;
@@ -149,9 +149,10 @@ export class KeyedAccess extends AST {
149149
}
150150

151151
export class Formatter extends AST {
152-
@FIELD('final exp:AST')
153-
@FIELD('final name:string')
154-
@FIELD('final args:List<AST>')
152+
exp:AST;
153+
name:string;
154+
args:List<AST>;
155+
allArgs:List<AST>;
155156
constructor(exp:AST, name:string, args:List) {
156157
this.exp = exp;
157158
this.name = name;
@@ -165,7 +166,7 @@ export class Formatter extends AST {
165166
}
166167

167168
export class LiteralPrimitive extends AST {
168-
@FIELD('final value')
169+
value;
169170
constructor(value) {
170171
this.value = value;
171172
}
@@ -180,7 +181,7 @@ export class LiteralPrimitive extends AST {
180181
}
181182

182183
export class LiteralArray extends AST {
183-
@FIELD('final expressions:List')
184+
expressions:List;
184185
constructor(expressions:List) {
185186
this.expressions = expressions;
186187
}
@@ -195,8 +196,8 @@ export class LiteralArray extends AST {
195196
}
196197

197198
export class LiteralMap extends AST {
198-
@FIELD('final keys:List')
199-
@FIELD('final values:List')
199+
keys:List;
200+
values:List;
200201
constructor(keys:List, values:List) {
201202
this.keys = keys;
202203
this.values = values;
@@ -216,9 +217,9 @@ export class LiteralMap extends AST {
216217
}
217218

218219
export class Binary extends AST {
219-
@FIELD('final operation:string')
220-
@FIELD('final left:AST')
221-
@FIELD('final right:AST')
220+
operation:string;
221+
left:AST;
222+
right:AST;
222223
constructor(operation:string, left:AST, right:AST) {
223224
this.operation = operation;
224225
this.left = left;
@@ -262,7 +263,7 @@ export class Binary extends AST {
262263
}
263264

264265
export class PrefixNot extends AST {
265-
@FIELD('final expression:AST')
266+
expression:AST;
266267
constructor(expression:AST) {
267268
this.expression = expression;
268269
}
@@ -277,8 +278,8 @@ export class PrefixNot extends AST {
277278
}
278279

279280
export class Assignment extends AST {
280-
@FIELD('final target:AST')
281-
@FIELD('final value:AST')
281+
target:AST;
282+
value:AST;
282283
constructor(target:AST, value:AST) {
283284
this.target = target;
284285
this.value = value;
@@ -294,9 +295,9 @@ export class Assignment extends AST {
294295
}
295296

296297
export class MethodCall extends AST {
297-
@FIELD('final receiver:AST')
298-
@FIELD('final fn:Function')
299-
@FIELD('final args:List')
298+
receiver:AST;
299+
fn:Function;
300+
args:List;
300301
constructor(receiver:AST, fn:Function, args:List) {
301302
this.receiver = receiver;
302303
this.fn = fn;
@@ -314,9 +315,9 @@ export class MethodCall extends AST {
314315
}
315316

316317
export class FunctionCall extends AST {
317-
@FIELD('final target:AST')
318-
@FIELD('final closureMap:ClosureMap')
319-
@FIELD('final args:List')
318+
target:AST;
319+
closureMap:ClosureMap;
320+
args:List;
320321
constructor(target:AST, closureMap:ClosureMap, args:List) {
321322
this.target = target;
322323
this.closureMap = closureMap;
@@ -337,13 +338,18 @@ export class FunctionCall extends AST {
337338
}
338339

339340
export class ASTWithSource {
341+
ast:AST;
342+
source:string;
340343
constructor(ast:AST, source:string) {
341344
this.source = source;
342345
this.ast = ast;
343346
}
344347
}
345348

346349
export class TemplateBinding {
350+
key:string;
351+
name:string;
352+
expression:ASTWithSource;
347353
constructor(key:string, name:string, expression:ASTWithSource) {
348354
this.key = key;
349355
// only either name or expression will be filled.

0 commit comments

Comments
 (0)
X Tutup