feat(transpiler): constructor and typed field semantics
fixes #11 (constructor and typed field semantics) fixes #42 (Should we infer class property types from ctor args ?) fixes #17 (number (js) should map to num (dart)) Closes #45
This commit is contained in:

committed by
Misko Hevery

parent
fd0c2d8063
commit
089a2f1b62
@ -1,4 +1,5 @@
|
||||
import {describe, it, expect} from 'test_lib/test_lib';
|
||||
import {CONST} from './fixtures/annotations';
|
||||
|
||||
// Constructor
|
||||
// Define fields
|
||||
@ -13,6 +14,28 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
class SubFoo extends Foo {
|
||||
constructor(a, b) {
|
||||
this.c = 3;
|
||||
super(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
class Const {
|
||||
@CONST
|
||||
constructor(a:number) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
class SubConst extends Const {
|
||||
@CONST
|
||||
constructor(a:number, b:number) {
|
||||
super(a);
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('classes', function() {
|
||||
it('should work', function() {
|
||||
@ -22,5 +45,21 @@ export function main() {
|
||||
expect(foo.b).toBe(3);
|
||||
expect(foo.sum()).toBe(5);
|
||||
});
|
||||
|
||||
it('@CONST should be transpiled to a const constructor', function() {
|
||||
var subConst = new SubConst(1, 2);
|
||||
expect(subConst.a).toBe(1);
|
||||
expect(subConst.b).toBe(2);
|
||||
});
|
||||
|
||||
describe('inheritance', function() {
|
||||
it('should support super call', function () {
|
||||
var subFoo = new SubFoo(1, 2);
|
||||
expect(subFoo.a).toBe(1);
|
||||
expect(subFoo.b).toBe(2);
|
||||
expect(subFoo.c).toBe(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,10 @@ class Provide {
|
||||
const Provide(this.token);
|
||||
}
|
||||
|
||||
class CONST {
|
||||
const CONST();
|
||||
}
|
||||
|
||||
// TODO: this api does not yet return an array as we don't have
|
||||
// a nice array wrapper for Dart
|
||||
readFirstAnnotation(clazz) {
|
||||
|
@ -10,6 +10,8 @@ export class Provide {
|
||||
}
|
||||
}
|
||||
|
||||
export class CONST {
|
||||
}
|
||||
|
||||
// TODO: this api does not yet return an array as we don't have
|
||||
// a nice array wrapper for Dart
|
||||
|
Reference in New Issue
Block a user