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’;
  }
}
```
This commit is contained in:
Misko Hevery
2014-11-21 21:19:23 -08:00
committed by vsavkin
parent ab961b327e
commit 044625a098
69 changed files with 572 additions and 504 deletions

View File

@ -6,8 +6,7 @@ export * from './record';
export * from './record_range'
export class ChangeDetector {
@FIELD('final _rootRecordRange:RecordRange')
_rootRecordRange:RecordRange;
constructor(recordRange:RecordRange) {
this._rootRecordRange = recordRange;
}

View File

@ -13,18 +13,19 @@ import {
} from 'facade/lang';
export class CollectionChanges {
// todo(vicb) Add fields when supported
/*
_collection;
int _length;
DuplicateMap _linkedRecords;
DuplicateMap _unlinkedRecords;
CollectionChangeItem<V> _previousItHead;
CollectionChangeItem<V> _itHead, _itTail;
CollectionChangeItem<V> _additionsHead, _additionsTail;
CollectionChangeItem<V> _movesHead, _movesTail;
CollectionChangeItem<V> _removalsHead, _removalsTail;
*/
_length:int;
_linkedRecords:_DuplicateMap;
_unlinkedRecords:_DuplicateMap;
_previousItHead:CollectionChangeRecord<V> ;
_itHead:CollectionChangeRecord<V>;
_itTail:CollectionChangeRecord<V> ;
_additionsHead:CollectionChangeRecord<V>;
_additionsTail:CollectionChangeRecord<V> ;
_movesHead:CollectionChangeRecord<V>;
_movesTail:CollectionChangeRecord<V> ;
_removalsHead:CollectionChangeRecord<V>;
_removalsTail:CollectionChangeRecord<V> ;
constructor() {
this._collection = null;
this._length = null;
@ -236,9 +237,9 @@ export class CollectionChanges {
}
/**
* Get rid of any excess [CollectionChangeItem]s from the previous collection
* Get rid of any excess [CollectionChangeRecord]s from the previous collection
*
* - [record] The first excess [CollectionChangeItem].
* - [record] The first excess [CollectionChangeRecord].
*/
_truncate(record:CollectionChangeRecord) {
// Anything after that needs to be removed;
@ -457,19 +458,16 @@ export class CollectionChanges {
}
export class CollectionChangeRecord {
// todo(vicb) add fields when supported
/*
int currentIndex;
int previousIndex;
V item;
currentIndex:int;
previousIndex:int;
item;
CollectionChangeItem<V> _nextPrevious;
CollectionChangeItem<V> _prev, _next;
CollectionChangeItem<V> _prevDup, _nextDup;
CollectionChangeItem<V> _prevRemoved, _nextRemoved;
CollectionChangeItem<V> _nextAdded;
CollectionChangeItem<V> _nextMoved;
*/
_nextPrevious:CollectionChangeRecord;
_prev:CollectionChangeRecord; _next:CollectionChangeRecord;
_prevDup:CollectionChangeRecord; _nextDup:CollectionChangeRecord;
_prevRemoved:CollectionChangeRecord; _nextRemoved:CollectionChangeRecord;
_nextAdded:CollectionChangeRecord;
_nextMoved:CollectionChangeRecord;
constructor(item) {
this.currentIndex = null;
@ -497,10 +495,8 @@ export class CollectionChangeRecord {
// A linked list of CollectionChangeRecords with the same CollectionChangeRecord.item
class _DuplicateItemRecordList {
/*
todo(vicb): add fields when supported
CollectionChangeRecord _head, _tail;
*/
_head:CollectionChangeRecord;
_tail:CollectionChangeRecord;
constructor() {
this._head = null;
@ -542,7 +538,7 @@ class _DuplicateItemRecordList {
}
/**
* Remove one [CollectionChangeItem] from the list of duplicates.
* Remove one [CollectionChangeRecord] from the list of duplicates.
*
* Returns whether the list of duplicates is empty.
*/
@ -550,7 +546,7 @@ class _DuplicateItemRecordList {
// todo(vicb)
//assert(() {
// // verify that the record being removed is in the list.
// for (CollectionChangeItem cursor = _head; cursor != null; cursor = cursor._nextDup) {
// for (CollectionChangeRecord cursor = _head; cursor != null; cursor = cursor._nextDup) {
// if (identical(cursor, record)) return true;
// }
// return false;
@ -573,7 +569,7 @@ class _DuplicateItemRecordList {
}
class _DuplicateMap {
// todo(vicb): add fields when supported
map:Map;
constructor() {
this.map = MapWrapper.create();
}
@ -605,7 +601,7 @@ class _DuplicateMap {
}
/**
* Removes an [CollectionChangeItem] from the list of duplicates.
* Removes an [CollectionChangeRecord] from the list of duplicates.
*
* The list of duplicates also is removed from the map if it gets empty.
*/

View File

@ -3,19 +3,17 @@ import {ListWrapper, MapWrapper} from 'facade/collection';
import {stringify, looseIdentical} from 'facade/lang';
export class MapChanges {
// todo(vicb) add as fields when supported
/*
final _records = new HashMap<dynamic, MapKeyValue>();
Map _map;
_records:Map;
_map:Map;
Map get map => _map;
MapKeyValue<K, V> _mapHead;
MapKeyValue<K, V> _previousMapHead;
MapKeyValue<K, V> _changesHead, _changesTail;
MapKeyValue<K, V> _additionsHead, _additionsTail;
MapKeyValue<K, V> _removalsHead, _removalsTail;
*/
_mapHead:MapChangeRecord;
_previousMapHead:MapChangeRecord;
_changesHead:MapChangeRecord;
_changesTail:MapChangeRecord;
_additionsHead:MapChangeRecord;
_additionsTail:MapChangeRecord;
_removalsHead:MapChangeRecord;
_removalsTail:MapChangeRecord;
constructor() {
this._records = MapWrapper.create();
@ -317,18 +315,16 @@ export class MapChanges {
}
export class MapChangeRecord {
// todo(vicb) add as fields
//final K key;
//V _previousValue, _currentValue;
//
//V get previousValue => _previousValue;
//V get currentValue => _currentValue;
//
//MapKeyValue<K, V> _nextPrevious;
//MapKeyValue<K, V> _next;
//MapKeyValue<K, V> _nextAdded;
//MapKeyValue<K, V> _nextRemoved, _prevRemoved;
//MapKeyValue<K, V> _nextChanged;
key;
_previousValue;
_currentValue;
_nextPrevious:MapChangeRecord;
_next:MapChangeRecord;
_nextAdded:MapChangeRecord;
_nextRemoved:MapChangeRecord;
_prevRemoved:MapChangeRecord;
_nextChanged:MapChangeRecord;
constructor(key) {
this.key = key;

View File

@ -33,7 +33,7 @@ export class ImplicitReceiver extends AST {
* Multiple expressions separated by a semicolon.
*/
export class Chain extends AST {
@FIELD('final expressions:List')
expressions:List;
constructor(expressions:List) {
this.expressions = expressions;
}
@ -53,9 +53,9 @@ export class Chain extends AST {
}
export class Conditional extends AST {
@FIELD('final condition:AST')
@FIELD('final trueExp:AST')
@FIELD('final falseExp:AST')
condition:AST;
trueExp:AST;
falseExp:AST;
constructor(condition:AST, trueExp:AST, falseExp:AST){
this.condition = condition;
this.trueExp = trueExp;
@ -76,10 +76,10 @@ export class Conditional extends AST {
}
export class AccessMember extends AST {
@FIELD('final receiver:AST')
@FIELD('final name:string')
@FIELD('final getter:Function')
@FIELD('final setter:Function')
receiver:AST;
name:string;
getter:Function;
setter:Function;
constructor(receiver:AST, name:string, getter:Function, setter:Function) {
this.receiver = receiver;
this.name = name;
@ -105,8 +105,8 @@ export class AccessMember extends AST {
}
export class KeyedAccess extends AST {
@FIELD('final obj:AST')
@FIELD('final key:AST')
obj:AST;
key:AST;
constructor(obj:AST, key:AST) {
this.obj = obj;
this.key = key;
@ -149,9 +149,10 @@ export class KeyedAccess extends AST {
}
export class Formatter extends AST {
@FIELD('final exp:AST')
@FIELD('final name:string')
@FIELD('final args:List<AST>')
exp:AST;
name:string;
args:List<AST>;
allArgs:List<AST>;
constructor(exp:AST, name:string, args:List) {
this.exp = exp;
this.name = name;
@ -165,7 +166,7 @@ export class Formatter extends AST {
}
export class LiteralPrimitive extends AST {
@FIELD('final value')
value;
constructor(value) {
this.value = value;
}
@ -180,7 +181,7 @@ export class LiteralPrimitive extends AST {
}
export class LiteralArray extends AST {
@FIELD('final expressions:List')
expressions:List;
constructor(expressions:List) {
this.expressions = expressions;
}
@ -195,8 +196,8 @@ export class LiteralArray extends AST {
}
export class LiteralMap extends AST {
@FIELD('final keys:List')
@FIELD('final values:List')
keys:List;
values:List;
constructor(keys:List, values:List) {
this.keys = keys;
this.values = values;
@ -216,9 +217,9 @@ export class LiteralMap extends AST {
}
export class Binary extends AST {
@FIELD('final operation:string')
@FIELD('final left:AST')
@FIELD('final right:AST')
operation:string;
left:AST;
right:AST;
constructor(operation:string, left:AST, right:AST) {
this.operation = operation;
this.left = left;
@ -262,7 +263,7 @@ export class Binary extends AST {
}
export class PrefixNot extends AST {
@FIELD('final expression:AST')
expression:AST;
constructor(expression:AST) {
this.expression = expression;
}
@ -277,8 +278,8 @@ export class PrefixNot extends AST {
}
export class Assignment extends AST {
@FIELD('final target:AST')
@FIELD('final value:AST')
target:AST;
value:AST;
constructor(target:AST, value:AST) {
this.target = target;
this.value = value;
@ -294,9 +295,9 @@ export class Assignment extends AST {
}
export class MethodCall extends AST {
@FIELD('final receiver:AST')
@FIELD('final fn:Function')
@FIELD('final args:List')
receiver:AST;
fn:Function;
args:List;
constructor(receiver:AST, fn:Function, args:List) {
this.receiver = receiver;
this.fn = fn;
@ -314,9 +315,9 @@ export class MethodCall extends AST {
}
export class FunctionCall extends AST {
@FIELD('final target:AST')
@FIELD('final closureMap:ClosureMap')
@FIELD('final args:List')
target:AST;
closureMap:ClosureMap;
args:List;
constructor(target:AST, closureMap:ClosureMap, args:List) {
this.target = target;
this.closureMap = closureMap;
@ -337,6 +338,8 @@ export class FunctionCall extends AST {
}
export class ASTWithSource {
ast:AST;
source:string;
constructor(ast:AST, source:string) {
this.source = source;
this.ast = ast;
@ -344,6 +347,9 @@ export class ASTWithSource {
}
export class TemplateBinding {
key:string;
name:string;
expression:ASTWithSource;
constructor(key:string, name:string, expression:ASTWithSource) {
this.key = key;
// only either name or expression will be filled.

View File

@ -9,6 +9,7 @@ export const TOKEN_TYPE_OPERATOR = 5;
export const TOKEN_TYPE_NUMBER = 6;
export class Lexer {
text:string;
tokenize(text:string):List {
var scanner = new _Scanner(text);
var tokens = [];
@ -22,10 +23,10 @@ export class Lexer {
}
export class Token {
@FIELD('final index:int')
@FIELD('final type:int')
@FIELD('final _numValue:int')
@FIELD('final _strValue:int')
index:int;
type:int;
_numValue:number;
_strValue:string;
constructor(index:int, type:int, numValue:number, strValue:string) {
/**
* NOTE: To ensure that this constructor creates the same hidden class each time, ensure that
@ -177,6 +178,7 @@ const $NBSP = 160;
export class ScannerError extends Error {
message:string;
constructor(message) {
this.message = message;
}
@ -187,10 +189,10 @@ export class ScannerError extends Error {
}
class _Scanner {
@FIELD('final input:String')
@FIELD('final length:int')
@FIELD('peek:int')
@FIELD('index:int')
input:string;
length:int;
peek:int;
index:int;
constructor(input:string) {
this.input = input;

View File

@ -28,8 +28,8 @@ import {
var _implicitReceiver = new ImplicitReceiver();
export class Parser {
@FIELD('final _lexer:Lexer')
@FIELD('final _closureMap:ClosureMap')
_lexer:Lexer;
_closureMap:ClosureMap;
constructor(lexer:Lexer, closureMap:ClosureMap){
this._lexer = lexer;
this._closureMap = closureMap;
@ -54,11 +54,11 @@ export class Parser {
}
class _ParseAST {
@FIELD('final input:string')
@FIELD('final tokens:List<Token>')
@FIELD('final closureMap:ClosureMap')
@FIELD('final parseAction:boolean')
@FIELD('index:int')
input:string;
tokens:List<Token>;
closureMap:ClosureMap;
parseAction:boolean;
index:int;
constructor(input:string, tokens:List, closureMap:ClosureMap, parseAction:boolean) {
this.input = input;
this.tokens = tokens;

View File

@ -1,6 +1,6 @@
import {ProtoRecordRange, RecordRange} from './record_range';
import {FIELD, isPresent, isBlank, int, StringWrapper, FunctionWrapper, BaseException} from 'facade/lang';
import {ListWrapper, MapWrapper} from 'facade/collection';
import {List, Map, ListWrapper, MapWrapper} from 'facade/collection';
import {ClosureMap} from 'change_detection/parser/closure_map';
var _fresh = new Object();
@ -26,15 +26,16 @@ export const RECORD_FLAG_IMPLICIT_RECEIVER = 0x0200;
* real world numbers show that it does not provide significant benefits.
*/
export class ProtoRecord {
@FIELD('final recordRange:ProtoRecordRange')
@FIELD('final context:Object')
@FIELD('final funcOrValue:Object')
@FIELD('final arity:int')
@FIELD('final dest')
recordRange:ProtoRecordRange;
_mode:int;
context:any;
funcOrValue:any;
arity:int;
dest;
@FIELD('next:ProtoRecord')
@FIELD('prev:ProtoRecord')
@FIELD('recordInConstruction:Record')
next:ProtoRecord;
prev:ProtoRecord;
recordInConstruction:Record;
constructor(recordRange:ProtoRecordRange,
mode:int,
funcOrValue,
@ -74,30 +75,29 @@ export class ProtoRecord {
* - Keep this object as lean as possible. (Lean in number of fields)
*/
export class Record {
@FIELD('final recordRange:RecordRange')
@FIELD('final protoRecord:ProtoRecord')
@FIELD('next:Record')
@FIELD('prev:Record')
recordRange:RecordRange;
protoRecord:ProtoRecord;
next:Record;
prev:Record;
/// This reference can change.
@FIELD('nextEnabled:Record')
nextEnabled:Record;
/// This reference can change.
@FIELD('prevEnabled:Record')
@FIELD('dest:Record')
prevEnabled:Record;
@FIELD('previousValue')
@FIELD('currentValue')
previousValue;
currentValue;
@FIELD('mode:int')
@FIELD('context')
@FIELD('funcOrValue')
@FIELD('args:List')
_mode:int;
context;
funcOrValue;
args:List;
// Opaque data which will be the target of notification.
// If the object is instance of Record, then it it is directly processed
// Otherwise it is the context used by WatchGroupDispatcher.
@FIELD('dest')
dest;
constructor(recordRange:RecordRange, protoRecord:ProtoRecord, formatters:Map) {
this.recordRange = recordRange;

View File

@ -11,15 +11,15 @@ import {
} from './record';
import {FIELD, IMPLEMENTS, isBlank, isPresent, int, toBool, autoConvertAdd, BaseException} from 'facade/lang';
import {ListWrapper, MapWrapper} from 'facade/collection';
import {List, Map, ListWrapper, MapWrapper} from 'facade/collection';
import {AST, AccessMember, ImplicitReceiver, AstVisitor, LiteralPrimitive,
Binary, Formatter, MethodCall, FunctionCall, PrefixNot, Conditional,
LiteralArray, LiteralMap, KeyedAccess, Chain, Assignment} from './parser/ast';
export class ProtoRecordRange {
@FIELD('headRecord:ProtoRecord')
@FIELD('tailRecord:ProtoRecord')
headRecord:ProtoRecord;
tailRecord:ProtoRecord;
constructor() {
this.headRecord = null;
this.tailRecord = null;
@ -84,11 +84,11 @@ export class ProtoRecordRange {
}
export class RecordRange {
@FIELD('final protoRecordRange:ProtoRecordRange')
@FIELD('final dispatcher:WatchGroupDispatcher')
@FIELD('final headRecord:Record')
@FIELD('final tailRecord:Record')
@FIELD('final disabled:boolean')
protoRecordRange:ProtoRecordRange;
dispatcher:any; //WatchGroupDispatcher
headRecord:Record;
tailRecord:Record;
disabled:boolean;
// TODO(rado): the type annotation should be dispatcher:WatchGroupDispatcher.
// but @Implements is not ready yet.
constructor(protoRecordRange:ProtoRecordRange, dispatcher) {
@ -270,6 +270,8 @@ export class WatchGroupDispatcher {
//todo: vsavkin: Create Array and Context destinations?
class Destination {
record:ProtoRecord;
position:int;
constructor(record:ProtoRecord, position:int) {
this.record = record;
this.position = position;
@ -279,9 +281,9 @@ class Destination {
@IMPLEMENTS(AstVisitor)
class ProtoRecordCreator {
@FIELD('final protoRecordRange:ProtoRecordRange')
@FIELD('headRecord:ProtoRecord')
@FIELD('tailRecord:ProtoRecord')
protoRecordRange:ProtoRecordRange;
headRecord:ProtoRecord;
tailRecord:ProtoRecord;
constructor(protoRecordRange) {
this.protoRecordRange = protoRecordRange;
this.headRecord = null;

View File

@ -189,6 +189,8 @@ export function main() {
}
class Person {
name:string;
address:Address;
constructor(name:string, address:Address = null) {
this.name = name;
this.address = address;
@ -206,6 +208,7 @@ class Person {
}
class Address {
city:string;
constructor(city:string) {
this.city = city;
}
@ -216,12 +219,15 @@ class Address {
}
class TestData {
a;
constructor(a) {
this.a = a;
}
}
class LoggingDispatcher extends WatchGroupDispatcher {
log:List;
loggedValues:List;
constructor() {
this.log = null;
this.loggedValues = null;

View File

@ -7,6 +7,9 @@ import {Formatter, LiteralPrimitive} from 'change_detection/parser/ast';
import {ClosureMap} from 'change_detection/parser/closure_map';
class TestData {
a;
b;
fnReturnValue;
constructor(a, b, fnReturnValue) {
this.a = a;
this.b = b;