Index: test/decorator_test.ts |
diff --git a/test/decorator_test.ts b/test/decorator_test.ts |
index 72e00862f7d52ce4c27a9c136f606b551b294526..d411a19aa9c57ffb74e9653ff7dfb2c917041d49 100644 |
--- a/test/decorator_test.ts |
+++ b/test/decorator_test.ts |
@@ -1,82 +1,115 @@ |
/// <reference path="../typings/mocha/mocha.d.ts"/> |
-import {expectTranslate, expectErroneousCode} from './test_support'; |
+import {expectTranslate} from './test_support'; |
-describe('decorators', () => { |
+ |
+// We want to ignore decorators on JS interop for now. |
+// These tests make sure we haven't accidentally left in historic code from |
+// ts2dart that export decorators. |
+describe('ignore decorators', () => { |
it('translates plain decorators', () => { |
- expectTranslate('@A class X {}').to.equal(`@A |
-class X {}`); |
+ expectTranslate('@A class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
}); |
- it('translates plain decorators when applied to abstract classes', () => { |
- expectTranslate('@A abstract class X {}').to.equal(`@A |
-abstract class X {}`); |
+ it('ignore plain decorators applied to abstract classes', () => { |
+ expectTranslate('@A abstract class X {}').to.equal(`@JS() |
+abstract class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
}); |
it('translates arguments', () => { |
- expectTranslate('@A(a, b) class X {}').to.equal(`@A(a, b) |
-class X {}`); |
+ expectTranslate('@A(a, b) class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
}); |
it('translates const arguments', () => { |
- expectTranslate('@A([1]) class X {}').to.equal(`@A(const [1]) |
-class X {}`); |
- expectTranslate('@A({"a": 1}) class X {}').to.equal(`@A(const {"a": 1}) |
-class X {}`); |
- expectTranslate('@A(new B()) class X {}').to.equal(`@A(const B()) |
-class X {}`); |
+ expectTranslate('@A([1]) class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
+ expectTranslate('@A({"a": 1}) class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
+ expectTranslate('@A(new B()) class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+}`); |
}); |
it('translates on functions', () => { |
- expectTranslate('@A function f() {}').to.equal(`@A |
-f() {}`); |
+ expectTranslate('@A function f() {}').to.equal(`@JS() |
+external f();`); |
}); |
it('translates on properties', () => { |
- expectTranslate('class X { @A p; }').to.equal(`class X { |
- @A |
- var p; |
+ expectTranslate('class X { @A p; }').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+ external get p; |
+ external set p(v); |
}`); |
}); |
- it('translates on parameters', |
- () => { expectTranslate('function f (@A p) {}').to.equal('f(@A p) {}'); }); |
- it('special cases @CONST', () => { |
- expectTranslate('@CONST class X {}').to.equal(`class X { |
- const X(); |
+ it('translates on parameters', () => { |
+ expectTranslate('function f (@A p) {}').to.equal(`@JS() |
+external f(p);`); |
+ }); |
+ it('ignore special cases @CONST', () => { |
+ expectTranslate('@CONST class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
}`); |
- expectTranslate('@CONST() class X {}').to.equal(`class X { |
- const X(); |
+ expectTranslate('@CONST() class X {}').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
}`); |
expectTranslate(`@CONST class X { |
x: number; |
y; |
constructor() { super(3); this.x = 1; this.y = 2; } |
}`) |
- .to.equal(`class X { |
- final num x; |
- final y; |
- const X() |
- : x = 1, |
- y = 2, |
- super(3); |
+ .to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+ external num get x; |
+ external set x(num v); |
+ external get y; |
+ external set y(v); |
+ external factory X(); |
}`); |
// @CONST constructors. |
- expectTranslate('@CONST class X { constructor() {} }').to.equal(`class X { |
- const X(); |
+ expectTranslate('@CONST class X { constructor() {} }').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+ external factory X(); |
}`); |
// For backwards-compatibility for traceur inputs (not valid TS input) |
- expectTranslate('class X { @CONST constructor() {} }').to.equal(`class X { |
- const X(); |
+ expectTranslate('class X { @CONST constructor() {} }').to.equal(`@JS() |
+class X { |
+ // @Ignore |
+ X.fakeConstructor$(); |
+ external factory X(); |
}`); |
- expectErroneousCode('@CONST class X { constructor() { if (1); } }') |
- .to.throw('const constructors can only contain assignments and super calls'); |
- expectErroneousCode('@CONST class X { constructor() { f(); } }') |
- .to.throw('const constructors can only contain assignments and super calls'); |
- expectErroneousCode('@CONST class X { constructor() { "string literal"; } }') |
- .to.throw('const constructors can only contain assignments and super calls'); |
- expectErroneousCode('class X { @CONST constructor() { x = 1; } }') |
- .to.throw('assignments in const constructors must assign into this.'); |
- expectErroneousCode('class X { @CONST constructor() { thax = 1; } }') |
- .to.throw('assignments in const constructors must assign into this.'); |
// @CONST properties. |
- expectTranslate('class Foo { @CONST() static foo = 1; }').to.equal(`class Foo { |
- static const foo = 1; |
+ expectTranslate('class Foo { @CONST() static foo = 1; }').to.equal(`@JS() |
+class Foo { |
+ // @Ignore |
+ Foo.fakeConstructor$(); |
+ external static get foo; |
+ external static set foo(v); |
}`); |
}); |
}); |