99 unsupportedOptionalCompileMembersOnly ,
1010} from "../utils/diagnostics" ;
1111import { getExtensionKindForNode } from "../utils/language-extensions" ;
12- import { addToNumericExpression } from "../utils/lua-ast" ;
12+ import { addToNumericExpression , createExportsIdentifier } from "../utils/lua-ast" ;
1313import { LuaLibFeature , transformLuaLibFunction } from "../utils/lualib" ;
1414import { isArrayType , isNumberType , isStringType } from "../utils/typescript" ;
1515import { tryGetConstEnumValue } from "./enum" ;
@@ -24,6 +24,7 @@ import {
2424} from "./optional-chaining" ;
2525import { SyntaxKind } from "typescript" ;
2626import { getCustomNameFromSymbol } from "./identifier" ;
27+ import { getSymbolExportScope , isSymbolExported } from "../utils/export" ;
2728
2829function addOneToArrayAccessArgument (
2930 context : TransformationContext ,
@@ -138,6 +139,7 @@ export function transformPropertyAccessExpressionWithCapture(
138139 if ( isOptionalLeft ) {
139140 context . diagnostics . push ( unsupportedOptionalCompileMembersOnly ( node ) ) ;
140141 }
142+
141143 if ( ts . isPropertyAccessExpression ( node . expression ) ) {
142144 // in case of ...x.enum.y transform to ...x.y
143145 const expression = lua . createTableIndexExpression (
@@ -147,7 +149,21 @@ export function transformPropertyAccessExpressionWithCapture(
147149 ) ;
148150 return { expression } ;
149151 } else {
150- return { expression : lua . createIdentifier ( property , node ) } ;
152+ // Check if we need to account for enum being exported int his file
153+ if (
154+ isSymbolExported ( context , type . symbol ) &&
155+ getSymbolExportScope ( context , type . symbol ) === node . expression . getSourceFile ( )
156+ ) {
157+ return {
158+ expression : lua . createTableIndexExpression (
159+ createExportsIdentifier ( ) ,
160+ lua . createStringLiteral ( property ) ,
161+ node
162+ ) ,
163+ } ;
164+ } else {
165+ return { expression : lua . createIdentifier ( property , node ) } ;
166+ }
151167 }
152168 }
153169
0 commit comments