OLD | NEW |
1 /// <reference path="../typings/mocha/mocha.d.ts"/> | 1 /// <reference path="../typings/mocha/mocha.d.ts"/> |
2 import {expectTranslate, expectErroneousCode} from './test_support'; | 2 import {expectTranslate} from './test_support'; |
3 | 3 |
4 describe('calls', () => { | 4 describe('calls', () => { |
5 it('translates destructuring parameters', () => { | 5 it('translates destructuring parameters', () => { |
6 expectTranslate('function x({p = null, d = false} = {}) {}') | 6 expectTranslate('function x({p = null, d = false} = {}) {}').to.equal(`@JS() |
7 .to.equal('x({p: null, d: false}) {}'); | 7 external x(Object p_d /*{p = null, d = false}*/);`); |
8 expectErroneousCode('function x({a=false}={a:true})') | 8 expectTranslate('function x({a=false}={a:true})').to.equal(`@JS() |
9 .to.throw('cannot have both an inner and outer initializer'); | 9 external x(Object a /*{a=false}*/);`); |
10 expectErroneousCode('function x({a=false}=true)') | 10 expectTranslate('function x({a=false}=true)').to.equal(`@JS() |
11 .to.throw('initializers for named parameters must be object literals'); | 11 external x(Object a /*{a=false}*/);`); |
12 expectTranslate('class X { constructor() { super({p: 1}); } }').to.equal(`cl
ass X { | 12 expectTranslate('class X { constructor() { super({p: 1}); } }').to.equal(`@J
S() |
13 X() : super(p: 1) { | 13 class X { |
14 /* super call moved to initializer */; | 14 // @Ignore |
15 } | 15 X.fakeConstructor$(); |
| 16 external factory X(); |
16 }`); | 17 }`); |
17 }); | 18 }); |
18 it('hacks last object literal parameters into named parameter', () => { | 19 it('suppress calls with literal parameters', () => { |
19 expectTranslate('f(x, {a: 12, b: 4});').to.equal('f(x, a: 12, b: 4);'); | 20 expectTranslate('f(x, {a: 12, b: 4});').to.equal(''); |
20 expectTranslate('f({a: 12});').to.equal('f(a: 12);'); | 21 expectTranslate('f({a: 12});').to.equal(''); |
21 expectTranslate('f({"a": 12});').to.equal('f({"a": 12});'); | 22 expectTranslate('f({"a": 12});').to.equal(''); |
22 expectTranslate('new X(x, {a: 12, b: 4});').to.equal('new X(x, a: 12, b: 4);
'); | 23 expectTranslate('new X(x, {a: 12, b: 4});').to.equal(''); |
23 expectTranslate('f(x, {});').to.equal('f(x, {});'); | 24 expectTranslate('f(x, {});').to.equal(''); |
24 }); | 25 }); |
25 it('translates calls', () => { | 26 it('suppress calls', () => { |
26 expectTranslate('foo();').to.equal('foo();'); | 27 expectTranslate('foo();').to.equal(''); |
27 expectTranslate('foo(1, 2);').to.equal('foo(1, 2);'); | 28 expectTranslate('foo(1, 2);').to.equal(''); |
28 }); | 29 }); |
29 it('translates new calls', () => { | 30 it('suppress new calls', () => { |
30 expectTranslate('new Foo();').to.equal('new Foo();'); | 31 expectTranslate('new Foo();').to.equal(''); |
31 expectTranslate('new Foo(1, 2);').to.equal('new Foo(1, 2);'); | 32 expectTranslate('new Foo(1, 2);').to.equal(''); |
32 expectTranslate('new Foo<number, string>(1, 2);').to.equal('new Foo<num, Str
ing>(1, 2);'); | 33 expectTranslate('new Foo<number, string>(1, 2);').to.equal(''); |
33 }); | 34 }); |
34 it('supports generic type parameters', | 35 it('suppress "super()" constructor calls', () => { |
35 () => { expectTranslate('var s = foo<string>();').to.equal('var s = foo/*<
String >*/();'); }); | 36 expectTranslate('class X { constructor() { super(1); } }').to.equal(`@JS() |
36 it('translates "super()" constructor calls', () => { | 37 class X { |
37 expectTranslate('class X { constructor() { super(1); } }').to.equal(`class X
{ | 38 // @Ignore |
38 X() : super(1) { | 39 X.fakeConstructor$(); |
39 /* super call moved to initializer */; | 40 external factory X(); |
40 } | |
41 }`); | 41 }`); |
42 expectErroneousCode('class X { constructor() { if (y) super(1, 2); } }') | 42 expectTranslate('class X { constructor() { if (y) super(1, 2); } }').to.equa
l(`@JS() |
43 .to.throw('super calls must be immediate children of their constructors'
); | 43 class X { |
44 expectTranslate('class X { constructor() { a(); super(1); b(); } }').to.equa
l(`class X { | 44 // @Ignore |
45 X() : super(1) { | 45 X.fakeConstructor$(); |
46 a(); | 46 external factory X(); |
47 /* super call moved to initializer */ | 47 }`); |
48 ; | 48 expectTranslate('class X { constructor() { a(); super(1); b(); } }').to.equa
l(`@JS() |
49 b(); | 49 class X { |
50 } | 50 // @Ignore |
| 51 X.fakeConstructor$(); |
| 52 external factory X(); |
51 }`); | 53 }`); |
52 }); | 54 }); |
53 it('translates "super.x()" super method calls', () => { | 55 it('ignore "super.x()" super method calls', () => { |
54 expectTranslate('class X { y() { super.z(1); } }').to.equal(`class X { | 56 expectTranslate('class X { y() { super.z(1); } }').to.equal(`@JS() |
55 y() { | 57 class X { |
56 super.z(1); | 58 // @Ignore |
57 } | 59 X.fakeConstructor$(); |
| 60 external y(); |
58 }`); | 61 }`); |
59 }); | 62 }); |
60 it('transpiles new calls without arguments', | 63 it('suppress new calls without arguments', () => { expectTranslate('new Foo;')
.to.equal(''); }); |
61 () => { expectTranslate('new Foo;').to.equal('new Foo();'); }); | |
62 }); | 64 }); |
OLD | NEW |