feat(transpiler): add support for getters

This commit is contained in:
vsavkin 2014-10-16 16:10:21 -04:00
parent 2f732c6b84
commit 035dc5ba44
2 changed files with 41 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import {describe, it, expect} from 'test_lib/test_lib'; import {ddescribe, describe, it, expect} from 'test_lib/test_lib';
import {CONST} from './fixtures/annotations'; import {CONST} from './fixtures/annotations';
// Constructor // Constructor
@ -36,6 +36,16 @@ class SubConst extends Const {
} }
} }
class HasGetters {
get getter():string {
return 'getter';
}
static get staticGetter():string {
return 'getter';
}
}
export function main() { export function main() {
describe('classes', function() { describe('classes', function() {
it('should work', function() { it('should work', function() {
@ -60,6 +70,17 @@ export function main() {
expect(subFoo.c).toBe(3); expect(subFoo.c).toBe(3);
}); });
}); });
describe("getters", function () {
it("should call instance getters", function () {
var obj = new HasGetters();
expect(obj.getter).toEqual('getter');
});
it("should call static getters", function () {
expect(HasGetters.staticGetter).toEqual('getter');
});
});
}); });
} }

View File

@ -18,6 +18,10 @@ import {
STATIC STATIC
} from 'traceur/src/syntax/TokenType'; } from 'traceur/src/syntax/TokenType';
import {
GET
} from 'traceur/src/syntax/PredefinedName';
import {ParseTreeWriter as JavaScriptParseTreeWriter, ObjectLiteralExpression} from 'traceur/src/outputgeneration/ParseTreeWriter'; import {ParseTreeWriter as JavaScriptParseTreeWriter, ObjectLiteralExpression} from 'traceur/src/outputgeneration/ParseTreeWriter';
import {ImportedBinding, BindingIdentifier} from 'traceur/src/syntax/trees/ParseTrees'; import {ImportedBinding, BindingIdentifier} from 'traceur/src/syntax/trees/ParseTrees';
import {IdentifierToken} from 'traceur/src/syntax/IdentifierToken'; import {IdentifierToken} from 'traceur/src/syntax/IdentifierToken';
@ -369,6 +373,21 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
this.writeSpace_() this.writeSpace_()
} }
visitGetAccessor(tree) {
this.writeAnnotations_(tree.annotations);
if (tree.isStatic) {
this.write_(STATIC);
this.writeSpace_();
}
this.writeType_(tree.typeAnnotation);
this.writeSpace_();
this.write_(GET);
this.writeSpace_();
this.visitAny(tree.name);
this.writeSpace_();
this.visitAny(tree.body);
}
visitNamedParameterList(tree) { visitNamedParameterList(tree) {
this.writeList_(tree.parameterNameAndValues, COMMA, false); this.writeList_(tree.parameterNameAndValues, COMMA, false);
} }