diff --git a/tools/transpiler/spec/classes_spec.js b/tools/transpiler/spec/classes_spec.js index 8690aa7bc5..5032b4fd24 100644 --- a/tools/transpiler/spec/classes_spec.js +++ b/tools/transpiler/spec/classes_spec.js @@ -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'; // 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() { describe('classes', function() { it('should work', function() { @@ -60,6 +70,17 @@ export function main() { 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'); + }); + }); }); } diff --git a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js index 1f0a4508c8..2f3e083d7f 100644 --- a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js +++ b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js @@ -18,6 +18,10 @@ import { STATIC } from 'traceur/src/syntax/TokenType'; +import { + GET +} from 'traceur/src/syntax/PredefinedName'; + import {ParseTreeWriter as JavaScriptParseTreeWriter, ObjectLiteralExpression} from 'traceur/src/outputgeneration/ParseTreeWriter'; import {ImportedBinding, BindingIdentifier} from 'traceur/src/syntax/trees/ParseTrees'; import {IdentifierToken} from 'traceur/src/syntax/IdentifierToken'; @@ -369,6 +373,21 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter { 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) { this.writeList_(tree.parameterNameAndValues, COMMA, false); }