@@ -4,50 +4,59 @@ import {expectTranslate, expectErroneousCode} from './test_support';
4
4
describe ( 'calls' , ( ) => {
5
5
it ( 'translates destructuring parameters' , ( ) => {
6
6
expectTranslate ( 'function x({p = null, d = false} = {}) {}' )
7
- . to . equal ( ' x ( { p : null , d : false } ) { }' ) ;
7
+ . to . equal ( 'x({p : null, d: false} ) {}' ) ;
8
8
expectErroneousCode ( 'function x({a=false}={a:true})' )
9
9
. to . throw ( 'initializers for named parameters must be empty object literals' ) ;
10
10
expectErroneousCode ( 'function x({a=false}=true)' )
11
11
. to . throw ( 'initializers for named parameters must be empty object literals' ) ;
12
- expectTranslate ( 'class X { constructor() { super({p: 1}); } }' )
13
- . to . equal (
14
- ' class X { X ( ) : super ( p : 1 ) {' +
15
- ' /* super call moved to initializer */ ; } }' ) ;
12
+ expectTranslate ( 'class X { constructor() { super({p: 1}); } }' ) . to . equal ( `class X {
13
+ X() : super(p: 1) {
14
+ /* super call moved to initializer */;
15
+ }
16
+ }` ) ;
16
17
} ) ;
17
18
it ( 'hacks last object literal parameters into named parameter' , ( ) => {
18
- expectTranslate ( 'f(x, {a: 12, b: 4});' ) . to . equal ( ' f ( x , a : 12 , b : 4 ) ;' ) ;
19
- expectTranslate ( 'f({a: 12});' ) . to . equal ( ' f ( a : 12 ) ;' ) ;
20
- expectTranslate ( 'f({"a": 12});' ) . to . equal ( ' f ( { "a" : 12 } ) ;' ) ;
21
- expectTranslate ( 'new X(x, {a: 12, b: 4});' ) . to . equal ( ' new X ( x , a : 12 , b : 4 ) ;' ) ;
22
- expectTranslate ( 'f(x, {});' ) . to . equal ( ' f ( x , { } ) ;' ) ;
19
+ expectTranslate ( 'f(x, {a: 12, b: 4});' ) . to . equal ( 'f(x , a: 12, b: 4) ;' ) ;
20
+ expectTranslate ( 'f({a: 12});' ) . to . equal ( 'f(a : 12) ;' ) ;
21
+ expectTranslate ( 'f({"a": 12});' ) . to . equal ( 'f({ "a": 12}) ;' ) ;
22
+ expectTranslate ( 'new X(x, {a: 12, b: 4});' ) . to . equal ( 'new X(x , a: 12, b: 4) ;' ) ;
23
+ expectTranslate ( 'f(x, {});' ) . to . equal ( 'f(x , {}) ;' ) ;
23
24
} ) ;
24
25
it ( 'translates calls' , ( ) => {
25
- expectTranslate ( 'foo();' ) . to . equal ( ' foo ( ) ;' ) ;
26
- expectTranslate ( 'foo(1, 2);' ) . to . equal ( ' foo ( 1 , 2 ) ;' ) ;
26
+ expectTranslate ( 'foo();' ) . to . equal ( 'foo() ;' ) ;
27
+ expectTranslate ( 'foo(1, 2);' ) . to . equal ( 'foo(1 , 2) ;' ) ;
27
28
} ) ;
28
29
it ( 'translates new calls' , ( ) => {
29
- expectTranslate ( 'new Foo();' ) . to . equal ( ' new Foo ( ) ;' ) ;
30
- expectTranslate ( 'new Foo(1, 2);' ) . to . equal ( ' new Foo ( 1 , 2 ) ;' ) ;
31
- expectTranslate ( 'new Foo<number, string>(1, 2);' )
32
- . to . equal ( ' new Foo < num , String > ( 1 , 2 ) ;' ) ;
30
+ expectTranslate ( 'new Foo();' ) . to . equal ( 'new Foo();' ) ;
31
+ expectTranslate ( 'new Foo(1, 2);' ) . to . equal ( 'new Foo(1, 2);' ) ;
32
+ expectTranslate ( 'new Foo<number, string>(1, 2);' ) . to . equal ( 'new Foo<num, String>(1, 2);' ) ;
33
33
} ) ;
34
34
it ( 'throws away generic type parameters' ,
35
- ( ) => { expectTranslate ( 'var s = foo<string>();' ) . to . equal ( ' var s = foo ( ) ;' ) ; } ) ;
35
+ ( ) => { expectTranslate ( 'var s = foo<string>();' ) . to . equal ( 'var s = foo() ;' ) ; } ) ;
36
36
it ( 'translates "super()" constructor calls' , ( ) => {
37
- expectTranslate ( 'class X { constructor() { super(1); } }' )
38
- . to . equal ( ' class X { X ( ) : super ( 1 ) { /* super call moved to initializer */ ; } }' ) ;
37
+ expectTranslate ( 'class X { constructor() { super(1); } }' ) . to . equal ( `class X {
38
+ X() : super(1) {
39
+ /* super call moved to initializer */;
40
+ }
41
+ }` ) ;
39
42
expectErroneousCode ( 'class X { constructor() { if (y) super(1, 2); } }' )
40
43
. to . throw ( 'super calls must be immediate children of their constructors' ) ;
41
- expectTranslate ( 'class X { constructor() { a(); super(1); b(); } }' )
42
- . to . equal (
43
- ' class X { X ( ) : super ( 1 ) {' +
44
- ' a ( ) ; /* super call moved to initializer */ ; b ( ) ;' +
45
- ' } }' ) ;
44
+ expectTranslate ( 'class X { constructor() { a(); super(1); b(); } }' ) . to . equal ( `class X {
45
+ X() : super(1) {
46
+ a();
47
+ /* super call moved to initializer */
48
+ ;
49
+ b();
50
+ }
51
+ }` ) ;
46
52
} ) ;
47
53
it ( 'translates "super.x()" super method calls' , ( ) => {
48
- expectTranslate ( 'class X { y() { super.z(1); } }' )
49
- . to . equal ( ' class X { y ( ) { super . z ( 1 ) ; } }' ) ;
54
+ expectTranslate ( 'class X { y() { super.z(1); } }' ) . to . equal ( `class X {
55
+ y() {
56
+ super.z(1);
57
+ }
58
+ }` ) ;
50
59
} ) ;
51
60
it ( 'transpiles new calls without arguments' ,
52
- ( ) => { expectTranslate ( 'new Foo;' ) . to . equal ( ' new Foo ( ) ;' ) ; } ) ;
61
+ ( ) => { expectTranslate ( 'new Foo;' ) . to . equal ( 'new Foo() ;' ) ; } ) ;
53
62
} ) ;
0 commit comments