@@ -4477,8 +4477,7 @@ export class LuaTransformer {
44774477 }
44784478
44794479 if ( decorators . has ( DecoratorKind . LuaTable ) ) {
4480- const [ luaTable ] = this . parseLuaTableExpression ( expression ) ;
4481- return luaTable ;
4480+ return this . transformLuaTableProperty ( expression ) ;
44824481 }
44834482
44844483 // Catch math expressions
@@ -4621,21 +4620,14 @@ export class LuaTransformer {
46214620 }
46224621 }
46234622
4624- protected parseLuaTableExpression ( node : ts . PropertyAccessExpression ) : [ tstl . Expression , string ] {
4625- const methodName = node . name . text ;
4626- switch ( methodName ) {
4627- case "set" :
4628- case "get" : {
4629- return [ this . transformExpression ( node . expression ) , methodName ] ;
4630- }
4631- case "length" : {
4632- const luaTable = this . transformExpression ( node . expression ) ;
4623+ protected transformLuaTableProperty ( node : ts . PropertyAccessExpression ) : tstl . Expression {
4624+ const [ luaTable , propertyName ] = this . parseLuaTableExpression ( node ) ;
4625+ switch ( propertyName ) {
4626+ case "length" :
46334627 const unaryExpression = tstl . createUnaryExpression ( luaTable , tstl . SyntaxKind . LengthOperator , node ) ;
4634- return [ unaryExpression , methodName ] ;
4635- }
4636- default : {
4637- throw TSTLErrors . UnsupportedProperty ( "LuaTable" , methodName , node ) ;
4638- }
4628+ return unaryExpression ;
4629+ default :
4630+ throw TSTLErrors . UnsupportedProperty ( "LuaTable" , propertyName , node ) ;
46394631 }
46404632 }
46414633
@@ -4989,7 +4981,7 @@ export class LuaTransformer {
49894981 }
49904982
49914983 protected validateLuaTableCall ( expression : ts . CallExpression ) : void {
4992- const methodName = this . getLuaTablePropertyName ( expression . expression ) ;
4984+ const [ , methodName ] = this . parseLuaTableExpression ( expression . expression ) ;
49934985 if ( expression . arguments . some ( argument => ts . isSpreadElement ( argument ) ) ) {
49944986 throw TSTLErrors . ForbiddenLuaTableUseException ( "Arguments cannot be spread." , expression ) ;
49954987 }
@@ -5015,9 +5007,8 @@ export class LuaTransformer {
50155007 }
50165008
50175009 protected transformLuaTableExpressionAsExpressionStatement ( expression : ts . CallExpression ) : tstl . Statement {
5018- const methodName = this . getLuaTablePropertyName ( expression . expression ) ;
5010+ const [ luaTable , methodName ] = this . parseLuaTableExpression ( expression . expression ) ;
50195011 const signature = this . checker . getResolvedSignature ( expression ) ;
5020- const luaTable = this . transformExpression ( expression . expression ) ;
50215012 const params = this . transformArguments ( expression . arguments , signature ) ;
50225013
50235014 switch ( methodName ) {
@@ -5039,9 +5030,8 @@ export class LuaTransformer {
50395030 }
50405031
50415032 protected transformLuaTableCallExpression ( expression : ts . CallExpression ) : tstl . Expression {
5042- const methodName = this . getLuaTablePropertyName ( expression . expression ) ;
5033+ const [ luaTable , methodName ] = this . parseLuaTableExpression ( expression . expression ) ;
50435034 const signature = this . checker . getResolvedSignature ( expression ) ;
5044- const luaTable = this . transformExpression ( expression . expression ) ;
50455035 const params = this . transformArguments ( expression . arguments , signature ) ;
50465036
50475037 switch ( methodName ) {
@@ -5447,9 +5437,9 @@ export class LuaTransformer {
54475437 return scope ;
54485438 }
54495439
5450- protected getLuaTablePropertyName ( node : ts . LeftHandSideExpression ) : string {
5440+ protected parseLuaTableExpression ( node : ts . LeftHandSideExpression ) : [ tstl . Expression , string ] {
54515441 if ( ts . isPropertyAccessExpression ( node ) ) {
5452- return node . name . text ;
5442+ return [ this . transformExpression ( node . expression ) , node . name . text ] ;
54535443 } else {
54545444 throw TSTLErrors . UnsupportedKind ( "LuaTable access expression" , node . kind , node ) ;
54555445 }
0 commit comments