@@ -6,7 +6,7 @@ import * as util from "../src/util";
66export class FunctionTests {
77
88 @Test ( "Arrow Function Expression" )
9- public arrowFunctionExpression ( ) {
9+ public arrowFunctionExpression ( ) : void {
1010 // Transpile
1111 const lua = util . transpileString ( `let add = (a, b) => a+b; return add(1,2);` ) ;
1212
@@ -25,7 +25,7 @@ export class FunctionTests {
2525 @TestCase ( "b => a **= b" , 100000 )
2626 @TestCase ( "b => a %= b" , 0 )
2727 @Test ( "Arrow function assignment" )
28- public arrowFunctionAssignment ( lambda : string , expected : number ) {
28+ public arrowFunctionAssignment ( lambda : string , expected : number ) : void {
2929 // Transpile
3030 const lua = util . transpileString ( `let a = 10; let lambda = ${ lambda } ;
3131 lambda(5); return a;` ) ;
@@ -41,7 +41,7 @@ export class FunctionTests {
4141 @TestCase ( [ 5 ] )
4242 @TestCase ( [ 1 , 2 ] )
4343 @Test ( "Arrow Default Values" )
44- public arrowFunctionDefaultValues ( inp : number [ ] ) {
44+ public arrowFunctionDefaultValues ( inp : number [ ] ) : void {
4545 // Default value is 3 for v1
4646 const v1 = inp . length > 0 ? inp [ 0 ] : 3 ;
4747 // Default value is 4 for v2
@@ -61,7 +61,7 @@ export class FunctionTests {
6161 }
6262
6363 @Test ( "Function Expression" )
64- public functionExpression ( ) {
64+ public functionExpression ( ) : void {
6565 // Transpile
6666 const lua = util . transpileString ( `let add = function(a, b) {return a+b}; return add(1,2);` ) ;
6767
@@ -76,7 +76,7 @@ export class FunctionTests {
7676 @TestCase ( [ 5 ] , 9 )
7777 @TestCase ( [ 1 , 2 ] , 3 )
7878 @Test ( "Arrow Default Values" )
79- public functionExpressionDefaultValues ( inp : number [ ] ) {
79+ public functionExpressionDefaultValues ( inp : number [ ] ) : void {
8080 // Default value is 3 for v1
8181 const v1 = inp . length > 0 ? inp [ 0 ] : 3 ;
8282 // Default value is 4 for v2
@@ -96,7 +96,7 @@ export class FunctionTests {
9696 }
9797
9898 @Test ( "Class method call" )
99- public classMethod ( ) {
99+ public classMethod ( ) : void {
100100 const returnValue = 4 ;
101101 const source = `class TestClass {
102102 public classMethod(): number { return ${ returnValue } ; }
@@ -116,7 +116,7 @@ export class FunctionTests {
116116 }
117117
118118 @Test ( "Class dot method call void" )
119- public classDotMethod ( ) {
119+ public classDotMethod ( ) : void {
120120 const returnValue = 4 ;
121121 const source = `class TestClass {
122122 public dotMethod: () => number = () => ${ returnValue } ;
@@ -136,7 +136,7 @@ export class FunctionTests {
136136 }
137137
138138 @Test ( "Class dot method call with parameter" )
139- public classDotMethod2 ( ) {
139+ public classDotMethod2 ( ) : void {
140140 const returnValue = 4 ;
141141 const source = `class TestClass {
142142 public dotMethod: (x: number) => number = x => 3 * x;
@@ -156,7 +156,7 @@ export class FunctionTests {
156156 }
157157
158158 @Test ( "Class static dot method" )
159- public classDotMethodStatic ( ) {
159+ public classDotMethodStatic ( ) : void {
160160 const returnValue = 4 ;
161161 const source = `class TestClass {
162162 public static dotMethod: () => number = () => ${ returnValue } ;
@@ -175,7 +175,7 @@ export class FunctionTests {
175175 }
176176
177177 @Test ( "Class static dot method with parameter" )
178- public classDotMethodStaticWithParameter ( ) {
178+ public classDotMethodStaticWithParameter ( ) : void {
179179 const returnValue = 4 ;
180180 const source = `class TestClass {
181181 public static dotMethod: (x: number) => number = x => 3 * x;
@@ -194,7 +194,7 @@ export class FunctionTests {
194194 }
195195
196196 @Test ( "Invalid property access call transpilation" )
197- public invalidPropertyCall ( ) {
197+ public invalidPropertyCall ( ) : void {
198198 const transpiler = util . makeTestTranspiler ( ) ;
199199
200200 const mockObject : any = {
@@ -204,4 +204,20 @@ export class FunctionTests {
204204 Expect ( ( ) => transpiler . transpilePropertyCall ( mockObject as ts . CallExpression ) )
205205 . toThrowError ( Error , "Tried to transpile a non-property call as property call." ) ;
206206 }
207+
208+ @Test ( "Function dead code after return" )
209+ public functionDeadCodeAfterReturn ( ) : void {
210+ const result = util . transpileAndExecute (
211+ `function abc() { return 3; const a = 5; } return abc();` ) ;
212+
213+ Expect ( result ) . toBe ( 3 ) ;
214+ }
215+
216+ @Test ( "Method dead code after return" )
217+ public methodDeadCodeAfterReturn ( ) : void {
218+ const result = util . transpileAndExecute (
219+ `class def { public static abc() { return 3; const a = 5; } } return def.abc();` ) ;
220+
221+ Expect ( result ) . toBe ( 3 ) ;
222+ }
207223}
0 commit comments