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

@ -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;