File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1861,6 +1861,9 @@ export abstract class LuaTranspiler {
18611861 properties . push ( `${ name } = ${ expression } ` ) ;
18621862 } else if ( ts . isShorthandPropertyAssignment ( element ) ) {
18631863 properties . push ( `${ name } = ${ name } ` ) ;
1864+ } else if ( ts . isMethodDeclaration ( element ) ) {
1865+ const expression = this . transpileFunctionExpression ( element ) ;
1866+ properties . push ( `${ name } = ${ expression } ` ) ;
18641867 } else {
18651868 throw TSTLErrors . UnsupportedKind ( "object literal element" , element . kind , node ) ;
18661869 }
@@ -1869,9 +1872,12 @@ export abstract class LuaTranspiler {
18691872 return "{" + properties . join ( "," ) + "}" ;
18701873 }
18711874
1872- public transpileFunctionExpression ( node : ts . ArrowFunction ) : string {
1875+ public transpileFunctionExpression ( node : ts . FunctionLikeDeclaration ) : string {
18731876 // Build parameter string
18741877 const paramNames : string [ ] = [ ] ;
1878+ if ( ts . isMethodDeclaration ( node ) ) {
1879+ paramNames . push ( "self" ) ;
1880+ }
18751881 node . parameters . forEach ( param => {
18761882 paramNames . push ( this . transpileIdentifier ( param . name as ts . Identifier ) ) ;
18771883 } ) ;
Original file line number Diff line number Diff line change @@ -282,4 +282,11 @@ export class FunctionTests {
282282
283283 Expect ( result ) . toBe ( "function" ) ;
284284 }
285+
286+ @Test ( "Object method declaration" )
287+ public objectMethodDeclaration ( ) : void {
288+ const result = util . transpileAndExecute (
289+ `let o = { v: 4, m(i: number): number { return this.v * i; } }; return o.m(3);` ) ;
290+ Expect ( result ) . toBe ( 12 ) ;
291+ }
285292}
You can’t perform that action at this time.
0 commit comments