@@ -3597,6 +3597,9 @@ export class LuaTransformer {
35973597 properties . push ( tstl . createTableFieldExpression ( expression , name , element ) ) ;
35983598 } else if ( ts . isShorthandPropertyAssignment ( element ) ) {
35993599 const valueSymbol = this . checker . getShorthandAssignmentValueSymbol ( element ) ;
3600+ if ( valueSymbol ) {
3601+ this . trackSymbolReference ( valueSymbol , element . name ) ;
3602+ }
36003603 const identifier = this . createShorthandIdentifier ( valueSymbol , element . name ) ;
36013604 properties . push ( tstl . createTableFieldExpression ( identifier , name , element ) ) ;
36023605 } else if ( ts . isMethodDeclaration ( element ) ) {
@@ -5525,47 +5528,50 @@ export class LuaTransformer {
55255528 return "____" + tsHelper . fixInvalidLuaIdentifier ( name ) ;
55265529 }
55275530
5528- protected getIdentifierSymbolId ( identifier : ts . Identifier ) : tstl . SymbolId | undefined {
5529- const symbol = this . checker . getSymbolAtLocation ( identifier ) ;
5530- let symbolId : tstl . SymbolId | undefined ;
5531- if ( symbol ) {
5532- // Track first time symbols are seen
5533- if ( ! this . symbolIds . has ( symbol ) ) {
5534- symbolId = this . genSymbolIdCounter ++ ;
5531+ protected trackSymbolReference ( symbol : ts . Symbol , identifier : ts . Identifier ) : tstl . SymbolId | undefined {
5532+ // Track first time symbols are seen
5533+ let symbolId = this . symbolIds . get ( symbol ) ;
5534+ if ( ! symbolId ) {
5535+ symbolId = this . genSymbolIdCounter ++ ;
55355536
5536- const symbolInfo : SymbolInfo = { symbol, firstSeenAtPos : identifier . pos } ;
5537- this . symbolIds . set ( symbol , symbolId ) ;
5538- this . symbolInfo . set ( symbolId , symbolInfo ) ;
5539- } else {
5540- symbolId = this . symbolIds . get ( symbol ) ;
5541- }
5537+ const symbolInfo : SymbolInfo = { symbol, firstSeenAtPos : identifier . pos } ;
5538+ this . symbolIds . set ( symbol , symbolId ) ;
5539+ this . symbolInfo . set ( symbolId , symbolInfo ) ;
5540+ }
55425541
5543- if ( this . options . noHoisting ) {
5544- // Check for reference-before-declaration
5545- const declaration = tsHelper . getFirstDeclaration ( symbol , this . currentSourceFile ) ;
5546- if ( declaration && identifier . pos < declaration . pos ) {
5547- throw TSTLErrors . ReferencedBeforeDeclaration ( identifier ) ;
5548- }
5542+ if ( this . options . noHoisting ) {
5543+ // Check for reference-before-declaration
5544+ const declaration = tsHelper . getFirstDeclaration ( symbol , this . currentSourceFile ) ;
5545+ if ( declaration && identifier . pos < declaration . pos ) {
5546+ throw TSTLErrors . ReferencedBeforeDeclaration ( identifier ) ;
55495547 }
5548+ }
55505549
5551- if ( symbolId !== undefined ) {
5552- //Mark symbol as seen in all current scopes
5553- for ( const scope of this . scopeStack ) {
5554- if ( ! scope . referencedSymbols ) {
5555- scope . referencedSymbols = new Map ( ) ;
5556- }
5557- let references = scope . referencedSymbols . get ( symbolId ) ;
5558- if ( ! references ) {
5559- references = [ ] ;
5560- scope . referencedSymbols . set ( symbolId , references ) ;
5561- }
5562- references . push ( identifier ) ;
5563- }
5550+ //Mark symbol as seen in all current scopes
5551+ for ( const scope of this . scopeStack ) {
5552+ if ( ! scope . referencedSymbols ) {
5553+ scope . referencedSymbols = new Map ( ) ;
5554+ }
5555+ let references = scope . referencedSymbols . get ( symbolId ) ;
5556+ if ( ! references ) {
5557+ references = [ ] ;
5558+ scope . referencedSymbols . set ( symbolId , references ) ;
55645559 }
5560+ references . push ( identifier ) ;
55655561 }
5562+
55665563 return symbolId ;
55675564 }
55685565
5566+ protected getIdentifierSymbolId ( identifier : ts . Identifier ) : tstl . SymbolId | undefined {
5567+ const symbol = this . checker . getSymbolAtLocation ( identifier ) ;
5568+ if ( symbol ) {
5569+ return this . trackSymbolReference ( symbol , identifier ) ;
5570+ } else {
5571+ return undefined ;
5572+ }
5573+ }
5574+
55695575 protected findScope ( scopeTypes : ScopeType ) : Scope | undefined {
55705576 return this . scopeStack
55715577 . slice ( )
0 commit comments