ticbuild 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (826) hide show
  1. package/README.md +1057 -199
  2. package/dist/backend/ImportedResourceTypes.d.ts +22 -10
  3. package/dist/backend/ImportedResourceTypes.d.ts.map +1 -1
  4. package/dist/backend/ImportedResourceTypes.js +42 -13
  5. package/dist/backend/ImportedResourceTypes.js.map +1 -1
  6. package/dist/backend/assembly.d.ts +11 -0
  7. package/dist/backend/assembly.d.ts.map +1 -0
  8. package/dist/backend/assembly.js +150 -0
  9. package/dist/backend/assembly.js.map +1 -0
  10. package/dist/backend/assetBanking.test.d.ts +2 -0
  11. package/dist/backend/assetBanking.test.d.ts.map +1 -0
  12. package/dist/backend/assetBanking.test.js +242 -0
  13. package/dist/backend/assetBanking.test.js.map +1 -0
  14. package/dist/backend/codeBanking.test.js +7 -5
  15. package/dist/backend/codeBanking.test.js.map +1 -1
  16. package/dist/backend/codeSnippetProcessor.d.ts +78 -0
  17. package/dist/backend/codeSnippetProcessor.d.ts.map +1 -0
  18. package/dist/backend/codeSnippetProcessor.js +241 -0
  19. package/dist/backend/codeSnippetProcessor.js.map +1 -0
  20. package/dist/backend/codeSnippetProcessor.test.d.ts +2 -0
  21. package/dist/backend/codeSnippetProcessor.test.d.ts.map +1 -0
  22. package/dist/backend/codeSnippetProcessor.test.js +221 -0
  23. package/dist/backend/codeSnippetProcessor.test.js.map +1 -0
  24. package/dist/backend/importReference.d.ts +4 -0
  25. package/dist/backend/importReference.d.ts.map +1 -0
  26. package/dist/backend/importReference.js +43 -0
  27. package/dist/backend/importReference.js.map +1 -0
  28. package/dist/backend/importResources.d.ts +3 -1
  29. package/dist/backend/importResources.d.ts.map +1 -1
  30. package/dist/backend/importResources.js +124 -36
  31. package/dist/backend/importResources.js.map +1 -1
  32. package/dist/backend/importResources.test.d.ts +2 -0
  33. package/dist/backend/importResources.test.d.ts.map +1 -0
  34. package/dist/backend/importResources.test.js +87 -0
  35. package/dist/backend/importResources.test.js.map +1 -0
  36. package/dist/backend/importSources.d.ts +51 -0
  37. package/dist/backend/importSources.d.ts.map +1 -0
  38. package/dist/backend/importSources.js +261 -0
  39. package/dist/backend/importSources.js.map +1 -0
  40. package/dist/backend/importSources.test.d.ts +2 -0
  41. package/dist/backend/importSources.test.d.ts.map +1 -0
  42. package/dist/backend/importSources.test.js +271 -0
  43. package/dist/backend/importSources.test.js.map +1 -0
  44. package/dist/backend/importUtils.d.ts +5 -10
  45. package/dist/backend/importUtils.d.ts.map +1 -1
  46. package/dist/backend/importUtils.js +13 -48
  47. package/dist/backend/importUtils.js.map +1 -1
  48. package/dist/backend/importers/CodeDeclarationAnalysis.d.ts +37 -0
  49. package/dist/backend/importers/CodeDeclarationAnalysis.d.ts.map +1 -0
  50. package/dist/backend/importers/CodeDeclarationAnalysis.js +288 -0
  51. package/dist/backend/importers/CodeDeclarationAnalysis.js.map +1 -0
  52. package/dist/backend/importers/CodeResource.d.ts +90 -0
  53. package/dist/backend/importers/CodeResource.d.ts.map +1 -0
  54. package/dist/backend/importers/CodeResource.js +480 -0
  55. package/dist/backend/importers/CodeResource.js.map +1 -0
  56. package/dist/backend/importers/CodeResource.test.d.ts +2 -0
  57. package/dist/backend/importers/CodeResource.test.d.ts.map +1 -0
  58. package/dist/backend/importers/CodeResource.test.js +106 -0
  59. package/dist/backend/importers/CodeResource.test.js.map +1 -0
  60. package/dist/backend/importers/LuaAssetTypeScriptModules.d.ts +38 -0
  61. package/dist/backend/importers/LuaAssetTypeScriptModules.d.ts.map +1 -0
  62. package/dist/backend/importers/LuaAssetTypeScriptModules.js +437 -0
  63. package/dist/backend/importers/LuaAssetTypeScriptModules.js.map +1 -0
  64. package/dist/backend/importers/LuaCodeImporter.d.ts +9 -49
  65. package/dist/backend/importers/LuaCodeImporter.d.ts.map +1 -1
  66. package/dist/backend/importers/LuaCodeImporter.js +28 -255
  67. package/dist/backend/importers/LuaCodeImporter.js.map +1 -1
  68. package/dist/backend/importers/LuaCodeImporter.test.js +89 -46
  69. package/dist/backend/importers/LuaCodeImporter.test.js.map +1 -1
  70. package/dist/backend/importers/LuaTypeCatalog.d.ts +26 -0
  71. package/dist/backend/importers/LuaTypeCatalog.d.ts.map +1 -0
  72. package/dist/backend/importers/LuaTypeCatalog.js +185 -0
  73. package/dist/backend/importers/LuaTypeCatalog.js.map +1 -0
  74. package/dist/backend/importers/ManifestCodeTypeScriptModules.d.ts +10 -0
  75. package/dist/backend/importers/ManifestCodeTypeScriptModules.d.ts.map +1 -0
  76. package/dist/backend/importers/ManifestCodeTypeScriptModules.js +31 -0
  77. package/dist/backend/importers/ManifestCodeTypeScriptModules.js.map +1 -0
  78. package/dist/backend/importers/TypeScriptBuildConstants.d.ts +6 -0
  79. package/dist/backend/importers/TypeScriptBuildConstants.d.ts.map +1 -0
  80. package/dist/backend/importers/TypeScriptBuildConstants.js +79 -0
  81. package/dist/backend/importers/TypeScriptBuildConstants.js.map +1 -0
  82. package/dist/backend/importers/TypeScriptCodeImporter.d.ts +26 -0
  83. package/dist/backend/importers/TypeScriptCodeImporter.d.ts.map +1 -0
  84. package/dist/backend/importers/TypeScriptCodeImporter.js +57 -0
  85. package/dist/backend/importers/TypeScriptCodeImporter.js.map +1 -0
  86. package/dist/backend/importers/TypeScriptCodeImporter.test.d.ts +2 -0
  87. package/dist/backend/importers/TypeScriptCodeImporter.test.d.ts.map +1 -0
  88. package/dist/backend/importers/TypeScriptCodeImporter.test.js +1795 -0
  89. package/dist/backend/importers/TypeScriptCodeImporter.test.js.map +1 -0
  90. package/dist/backend/importers/TypeScriptConstantPlugin.d.ts +8 -0
  91. package/dist/backend/importers/TypeScriptConstantPlugin.d.ts.map +1 -0
  92. package/dist/backend/importers/TypeScriptConstantPlugin.js +412 -0
  93. package/dist/backend/importers/TypeScriptConstantPlugin.js.map +1 -0
  94. package/dist/backend/importers/TypeScriptDeclarationSources.d.ts +19 -0
  95. package/dist/backend/importers/TypeScriptDeclarationSources.d.ts.map +1 -0
  96. package/dist/backend/importers/TypeScriptDeclarationSources.js +119 -0
  97. package/dist/backend/importers/TypeScriptDeclarationSources.js.map +1 -0
  98. package/dist/backend/importers/TypeScriptDeclarationSyntax.d.ts +8 -0
  99. package/dist/backend/importers/TypeScriptDeclarationSyntax.d.ts.map +1 -0
  100. package/dist/backend/importers/TypeScriptDeclarationSyntax.js +29 -0
  101. package/dist/backend/importers/TypeScriptDeclarationSyntax.js.map +1 -0
  102. package/dist/backend/importers/TypeScriptLuaDeclarations.d.ts +23 -0
  103. package/dist/backend/importers/TypeScriptLuaDeclarations.d.ts.map +1 -0
  104. package/dist/backend/importers/TypeScriptLuaDeclarations.js +553 -0
  105. package/dist/backend/importers/TypeScriptLuaDeclarations.js.map +1 -0
  106. package/dist/backend/importers/TypeScriptLuaDeclarations.test.d.ts +2 -0
  107. package/dist/backend/importers/TypeScriptLuaDeclarations.test.d.ts.map +1 -0
  108. package/dist/backend/importers/TypeScriptLuaDeclarations.test.js +29 -0
  109. package/dist/backend/importers/TypeScriptLuaDeclarations.test.js.map +1 -0
  110. package/dist/backend/importers/TypeScriptManifestModules.d.ts +36 -0
  111. package/dist/backend/importers/TypeScriptManifestModules.d.ts.map +1 -0
  112. package/dist/backend/importers/TypeScriptManifestModules.js +347 -0
  113. package/dist/backend/importers/TypeScriptManifestModules.js.map +1 -0
  114. package/dist/backend/importers/TypeScriptNamedTypes.d.ts +22 -0
  115. package/dist/backend/importers/TypeScriptNamedTypes.d.ts.map +1 -0
  116. package/dist/backend/importers/TypeScriptNamedTypes.js +193 -0
  117. package/dist/backend/importers/TypeScriptNamedTypes.js.map +1 -0
  118. package/dist/backend/importers/TypeScriptProgram.d.ts +24 -0
  119. package/dist/backend/importers/TypeScriptProgram.d.ts.map +1 -0
  120. package/dist/backend/importers/TypeScriptProgram.js +141 -0
  121. package/dist/backend/importers/TypeScriptProgram.js.map +1 -0
  122. package/dist/backend/importers/TypeScriptStaticLinker.d.ts +17 -0
  123. package/dist/backend/importers/TypeScriptStaticLinker.d.ts.map +1 -0
  124. package/dist/backend/importers/TypeScriptStaticLinker.js +702 -0
  125. package/dist/backend/importers/TypeScriptStaticLinker.js.map +1 -0
  126. package/dist/backend/importers/TypeScriptTranspilationOptions.d.ts +3 -0
  127. package/dist/backend/importers/TypeScriptTranspilationOptions.d.ts.map +1 -0
  128. package/dist/backend/importers/TypeScriptTranspilationOptions.js +82 -0
  129. package/dist/backend/importers/TypeScriptTranspilationOptions.js.map +1 -0
  130. package/dist/backend/importers/TypeScriptTranspiler.d.ts +13 -0
  131. package/dist/backend/importers/TypeScriptTranspiler.d.ts.map +1 -0
  132. package/dist/backend/importers/TypeScriptTranspiler.js +241 -0
  133. package/dist/backend/importers/TypeScriptTranspiler.js.map +1 -0
  134. package/dist/backend/importers/binaryResourceImporter.d.ts +5 -14
  135. package/dist/backend/importers/binaryResourceImporter.d.ts.map +1 -1
  136. package/dist/backend/importers/binaryResourceImporter.js +6 -34
  137. package/dist/backend/importers/binaryResourceImporter.js.map +1 -1
  138. package/dist/backend/importers/textResourceImporter.d.ts +5 -15
  139. package/dist/backend/importers/textResourceImporter.d.ts.map +1 -1
  140. package/dist/backend/importers/textResourceImporter.js +6 -36
  141. package/dist/backend/importers/textResourceImporter.js.map +1 -1
  142. package/dist/backend/importers/tic80CartImporter.d.ts +12 -15
  143. package/dist/backend/importers/tic80CartImporter.d.ts.map +1 -1
  144. package/dist/backend/importers/tic80CartImporter.js +49 -84
  145. package/dist/backend/importers/tic80CartImporter.js.map +1 -1
  146. package/dist/backend/importers/tsconfigUtils.d.ts +10 -0
  147. package/dist/backend/importers/tsconfigUtils.d.ts.map +1 -0
  148. package/dist/backend/importers/tsconfigUtils.js +152 -0
  149. package/dist/backend/importers/tsconfigUtils.js.map +1 -0
  150. package/dist/backend/luaEncode.d.ts +4 -4
  151. package/dist/backend/luaEncode.d.ts.map +1 -1
  152. package/dist/backend/luaEncode.js +39 -39
  153. package/dist/backend/luaEncode.js.map +1 -1
  154. package/dist/backend/luaEncode.test.js +68 -0
  155. package/dist/backend/luaEncode.test.js.map +1 -1
  156. package/dist/backend/luaPreprocessor.d.ts +18 -1
  157. package/dist/backend/luaPreprocessor.d.ts.map +1 -1
  158. package/dist/backend/luaPreprocessor.js +581 -232
  159. package/dist/backend/luaPreprocessor.js.map +1 -1
  160. package/dist/backend/luaPreprocessor.test.js +293 -12
  161. package/dist/backend/luaPreprocessor.test.js.map +1 -1
  162. package/dist/backend/luaPreprocessorSyntax.d.ts +25 -0
  163. package/dist/backend/luaPreprocessorSyntax.d.ts.map +1 -0
  164. package/dist/backend/luaPreprocessorSyntax.js +74 -0
  165. package/dist/backend/luaPreprocessorSyntax.js.map +1 -0
  166. package/dist/backend/luaPreprocessorSyntax.test.d.ts +2 -0
  167. package/dist/backend/luaPreprocessorSyntax.test.d.ts.map +1 -0
  168. package/dist/backend/luaPreprocessorSyntax.test.js +30 -0
  169. package/dist/backend/luaPreprocessorSyntax.test.js.map +1 -0
  170. package/dist/backend/manifestLoader.test.js +174 -1
  171. package/dist/backend/manifestLoader.test.js.map +1 -1
  172. package/dist/backend/manifestTypes.d.ts +127 -65
  173. package/dist/backend/manifestTypes.d.ts.map +1 -1
  174. package/dist/backend/manifestTypes.js +3 -0
  175. package/dist/backend/manifestTypes.js.map +1 -1
  176. package/dist/backend/preprocessorDefines.d.ts +4 -0
  177. package/dist/backend/preprocessorDefines.d.ts.map +1 -0
  178. package/dist/backend/preprocessorDefines.js +15 -0
  179. package/dist/backend/preprocessorDefines.js.map +1 -0
  180. package/dist/backend/project.d.ts +8 -2
  181. package/dist/backend/project.d.ts.map +1 -1
  182. package/dist/backend/project.js +159 -115
  183. package/dist/backend/project.js.map +1 -1
  184. package/dist/backend/project.test.d.ts +2 -0
  185. package/dist/backend/project.test.d.ts.map +1 -0
  186. package/dist/backend/project.test.js +196 -0
  187. package/dist/backend/project.test.js.map +1 -0
  188. package/dist/backend/projectCore.d.ts +6 -4
  189. package/dist/backend/projectCore.d.ts.map +1 -1
  190. package/dist/backend/projectCore.js +36 -44
  191. package/dist/backend/projectCore.js.map +1 -1
  192. package/dist/backend/projectCore.test.d.ts +2 -0
  193. package/dist/backend/projectCore.test.d.ts.map +1 -0
  194. package/dist/backend/projectCore.test.js +12 -0
  195. package/dist/backend/projectCore.test.js.map +1 -0
  196. package/dist/backend/projectEnvironment.d.ts +8 -0
  197. package/dist/backend/projectEnvironment.d.ts.map +1 -0
  198. package/dist/backend/projectEnvironment.js +70 -0
  199. package/dist/backend/projectEnvironment.js.map +1 -0
  200. package/dist/backend/projectEnvironment.test.d.ts +2 -0
  201. package/dist/backend/projectEnvironment.test.d.ts.map +1 -0
  202. package/dist/backend/projectEnvironment.test.js +90 -0
  203. package/dist/backend/projectEnvironment.test.js.map +1 -0
  204. package/dist/backend/projectFiles.d.ts +32 -0
  205. package/dist/backend/projectFiles.d.ts.map +1 -0
  206. package/dist/backend/projectFiles.js +148 -0
  207. package/dist/backend/projectFiles.js.map +1 -0
  208. package/dist/backend/projectFiles.test.d.ts +2 -0
  209. package/dist/backend/projectFiles.test.d.ts.map +1 -0
  210. package/dist/backend/projectFiles.test.js +136 -0
  211. package/dist/backend/projectFiles.test.js.map +1 -0
  212. package/dist/backend/sourceMap.d.ts +40 -3
  213. package/dist/backend/sourceMap.d.ts.map +1 -1
  214. package/dist/backend/sourceMap.js +333 -64
  215. package/dist/backend/sourceMap.js.map +1 -1
  216. package/dist/backend/sourceMap.test.js +81 -0
  217. package/dist/backend/sourceMap.test.js.map +1 -1
  218. package/dist/backend/sourceMapLookup.d.ts +36 -0
  219. package/dist/backend/sourceMapLookup.d.ts.map +1 -0
  220. package/dist/backend/sourceMapLookup.js +170 -0
  221. package/dist/backend/sourceMapLookup.js.map +1 -0
  222. package/dist/backend/sourceMapLookup.test.d.ts +2 -0
  223. package/dist/backend/sourceMapLookup.test.d.ts.map +1 -0
  224. package/dist/backend/sourceMapLookup.test.js +132 -0
  225. package/dist/backend/sourceMapLookup.test.js.map +1 -0
  226. package/dist/backend/sourceMapV3.d.ts +8 -0
  227. package/dist/backend/sourceMapV3.d.ts.map +1 -0
  228. package/dist/backend/sourceMapV3.js +212 -0
  229. package/dist/backend/sourceMapV3.js.map +1 -0
  230. package/dist/backend/sourceMapV3.test.d.ts +2 -0
  231. package/dist/backend/sourceMapV3.test.d.ts.map +1 -0
  232. package/dist/backend/sourceMapV3.test.js +109 -0
  233. package/dist/backend/sourceMapV3.test.js.map +1 -0
  234. package/dist/backend/symbolIndex.d.ts +2 -12
  235. package/dist/backend/symbolIndex.d.ts.map +1 -1
  236. package/dist/backend/symbolIndex.js +18 -107
  237. package/dist/backend/symbolIndex.js.map +1 -1
  238. package/dist/backend/symbolIndex.test.js +6 -1
  239. package/dist/backend/symbolIndex.test.js.map +1 -1
  240. package/dist/backend/tic80Controller/customController.d.ts +7 -1
  241. package/dist/backend/tic80Controller/customController.d.ts.map +1 -1
  242. package/dist/backend/tic80Controller/customController.js +25 -11
  243. package/dist/backend/tic80Controller/customController.js.map +1 -1
  244. package/dist/backend/tic80Controller/customController.test.js +17 -4
  245. package/dist/backend/tic80Controller/customController.test.js.map +1 -1
  246. package/dist/backend/tic80Controller/remotingClient.d.ts.map +1 -1
  247. package/dist/backend/tic80Controller/remotingClient.js +2 -1
  248. package/dist/backend/tic80Controller/remotingClient.js.map +1 -1
  249. package/dist/backend/tic80Controller/remotingProtocol.d.ts +2 -0
  250. package/dist/backend/tic80Controller/remotingProtocol.d.ts.map +1 -1
  251. package/dist/backend/tic80Controller/remotingProtocol.js +19 -0
  252. package/dist/backend/tic80Controller/remotingProtocol.js.map +1 -1
  253. package/dist/backend/tic80Controller/remotingProtocol.test.js +16 -0
  254. package/dist/backend/tic80Controller/remotingProtocol.test.js.map +1 -1
  255. package/dist/backend/tic80Controller/scriptErrorProtocol.d.ts +41 -0
  256. package/dist/backend/tic80Controller/scriptErrorProtocol.d.ts.map +1 -0
  257. package/dist/backend/tic80Controller/scriptErrorProtocol.js +98 -0
  258. package/dist/backend/tic80Controller/scriptErrorProtocol.js.map +1 -0
  259. package/dist/backend/tic80Controller/scriptErrorProtocol.test.d.ts +2 -0
  260. package/dist/backend/tic80Controller/scriptErrorProtocol.test.d.ts.map +1 -0
  261. package/dist/backend/tic80Controller/scriptErrorProtocol.test.js +78 -0
  262. package/dist/backend/tic80Controller/scriptErrorProtocol.test.js.map +1 -0
  263. package/dist/backend/tic80Controller/tic80Controller.d.ts +7 -0
  264. package/dist/backend/tic80Controller/tic80Controller.d.ts.map +1 -1
  265. package/dist/backend/tic80Controller/vanillaController.d.ts +3 -5
  266. package/dist/backend/tic80Controller/vanillaController.d.ts.map +1 -1
  267. package/dist/backend/tic80Controller/vanillaController.js +19 -18
  268. package/dist/backend/tic80Controller/vanillaController.js.map +1 -1
  269. package/dist/backend/tic80Controller/vanillaController.test.d.ts +2 -0
  270. package/dist/backend/tic80Controller/vanillaController.test.d.ts.map +1 -0
  271. package/dist/backend/tic80Controller/vanillaController.test.js +36 -0
  272. package/dist/backend/tic80Controller/vanillaController.test.js.map +1 -0
  273. package/dist/backend/tic80Resolver.d.ts +2 -0
  274. package/dist/backend/tic80Resolver.d.ts.map +1 -1
  275. package/dist/backend/tic80Resolver.js +15 -47
  276. package/dist/backend/tic80Resolver.js.map +1 -1
  277. package/dist/backend/tic80Resolver.test.d.ts +2 -0
  278. package/dist/backend/tic80Resolver.test.d.ts.map +1 -0
  279. package/dist/backend/tic80Resolver.test.js +34 -0
  280. package/dist/backend/tic80Resolver.test.js.map +1 -0
  281. package/dist/benchmarks/luaMinifiers.d.ts +50 -0
  282. package/dist/benchmarks/luaMinifiers.d.ts.map +1 -0
  283. package/dist/benchmarks/luaMinifiers.js +219 -0
  284. package/dist/benchmarks/luaMinifiers.js.map +1 -0
  285. package/dist/benchmarks/luaMinifiers.test.d.ts +2 -0
  286. package/dist/benchmarks/luaMinifiers.test.d.ts.map +1 -0
  287. package/dist/benchmarks/luaMinifiers.test.js +68 -0
  288. package/dist/benchmarks/luaMinifiers.test.js.map +1 -0
  289. package/dist/buildInfo.d.ts +8 -5
  290. package/dist/buildInfo.d.ts.map +1 -1
  291. package/dist/buildInfo.js +8 -5
  292. package/dist/buildInfo.js.map +1 -1
  293. package/dist/frontend/build.d.ts.map +1 -1
  294. package/dist/frontend/build.js +3 -5
  295. package/dist/frontend/build.js.map +1 -1
  296. package/dist/frontend/buildReporter.d.ts +10 -2
  297. package/dist/frontend/buildReporter.d.ts.map +1 -1
  298. package/dist/frontend/buildReporter.js +4 -1
  299. package/dist/frontend/buildReporter.js.map +1 -1
  300. package/dist/frontend/buildReporter.test.js +51 -2
  301. package/dist/frontend/buildReporter.test.js.map +1 -1
  302. package/dist/frontend/cartUsage.d.ts +20 -0
  303. package/dist/frontend/cartUsage.d.ts.map +1 -0
  304. package/dist/frontend/cartUsage.js +103 -0
  305. package/dist/frontend/cartUsage.js.map +1 -0
  306. package/dist/frontend/codeBankPlacement.test.d.ts +2 -0
  307. package/dist/frontend/codeBankPlacement.test.d.ts.map +1 -0
  308. package/dist/frontend/codeBankPlacement.test.js +89 -0
  309. package/dist/frontend/codeBankPlacement.test.js.map +1 -0
  310. package/dist/frontend/codeBankWarnings.test.js +1 -0
  311. package/dist/frontend/codeBankWarnings.test.js.map +1 -1
  312. package/dist/frontend/core.d.ts +7 -2
  313. package/dist/frontend/core.d.ts.map +1 -1
  314. package/dist/frontend/core.js +301 -300
  315. package/dist/frontend/core.js.map +1 -1
  316. package/dist/frontend/init.d.ts +1 -0
  317. package/dist/frontend/init.d.ts.map +1 -1
  318. package/dist/frontend/init.js +34 -11
  319. package/dist/frontend/init.js.map +1 -1
  320. package/dist/frontend/init.test.d.ts +2 -0
  321. package/dist/frontend/init.test.d.ts.map +1 -0
  322. package/dist/frontend/init.test.js +190 -0
  323. package/dist/frontend/init.test.js.map +1 -0
  324. package/dist/frontend/inspect.d.ts +2 -0
  325. package/dist/frontend/inspect.d.ts.map +1 -0
  326. package/dist/frontend/inspect.js +62 -0
  327. package/dist/frontend/inspect.js.map +1 -0
  328. package/dist/frontend/inspect.test.d.ts +2 -0
  329. package/dist/frontend/inspect.test.d.ts.map +1 -0
  330. package/dist/frontend/inspect.test.js +126 -0
  331. package/dist/frontend/inspect.test.js.map +1 -0
  332. package/dist/frontend/luaCodeArtifacts.test.js +39 -1
  333. package/dist/frontend/luaCodeArtifacts.test.js.map +1 -1
  334. package/dist/frontend/packageInstaller.d.ts +2 -0
  335. package/dist/frontend/packageInstaller.d.ts.map +1 -0
  336. package/dist/frontend/packageInstaller.js +59 -0
  337. package/dist/frontend/packageInstaller.js.map +1 -0
  338. package/dist/frontend/parseOptions.d.ts +4 -1
  339. package/dist/frontend/parseOptions.d.ts.map +1 -1
  340. package/dist/frontend/parseOptions.js +13 -8
  341. package/dist/frontend/parseOptions.js.map +1 -1
  342. package/dist/frontend/parseOptions.test.d.ts +2 -0
  343. package/dist/frontend/parseOptions.test.d.ts.map +1 -0
  344. package/dist/frontend/parseOptions.test.js +65 -0
  345. package/dist/frontend/parseOptions.test.js.map +1 -0
  346. package/dist/frontend/projectFiles.d.ts +4 -0
  347. package/dist/frontend/projectFiles.d.ts.map +1 -0
  348. package/dist/frontend/projectFiles.js +95 -0
  349. package/dist/frontend/projectFiles.js.map +1 -0
  350. package/dist/frontend/projectFiles.test.d.ts +2 -0
  351. package/dist/frontend/projectFiles.test.d.ts.map +1 -0
  352. package/dist/frontend/projectFiles.test.js +106 -0
  353. package/dist/frontend/projectFiles.test.js.map +1 -0
  354. package/dist/frontend/run.d.ts.map +1 -1
  355. package/dist/frontend/run.js +3 -1
  356. package/dist/frontend/run.js.map +1 -1
  357. package/dist/frontend/scriptErrorPresentation.d.ts +9 -0
  358. package/dist/frontend/scriptErrorPresentation.d.ts.map +1 -0
  359. package/dist/frontend/scriptErrorPresentation.js +76 -0
  360. package/dist/frontend/scriptErrorPresentation.js.map +1 -0
  361. package/dist/frontend/scriptErrorPresentation.test.d.ts +2 -0
  362. package/dist/frontend/scriptErrorPresentation.test.d.ts.map +1 -0
  363. package/dist/frontend/scriptErrorPresentation.test.js +137 -0
  364. package/dist/frontend/scriptErrorPresentation.test.js.map +1 -0
  365. package/dist/frontend/scriptErrorSourceMapper.d.ts +15 -0
  366. package/dist/frontend/scriptErrorSourceMapper.d.ts.map +1 -0
  367. package/dist/frontend/scriptErrorSourceMapper.js +177 -0
  368. package/dist/frontend/scriptErrorSourceMapper.js.map +1 -0
  369. package/dist/frontend/scriptErrorSourceMapper.test.d.ts +2 -0
  370. package/dist/frontend/scriptErrorSourceMapper.test.d.ts.map +1 -0
  371. package/dist/frontend/scriptErrorSourceMapper.test.js +189 -0
  372. package/dist/frontend/scriptErrorSourceMapper.test.js.map +1 -0
  373. package/dist/frontend/terminal.d.ts +28 -2
  374. package/dist/frontend/terminal.d.ts.map +1 -1
  375. package/dist/frontend/terminal.js +465 -25
  376. package/dist/frontend/terminal.js.map +1 -1
  377. package/dist/frontend/terminal.test.js +563 -0
  378. package/dist/frontend/terminal.test.js.map +1 -1
  379. package/dist/frontend/typescriptExample.test.d.ts +2 -0
  380. package/dist/frontend/typescriptExample.test.d.ts.map +1 -0
  381. package/dist/frontend/typescriptExample.test.js +92 -0
  382. package/dist/frontend/typescriptExample.test.js.map +1 -0
  383. package/dist/frontend/watch.d.ts.map +1 -1
  384. package/dist/frontend/watch.js +160 -39
  385. package/dist/frontend/watch.js.map +1 -1
  386. package/dist/frontend/watch.test.js +3 -1
  387. package/dist/frontend/watch.test.js.map +1 -1
  388. package/dist/index.js +61 -20
  389. package/dist/index.js.map +1 -1
  390. package/dist/obj/build.jsonl +5 -0
  391. package/dist/obj/build.log +11 -5
  392. package/dist/obj/build.trace.json +89 -0
  393. package/dist/obj/resolvedManifest.ticbuild.jsonc +4 -3
  394. package/dist/obj/variables.json +2 -2
  395. package/dist/projectFileInventory.d.ts +40 -0
  396. package/dist/projectFileInventory.d.ts.map +1 -0
  397. package/dist/projectFileInventory.js +36 -0
  398. package/dist/projectFileInventory.js.map +1 -0
  399. package/dist/utils/console.d.ts +1 -1
  400. package/dist/utils/console.d.ts.map +1 -1
  401. package/dist/utils/console.js +1 -1
  402. package/dist/utils/console.js.map +1 -1
  403. package/dist/utils/encoding/base64.d.ts +3 -0
  404. package/dist/utils/encoding/base64.d.ts.map +1 -0
  405. package/dist/utils/encoding/base64.js +51 -0
  406. package/dist/utils/encoding/base64.js.map +1 -0
  407. package/dist/utils/encoding/codecRegistry.d.ts +69 -12
  408. package/dist/utils/encoding/codecRegistry.d.ts.map +1 -1
  409. package/dist/utils/encoding/codecRegistry.js +6 -0
  410. package/dist/utils/encoding/codecRegistry.js.map +1 -1
  411. package/dist/utils/encoding/hex.d.ts.map +1 -1
  412. package/dist/utils/encoding/hex.js +3 -0
  413. package/dist/utils/encoding/hex.js.map +1 -1
  414. package/dist/utils/encoding/lz.d.ts +25 -5
  415. package/dist/utils/encoding/lz.d.ts.map +1 -1
  416. package/dist/utils/encoding/lz.js +160 -48
  417. package/dist/utils/encoding/lz.js.map +1 -1
  418. package/dist/utils/encoding/lz.test.d.ts +2 -0
  419. package/dist/utils/encoding/lz.test.d.ts.map +1 -0
  420. package/dist/utils/encoding/lz.test.js +95 -0
  421. package/dist/utils/encoding/lz.test.js.map +1 -0
  422. package/dist/utils/encoding/payloadOutput.d.ts +4 -0
  423. package/dist/utils/encoding/payloadOutput.d.ts.map +1 -0
  424. package/dist/utils/encoding/payloadOutput.js +12 -0
  425. package/dist/utils/encoding/payloadOutput.js.map +1 -0
  426. package/dist/utils/encoding/payloadOutput.test.d.ts +2 -0
  427. package/dist/utils/encoding/payloadOutput.test.d.ts.map +1 -0
  428. package/dist/utils/encoding/payloadOutput.test.js +21 -0
  429. package/dist/utils/encoding/payloadOutput.test.js.map +1 -0
  430. package/dist/utils/encoding/payloadTextEncoding.d.ts +6 -0
  431. package/dist/utils/encoding/payloadTextEncoding.d.ts.map +1 -0
  432. package/dist/utils/encoding/payloadTextEncoding.js +39 -0
  433. package/dist/utils/encoding/payloadTextEncoding.js.map +1 -0
  434. package/dist/utils/encoding/payloadTextEncoding.test.d.ts +2 -0
  435. package/dist/utils/encoding/payloadTextEncoding.test.d.ts.map +1 -0
  436. package/dist/utils/encoding/payloadTextEncoding.test.js +31 -0
  437. package/dist/utils/encoding/payloadTextEncoding.test.js.map +1 -0
  438. package/dist/utils/errorHandling.d.ts +1 -0
  439. package/dist/utils/errorHandling.d.ts.map +1 -1
  440. package/dist/utils/errorHandling.js +4 -0
  441. package/dist/utils/errorHandling.js.map +1 -1
  442. package/dist/utils/errorHandling.test.d.ts +2 -0
  443. package/dist/utils/errorHandling.test.d.ts.map +1 -0
  444. package/dist/utils/errorHandling.test.js +17 -0
  445. package/dist/utils/errorHandling.test.js.map +1 -0
  446. package/dist/utils/fileSystem.d.ts +3 -1
  447. package/dist/utils/fileSystem.d.ts.map +1 -1
  448. package/dist/utils/fileSystem.js +16 -16
  449. package/dist/utils/fileSystem.js.map +1 -1
  450. package/dist/utils/help.d.ts +2 -1
  451. package/dist/utils/help.d.ts.map +1 -1
  452. package/dist/utils/help.js +8 -3
  453. package/dist/utils/help.js.map +1 -1
  454. package/dist/utils/lua/LuaCATS.d.ts +31 -0
  455. package/dist/utils/lua/LuaCATS.d.ts.map +1 -0
  456. package/dist/utils/lua/LuaCATS.js +159 -0
  457. package/dist/utils/lua/LuaCATS.js.map +1 -0
  458. package/dist/utils/lua/LuaCATS_declarations.d.ts +22 -0
  459. package/dist/utils/lua/LuaCATS_declarations.d.ts.map +1 -0
  460. package/dist/utils/lua/LuaCATS_declarations.js +107 -0
  461. package/dist/utils/lua/LuaCATS_declarations.js.map +1 -0
  462. package/dist/utils/lua/LuaCATS_declarations.test.d.ts +2 -0
  463. package/dist/utils/lua/LuaCATS_declarations.test.d.ts.map +1 -0
  464. package/dist/utils/lua/LuaCATS_declarations.test.js +38 -0
  465. package/dist/utils/lua/LuaCATS_declarations.test.js.map +1 -0
  466. package/dist/utils/lua/LuaCATS_types.d.ts +52 -0
  467. package/dist/utils/lua/LuaCATS_types.d.ts.map +1 -0
  468. package/dist/utils/lua/LuaCATS_types.js +202 -0
  469. package/dist/utils/lua/LuaCATS_types.js.map +1 -0
  470. package/dist/utils/lua/LuaCATS_types.test.d.ts +2 -0
  471. package/dist/utils/lua/LuaCATS_types.test.d.ts.map +1 -0
  472. package/dist/utils/lua/LuaCATS_types.test.js +38 -0
  473. package/dist/utils/lua/LuaCATS_types.test.js.map +1 -0
  474. package/dist/utils/lua/lua_alias_expressions.d.ts +2 -0
  475. package/dist/utils/lua/lua_alias_expressions.d.ts.map +1 -1
  476. package/dist/utils/lua/lua_alias_expressions.js +12 -1
  477. package/dist/utils/lua/lua_alias_expressions.js.map +1 -1
  478. package/dist/utils/lua/lua_alias_literals.d.ts +2 -0
  479. package/dist/utils/lua/lua_alias_literals.d.ts.map +1 -1
  480. package/dist/utils/lua/lua_alias_literals.js +12 -1
  481. package/dist/utils/lua/lua_alias_literals.js.map +1 -1
  482. package/dist/utils/lua/lua_alias_shared.d.ts +0 -1
  483. package/dist/utils/lua/lua_alias_shared.d.ts.map +1 -1
  484. package/dist/utils/lua/lua_alias_shared.js +60 -56
  485. package/dist/utils/lua/lua_alias_shared.js.map +1 -1
  486. package/dist/utils/lua/lua_ast.d.ts +0 -1
  487. package/dist/utils/lua/lua_ast.d.ts.map +1 -1
  488. package/dist/utils/lua/lua_ast.js +0 -6
  489. package/dist/utils/lua/lua_ast.js.map +1 -1
  490. package/dist/utils/lua/lua_ast_printer.d.ts +55 -0
  491. package/dist/utils/lua/lua_ast_printer.d.ts.map +1 -0
  492. package/dist/utils/lua/lua_ast_printer.js +1043 -0
  493. package/dist/utils/lua/lua_ast_printer.js.map +1 -0
  494. package/dist/utils/lua/lua_ast_provenance.d.ts +13 -0
  495. package/dist/utils/lua/lua_ast_provenance.d.ts.map +1 -0
  496. package/dist/utils/lua/lua_ast_provenance.js +67 -0
  497. package/dist/utils/lua/lua_ast_provenance.js.map +1 -0
  498. package/dist/utils/lua/lua_ast_rewrite.d.ts +20 -0
  499. package/dist/utils/lua/lua_ast_rewrite.d.ts.map +1 -0
  500. package/dist/utils/lua/lua_ast_rewrite.js +198 -0
  501. package/dist/utils/lua/lua_ast_rewrite.js.map +1 -0
  502. package/dist/utils/lua/lua_binding_optimizations.test.d.ts +2 -0
  503. package/dist/utils/lua/lua_binding_optimizations.test.d.ts.map +1 -0
  504. package/dist/utils/lua/lua_binding_optimizations.test.js +247 -0
  505. package/dist/utils/lua/lua_binding_optimizations.test.js.map +1 -0
  506. package/dist/utils/lua/lua_canonicalization_rules.test.d.ts +2 -0
  507. package/dist/utils/lua/lua_canonicalization_rules.test.d.ts.map +1 -0
  508. package/dist/utils/lua/lua_canonicalization_rules.test.js +194 -0
  509. package/dist/utils/lua/lua_canonicalization_rules.test.js.map +1 -0
  510. package/dist/utils/lua/lua_constant_literals.d.ts +7 -0
  511. package/dist/utils/lua/lua_constant_literals.d.ts.map +1 -0
  512. package/dist/utils/lua/lua_constant_literals.js +39 -0
  513. package/dist/utils/lua/lua_constant_literals.js.map +1 -0
  514. package/dist/utils/lua/lua_control_flow_invert_negated_if.d.ts +3 -0
  515. package/dist/utils/lua/lua_control_flow_invert_negated_if.d.ts.map +1 -0
  516. package/dist/utils/lua/lua_control_flow_invert_negated_if.js +37 -0
  517. package/dist/utils/lua/lua_control_flow_invert_negated_if.js.map +1 -0
  518. package/dist/utils/lua/lua_control_flow_remove_false_while.d.ts +3 -0
  519. package/dist/utils/lua/lua_control_flow_remove_false_while.d.ts.map +1 -0
  520. package/dist/utils/lua/lua_control_flow_remove_false_while.js +26 -0
  521. package/dist/utils/lua/lua_control_flow_remove_false_while.js.map +1 -0
  522. package/dist/utils/lua/lua_control_flow_resolve_constant_if.d.ts +3 -0
  523. package/dist/utils/lua/lua_control_flow_resolve_constant_if.d.ts.map +1 -0
  524. package/dist/utils/lua/lua_control_flow_resolve_constant_if.js +83 -0
  525. package/dist/utils/lua/lua_control_flow_resolve_constant_if.js.map +1 -0
  526. package/dist/utils/lua/lua_debug.d.ts +16 -0
  527. package/dist/utils/lua/lua_debug.d.ts.map +1 -0
  528. package/dist/utils/lua/lua_debug.js +42 -0
  529. package/dist/utils/lua/lua_debug.js.map +1 -0
  530. package/dist/utils/lua/lua_debug.test.d.ts +2 -0
  531. package/dist/utils/lua/lua_debug.test.d.ts.map +1 -0
  532. package/dist/utils/lua/lua_debug.test.js +24 -0
  533. package/dist/utils/lua/lua_debug.test.js.map +1 -0
  534. package/dist/utils/lua/lua_doc.d.ts +15 -0
  535. package/dist/utils/lua/lua_doc.d.ts.map +1 -1
  536. package/dist/utils/lua/lua_doc.js +96 -0
  537. package/dist/utils/lua/lua_doc.js.map +1 -1
  538. package/dist/utils/lua/lua_doc_types.d.ts +36 -0
  539. package/dist/utils/lua/lua_doc_types.d.ts.map +1 -0
  540. package/dist/utils/lua/lua_doc_types.js +122 -0
  541. package/dist/utils/lua/lua_doc_types.js.map +1 -0
  542. package/dist/utils/lua/lua_doc_types.test.d.ts +2 -0
  543. package/dist/utils/lua/lua_doc_types.test.d.ts.map +1 -0
  544. package/dist/utils/lua/lua_doc_types.test.js +33 -0
  545. package/dist/utils/lua/lua_doc_types.test.js.map +1 -0
  546. package/dist/utils/lua/lua_expression_effects.d.ts +3 -0
  547. package/dist/utils/lua/lua_expression_effects.d.ts.map +1 -0
  548. package/dist/utils/lua/lua_expression_effects.js +33 -0
  549. package/dist/utils/lua/lua_expression_effects.js.map +1 -0
  550. package/dist/utils/lua/lua_fundamentals.d.ts +4 -0
  551. package/dist/utils/lua/lua_fundamentals.d.ts.map +1 -1
  552. package/dist/utils/lua/lua_fundamentals.js +35 -3
  553. package/dist/utils/lua/lua_fundamentals.js.map +1 -1
  554. package/dist/utils/lua/lua_inline_immutable_aliases.d.ts +3 -0
  555. package/dist/utils/lua/lua_inline_immutable_aliases.d.ts.map +1 -0
  556. package/dist/utils/lua/lua_inline_immutable_aliases.js +124 -0
  557. package/dist/utils/lua/lua_inline_immutable_aliases.js.map +1 -0
  558. package/dist/utils/lua/lua_inline_immutable_scalars.d.ts +3 -0
  559. package/dist/utils/lua/lua_inline_immutable_scalars.d.ts.map +1 -0
  560. package/dist/utils/lua/lua_inline_immutable_scalars.js +230 -0
  561. package/dist/utils/lua/lua_inline_immutable_scalars.js.map +1 -0
  562. package/dist/utils/lua/lua_inline_single_use_expressions.d.ts +3 -0
  563. package/dist/utils/lua/lua_inline_single_use_expressions.d.ts.map +1 -0
  564. package/dist/utils/lua/lua_inline_single_use_expressions.js +105 -0
  565. package/dist/utils/lua/lua_inline_single_use_expressions.js.map +1 -0
  566. package/dist/utils/lua/lua_lexical_bindings.d.ts +25 -0
  567. package/dist/utils/lua/lua_lexical_bindings.d.ts.map +1 -0
  568. package/dist/utils/lua/lua_lexical_bindings.js +233 -0
  569. package/dist/utils/lua/lua_lexical_bindings.js.map +1 -0
  570. package/dist/utils/lua/lua_local_budget.test.js +12 -1
  571. package/dist/utils/lua/lua_local_budget.test.js.map +1 -1
  572. package/dist/utils/lua/lua_optimizer.d.ts +10 -0
  573. package/dist/utils/lua/lua_optimizer.d.ts.map +1 -0
  574. package/dist/utils/lua/lua_optimizer.js +128 -0
  575. package/dist/utils/lua/lua_optimizer.js.map +1 -0
  576. package/dist/utils/lua/lua_optimizer.test.d.ts +2 -0
  577. package/dist/utils/lua/lua_optimizer.test.d.ts.map +1 -0
  578. package/dist/utils/lua/lua_optimizer.test.js +262 -0
  579. package/dist/utils/lua/lua_optimizer.test.js.map +1 -0
  580. package/dist/utils/lua/lua_optimizer_fingerprint.d.ts +3 -0
  581. package/dist/utils/lua/lua_optimizer_fingerprint.d.ts.map +1 -0
  582. package/dist/utils/lua/lua_optimizer_fingerprint.js +50 -0
  583. package/dist/utils/lua/lua_optimizer_fingerprint.js.map +1 -0
  584. package/dist/utils/lua/lua_optimizer_rules.d.ts +3 -0
  585. package/dist/utils/lua/lua_optimizer_rules.d.ts.map +1 -0
  586. package/dist/utils/lua/lua_optimizer_rules.js +57 -0
  587. package/dist/utils/lua/lua_optimizer_rules.js.map +1 -0
  588. package/dist/utils/lua/lua_optimizer_types.d.ts +55 -0
  589. package/dist/utils/lua/lua_optimizer_types.d.ts.map +1 -0
  590. package/dist/utils/lua/lua_optimizer_types.js +31 -0
  591. package/dist/utils/lua/lua_optimizer_types.js.map +1 -0
  592. package/dist/utils/lua/lua_pack_locals.d.ts +2 -0
  593. package/dist/utils/lua/lua_pack_locals.d.ts.map +1 -1
  594. package/dist/utils/lua/lua_pack_locals.js +58 -14
  595. package/dist/utils/lua/lua_pack_locals.js.map +1 -1
  596. package/dist/utils/lua/lua_print_trace.d.ts +4 -0
  597. package/dist/utils/lua/lua_print_trace.d.ts.map +1 -0
  598. package/dist/utils/lua/lua_print_trace.js +166 -0
  599. package/dist/utils/lua/lua_print_trace.js.map +1 -0
  600. package/dist/utils/lua/lua_printer.d.ts +11 -0
  601. package/dist/utils/lua/lua_printer.d.ts.map +1 -0
  602. package/dist/utils/lua/lua_printer.js +105 -0
  603. package/dist/utils/lua/lua_printer.js.map +1 -0
  604. package/dist/utils/lua/lua_printer_lexemes.d.ts +22 -0
  605. package/dist/utils/lua/lua_printer_lexemes.d.ts.map +1 -0
  606. package/dist/utils/lua/lua_printer_lexemes.js +111 -0
  607. package/dist/utils/lua/lua_printer_lexemes.js.map +1 -0
  608. package/dist/utils/lua/lua_printer_tight2.d.ts +2 -0
  609. package/dist/utils/lua/lua_printer_tight2.d.ts.map +1 -0
  610. package/dist/utils/lua/lua_printer_tight2.js +64 -0
  611. package/dist/utils/lua/lua_printer_tight2.js.map +1 -0
  612. package/dist/utils/lua/lua_printer_traceable.d.ts +2 -0
  613. package/dist/utils/lua/lua_printer_traceable.d.ts.map +1 -0
  614. package/dist/utils/lua/lua_printer_traceable.js +107 -0
  615. package/dist/utils/lua/lua_printer_traceable.js.map +1 -0
  616. package/dist/utils/lua/lua_printer_types.d.ts +7 -0
  617. package/dist/utils/lua/lua_printer_types.d.ts.map +1 -0
  618. package/dist/utils/lua/lua_printer_types.js +3 -0
  619. package/dist/utils/lua/lua_printer_types.js.map +1 -0
  620. package/dist/utils/lua/lua_processor.d.ts +15 -72
  621. package/dist/utils/lua/lua_processor.d.ts.map +1 -1
  622. package/dist/utils/lua/lua_processor.js +177 -1205
  623. package/dist/utils/lua/lua_processor.js.map +1 -1
  624. package/dist/utils/lua/lua_processor.test.js +450 -101
  625. package/dist/utils/lua/lua_processor.test.js.map +1 -1
  626. package/dist/utils/lua/lua_remove_dead_stores.d.ts +3 -0
  627. package/dist/utils/lua/lua_remove_dead_stores.d.ts.map +1 -0
  628. package/dist/utils/lua/lua_remove_dead_stores.js +108 -0
  629. package/dist/utils/lua/lua_remove_dead_stores.js.map +1 -0
  630. package/dist/utils/lua/lua_remove_self_assignments.d.ts +3 -0
  631. package/dist/utils/lua/lua_remove_self_assignments.d.ts.map +1 -0
  632. package/dist/utils/lua/lua_remove_self_assignments.js +40 -0
  633. package/dist/utils/lua/lua_remove_self_assignments.js.map +1 -0
  634. package/dist/utils/lua/lua_remove_unused_for_variables.d.ts +3 -0
  635. package/dist/utils/lua/lua_remove_unused_for_variables.d.ts.map +1 -0
  636. package/dist/utils/lua/lua_remove_unused_for_variables.js +40 -0
  637. package/dist/utils/lua/lua_remove_unused_for_variables.js.map +1 -0
  638. package/dist/utils/lua/lua_remove_unused_functions.d.ts +2 -0
  639. package/dist/utils/lua/lua_remove_unused_functions.d.ts.map +1 -1
  640. package/dist/utils/lua/lua_remove_unused_functions.js +29 -6
  641. package/dist/utils/lua/lua_remove_unused_functions.js.map +1 -1
  642. package/dist/utils/lua/lua_remove_unused_locals.d.ts +2 -0
  643. package/dist/utils/lua/lua_remove_unused_locals.d.ts.map +1 -1
  644. package/dist/utils/lua/lua_remove_unused_locals.js +72 -289
  645. package/dist/utils/lua/lua_remove_unused_locals.js.map +1 -1
  646. package/dist/utils/lua/lua_remove_unused_parameters.d.ts +3 -0
  647. package/dist/utils/lua/lua_remove_unused_parameters.d.ts.map +1 -0
  648. package/dist/utils/lua/lua_remove_unused_parameters.js +124 -0
  649. package/dist/utils/lua/lua_remove_unused_parameters.js.map +1 -0
  650. package/dist/utils/lua/lua_rename_allowed_globals.d.ts +3 -0
  651. package/dist/utils/lua/lua_rename_allowed_globals.d.ts.map +1 -1
  652. package/dist/utils/lua/lua_rename_allowed_globals.js +78 -41
  653. package/dist/utils/lua/lua_rename_allowed_globals.js.map +1 -1
  654. package/dist/utils/lua/lua_rename_allowed_table_keys.d.ts +2 -0
  655. package/dist/utils/lua/lua_rename_allowed_table_keys.d.ts.map +1 -1
  656. package/dist/utils/lua/lua_rename_allowed_table_keys.js +57 -20
  657. package/dist/utils/lua/lua_rename_allowed_table_keys.js.map +1 -1
  658. package/dist/utils/lua/lua_rename_table_fields.d.ts +2 -0
  659. package/dist/utils/lua/lua_rename_table_fields.d.ts.map +1 -1
  660. package/dist/utils/lua/lua_rename_table_fields.js +15 -2
  661. package/dist/utils/lua/lua_rename_table_fields.js.map +1 -1
  662. package/dist/utils/lua/lua_renamer.d.ts +2 -0
  663. package/dist/utils/lua/lua_renamer.d.ts.map +1 -1
  664. package/dist/utils/lua/lua_renamer.js +146 -157
  665. package/dist/utils/lua/lua_renamer.js.map +1 -1
  666. package/dist/utils/lua/lua_scalar_simplification.test.d.ts +2 -0
  667. package/dist/utils/lua/lua_scalar_simplification.test.d.ts.map +1 -0
  668. package/dist/utils/lua/lua_scalar_simplification.test.js +293 -0
  669. package/dist/utils/lua/lua_scalar_simplification.test.js.map +1 -0
  670. package/dist/utils/lua/lua_scope_name_reuse.test.d.ts +2 -0
  671. package/dist/utils/lua/lua_scope_name_reuse.test.d.ts.map +1 -0
  672. package/dist/utils/lua/lua_scope_name_reuse.test.js +159 -0
  673. package/dist/utils/lua/lua_scope_name_reuse.test.js.map +1 -0
  674. package/dist/utils/lua/lua_simplify.d.ts +2 -0
  675. package/dist/utils/lua/lua_simplify.d.ts.map +1 -1
  676. package/dist/utils/lua/lua_simplify.js +236 -500
  677. package/dist/utils/lua/lua_simplify.js.map +1 -1
  678. package/dist/utils/lua/lua_source_mapping.test.d.ts +2 -0
  679. package/dist/utils/lua/lua_source_mapping.test.d.ts.map +1 -0
  680. package/dist/utils/lua/lua_source_mapping.test.js +182 -0
  681. package/dist/utils/lua/lua_source_mapping.test.js.map +1 -0
  682. package/dist/utils/lua/lua_string_literal.test.d.ts +2 -0
  683. package/dist/utils/lua/lua_string_literal.test.d.ts.map +1 -0
  684. package/dist/utils/lua/lua_string_literal.test.js +70 -0
  685. package/dist/utils/lua/lua_string_literal.test.js.map +1 -0
  686. package/dist/utils/lua/lua_strip_comments.d.ts +3 -0
  687. package/dist/utils/lua/lua_strip_comments.d.ts.map +1 -0
  688. package/dist/utils/lua/lua_strip_comments.js +15 -0
  689. package/dist/utils/lua/lua_strip_comments.js.map +1 -0
  690. package/dist/utils/lua/lua_symbol_collision.test.d.ts +2 -0
  691. package/dist/utils/lua/lua_symbol_collision.test.d.ts.map +1 -0
  692. package/dist/utils/lua/lua_symbol_collision.test.js +55 -0
  693. package/dist/utils/lua/lua_symbol_collision.test.js.map +1 -0
  694. package/dist/utils/lua/lua_symbols.d.ts +19 -0
  695. package/dist/utils/lua/lua_symbols.d.ts.map +1 -0
  696. package/dist/utils/lua/lua_symbols.js +258 -0
  697. package/dist/utils/lua/lua_symbols.js.map +1 -0
  698. package/dist/utils/lua/lua_symbols.test.d.ts +2 -0
  699. package/dist/utils/lua/lua_symbols.test.d.ts.map +1 -0
  700. package/dist/utils/lua/lua_symbols.test.js +75 -0
  701. package/dist/utils/lua/lua_symbols.test.js.map +1 -0
  702. package/dist/utils/lua/lua_syntax_bare_table_key.d.ts +3 -0
  703. package/dist/utils/lua/lua_syntax_bare_table_key.d.ts.map +1 -0
  704. package/dist/utils/lua/lua_syntax_bare_table_key.js +55 -0
  705. package/dist/utils/lua/lua_syntax_bare_table_key.js.map +1 -0
  706. package/dist/utils/lua/lua_syntax_member_access.d.ts +3 -0
  707. package/dist/utils/lua/lua_syntax_member_access.d.ts.map +1 -0
  708. package/dist/utils/lua/lua_syntax_member_access.js +40 -0
  709. package/dist/utils/lua/lua_syntax_member_access.js.map +1 -0
  710. package/dist/utils/lua/lua_syntax_omit_local_nil.d.ts +3 -0
  711. package/dist/utils/lua/lua_syntax_omit_local_nil.d.ts.map +1 -0
  712. package/dist/utils/lua/lua_syntax_omit_local_nil.js +32 -0
  713. package/dist/utils/lua/lua_syntax_omit_local_nil.js.map +1 -0
  714. package/dist/utils/lua/lua_syntax_remove_redundant_do.d.ts +3 -0
  715. package/dist/utils/lua/lua_syntax_remove_redundant_do.d.ts.map +1 -0
  716. package/dist/utils/lua/lua_syntax_remove_redundant_do.js +50 -0
  717. package/dist/utils/lua/lua_syntax_remove_redundant_do.js.map +1 -0
  718. package/dist/utils/lua/lua_transform_map.d.ts +36 -0
  719. package/dist/utils/lua/lua_transform_map.d.ts.map +1 -0
  720. package/dist/utils/lua/lua_transform_map.js +205 -0
  721. package/dist/utils/lua/lua_transform_map.js.map +1 -0
  722. package/dist/utils/lua/lua_utils.d.ts +2 -4
  723. package/dist/utils/lua/lua_utils.d.ts.map +1 -1
  724. package/dist/utils/lua/lua_utils.js +100 -37
  725. package/dist/utils/lua/lua_utils.js.map +1 -1
  726. package/dist/utils/templates.d.ts +1 -0
  727. package/dist/utils/templates.d.ts.map +1 -1
  728. package/dist/utils/templates.js +4 -0
  729. package/dist/utils/templates.js.map +1 -1
  730. package/dist/utils/tic80/cartLoader.d.ts.map +1 -1
  731. package/dist/utils/tic80/cartLoader.js +7 -5
  732. package/dist/utils/tic80/cartLoader.js.map +1 -1
  733. package/dist/utils/tic80/cartLoader.test.d.ts +2 -0
  734. package/dist/utils/tic80/cartLoader.test.d.ts.map +1 -0
  735. package/dist/utils/tic80/cartLoader.test.js +100 -0
  736. package/dist/utils/tic80/cartLoader.test.js.map +1 -0
  737. package/dist/utils/tic80/cartWriter.d.ts +2 -2
  738. package/dist/utils/tic80/cartWriter.d.ts.map +1 -1
  739. package/dist/utils/tic80/cartWriter.js +22 -17
  740. package/dist/utils/tic80/cartWriter.js.map +1 -1
  741. package/dist/utils/tic80/launch.d.ts +1 -1
  742. package/dist/utils/tic80/launch.d.ts.map +1 -1
  743. package/dist/utils/tic80/launch.js +2 -1
  744. package/dist/utils/tic80/launch.js.map +1 -1
  745. package/dist/utils/tic80/tic80.d.ts +52 -50
  746. package/dist/utils/tic80/tic80.d.ts.map +1 -1
  747. package/dist/utils/tic80/tic80.js +11 -7
  748. package/dist/utils/tic80/tic80.js.map +1 -1
  749. package/dist/utils/traceProfiler.d.ts +86 -0
  750. package/dist/utils/traceProfiler.d.ts.map +1 -0
  751. package/dist/utils/traceProfiler.js +241 -0
  752. package/dist/utils/traceProfiler.js.map +1 -0
  753. package/dist/utils/traceProfiler.test.d.ts +2 -0
  754. package/dist/utils/traceProfiler.test.d.ts.map +1 -0
  755. package/dist/utils/traceProfiler.test.js +236 -0
  756. package/dist/utils/traceProfiler.test.js.map +1 -0
  757. package/dist/utils/utils.d.ts +5 -0
  758. package/dist/utils/utils.d.ts.map +1 -1
  759. package/dist/utils/utils.js +35 -0
  760. package/dist/utils/utils.js.map +1 -1
  761. package/dist/utils/windowPosition.d.ts.map +1 -1
  762. package/dist/utils/windowPosition.js +2 -1
  763. package/dist/utils/windowPosition.js.map +1 -1
  764. package/package.json +31 -4
  765. package/scripts/benchmark-lua-minifiers.js +221 -0
  766. package/scripts/benchmark-lz-configs.js +247 -0
  767. package/scripts/gen-build-info.js +6 -0
  768. package/templates/TIC-80-ticbuild/tic80.exe +0 -0
  769. package/templates/declarations/tic80.d.ts +233 -0
  770. package/templates/env.template +11 -0
  771. package/templates/gitignore.template +7 -3
  772. package/templates/help/build.txt +2 -0
  773. package/templates/help/init.txt +3 -1
  774. package/templates/help/inspect.txt +14 -0
  775. package/templates/help/main.txt +3 -1
  776. package/templates/help/project.txt +27 -0
  777. package/templates/help/run.txt +4 -3
  778. package/templates/help/terminal.txt +32 -18
  779. package/templates/help/watch.txt +19 -5
  780. package/templates/minimal/project.ticbuild.jsonc +2 -1
  781. package/templates/piggybossa/project.ticbuild.jsonc +2 -1
  782. package/templates/pointsphere/project.ticbuild.jsonc +9 -15
  783. package/templates/pointsphere/src/palette.lua +5 -3
  784. package/templates/typescript/.luarc.json +5 -0
  785. package/templates/typescript/.vscode/extensions.json +3 -0
  786. package/templates/typescript/eslint.config.mjs +28 -0
  787. package/templates/typescript/package.json +22 -0
  788. package/templates/typescript/project.ticbuild.jsonc +28 -0
  789. package/templates/typescript/src/main.ts +6 -0
  790. package/templates/typescript/tsconfig.json +10 -0
  791. package/templates/vscode_extensions.template.json +3 -0
  792. package/templates/vscode_settings.template.json +3 -0
  793. package/ticbuild.schema.json +274 -110
  794. package/dist/backend/ImportedResource.d.ts +0 -11
  795. package/dist/backend/ImportedResource.d.ts.map +0 -1
  796. package/dist/backend/ImportedResource.js +0 -53
  797. package/dist/backend/ImportedResource.js.map +0 -1
  798. package/dist/backend/importers/luaImporter.d.ts +0 -1
  799. package/dist/backend/importers/luaImporter.d.ts.map +0 -1
  800. package/dist/backend/importers/luaImporter.js +0 -3
  801. package/dist/backend/importers/luaImporter.js.map +0 -1
  802. package/dist/backend/loadAllImports.d.ts +0 -1
  803. package/dist/backend/loadAllImports.d.ts.map +0 -1
  804. package/dist/backend/loadAllImports.js +0 -3
  805. package/dist/backend/loadAllImports.js.map +0 -1
  806. package/dist/backend/tic80Controller/externalController.d.ts +0 -18
  807. package/dist/backend/tic80Controller/externalController.d.ts.map +0 -1
  808. package/dist/backend/tic80Controller/externalController.js +0 -68
  809. package/dist/backend/tic80Controller/externalController.js.map +0 -1
  810. package/dist/backend/tic80Controller/internalController.d.ts +0 -13
  811. package/dist/backend/tic80Controller/internalController.d.ts.map +0 -1
  812. package/dist/backend/tic80Controller/internalController.js +0 -44
  813. package/dist/backend/tic80Controller/internalController.js.map +0 -1
  814. package/dist/frontend/manifestSchemaSync.test.d.ts +0 -2
  815. package/dist/frontend/manifestSchemaSync.test.d.ts.map +0 -1
  816. package/dist/frontend/manifestSchemaSync.test.js +0 -127
  817. package/dist/frontend/manifestSchemaSync.test.js.map +0 -1
  818. package/dist/frontend/repl.d.ts +0 -7
  819. package/dist/frontend/repl.d.ts.map +0 -1
  820. package/dist/frontend/repl.js +0 -271
  821. package/dist/frontend/repl.js.map +0 -1
  822. package/dist/utils/lua/luaUtils.d.ts +0 -1
  823. package/dist/utils/lua/luaUtils.d.ts.map +0 -1
  824. package/dist/utils/lua/luaUtils.js +0 -3
  825. package/dist/utils/lua/luaUtils.js.map +0 -1
  826. package/templates/help/repl.txt +0 -46
@@ -0,0 +1,1795 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const fs = __importStar(require("node:fs"));
37
+ const os = __importStar(require("node:os"));
38
+ const path = __importStar(require("node:path"));
39
+ const node_url_1 = require("node:url");
40
+ const cons = __importStar(require("../../utils/console"));
41
+ const lua_processor_1 = require("../../utils/lua/lua_processor");
42
+ const importResources_1 = require("../importResources");
43
+ const projectCore_1 = require("../projectCore");
44
+ const projectFiles_1 = require("../projectFiles");
45
+ const sourceMap_1 = require("../sourceMap");
46
+ const LuaAssetTypeScriptModules_1 = require("./LuaAssetTypeScriptModules");
47
+ const LuaCodeImporter_1 = require("./LuaCodeImporter");
48
+ const TypeScriptBuildConstants_1 = require("./TypeScriptBuildConstants");
49
+ const TypeScriptCodeImporter_1 = require("./TypeScriptCodeImporter");
50
+ const TypeScriptLuaDeclarations_1 = require("./TypeScriptLuaDeclarations");
51
+ const TypeScriptManifestModules_1 = require("./TypeScriptManifestModules");
52
+ const buildReporter_1 = require("../../frontend/buildReporter");
53
+ function createProject(projectDir, imports, defines, variables = { "project.name": "typescript-test" }, processEnvironment) {
54
+ const declarationsPath = (0, projectFiles_1.getProjectTic80DeclarationsPath)(projectDir);
55
+ fs.mkdirSync(path.dirname(declarationsPath), { recursive: true });
56
+ fs.copyFileSync((0, projectFiles_1.getBundledTic80DeclarationsPath)(), declarationsPath);
57
+ const languageExtensionsSource = path.resolve(__dirname, "..", "..", "..", "node_modules", "@typescript-to-lua", "language-extensions");
58
+ const languageExtensionsTarget = path.join(projectDir, "node_modules", "@typescript-to-lua", "language-extensions");
59
+ fs.mkdirSync(path.dirname(languageExtensionsTarget), { recursive: true });
60
+ if (!fs.existsSync(languageExtensionsTarget)) {
61
+ fs.symlinkSync(languageExtensionsSource, languageExtensionsTarget, "junction");
62
+ }
63
+ const manifest = {
64
+ buildConfiguration: "release",
65
+ project: {
66
+ name: "typescript-test",
67
+ binDir: "./bin",
68
+ objDir: "./obj",
69
+ outputCartName: "test.tic",
70
+ },
71
+ preprocessor: defines ? { defines } : undefined,
72
+ variables,
73
+ imports,
74
+ assembly: { blocks: [{ asset: imports[0].name }] },
75
+ };
76
+ return new projectCore_1.TicbuildProjectCore({
77
+ manifest,
78
+ manifestPath: path.join(projectDir, "manifest.ticbuild.jsonc"),
79
+ projectDir,
80
+ processEnvironment,
81
+ });
82
+ }
83
+ function getTypeScriptResource(resources, name) {
84
+ const resource = resources.items.get(name);
85
+ expect(resource).toBeInstanceOf(TypeScriptCodeImporter_1.TypeScriptCodeResource);
86
+ return resource;
87
+ }
88
+ async function withDeclarationProject(files, imports, run) {
89
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-declaration-analysis-"));
90
+ try {
91
+ for (const [file, content] of Object.entries(files)) {
92
+ const filePath = path.join(projectDir, file);
93
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
94
+ fs.writeFileSync(filePath, content, "utf-8");
95
+ }
96
+ await run(createProject(projectDir, imports), projectDir);
97
+ }
98
+ finally {
99
+ fs.rmSync(projectDir, { recursive: true, force: true });
100
+ }
101
+ }
102
+ describe("declaration analysis", () => {
103
+ const imports = [
104
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
105
+ { name: "geometry", path: "geometry.lua", kind: "LuaCode" },
106
+ ];
107
+ it("resolves a Lua signature back to its TypeScript caller on the first build", async () => {
108
+ await withDeclarationProject({
109
+ "main.ts": [
110
+ 'import { Move } from "ticbuild-assets/geometry";',
111
+ "export interface Vec2 { x: number; y: number; }",
112
+ "export function roundtrip(value: Vec2) { return Move(value); }",
113
+ "export function TIC() { print(roundtrip({ x: 1, y: 2 }).x); }",
114
+ ].join("\n"),
115
+ "geometry.lua": "---@param value ticbuild.main.Vec2\n---@return ticbuild.main.Vec2\nfunction Move(value) return value end",
116
+ }, imports, async (project, dir) => {
117
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
118
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
119
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('Move(value: import("ticbuild-assets/main").Vec2): import("ticbuild-assets/main").Vec2');
120
+ expect(fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(dir), "utf-8")).toContain("roundtrip(value: Vec2): Vec2");
121
+ expect(getTypeScriptResource(resources, "main").getCodeArtifacts(project).preprocessedSource).toContain("function Move");
122
+ fs.writeFileSync(path.join(dir, "main.ts"), 'import { Move } from "ticbuild-assets/geometry"; export interface Vec2 { x: number; y: number; } export function TIC() { Move("wrong"); }');
123
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Argument of type 'string' is not assignable to parameter of type 'Vec2'");
124
+ });
125
+ });
126
+ it("resolves Lua classes, aliases, inheritance and annotated globals through includes", async () => {
127
+ await withDeclarationProject({
128
+ "main.ts": [
129
+ 'import { Move, Position } from "ticbuild-assets/geometry";',
130
+ 'import type { Vec2, Mode } from "ticbuild-assets/other";',
131
+ 'const mode: Mode = "fast";',
132
+ 'const value: Vec2 = { x: 1, y: 2, mode };',
133
+ 'export function TIC() { print(Move(value).x + Position.y); }',
134
+ ].join("\n"),
135
+ "geometry.lua": '--#include "types.lua"\n---@param value Vec2\n---@return Vec2\nfunction Move(value) return value end\n---@type Vec2\nPosition = {x=0,y=0}',
136
+ "other.lua": '--#include "types.lua"',
137
+ "types.lua": [
138
+ '---@alias Mode "fast" | "safe"',
139
+ '---@class Point', '---@field x number', 'local Point = {}',
140
+ '---@class Vec2: Point', '---@field y number', '---@field mode? Mode',
141
+ '---@field next? Vec2', 'local Vec2 = {}',
142
+ ].join("\n"),
143
+ }, [...imports, { name: "other", path: "other.lua", kind: "LuaCode" }], async (project, dir) => {
144
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
145
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
146
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('Position: import("ticbuild-assets/geometry").Vec2');
147
+ expect(resources.getDependencyList().map(dependency => dependency.path)).toContain(path.join(dir, "types.lua"));
148
+ fs.writeFileSync(path.join(dir, "main.ts"), 'import { Move } from "ticbuild-assets/geometry"; export function TIC() { Move({ x: 1, y: "wrong" }); }');
149
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Type 'string' is not assignable to type 'number'");
150
+ });
151
+ });
152
+ it("uses authored ambient types and discards stale generated declarations", async () => {
153
+ await withDeclarationProject({
154
+ "main.ts": 'import { Move } from "ticbuild-assets/geometry"; export function TIC() { Move({ x: 1 }); }',
155
+ "geometry.lua": '---@param value Vec2 | nil\nfunction Move(value) end',
156
+ "globals.d.ts": 'interface Vec2 { x: number; }',
157
+ "unused.ts": 'export const UNUSED = 1;',
158
+ "tsconfig.json": JSON.stringify({ include: ["*.ts", ".ticbuild/declarations/**/*.d.ts"] }),
159
+ ".ticbuild/declarations/typescript-assets.d.ts": 'import "ticbuild-assets/unused"; interface Vec2 { stale: string; }',
160
+ ".ticbuild/declarations/lua-assets.d.ts": 'declare module "ticbuild-assets/geometry" { export function Move(value: string): void; }',
161
+ }, [{ ...imports[0], typescript: { tsconfig: "tsconfig.json" } }, imports[1],
162
+ { name: "unused", path: "unused.ts", kind: "TypeScriptCode" }], async (project, dir) => {
163
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
164
+ expect((await (0, importResources_1.loadAllImports)(project, reporter)).items.has("unused")).toBe(false);
165
+ const first = fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8");
166
+ expect(first).toContain("(Vec2) | (undefined)");
167
+ await (0, importResources_1.loadAllImports)(project, reporter);
168
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toBe(first);
169
+ fs.writeFileSync(path.join(dir, "globals.d.ts"), "interface Vec2 { x: string; }");
170
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Type 'number' is not assignable to type 'string'");
171
+ });
172
+ });
173
+ it("allows type-only cycles without generating or including their runtime code", async () => {
174
+ await withDeclarationProject({
175
+ "main.ts": 'import type { Config } from "ticbuild-assets/types"; export interface State { config?: Config; } export function TIC() {}',
176
+ "types.ts": 'import type { State } from "ticbuild-assets/main"; export interface Config { state?: State; } export const TypeRuntimeMarker = "type-runtime-marker";',
177
+ }, [imports[0], { name: "types", path: "types.ts", kind: "TypeScriptCode" }], async (project, dir) => {
178
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
179
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
180
+ expect(getTypeScriptResource(resources, "types").hasGeneratedLuaSource()).toBe(false);
181
+ expect(fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(dir), "utf-8")).toContain("interface Config");
182
+ expect(fs.readFileSync((0, TypeScriptLuaDeclarations_1.getTypeScriptLuaDeclarationsPath)(dir), "utf-8")).not.toContain("TypeRuntimeMarker");
183
+ expect(resources.getDependencyList().map(dependency => dependency.path)).toContain(path.join(dir, "types.ts"));
184
+ });
185
+ });
186
+ it("checks declaration-only TypeScript resources without generating Lua", async () => {
187
+ await withDeclarationProject({
188
+ "main.ts": 'import type { Config } from "ticbuild-assets/types"; export function TIC() {}',
189
+ "types.ts": 'export interface Config { value: MissingType; }',
190
+ }, [imports[0], { name: "types", path: "types.ts", kind: "TypeScriptCode" }], async (project) => {
191
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
192
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Cannot find name 'MissingType'");
193
+ });
194
+ });
195
+ it("discovers TypeScript includes authored in relative TypeScript modules", async () => {
196
+ await withDeclarationProject({
197
+ "main.ts": 'import "./helper"; export function TIC() {}',
198
+ "helper.ts": '//--#include "import:models"\nexport const HELPER = 1;',
199
+ "models.ts": 'export const MODEL_VERSION = 1;',
200
+ }, [imports[0], { name: "models", path: "models.ts", kind: "TypeScriptCode" }], async (project, dir) => {
201
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
202
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
203
+ expect(fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(dir), "utf-8")).toContain('declare module "ticbuild-assets/models"');
204
+ expect(getTypeScriptResource(resources, "main").getCodeArtifacts(project).preprocessedSource).toContain("MODEL_VERSION = 1");
205
+ });
206
+ });
207
+ it("discovers TypeScript types through Lua includes before compilation", async () => {
208
+ await withDeclarationProject({
209
+ "main.ts": 'import { Move } from "ticbuild-assets/geometry"; export function TIC() { print(Move({ x: 1 }).x); }',
210
+ "geometry.lua": '--#include "import:models"\n---@param value ticbuild.models.Vec2\n---@return ticbuild.models.Vec2\nfunction Move(value) return value end',
211
+ "models.ts": 'export interface Vec2 { x: number; } export const MODEL_VERSION = 1;',
212
+ }, [...imports, { name: "models", path: "models.ts", kind: "TypeScriptCode" }], async (project, dir) => {
213
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
214
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
215
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('import("ticbuild-assets/models").Vec2');
216
+ expect(getTypeScriptResource(resources, "main").getCodeArtifacts(project).preprocessedSource).toContain("MODEL_VERSION = 1");
217
+ });
218
+ });
219
+ it("reports ambiguous names instead of choosing one TypeScript module", async () => {
220
+ await withDeclarationProject({
221
+ "main.ts": 'import type { Vec2 as A } from "ticbuild-assets/left"; import type { Vec2 as B } from "ticbuild-assets/right"; import { Move } from "ticbuild-assets/geometry"; export function TIC() {}',
222
+ "geometry.lua": '---@param value Vec2\nfunction Move(value) end',
223
+ "left.ts": 'export interface Vec2 { x: number; }',
224
+ "right.ts": 'export interface Vec2 { y: number; }',
225
+ }, [...imports, { name: "left", path: "left.ts", kind: "TypeScriptCode" },
226
+ { name: "right", path: "right.ts", kind: "TypeScriptCode" }], async (project) => {
227
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
228
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Ambiguous LuaCATS type 'Vec2'");
229
+ });
230
+ });
231
+ it("preserves private TypeScript type identities when Lua refers back to the owner", async () => {
232
+ await withDeclarationProject({
233
+ "main.ts": [
234
+ 'import { Move } from "ticbuild-assets/geometry";',
235
+ 'class Vec2 { private marker = 0; x = 1; getMarker() { return this.marker; } }',
236
+ 'export function roundtrip(value: Vec2): Vec2 { return Move(value); }',
237
+ 'export function TIC() { print(roundtrip(new Vec2()).x); }',
238
+ ].join("\n"),
239
+ "geometry.lua": '---@param value ticbuild.main.Vec2\n---@return ticbuild.main.Vec2\nfunction Move(value) return value end',
240
+ }, imports, async (project, dir) => {
241
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
242
+ await (0, importResources_1.loadAllImports)(project, reporter);
243
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('import("ticbuild-assets/main").__ticbuild_type_Vec2');
244
+ expect(fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(dir), "utf-8")).toContain("export type __ticbuild_type_Vec2 = Vec2");
245
+ });
246
+ });
247
+ it("resolves each TypeScript resource using its configured paths", async () => {
248
+ await withDeclarationProject({
249
+ "main.ts": 'import type { Value } from "model"; import { Move } from "ticbuild-assets/geometry"; export interface Vec2 { x: Value; } export function TIC() { Move({ x: 1 }); }',
250
+ "second.ts": 'import type { Value } from "model"; import { Describe } from "ticbuild-assets/labels"; export interface Label { text: Value; } export function describe() { Describe({ text: "one" }); }',
251
+ "number.ts": 'export type Value = number;',
252
+ "string.ts": 'export type Value = string;',
253
+ "geometry.lua": '---@param value ticbuild.main.Vec2\nfunction Move(value) end',
254
+ "labels.lua": '---@param value ticbuild.second.Label\nfunction Describe(value) end',
255
+ "first.json": JSON.stringify({ compilerOptions: { baseUrl: ".", paths: { model: ["number.ts"] }, types: [] } }),
256
+ "second.json": JSON.stringify({ compilerOptions: { baseUrl: ".", paths: { model: ["string.ts"] }, types: [] } }),
257
+ }, [{ ...imports[0], typescript: { tsconfig: "first.json" } }, imports[1],
258
+ { name: "second", path: "second.ts", kind: "TypeScriptCode", typescript: { tsconfig: "second.json" } },
259
+ { name: "labels", path: "labels.lua", kind: "LuaCode" }], async (project, dir) => {
260
+ project.manifest.assembly.blocks.push({ asset: "second" });
261
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
262
+ await (0, importResources_1.loadAllImports)(project, reporter);
263
+ const declarations = fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(dir), "utf-8");
264
+ expect(declarations).toContain('ticbuild-assets/main/__types/number');
265
+ expect(declarations).toContain('ticbuild-assets/second/__types/string');
266
+ });
267
+ });
268
+ it("rejects conflicting Lua type definitions", async () => {
269
+ await withDeclarationProject({
270
+ "main.ts": 'import "ticbuild-assets/geometry"; import "ticbuild-assets/other"; export function TIC() {}',
271
+ "geometry.lua": '---@class Vec2\n---@field x number\nlocal Vec2 = {}',
272
+ "other.lua": '---@class Vec2\n---@field x string\nlocal Vec2 = {}',
273
+ }, [...imports, { name: "other", path: "other.lua", kind: "LuaCode" }], async (project) => {
274
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
275
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Conflicting Lua type 'Vec2'");
276
+ });
277
+ });
278
+ it("resolves named types inside generic Lua declarations and callback signatures", async () => {
279
+ await withDeclarationProject({
280
+ "main.ts": 'import { Unbox, Visit, MapVector } from "ticbuild-assets/geometry"; export interface Vec2 { x: number; } export function TIC() { const value: number = Unbox({ value: 1 }); Visit({ x: value }, p => MapVector(p)); }',
281
+ "geometry.lua": [
282
+ '---@class Box<T>', '---@field value T', 'local Box = {}',
283
+ '---@generic T', '---@param box Box<T>', '---@return T', 'function Unbox(box) return box.value end',
284
+ '---@param value ticbuild.main.Vec2', '---@param callback fun(value: ticbuild.main.Vec2): number',
285
+ 'function Visit(value, callback) return callback(value) end',
286
+ '---@alias Mapper fun(value: ticbuild.main.Vec2): number',
287
+ '---@type Mapper', 'function MapVector(value) return value.x end',
288
+ ].join("\n"),
289
+ }, imports, async (project, dir) => {
290
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
291
+ await (0, importResources_1.loadAllImports)(project, reporter);
292
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('Unbox<T>(box: import("ticbuild-assets/geometry").Box<T>): T');
293
+ expect(fs.readFileSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(dir), "utf-8")).toContain('export const MapVector: import("ticbuild-assets/geometry").Mapper');
294
+ fs.writeFileSync(path.join(dir, "main.ts"), 'import { Unbox } from "ticbuild-assets/geometry"; export interface Vec2 { x: number; } export function TIC() { const value: number = Unbox({ value: "wrong" }); }');
295
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Type 'string' is not assignable to type 'number'");
296
+ });
297
+ });
298
+ it("warns on unresolved named types while leaving unannotated values permissive", async () => {
299
+ const warning = jest.spyOn(cons, "warning").mockImplementation(() => { });
300
+ try {
301
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
302
+ await withDeclarationProject({
303
+ "main.ts": 'import { Move, Untyped } from "ticbuild-assets/geometry"; export function TIC() { Move(1); Untyped(2); }',
304
+ "geometry.lua": '---@param value MissingType\nfunction Move(value) end\nfunction Untyped(value) end',
305
+ }, imports, async (project) => { await (0, importResources_1.loadAllImports)(project, reporter); });
306
+ expect(warning.mock.calls.filter(([message]) => String(message).includes("Unresolved LuaCATS type"))).toHaveLength(1);
307
+ expect(warning).toHaveBeenCalledWith(expect.stringContaining("MissingType"));
308
+ }
309
+ finally {
310
+ warning.mockRestore();
311
+ }
312
+ });
313
+ });
314
+ describe("TypeScriptCodeResource", () => {
315
+ it("inlines typed build constants and writes active define declarations", async () => {
316
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-constants-"));
317
+ fs.writeFileSync(path.join(projectDir, "features.ts"), [
318
+ 'export const DEBUG_ENABLED = ticbuild.IsDefined("DEBUG");',
319
+ 'export const FALSE_DEFINE_IS_PRESENT = ticbuild.IsDefined("DISABLED_FEATURE");',
320
+ 'export const MISSING = ticbuild.IsDefined("MISSING");',
321
+ "export const AGE = ticbuild.MakeConstant<8>();",
322
+ 'export const LABEL = ticbuild.MakeConstant<"hello">();',
323
+ "export const OFF = ticbuild.MakeConstant<false>();",
324
+ 'trace("compile-time-only module side effect");',
325
+ ].join("\n"), "utf-8");
326
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
327
+ 'import { AGE, DEBUG_ENABLED, FALSE_DEFINE_IS_PRESENT, LABEL, MISSING, OFF } from "./features";',
328
+ "type Selected = ticbuild.IfDefined<\"DEBUG\", \"debug\", \"release\">;",
329
+ "type ProjectConstant<T extends ticbuild.ConstantValue> = ticbuild.Constant<T>;",
330
+ 'const selected: Selected = "debug";',
331
+ "const USER_CONSTANT = time() as unknown as ProjectConstant<9>;",
332
+ "ticbuild.assert_const(AGE);",
333
+ "export function TIC(): void {",
334
+ " print(AGE);",
335
+ " trace(DEBUG_ENABLED);",
336
+ " trace(FALSE_DEFINE_IS_PRESENT);",
337
+ " trace(MISSING);",
338
+ " print(LABEL);",
339
+ " trace(OFF);",
340
+ " print(USER_CONSTANT);",
341
+ ' trace(ticbuild.IsDefined("DEBUG"));',
342
+ " print(ticbuild.MakeConstant<4>());",
343
+ " print(selected);",
344
+ "}",
345
+ ].join("\n"), "utf-8");
346
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }], { DEBUG: true, DISABLED_FEATURE: false, MODE: "fast", COUNT: 3, PROJECT_NAME: "$(project.name)" });
347
+ try {
348
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
349
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
350
+ const resource = getTypeScriptResource(resources, "main");
351
+ const source = resource.getCodeArtifacts(project).inputSource;
352
+ const declarations = fs.readFileSync((0, TypeScriptBuildConstants_1.getTypeScriptBuildConstantsPath)(projectDir), "utf-8");
353
+ const luaDeclarations = fs.readFileSync((0, TypeScriptLuaDeclarations_1.getTypeScriptLuaDeclarationsPath)(projectDir), "utf-8");
354
+ expect(source).toContain("print(8)");
355
+ expect(source).toContain("print(9)");
356
+ expect(source).toContain("print(4)");
357
+ expect(source).toContain("trace(true)");
358
+ expect(source).toContain("trace(false)");
359
+ expect(source).toContain('print("hello")');
360
+ expect(source).not.toContain("compile-time-only module side effect");
361
+ expect(source).not.toContain("require(");
362
+ expect(source).not.toContain("ticbuild");
363
+ expect(source).not.toContain("assert_const");
364
+ expect(source).not.toContain("time()");
365
+ expect(source).not.toContain("DEBUG_ENABLED");
366
+ expect(source).not.toContain("FALSE_DEFINE_IS_PRESENT");
367
+ expect(source).not.toContain("MISSING");
368
+ expect(source).not.toContain("LABEL");
369
+ expect(source).not.toContain("OFF");
370
+ expect(declarations).toContain('readonly "DEBUG": true;');
371
+ expect(declarations).toContain('readonly "DISABLED_FEATURE": false;');
372
+ expect(declarations).toContain('readonly "MODE": "fast";');
373
+ expect(declarations).toContain('readonly "COUNT": 3;');
374
+ expect(declarations).toContain('readonly "PROJECT_NAME": "typescript-test";');
375
+ expect(declarations).not.toContain('readonly "MISSING"');
376
+ expect(luaDeclarations).not.toContain("AGE = nil");
377
+ }
378
+ finally {
379
+ fs.rmSync(projectDir, { recursive: true, force: true });
380
+ }
381
+ });
382
+ it("exposes resolved project variables and expands exact string constants", async () => {
383
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-vars-"));
384
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
385
+ "type Equal<Left, Right> =",
386
+ " (<T>() => T extends Left ? 1 : 2) extends (<T>() => T extends Right ? 1 : 2) ? true : false;",
387
+ "type Assert<T extends true> = T;",
388
+ 'type ProjectNameIsExact = Assert<Equal<ticbuild.Vars["project.name"], "typescript-test">>;',
389
+ 'type ExpandedIsExact = Assert<Equal<ticbuild.Expand<"this project is $(project.description)">, "this project is typescript-test cartridge">>;',
390
+ 'type ExpandedEnvIsPattern = Assert<Equal<ticbuild.Expand<"mode: $(env:BUILD_MODE)">, `mode: ${string}`>>;',
391
+ 'const TEMPLATE = "this project is $(project.description)" as const;',
392
+ 'const PROJECT_NAME = ticbuild.Vars["project.name"];',
393
+ "const DESCRIPTION = ticbuild.Expand(TEMPLATE);",
394
+ "ticbuild.assert_const(PROJECT_NAME);",
395
+ "ticbuild.assert_const(DESCRIPTION);",
396
+ "export function TIC(): void {",
397
+ " print(PROJECT_NAME);",
398
+ " print(DESCRIPTION);",
399
+ ' print(ticbuild.Expand("direct $(project.name)"));',
400
+ ' print(ticbuild.Expand("mode: $(env:BUILD_MODE)"));',
401
+ ' trace(ticbuild.IsDefined("project.name"));',
402
+ "}",
403
+ ].join("\n"), "utf-8");
404
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }],
405
+ // A colliding key intentionally proves that Vars and Defines remain separate maps.
406
+ { "project.name": false }, {
407
+ "project.name": "typescript-test",
408
+ "project.description": "$(project.name) cartridge",
409
+ }, { BUILD_MODE: "local" });
410
+ try {
411
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
412
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
413
+ const resource = getTypeScriptResource(resources, "main");
414
+ const source = resource.getCodeArtifacts(project).inputSource;
415
+ const declarations = fs.readFileSync((0, TypeScriptBuildConstants_1.getTypeScriptBuildConstantsPath)(projectDir), "utf-8");
416
+ expect(source).toContain('print("typescript-test")');
417
+ expect(source).toContain('print("this project is typescript-test cartridge")');
418
+ expect(source).toContain('print("direct typescript-test")');
419
+ expect(source).toContain('print("mode: local")');
420
+ expect(source).toContain("trace(true)");
421
+ expect(source).not.toContain("PROJECT_NAME");
422
+ expect(source).not.toContain("DESCRIPTION");
423
+ expect(source).not.toContain("ticbuild");
424
+ expect(declarations).toContain("interface Defines");
425
+ expect(declarations).toContain('readonly "project.name": false;');
426
+ expect(declarations).toContain("interface Vars");
427
+ expect(declarations).toContain('readonly "project.name": "typescript-test";');
428
+ expect(declarations).toContain('readonly "project.description": "typescript-test cartridge";');
429
+ expect(declarations).not.toContain('readonly "BUILD_MODE"');
430
+ expect(() => (0, lua_processor_1.parseLua)(source)).not.toThrow();
431
+ }
432
+ finally {
433
+ fs.rmSync(projectDir, { recursive: true, force: true });
434
+ }
435
+ });
436
+ it("reports invalid TypeScript variable expansion intentionally", async () => {
437
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-expand-diagnostics-"));
438
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
439
+ "declare const runtimeText: string;",
440
+ "export function TIC(): void {",
441
+ " print(ticbuild.Expand(runtimeText));",
442
+ ' print(ticbuild.Expand("$(missing.variable)"));',
443
+ "}",
444
+ ].join("\n"), "utf-8");
445
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }]);
446
+ try {
447
+ let thrown;
448
+ try {
449
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
450
+ await (0, importResources_1.loadAllImports)(project, reporter);
451
+ }
452
+ catch (error) {
453
+ thrown = error;
454
+ }
455
+ const message = String(thrown);
456
+ expect(message).toMatch(/ticbuild\.Expand\(\) requires one exact string literal; received string/);
457
+ expect(message).toMatch(/ticbuild\.Expand\(\): Undefined variable: missing\.variable/);
458
+ }
459
+ finally {
460
+ fs.rmSync(projectDir, { recursive: true, force: true });
461
+ }
462
+ });
463
+ it("supports compile-time constants with isolatedModules tooling", async () => {
464
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-constant-isolated-modules-"));
465
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify({
466
+ compilerOptions: { isolatedModules: true, strict: true },
467
+ include: ["*.ts", ".ticbuild/declarations/**/*.d.ts"],
468
+ }), "utf-8");
469
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
470
+ 'const ENABLED = ticbuild.IsDefined("DEBUG");',
471
+ "export function TIC(): void { trace(ENABLED); }",
472
+ ].join("\n"), "utf-8");
473
+ const project = createProject(projectDir, [{
474
+ name: "main",
475
+ path: "main.ts",
476
+ kind: "TypeScriptCode",
477
+ typescript: { tsconfig: "tsconfig.json" },
478
+ }], { DEBUG: true });
479
+ try {
480
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
481
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
482
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
483
+ expect(source).toContain("trace(true)");
484
+ expect(source).not.toContain("ENABLED");
485
+ }
486
+ finally {
487
+ fs.rmSync(projectDir, { recursive: true, force: true });
488
+ }
489
+ });
490
+ it("selects arbitrary IfDefined expressions at compile time", async () => {
491
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-if-defined-"));
492
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
493
+ "declare function debugString(): string;",
494
+ "declare function releaseString(): string;",
495
+ "declare function discardedDebugString(): string;",
496
+ "declare function discardedReleaseString(): string;",
497
+ 'const DEFINE_NAME = "DEBUG" as const;',
498
+ "export function TIC(): void {",
499
+ ' print(ticbuild.IfDefined("DEBUG", debugString(), discardedReleaseString()));',
500
+ ' print(ticbuild.IfDefined("MISSING", discardedDebugString(), releaseString()));',
501
+ " print(ticbuild.IfDefined(DEFINE_NAME, 10, 20));",
502
+ ' trace(ticbuild.IfDefined("DEBUG", ticbuild.MakeConstant<true>(), ticbuild.MakeConstant<false>()));',
503
+ "}",
504
+ ].join("\n"), "utf-8");
505
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }],
506
+ // Presence, rather than the define's truthiness, selects the first branch.
507
+ { DEBUG: false });
508
+ try {
509
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
510
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
511
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
512
+ expect(source).toContain("print(debugString())");
513
+ expect(source).toContain("print(releaseString())");
514
+ expect(source).toContain("print(10)");
515
+ expect(source).toContain("trace(true)");
516
+ expect(source).not.toContain("discardedDebugString");
517
+ expect(source).not.toContain("discardedReleaseString");
518
+ expect(source).not.toContain("ticbuild");
519
+ expect(() => (0, lua_processor_1.parseLua)(source)).not.toThrow();
520
+ }
521
+ finally {
522
+ fs.rmSync(projectDir, { recursive: true, force: true });
523
+ }
524
+ });
525
+ it("removes constant bindings while preserving mixed runtime module imports", async () => {
526
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-constant-mixed-import-"));
527
+ fs.writeFileSync(path.join(projectDir, "features.ts"), [
528
+ "export const AGE = ticbuild.MakeConstant<8>();",
529
+ "export function runtimeValue(): number { return 3; }",
530
+ ].join("\n"), "utf-8");
531
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
532
+ 'import { AGE, runtimeValue } from "./features";',
533
+ "export function TIC(): void { print(AGE + runtimeValue()); }",
534
+ ].join("\n"), "utf-8");
535
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }]);
536
+ try {
537
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
538
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
539
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
540
+ expect(source).toContain("function runtimeValue()");
541
+ expect(source).toContain("8 + runtimeValue()");
542
+ expect(source).not.toContain("AGE");
543
+ expect(source).not.toContain("require(");
544
+ }
545
+ finally {
546
+ fs.rmSync(projectDir, { recursive: true, force: true });
547
+ }
548
+ });
549
+ it("inlines constants exported by manifest TypeScript modules without including their runtime", async () => {
550
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-constant-manifest-module-"));
551
+ fs.writeFileSync(path.join(projectDir, "features.ts"), [
552
+ 'export const ENABLE_LOGGING = ticbuild.IsDefined("DEBUG");',
553
+ 'trace("manifest constant module side effect");',
554
+ ].join("\n"), "utf-8");
555
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
556
+ 'import { ENABLE_LOGGING } from "ticbuild-assets/features";',
557
+ "export function TIC(): void { trace(ENABLE_LOGGING); }",
558
+ ].join("\n"), "utf-8");
559
+ const project = createProject(projectDir, [
560
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
561
+ { name: "features", path: "features.ts", kind: "TypeScriptCode" },
562
+ ], { DEBUG: true });
563
+ try {
564
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
565
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
566
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
567
+ const declarations = fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(projectDir), "utf-8");
568
+ expect(declarations).toContain("export const ENABLE_LOGGING: ticbuild.Constant<true>;");
569
+ expect(source).toContain("trace(true)");
570
+ expect(source).not.toContain("manifest constant module side effect");
571
+ expect(source).not.toContain("import:features");
572
+ expect(source).not.toContain("ENABLE_LOGGING");
573
+ }
574
+ finally {
575
+ fs.rmSync(projectDir, { recursive: true, force: true });
576
+ }
577
+ });
578
+ it("reports non-literal and mutable ticbuild constants intentionally", async () => {
579
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-constant-diagnostics-"));
580
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
581
+ "let BROAD = ticbuild.MakeConstant<number>();",
582
+ "const CHOICE = ticbuild.MakeConstant<1 | 2>();",
583
+ 'const DEFINE_NAME: string = "DEBUG";',
584
+ "const DYNAMIC_DEFINE = ticbuild.IsDefined(DEFINE_NAME);",
585
+ 'const DEFINE_CHOICE = "" as "DEBUG" | "RELEASE";',
586
+ "ticbuild.IfDefined(DEFINE_CHOICE, 1, 0);",
587
+ "const holder = { value: ticbuild.MakeConstant<8>() };",
588
+ "holder.value = ticbuild.MakeConstant<8>();",
589
+ "export function TIC(): void { print(BROAD); }",
590
+ ].join("\n"), "utf-8");
591
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }]);
592
+ try {
593
+ let thrown;
594
+ try {
595
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
596
+ await (0, importResources_1.loadAllImports)(project, reporter);
597
+ }
598
+ catch (error) {
599
+ thrown = error;
600
+ }
601
+ const message = String(thrown);
602
+ expect(message).toMatch(/ticbuild\.Constant<T> requires one exact string, number, or boolean literal; received number/);
603
+ expect(message).toMatch(/received 1 \| 2/);
604
+ expect(message).toMatch(/ticbuild\.Constant binding must be declared with const/);
605
+ expect(message).toMatch(/ticbuild\.Constant value cannot be used as an assignment target/);
606
+ expect(message).toMatch(/Argument of type 'string' is not assignable to parameter of type 'never'/);
607
+ expect(message).toMatch(/ticbuild\.IfDefined\(\) requires one exact string literal define name; received "DEBUG" \| "RELEASE"/);
608
+ }
609
+ finally {
610
+ fs.rmSync(projectDir, { recursive: true, force: true });
611
+ }
612
+ });
613
+ it("uses assert_const as an erased TypeScript type assertion", async () => {
614
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-assert-constant-"));
615
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
616
+ "const AGE = ticbuild.MakeConstant<8>();",
617
+ "ticbuild.assert_const(AGE + 1);",
618
+ "export function TIC(): void {}",
619
+ ].join("\n"), "utf-8");
620
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }]);
621
+ try {
622
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
623
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(/Argument of type 'number' is not assignable/);
624
+ }
625
+ finally {
626
+ fs.rmSync(projectDir, { recursive: true, force: true });
627
+ }
628
+ });
629
+ it("emits LuaCATS definitions for TypeScript globals with checker types, docs, and source links", async () => {
630
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-definitions-"));
631
+ const mainPath = path.join(projectDir, "main.ts");
632
+ const mathPath = path.join(projectDir, "math.ts");
633
+ fs.writeFileSync(mathPath, [
634
+ "/** A two-dimensional vector. */",
635
+ "export interface Vec2 {",
636
+ " /** Horizontal coordinate. */",
637
+ " x: number;",
638
+ " y: number;",
639
+ "}",
640
+ "export type Mode = \"fast\" | \"safe\";",
641
+ "export const DEFAULT_SCALE = 2 as const;",
642
+ "/**",
643
+ " * Scales a vector.",
644
+ " * @param value Input vector.",
645
+ " * @param factor Scale amount.",
646
+ " * @returns The scaled vector.",
647
+ " * @deprecated Use transform instead.",
648
+ " */",
649
+ "export function scale(value: Vec2, factor: number = DEFAULT_SCALE): Vec2 {",
650
+ " return { x: value.x * factor, y: value.y * factor };",
651
+ "}",
652
+ "export function setMode(mode: Mode): Mode { return mode; }",
653
+ "export function acceptUnknown(value: unknown): unknown { return value; }",
654
+ "export function visit(values: number[], callback: (value: number) => boolean): boolean {",
655
+ " return callback(values[0]);",
656
+ "}",
657
+ "export const CONFIG: { label: string; enabled?: boolean } = { label: \"test\" };",
658
+ "export function convert(value: string): number;",
659
+ "export function convert(value: number): string;",
660
+ "export function convert(value: string | number): string | number { return String(value); }",
661
+ "export function pair(value: number): LuaMultiReturn<[number, string]> {",
662
+ " return $multi(value, String(value));",
663
+ "}",
664
+ "function privateHelper(): void {}",
665
+ ].join("\n"), "utf-8");
666
+ fs.writeFileSync(mainPath, [
667
+ 'export { CONFIG, DEFAULT_SCALE, acceptUnknown, convert, pair, scale, setMode, visit } from "./math";',
668
+ "const TIC = () => {};",
669
+ ].join("\n"), "utf-8");
670
+ const project = createProject(projectDir, [
671
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
672
+ ]);
673
+ try {
674
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
675
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
676
+ const resource = getTypeScriptResource(resources, "main");
677
+ const declarationPath = (0, TypeScriptLuaDeclarations_1.getTypeScriptLuaDeclarationsPath)(projectDir);
678
+ const declarations = fs.readFileSync(declarationPath, "utf-8");
679
+ expect(declarations.startsWith("---@meta _\n-- Generated by ticbuild. Do not edit.\n")).toBe(true);
680
+ expect(declarations).toContain("---@class ticbuild.math.Vec2");
681
+ expect(declarations).toContain("---@field x number Horizontal coordinate.");
682
+ expect(declarations).toContain('---@alias ticbuild.math.Mode "fast"|"safe"');
683
+ expect(declarations).toContain("---@type 2\nDEFAULT_SCALE = nil");
684
+ expect(declarations).toContain("--- Scales a vector.");
685
+ expect(declarations).toContain("---@deprecated Use transform instead.");
686
+ expect(declarations).toContain("---@param value ticbuild.math.Vec2 Input vector.");
687
+ expect(declarations).toContain("---@param factor? number Scale amount.");
688
+ expect(declarations).toContain("---@return ticbuild.math.Vec2 # The scaled vector.");
689
+ expect(declarations).toContain("function scale(value, factor) end");
690
+ expect(declarations).toContain("---@param value any\n---@return any\nfunction acceptUnknown(value) end");
691
+ expect(declarations).toContain("---@param values number[]");
692
+ expect(declarations).toContain("---@param callback fun(value: number): boolean");
693
+ expect(declarations).toContain("function visit(values, callback) end");
694
+ expect(declarations).toContain("---@type { label: string, enabled?: boolean }\nCONFIG = nil");
695
+ expect(declarations).toContain("---@overload fun(value: number): string");
696
+ expect(declarations).toContain("function convert(value) end");
697
+ expect(declarations).toContain("---@return number\n---@return string\nfunction pair(value) end");
698
+ expect(declarations).toContain("function TIC() end");
699
+ expect(declarations).toContain(`---@source ${(0, node_url_1.pathToFileURL)(mathPath).href}:16:1`);
700
+ expect(declarations).not.toContain("privateHelper");
701
+ expect((0, lua_processor_1.parseLua)(declarations)).not.toBeNull();
702
+ expect(resource.getCodeArtifacts(project).inputSource).not.toContain("---@meta");
703
+ expect(resource.getDependencyList().map((dependency) => dependency.path)).not.toContain(declarationPath);
704
+ }
705
+ finally {
706
+ fs.rmSync(projectDir, { recursive: true, force: true });
707
+ }
708
+ });
709
+ it("emits Lua declarations only for reachable manifest TypeScript resources", async () => {
710
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-definitions-all-"));
711
+ fs.writeFileSync(path.join(projectDir, "left.ts"), "export function fromLeft(value: number): number { return value; }\n", "utf-8");
712
+ fs.writeFileSync(path.join(projectDir, "right.ts"), "this is not valid TypeScript @", "utf-8");
713
+ const project = createProject(projectDir, [
714
+ { name: "left", path: "left.ts", kind: "TypeScriptCode" },
715
+ { name: "right", path: "right.ts", kind: "TypeScriptCode" },
716
+ ]);
717
+ try {
718
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
719
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
720
+ const declarations = fs.readFileSync((0, TypeScriptLuaDeclarations_1.getTypeScriptLuaDeclarationsPath)(projectDir), "utf-8");
721
+ expect(declarations).toContain("function fromLeft(value) end");
722
+ expect(resources.items.has("right")).toBe(false);
723
+ }
724
+ finally {
725
+ fs.rmSync(projectDir, { recursive: true, force: true });
726
+ }
727
+ });
728
+ it("imports a manifest TypeScriptCode asset by name on the first build", async () => {
729
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-module-"));
730
+ const mainPath = path.join(projectDir, "main.ts");
731
+ const helpersPath = path.join(projectDir, "helpers.ts");
732
+ fs.writeFileSync(helpersPath, [
733
+ "/** Options accepted by Inc. */",
734
+ "export interface IncOptions { amount: number; }",
735
+ "/** Increments a value. */",
736
+ "export function Inc(value: number, options: IncOptions): number {",
737
+ " return value + options.amount;",
738
+ "}",
739
+ ].join("\n"), "utf-8");
740
+ fs.writeFileSync(mainPath, [
741
+ 'import { Inc, type IncOptions } from "ticbuild-assets/helpers";',
742
+ "const options: IncOptions = { amount: 2 };",
743
+ "export function TIC(): void { print(Inc(3, options)); }",
744
+ ].join("\n"), "utf-8");
745
+ const project = createProject(projectDir, [
746
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
747
+ { name: "helpers", path: "helpers.ts", kind: "TypeScriptCode" },
748
+ ]);
749
+ try {
750
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
751
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
752
+ const main = getTypeScriptResource(resources, "main");
753
+ const artifacts = main.getCodeArtifacts(project);
754
+ const declarations = fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(projectDir), "utf-8");
755
+ expect(declarations).toContain('declare module "ticbuild-assets/helpers"');
756
+ expect(declarations).toContain("export interface IncOptions");
757
+ expect(declarations).toContain("export function Inc(value: number, options: IncOptions): number;");
758
+ expect(artifacts.inputSource).toContain('--#include "import:helpers"');
759
+ expect(artifacts.inputSource).not.toContain("require(");
760
+ expect(artifacts.preprocessedSource).toContain("function Inc(");
761
+ expect(artifacts.preprocessedSource).toContain("function TIC(");
762
+ expect(artifacts.preprocessedSource.match(/function Inc\(/g)).toHaveLength(1);
763
+ expect(main.getDependencyList().map((dependency) => dependency.path)).toContain(helpersPath);
764
+ }
765
+ finally {
766
+ fs.rmSync(projectDir, { recursive: true, force: true });
767
+ }
768
+ });
769
+ it("typechecks manifest TypeScript imports against generated declarations on the first build", async () => {
770
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-typecheck-"));
771
+ fs.writeFileSync(path.join(projectDir, "helpers.ts"), "export function NumericOnly(value: number): number { return value; }\n", "utf-8");
772
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
773
+ 'import { NumericOnly } from "ticbuild-assets/helpers";',
774
+ 'export function TIC(): void { print(NumericOnly("wrong")); }',
775
+ ].join("\n"), "utf-8");
776
+ const project = createProject(projectDir, [
777
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
778
+ { name: "helpers", path: "helpers.ts", kind: "TypeScriptCode" },
779
+ ]);
780
+ try {
781
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
782
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(/main\.ts:2:\d+ - Argument of type 'string' is not assignable to parameter of type 'number'/);
783
+ }
784
+ finally {
785
+ fs.rmSync(projectDir, { recursive: true, force: true });
786
+ }
787
+ });
788
+ it("orders transitive manifest TypeScript modules and preserves referenced exported types", async () => {
789
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-transitive-"));
790
+ fs.writeFileSync(path.join(projectDir, "base.ts"), [
791
+ "export interface AddOptions { amount: number; }",
792
+ "export function Add(value: number, options: AddOptions): number { return value + options.amount; }",
793
+ ].join("\n"), "utf-8");
794
+ fs.writeFileSync(path.join(projectDir, "helpers.ts"), [
795
+ 'import { Add, type AddOptions } from "ticbuild-assets/base";',
796
+ "export function AddTwice(value: number, options: AddOptions): number {",
797
+ " return Add(Add(value, options), options);",
798
+ "}",
799
+ ].join("\n"), "utf-8");
800
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
801
+ 'import { AddTwice } from "ticbuild-assets/helpers";',
802
+ "export function TIC(): void { print(AddTwice(1, { amount: 2 })); }",
803
+ ].join("\n"), "utf-8");
804
+ const project = createProject(projectDir, [
805
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
806
+ { name: "helpers", path: "helpers.ts", kind: "TypeScriptCode" },
807
+ { name: "base", path: "base.ts", kind: "TypeScriptCode" },
808
+ ]);
809
+ try {
810
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
811
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
812
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
813
+ const declarations = fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(projectDir), "utf-8");
814
+ expect(declarations).toContain('declare module "ticbuild-assets/base"');
815
+ expect(declarations).toContain('declare module "ticbuild-assets/helpers"');
816
+ expect(declarations).toContain('from "ticbuild-assets/base"');
817
+ expect(artifacts.preprocessedSource.match(/function Add\(/g)).toHaveLength(1);
818
+ expect(artifacts.preprocessedSource.match(/function AddTwice\(/g)).toHaveLength(1);
819
+ expect(artifacts.preprocessedSource.indexOf("function Add(")).toBeLessThan(artifacts.preprocessedSource.indexOf("function AddTwice("));
820
+ expect(artifacts.preprocessedSource.indexOf("function AddTwice(")).toBeLessThan(artifacts.preprocessedSource.indexOf("function TIC("));
821
+ }
822
+ finally {
823
+ fs.rmSync(projectDir, { recursive: true, force: true });
824
+ }
825
+ });
826
+ it("preserves relative declaration dependencies behind a manifest TypeScript module", async () => {
827
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-relative-types-"));
828
+ fs.mkdirSync(path.join(projectDir, "helpers"));
829
+ fs.writeFileSync(path.join(projectDir, "helpers", "model.ts"), "export interface Adjustment { amount: number; }\n", "utf-8");
830
+ fs.writeFileSync(path.join(projectDir, "helpers", "index.ts"), [
831
+ 'import type { Adjustment } from "./model";',
832
+ "export function Adjust(value: number, adjustment: Adjustment): number {",
833
+ " return value + adjustment.amount;",
834
+ "}",
835
+ ].join("\n"), "utf-8");
836
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
837
+ 'import { Adjust } from "ticbuild-assets/helpers";',
838
+ "export function TIC(): void { print(Adjust(1, { amount: 3 })); }",
839
+ ].join("\n"), "utf-8");
840
+ const project = createProject(projectDir, [
841
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
842
+ { name: "helpers", path: "helpers/index.ts", kind: "TypeScriptCode" },
843
+ ]);
844
+ try {
845
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
846
+ await (0, importResources_1.loadAllImports)(project, reporter);
847
+ const declarations = fs.readFileSync((0, TypeScriptManifestModules_1.getTypeScriptManifestDeclarationsPath)(projectDir), "utf-8");
848
+ expect(declarations).toContain('declare module "ticbuild-assets/helpers"');
849
+ expect(declarations).toContain('declare module "ticbuild-assets/helpers/__types/helpers/model"');
850
+ expect(declarations).toContain('from "ticbuild-assets/helpers/__types/helpers/model"');
851
+ }
852
+ finally {
853
+ fs.rmSync(projectDir, { recursive: true, force: true });
854
+ }
855
+ });
856
+ it("does not include a manifest TypeScript module for a type-only import", async () => {
857
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-type-only-"));
858
+ fs.writeFileSync(path.join(projectDir, "types.ts"), [
859
+ "export interface Config { color: number; }",
860
+ 'export const TypeRuntimeMarker = "type-runtime-marker";',
861
+ ].join("\n"), "utf-8");
862
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
863
+ 'import type { Config } from "ticbuild-assets/types";',
864
+ "const config: Config = { color: 3 };",
865
+ "export function TIC(): void { cls(config.color); }",
866
+ ].join("\n"), "utf-8");
867
+ const project = createProject(projectDir, [
868
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
869
+ { name: "types", path: "types.ts", kind: "TypeScriptCode" },
870
+ ]);
871
+ try {
872
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
873
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
874
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
875
+ expect(artifacts.inputSource).not.toContain("import:types");
876
+ expect(artifacts.preprocessedSource).not.toContain("type-runtime-marker");
877
+ }
878
+ finally {
879
+ fs.rmSync(projectDir, { recursive: true, force: true });
880
+ }
881
+ });
882
+ it("imports a command-backed manifest TypeScript module", async () => {
883
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-command-"));
884
+ const generatedPath = path.join(projectDir, "generated", "helpers.ts");
885
+ const generatedSource = "export function GeneratedInc(value: number): number { return value + 1; }\n";
886
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
887
+ 'import { GeneratedInc } from "ticbuild-assets/generatedHelpers";',
888
+ "export function TIC(): void { print(GeneratedInc(4)); }",
889
+ ].join("\n"), "utf-8");
890
+ const project = createProject(projectDir, [
891
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
892
+ {
893
+ name: "generatedHelpers",
894
+ kind: "TypeScriptCode",
895
+ command: {
896
+ executable: process.execPath,
897
+ args: [
898
+ "-e",
899
+ 'require("fs").writeFileSync(process.argv[1], process.argv[2])',
900
+ "generated/helpers.ts",
901
+ generatedSource,
902
+ ],
903
+ outputFile: "generated/helpers.ts",
904
+ },
905
+ },
906
+ ]);
907
+ try {
908
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
909
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
910
+ const main = getTypeScriptResource(resources, "main");
911
+ const artifacts = main.getCodeArtifacts(project);
912
+ expect(fs.readFileSync(generatedPath, "utf-8")).toBe(generatedSource);
913
+ expect(artifacts.preprocessedSource).toContain("function GeneratedInc(");
914
+ expect(main.getDependencyList().map((dependency) => dependency.path)).not.toContain(generatedPath);
915
+ }
916
+ finally {
917
+ fs.rmSync(projectDir, { recursive: true, force: true });
918
+ }
919
+ });
920
+ it("rejects cycles between manifest TypeScript modules", async () => {
921
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-cycle-"));
922
+ fs.writeFileSync(path.join(projectDir, "left.ts"), 'import { right } from "ticbuild-assets/right"; export function left(): number { return right(); }\n', "utf-8");
923
+ fs.writeFileSync(path.join(projectDir, "right.ts"), 'import { left } from "ticbuild-assets/left"; export function right(): number { return left(); }\n', "utf-8");
924
+ const project = createProject(projectDir, [
925
+ { name: "left", path: "left.ts", kind: "TypeScriptCode" },
926
+ { name: "right", path: "right.ts", kind: "TypeScriptCode" },
927
+ ]);
928
+ try {
929
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
930
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("TypeScript manifest module cycles are not supported: left -> right -> left");
931
+ }
932
+ finally {
933
+ fs.rmSync(projectDir, { recursive: true, force: true });
934
+ }
935
+ });
936
+ it("rejects duplicate Lua globals across reachable manifest TypeScript resources", async () => {
937
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-manifest-global-collision-"));
938
+ fs.writeFileSync(path.join(projectDir, "left.ts"), 'import "ticbuild-assets/right"; export const SharedGlobal = 1;\n', "utf-8");
939
+ fs.writeFileSync(path.join(projectDir, "right.ts"), "export const SharedGlobal = 2;\n", "utf-8");
940
+ const project = createProject(projectDir, [
941
+ { name: "left", path: "left.ts", kind: "TypeScriptCode" },
942
+ { name: "right", path: "right.ts", kind: "TypeScriptCode" },
943
+ ]);
944
+ try {
945
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
946
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("manifest code asset 'right' and left.ts both declare Lua global 'SharedGlobal'");
947
+ }
948
+ finally {
949
+ fs.rmSync(projectDir, { recursive: true, force: true });
950
+ }
951
+ });
952
+ it("statically links imported TypeScript, preserves preprocessing, and exposes TIC callbacks", async () => {
953
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-"));
954
+ const mainPath = path.join(projectDir, "main.ts");
955
+ const helperPath = path.join(projectDir, "helper.ts");
956
+ fs.writeFileSync(helperPath, [
957
+ "export const helper = {",
958
+ ' suffix: " helper",',
959
+ " getSuffix() { return this.suffix; },",
960
+ "};",
961
+ ].join("\n"), "utf-8");
962
+ fs.writeFileSync(mainPath, [
963
+ 'import { helper } from "./helper";',
964
+ "const TIC = () => {",
965
+ " //--#ifdef FEATURE",
966
+ ' print(__EXPAND("$(project.name)") + helper.getSuffix());',
967
+ " //--#else",
968
+ ' print("disabled");',
969
+ " //--#endif",
970
+ "};",
971
+ ].join("\n"), "utf-8");
972
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }], { FEATURE: true });
973
+ try {
974
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
975
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
976
+ const resource = getTypeScriptResource(resources, "main");
977
+ const artifacts = resource.getCodeArtifacts(project);
978
+ expect(artifacts.inputSource).toContain('helper = {');
979
+ expect(artifacts.inputSource).toContain("helper:getSuffix()");
980
+ expect(artifacts.inputSource.indexOf('helper = {')).toBeLessThan(artifacts.inputSource.indexOf("TIC = function"));
981
+ expect(artifacts.inputSource).not.toContain("require(");
982
+ expect(artifacts.inputSource).not.toContain("____modules");
983
+ expect(artifacts.inputSource).not.toContain("____exports");
984
+ expect(artifacts.preprocessedSource).toContain('"typescript-test"');
985
+ expect(artifacts.preprocessedSource).not.toContain('"disabled"');
986
+ expect(artifacts.preprocessedSource).toContain("TIC = function");
987
+ expect(artifacts.preprocessedSource).not.toContain("_G[");
988
+ const helperLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, artifacts.preprocessedSource.indexOf('" helper"'), "right");
989
+ expect(helperLocation?.file).toBe(helperPath);
990
+ expect(helperLocation?.line).toBe(2);
991
+ const expandedLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, artifacts.preprocessedSource.indexOf('"typescript-test"'), "right");
992
+ expect(expandedLocation?.file).toBe(mainPath);
993
+ expect(expandedLocation?.line).toBe(4);
994
+ expect(artifacts.minifiedSourceMap.segments.map((segment) => segment.originalName)).toContain("helper");
995
+ expect(resource.getDependencyList()).toEqual(expect.arrayContaining([
996
+ { path: mainPath, reason: "Imported TypeScript code file" },
997
+ { path: helperPath, reason: "TypeScript compiler dependency" },
998
+ ]));
999
+ }
1000
+ finally {
1001
+ fs.rmSync(projectDir, { recursive: true, force: true });
1002
+ }
1003
+ });
1004
+ it("maps a traceable generated operator line to the authored TypeScript expression", async () => {
1005
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-traceable-"));
1006
+ const mainPath = path.join(projectDir, "main.ts");
1007
+ fs.writeFileSync(mainPath, [
1008
+ "export function TIC(): void {",
1009
+ " const lut = [1, 2, 3];",
1010
+ " const x = lut[8];",
1011
+ " poke(x + 1, 42);",
1012
+ "}",
1013
+ ].join("\n"), "utf-8");
1014
+ const project = createProject(projectDir, [{ name: "main", path: "main.ts", kind: "TypeScriptCode" }]);
1015
+ project.manifest.assembly.lua = {
1016
+ minify: true,
1017
+ minification: { lineBehavior: "traceable" },
1018
+ };
1019
+ try {
1020
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1021
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1022
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1023
+ const operatorOffset = artifacts.minifiedSource.indexOf("\n+\n") + 1;
1024
+ const mapped = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.minifiedSourceMap, operatorOffset, "right");
1025
+ expect(operatorOffset).toBeGreaterThan(0);
1026
+ expect(artifacts.minifiedSource.slice(operatorOffset, operatorOffset + 1)).toBe("+");
1027
+ expect(mapped).toMatchObject({ file: mainPath, line: 4, column: 7 });
1028
+ }
1029
+ finally {
1030
+ fs.rmSync(projectDir, { recursive: true, force: true });
1031
+ }
1032
+ });
1033
+ it("uses exports as direct globals while keeping non-exported module state local", async () => {
1034
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-static-scope-"));
1035
+ fs.writeFileSync(path.join(projectDir, "math.ts"), [
1036
+ "const privateScale = 2;",
1037
+ "export function scale(value: number): number { return value * privateScale; }",
1038
+ ].join("\n"), "utf-8");
1039
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1040
+ 'import { scale as importedScale } from "./math";',
1041
+ "export function TIC(): void { print(importedScale(3)); }",
1042
+ ].join("\n"), "utf-8");
1043
+ const project = createProject(projectDir, [
1044
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1045
+ ]);
1046
+ try {
1047
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1048
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1049
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1050
+ expect(artifacts.inputSource).toContain("local privateScale = 2");
1051
+ expect(artifacts.inputSource).toContain("function scale(value)");
1052
+ expect(artifacts.inputSource).toContain("print(scale(3))");
1053
+ expect(artifacts.inputSource).not.toContain("importedScale");
1054
+ expect(artifacts.inputSource).not.toContain("local function scale");
1055
+ expect(artifacts.inputSource.match(/^do$/gm)).toHaveLength(2);
1056
+ }
1057
+ finally {
1058
+ fs.rmSync(projectDir, { recursive: true, force: true });
1059
+ }
1060
+ });
1061
+ it("emits shared dependencies once in deterministic dependency-first order", async () => {
1062
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-diamond-"));
1063
+ fs.writeFileSync(path.join(projectDir, "shared.ts"), 'export const sharedMarker = "shared once";\n', "utf-8");
1064
+ fs.writeFileSync(path.join(projectDir, "left.ts"), ['import { sharedMarker } from "./shared";', "export const left = sharedMarker + \" left\";"].join("\n"), "utf-8");
1065
+ fs.writeFileSync(path.join(projectDir, "right.ts"), ['import { sharedMarker } from "./shared";', "export const right = sharedMarker + \" right\";"].join("\n"), "utf-8");
1066
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1067
+ 'import { left } from "./left";',
1068
+ 'import { right } from "./right";',
1069
+ "export function TIC(): void { print(left + right); }",
1070
+ ].join("\n"), "utf-8");
1071
+ const project = createProject(projectDir, [
1072
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1073
+ ]);
1074
+ try {
1075
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1076
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1077
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
1078
+ expect(source.match(/sharedMarker = "shared once"/g)).toHaveLength(1);
1079
+ expect(source.indexOf('sharedMarker = "shared once"')).toBeLessThan(source.indexOf("left ="));
1080
+ expect(source.indexOf('sharedMarker = "shared once"')).toBeLessThan(source.indexOf("right ="));
1081
+ expect(source.indexOf("left =")).toBeLessThan(source.indexOf("function TIC()"));
1082
+ expect(source.indexOf("right =")).toBeLessThan(source.indexOf("function TIC()"));
1083
+ }
1084
+ finally {
1085
+ fs.rmSync(projectDir, { recursive: true, force: true });
1086
+ }
1087
+ });
1088
+ it("treats relative declaration modules as typed Lua global contracts", async () => {
1089
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-contract-"));
1090
+ fs.writeFileSync(path.join(projectDir, "lua-env.d.ts"), "export declare function LuaFract(value: number): number;\n", "utf-8");
1091
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1092
+ 'import { LuaFract as fract } from "./lua-env";',
1093
+ "export function callLua(value: number): number { return fract(value); }",
1094
+ ].join("\n"), "utf-8");
1095
+ const project = createProject(projectDir, [
1096
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1097
+ ]);
1098
+ try {
1099
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1100
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1101
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1102
+ expect(artifacts.inputSource).toContain("return LuaFract(value)");
1103
+ expect(artifacts.inputSource).not.toContain("require(");
1104
+ expect(artifacts.inputSource).not.toContain("lua-env");
1105
+ }
1106
+ finally {
1107
+ fs.rmSync(projectDir, { recursive: true, force: true });
1108
+ }
1109
+ });
1110
+ it("links named re-exports without a runtime module object", async () => {
1111
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-reexport-"));
1112
+ fs.writeFileSync(path.join(projectDir, "base.ts"), "export function utility(): number { return 4; }\n", "utf-8");
1113
+ fs.writeFileSync(path.join(projectDir, "barrel.ts"), 'export { utility as renamedUtility } from "./base";\n', "utf-8");
1114
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1115
+ 'import { renamedUtility } from "./barrel";',
1116
+ "export function TIC(): void { print(renamedUtility()); }",
1117
+ ].join("\n"), "utf-8");
1118
+ const project = createProject(projectDir, [
1119
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1120
+ ]);
1121
+ try {
1122
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1123
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1124
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
1125
+ expect(source).toContain("function utility()");
1126
+ expect(source).toContain("renamedUtility = utility");
1127
+ expect(source).toContain("print(renamedUtility())");
1128
+ expect(source).not.toContain("require(");
1129
+ }
1130
+ finally {
1131
+ fs.rmSync(projectDir, { recursive: true, force: true });
1132
+ }
1133
+ });
1134
+ it("preserves temporary captures when calling an exported factory with optional arguments", async () => {
1135
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-export-temporaries-"));
1136
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1137
+ "export function createObject(options: { position: { x: number }; visible: boolean }) { return options; }",
1138
+ "export function evaluate(node: { position: { x: number }; params?: { visible: boolean } }) {",
1139
+ " node.position.x += 1;",
1140
+ " return createObject({ position: node.position, visible: node.params?.visible !== false });",
1141
+ "}",
1142
+ ].join("\n"), "utf-8");
1143
+ const project = createProject(projectDir, [
1144
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1145
+ ]);
1146
+ try {
1147
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1148
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1149
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
1150
+ // Capturing the exported callee preserves evaluation order. Generated
1151
+ // temporaries share a TSTL symbol marker, but are distinct local bindings.
1152
+ const calleeCapture = source.match(/local (\w+) = createObject\r?\n/);
1153
+ expect(calleeCapture).not.toBeNull();
1154
+ expect(source).toContain(`return ${calleeCapture[1]}({`);
1155
+ expect(source).not.toMatch(/local createObject\b/);
1156
+ const propertyCapture = source.match(/local (\w+), (\w+) = node\.position, "x"/);
1157
+ expect(propertyCapture).not.toBeNull();
1158
+ expect(propertyCapture[1]).not.toBe(propertyCapture[2]);
1159
+ expect(source).not.toMatch(/\b____exports\b/);
1160
+ expect(() => (0, lua_processor_1.parseLua)(source)).not.toThrow();
1161
+ }
1162
+ finally {
1163
+ fs.rmSync(projectDir, { recursive: true, force: true });
1164
+ }
1165
+ });
1166
+ it("keeps TypeScriptToLua helpers self-contained without runtime module loading", async () => {
1167
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-class-link-"));
1168
+ fs.writeFileSync(path.join(projectDir, "counter.ts"), [
1169
+ "export class Counter {",
1170
+ " public value = 0;",
1171
+ " public increment(): void { this.value++; }",
1172
+ "}",
1173
+ ].join("\n"), "utf-8");
1174
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1175
+ 'import { Counter } from "./counter";',
1176
+ "const counter = new Counter();",
1177
+ "export function TIC(): void { counter.increment(); }",
1178
+ ].join("\n"), "utf-8");
1179
+ const project = createProject(projectDir, [
1180
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1181
+ ]);
1182
+ try {
1183
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1184
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1185
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
1186
+ expect(source).toContain("Counter = __TS__Class()");
1187
+ expect(source).toContain("__TS__New(Counter)");
1188
+ expect(source).not.toContain("require(");
1189
+ expect(source).not.toContain("lualib_bundle");
1190
+ expect(source).not.toContain("____modules");
1191
+ }
1192
+ finally {
1193
+ fs.rmSync(projectDir, { recursive: true, force: true });
1194
+ }
1195
+ });
1196
+ it("rejects duplicate global exports before emitting ambiguous Lua", async () => {
1197
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-duplicate-export-"));
1198
+ fs.writeFileSync(path.join(projectDir, "left.ts"), "export function collide(): number { return 1; }\n", "utf-8");
1199
+ fs.writeFileSync(path.join(projectDir, "right.ts"), "export function collide(): number { return 2; }\n", "utf-8");
1200
+ fs.writeFileSync(path.join(projectDir, "main.ts"), ['import "./left";', 'import "./right";', "export function TIC(): void {}"].join("\n"), "utf-8");
1201
+ const project = createProject(projectDir, [
1202
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1203
+ ]);
1204
+ try {
1205
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1206
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(/exported Lua global 'collide'.*left\.ts.*right\.ts/);
1207
+ }
1208
+ finally {
1209
+ fs.rmSync(projectDir, { recursive: true, force: true });
1210
+ }
1211
+ });
1212
+ it("rejects static module cycles with the cycle path", async () => {
1213
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-cycle-"));
1214
+ fs.writeFileSync(path.join(projectDir, "a.ts"), ['import { b } from "./b";', "export function a(): number { return b(); }"].join("\n"), "utf-8");
1215
+ fs.writeFileSync(path.join(projectDir, "b.ts"), ['import { a } from "./a";', "export function b(): number { return a(); }"].join("\n"), "utf-8");
1216
+ fs.writeFileSync(path.join(projectDir, "main.ts"), ['import { a } from "./a";', "export function TIC(): void { print(a()); }"].join("\n"), "utf-8");
1217
+ const project = createProject(projectDir, [
1218
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1219
+ ]);
1220
+ try {
1221
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1222
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(/module cycles.*a\.ts -> b\.ts -> a\.ts/);
1223
+ }
1224
+ finally {
1225
+ fs.rmSync(projectDir, { recursive: true, force: true });
1226
+ }
1227
+ });
1228
+ it.each([
1229
+ ['import value from "./dep"; export function TIC() { print(value); }', "default imports"],
1230
+ ['import * as dep from "./dep"; export function TIC() { print(dep.value); }', "namespace imports"],
1231
+ ['export * from "./dep";', "export *"],
1232
+ ['export async function load() { return import("./dep"); }', "dynamic import()"],
1233
+ ])("rejects unsupported static module syntax: %s", async (mainSource, expectedMessage) => {
1234
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-module-syntax-"));
1235
+ fs.writeFileSync(path.join(projectDir, "dep.ts"), "const value = 1; export { value as default, value };\n", "utf-8");
1236
+ fs.writeFileSync(path.join(projectDir, "main.ts"), `${mainSource}\n`, "utf-8");
1237
+ const project = createProject(projectDir, [
1238
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1239
+ ]);
1240
+ try {
1241
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1242
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(expectedMessage);
1243
+ }
1244
+ finally {
1245
+ fs.rmSync(projectDir, { recursive: true, force: true });
1246
+ }
1247
+ });
1248
+ it("lets direct TypeScript globals participate in Lua global renaming", async () => {
1249
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-global-minify-"));
1250
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1251
+ "//--#minify allow_rename",
1252
+ "export function VeryLongTypeScriptFunction(): number { return 7; }",
1253
+ "export function TIC(): void { print(VeryLongTypeScriptFunction()); }",
1254
+ ].join("\n"), "utf-8");
1255
+ const project = createProject(projectDir, [
1256
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1257
+ ]);
1258
+ try {
1259
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1260
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1261
+ const resource = getTypeScriptResource(resources, "main");
1262
+ const artifacts = resource.getCodeArtifacts(project);
1263
+ expect(resource.getPreprocessResult().minifyAllowedGlobalNames).toContain("VeryLongTypeScriptFunction");
1264
+ expect(artifacts.preprocessedSource).toContain("function VeryLongTypeScriptFunction()");
1265
+ expect(artifacts.minifiedSource).not.toContain("VeryLongTypeScriptFunction");
1266
+ expect(artifacts.minifiedSourceMap.segments.map((segment) => segment.originalName)).toContain("VeryLongTypeScriptFunction");
1267
+ }
1268
+ finally {
1269
+ fs.rmSync(projectDir, { recursive: true, force: true });
1270
+ }
1271
+ });
1272
+ it("lets TypeScript globals opt out of automatic Lua global renaming", async () => {
1273
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-global-no-rename-"));
1274
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1275
+ "//--#minify no_rename",
1276
+ "export function PublicTypeScriptApi(): number { return InternalTypeScriptHelper(); }",
1277
+ "export function InternalTypeScriptHelper(): number { return 7; }",
1278
+ "export function TIC(): void { print(PublicTypeScriptApi()); }",
1279
+ ].join("\n"), "utf-8");
1280
+ const project = createProject(projectDir, [
1281
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1282
+ ]);
1283
+ project.manifest.assembly.lua = {
1284
+ minify: true,
1285
+ minification: { globalSymbolRenaming: "opt-out" },
1286
+ };
1287
+ try {
1288
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1289
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1290
+ const resource = getTypeScriptResource(resources, "main");
1291
+ const artifacts = resource.getCodeArtifacts(project);
1292
+ expect(resource.getPreprocessResult().minifyGlobalNamesToKeep).toContain("PublicTypeScriptApi");
1293
+ expect(artifacts.minifiedSource).toContain("function PublicTypeScriptApi()");
1294
+ expect(artifacts.minifiedSource).not.toContain("InternalTypeScriptHelper");
1295
+ expect(artifacts.minifiedSource).toContain("function TIC()");
1296
+ }
1297
+ finally {
1298
+ fs.rmSync(projectDir, { recursive: true, force: true });
1299
+ }
1300
+ });
1301
+ it("resolves relative Lua includes from the TypeScript module that authored the directive", async () => {
1302
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-relative-include-"));
1303
+ const featureDir = path.join(projectDir, "feature");
1304
+ fs.mkdirSync(featureDir);
1305
+ const mainPath = path.join(projectDir, "main.ts");
1306
+ const helperPath = path.join(featureDir, "helper.ts");
1307
+ const localLuaPath = path.join(featureDir, "local.lua");
1308
+ fs.writeFileSync(mainPath, ['import "./feature/helper";', "export function TIC(): void { cls(0); }"].join("\n"), "utf-8");
1309
+ fs.writeFileSync(helperPath, ['//--#include "./local.lua"', 'export const helper = "loaded";'].join("\n"), "utf-8");
1310
+ fs.writeFileSync(localLuaPath, 'trace("nested Lua include")\n', "utf-8");
1311
+ const project = createProject(projectDir, [
1312
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1313
+ ]);
1314
+ try {
1315
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1316
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1317
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1318
+ const includedOffset = artifacts.preprocessedSource.indexOf('trace("nested Lua include")');
1319
+ expect(includedOffset).toBeGreaterThanOrEqual(0);
1320
+ const includedLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, includedOffset, "right");
1321
+ expect(includedLocation).toMatchObject({ file: localLuaPath, line: 1, column: 0 });
1322
+ }
1323
+ finally {
1324
+ fs.rmSync(projectDir, { recursive: true, force: true });
1325
+ }
1326
+ });
1327
+ it("distinguishes source files with the same basename", async () => {
1328
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-duplicate-basename-"));
1329
+ const leftDir = path.join(projectDir, "left");
1330
+ const rightDir = path.join(projectDir, "right");
1331
+ fs.mkdirSync(leftDir);
1332
+ fs.mkdirSync(rightDir);
1333
+ const mainPath = path.join(projectDir, "main.ts");
1334
+ const leftPath = path.join(leftDir, "shared.ts");
1335
+ const rightPath = path.join(rightDir, "shared.ts");
1336
+ fs.writeFileSync(leftPath, 'export const left = "left source";\n', "utf-8");
1337
+ fs.writeFileSync(rightPath, 'export const right = "right source";\n', "utf-8");
1338
+ fs.writeFileSync(mainPath, [
1339
+ 'import { left } from "./left/shared";',
1340
+ 'import { right } from "./right/shared";',
1341
+ "export function TIC(): void { print(left + right); }",
1342
+ ].join("\n"), "utf-8");
1343
+ const project = createProject(projectDir, [
1344
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1345
+ ]);
1346
+ try {
1347
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1348
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1349
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1350
+ const leftLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, artifacts.preprocessedSource.indexOf('"left source"'), "right");
1351
+ const rightLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, artifacts.preprocessedSource.indexOf('"right source"'), "right");
1352
+ expect(leftLocation?.file).toBe(leftPath);
1353
+ expect(rightLocation?.file).toBe(rightPath);
1354
+ }
1355
+ finally {
1356
+ fs.rmSync(projectDir, { recursive: true, force: true });
1357
+ }
1358
+ });
1359
+ it("emits an exported TIC callback directly as a Lua global", async () => {
1360
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-exported-tic-"));
1361
+ fs.writeFileSync(path.join(projectDir, "main.ts"), "export function TIC(): void { cls(0); }\n", "utf-8");
1362
+ const project = createProject(projectDir, [
1363
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1364
+ ]);
1365
+ try {
1366
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1367
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1368
+ const resource = getTypeScriptResource(resources, "main");
1369
+ const artifacts = resource.getCodeArtifacts(project);
1370
+ expect(artifacts.inputSource).toContain("function TIC()");
1371
+ expect(artifacts.inputSource).not.toContain("____exports");
1372
+ expect(artifacts.inputSource).not.toContain("____entry");
1373
+ expect(artifacts.inputSource).not.toContain("_G[");
1374
+ expect(artifacts.inputSource).not.toContain("__TICBUILD_EXPORT_GLOBAL__");
1375
+ expect(artifacts.preprocessedSource).not.toContain("__TICBUILD_EXPORT_GLOBAL__");
1376
+ }
1377
+ finally {
1378
+ fs.rmSync(projectDir, { recursive: true, force: true });
1379
+ }
1380
+ });
1381
+ it("lets generated TypeScript Lua include a Lua code asset", async () => {
1382
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-include-"));
1383
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1384
+ "declare const fromLua: string;",
1385
+ '//--#include "import:luaHelper"',
1386
+ "const TIC = () => print(fromLua);",
1387
+ ].join("\n"), "utf-8");
1388
+ fs.writeFileSync(path.join(projectDir, "helper.lua"), 'local fromLua = "included"\n', "utf-8");
1389
+ const project = createProject(projectDir, [
1390
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1391
+ { name: "luaHelper", path: "helper.lua", kind: "LuaCode" },
1392
+ ]);
1393
+ try {
1394
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1395
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1396
+ const resource = getTypeScriptResource(resources, "main");
1397
+ expect(resource.getPreprocessResult().code).toContain('local fromLua = "included"');
1398
+ expect(resource.getDependencyList().map((dependency) => dependency.path)).toContain(path.join(projectDir, "helper.lua"));
1399
+ }
1400
+ finally {
1401
+ fs.rmSync(projectDir, { recursive: true, force: true });
1402
+ }
1403
+ });
1404
+ it("imports a manifest LuaCode asset as a typed TypeScript module", async () => {
1405
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-module-"));
1406
+ const mainPath = path.join(projectDir, "main.ts");
1407
+ const luaPath = path.join(projectDir, "luaUtils.lua");
1408
+ fs.writeFileSync(luaPath, [
1409
+ "--- Clamps a number to the supplied range.",
1410
+ "---@param value number",
1411
+ "---@param minimum integer",
1412
+ "---@param maximum number",
1413
+ "---@return number",
1414
+ "function Clamp(value, minimum, maximum)",
1415
+ " return math.min(math.max(value, minimum), maximum)",
1416
+ "end",
1417
+ "LuaVersion = \"one\"",
1418
+ "local function HiddenHelper() end",
1419
+ ].join("\n"), "utf-8");
1420
+ fs.writeFileSync(mainPath, [
1421
+ 'import { Clamp as clampFromLua, LuaVersion } from "ticbuild-assets/LuaUtils";',
1422
+ "export function TIC(): void {",
1423
+ " print(clampFromLua(12, 0, 10));",
1424
+ " print(LuaVersion);",
1425
+ "}",
1426
+ ].join("\n"), "utf-8");
1427
+ const project = createProject(projectDir, [
1428
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1429
+ { name: "LuaUtils", path: "luaUtils.lua", kind: "LuaCode" },
1430
+ ]);
1431
+ try {
1432
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1433
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1434
+ const resource = getTypeScriptResource(resources, "main");
1435
+ const artifacts = resource.getCodeArtifacts(project);
1436
+ const declarationsPath = (0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(projectDir);
1437
+ const declarations = fs.readFileSync(declarationsPath, "utf-8");
1438
+ expect(declarations).toContain('declare module "ticbuild-assets/LuaUtils"');
1439
+ expect(declarations).toContain("export function Clamp(value: number, minimum: number, maximum: number): number;");
1440
+ expect(declarations).toContain("export const LuaVersion: string;");
1441
+ expect(declarations).not.toContain("HiddenHelper");
1442
+ expect(artifacts.inputSource.match(/--#include "import:LuaUtils"/g)).toHaveLength(1);
1443
+ expect(artifacts.inputSource).not.toContain("require(");
1444
+ expect(artifacts.inputSource).not.toContain("clampFromLua");
1445
+ expect(artifacts.preprocessedSource).toContain("function Clamp(value, minimum, maximum)");
1446
+ expect(artifacts.preprocessedSource).toContain("print(Clamp(12, 0, 10))");
1447
+ expect(artifacts.preprocessedSource.indexOf("function Clamp")).toBeLessThan(artifacts.preprocessedSource.indexOf("function TIC"));
1448
+ expect(resource.getDependencyList()).toEqual(expect.arrayContaining([{ path: luaPath, reason: "Lua preprocessor dependency" }]));
1449
+ expect(resource.getDependencyList().map((dependency) => dependency.path)).not.toContain(declarationsPath);
1450
+ const luaLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(artifacts.preprocessedSourceMap, artifacts.preprocessedSource.indexOf("function Clamp"), "right");
1451
+ expect(luaLocation?.file).toBe(luaPath);
1452
+ expect(luaLocation?.line).toBe(6);
1453
+ }
1454
+ finally {
1455
+ fs.rmSync(projectDir, { recursive: true, force: true });
1456
+ }
1457
+ });
1458
+ it("includes a side-effect Lua asset once across multiple TypeScript modules", async () => {
1459
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-module-once-"));
1460
+ fs.writeFileSync(path.join(projectDir, "hooks.lua"), "function InstallHooks() end\n", "utf-8");
1461
+ fs.writeFileSync(path.join(projectDir, "helper.ts"), ['import "ticbuild-assets/Hooks";', "export const helper = 1;"].join("\n"), "utf-8");
1462
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1463
+ 'import "ticbuild-assets/Hooks";',
1464
+ 'import { helper } from "./helper";',
1465
+ "export function TIC(): void { print(helper); }",
1466
+ ].join("\n"), "utf-8");
1467
+ const project = createProject(projectDir, [
1468
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1469
+ { name: "Hooks", path: "hooks.lua", kind: "LuaCode" },
1470
+ ]);
1471
+ try {
1472
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1473
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1474
+ const artifacts = getTypeScriptResource(resources, "main").getCodeArtifacts(project);
1475
+ expect(artifacts.inputSource.match(/--#include "import:Hooks"/g)).toHaveLength(1);
1476
+ expect(artifacts.preprocessedSource.match(/function InstallHooks/g)).toHaveLength(1);
1477
+ }
1478
+ finally {
1479
+ fs.rmSync(projectDir, { recursive: true, force: true });
1480
+ }
1481
+ });
1482
+ it("typechecks TypeScript calls against generated LuaCATS signatures on the first build", async () => {
1483
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-module-types-"));
1484
+ fs.writeFileSync(path.join(projectDir, "math.lua"), ["---@param value number", "function Double(value)", " return value * 2", "end"].join("\n"), "utf-8");
1485
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1486
+ 'import { Double } from "ticbuild-assets/Math";',
1487
+ 'export function TIC(): void { print(Double("wrong")); }',
1488
+ ].join("\n"), "utf-8");
1489
+ const project = createProject(projectDir, [
1490
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1491
+ { name: "Math", path: "math.lua", kind: "LuaCode" },
1492
+ ]);
1493
+ try {
1494
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1495
+ await expect((0, importResources_1.loadAllImports)(project, reporter))
1496
+ .rejects
1497
+ .toThrow(/main\.ts:2:\d+ - Argument of type 'string' is not assignable to parameter of type 'number'/);
1498
+ expect(fs.existsSync((0, LuaAssetTypeScriptModules_1.getLuaAssetDeclarationsPath)(projectDir))).toBe(true);
1499
+ }
1500
+ finally {
1501
+ fs.rmSync(projectDir, { recursive: true, force: true });
1502
+ }
1503
+ });
1504
+ it("rejects first-class imports which do not name a manifest code asset", async () => {
1505
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-module-missing-"));
1506
+ fs.writeFileSync(path.join(projectDir, "main.ts"), ['import "ticbuild-assets/Missing";', "export function TIC(): void {}"].join("\n"), "utf-8");
1507
+ const project = createProject(projectDir, [
1508
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1509
+ ]);
1510
+ try {
1511
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1512
+ await expect((0, importResources_1.loadAllImports)(project, reporter))
1513
+ .rejects
1514
+ .toThrow(/ticbuild-assets\/Missing.*does not name a manifest LuaCode or TypeScriptCode asset/);
1515
+ }
1516
+ finally {
1517
+ fs.rmSync(projectDir, { recursive: true, force: true });
1518
+ }
1519
+ });
1520
+ it("rejects colliding globals from two imported Lua assets", async () => {
1521
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-module-collision-"));
1522
+ fs.writeFileSync(path.join(projectDir, "left.lua"), "function SharedLuaGlobal() end\n", "utf-8");
1523
+ fs.writeFileSync(path.join(projectDir, "right.lua"), "function SharedLuaGlobal() end\n", "utf-8");
1524
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1525
+ 'import { SharedLuaGlobal as left } from "ticbuild-assets/Left";',
1526
+ 'import { SharedLuaGlobal as right } from "ticbuild-assets/Right";',
1527
+ "export function TIC(): void { left(); right(); }",
1528
+ ].join("\n"), "utf-8");
1529
+ const project = createProject(projectDir, [
1530
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1531
+ { name: "Left", path: "left.lua", kind: "LuaCode" },
1532
+ { name: "Right", path: "right.lua", kind: "LuaCode" },
1533
+ ]);
1534
+ try {
1535
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1536
+ await expect((0, importResources_1.loadAllImports)(project, reporter))
1537
+ .rejects
1538
+ .toThrow(/manifest code assets 'Left' and 'Right' both declare Lua global 'SharedLuaGlobal'/);
1539
+ }
1540
+ finally {
1541
+ fs.rmSync(projectDir, { recursive: true, force: true });
1542
+ }
1543
+ });
1544
+ it("does not transport the legacy //# directive spelling", async () => {
1545
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-lua-include-"));
1546
+ fs.writeFileSync(path.join(projectDir, "main.ts"), [
1547
+ "declare const fromLua: string;",
1548
+ '//#include "import:luaHelper"',
1549
+ "const TIC = () => print(fromLua);",
1550
+ ].join("\n"), "utf-8");
1551
+ fs.writeFileSync(path.join(projectDir, "helper.lua"), 'local fromLua = "included"\n', "utf-8");
1552
+ const project = createProject(projectDir, [
1553
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1554
+ { name: "luaHelper", path: "helper.lua", kind: "LuaCode" },
1555
+ ]);
1556
+ try {
1557
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1558
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1559
+ const resource = getTypeScriptResource(resources, "main");
1560
+ expect(resource.getPreprocessResult().code).not.toContain('local fromLua = "included"');
1561
+ expect(resource.getDependencyList().map((dependency) => dependency.path)).not.toContain(path.join(projectDir, "helper.lua"));
1562
+ }
1563
+ finally {
1564
+ fs.rmSync(projectDir, { recursive: true, force: true });
1565
+ }
1566
+ });
1567
+ it("lets Lua include a transpiled TypeScript asset and continue afterward", async () => {
1568
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-lua-typescript-include-"));
1569
+ fs.writeFileSync(path.join(projectDir, "main.lua"), ['--#include "import:typed"', 'print("after TypeScript")'].join("\n"), "utf-8");
1570
+ fs.writeFileSync(path.join(projectDir, "typed.ts"), "export function typescriptTick() { return 1; }\n", "utf-8");
1571
+ const project = createProject(projectDir, [
1572
+ { name: "main", path: "main.lua", kind: "LuaCode" },
1573
+ { name: "typed", path: "typed.ts", kind: "TypeScriptCode" },
1574
+ ]);
1575
+ try {
1576
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1577
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1578
+ const resource = resources.items.get("main");
1579
+ expect(resource).toBeInstanceOf(LuaCodeImporter_1.LuaCodeResource);
1580
+ const artifacts = resource.getCodeArtifacts(project);
1581
+ expect(artifacts.preprocessedSource).toContain("function typescriptTick()");
1582
+ expect(artifacts.preprocessedSource).toContain('print("after TypeScript")');
1583
+ expect(artifacts.preprocessedSource).not.toContain("____entry");
1584
+ expect(artifacts.preprocessedSource).not.toContain("require(");
1585
+ expect(artifacts.minifiedSource.length).toBeGreaterThan(0);
1586
+ }
1587
+ finally {
1588
+ fs.rmSync(projectDir, { recursive: true, force: true });
1589
+ }
1590
+ });
1591
+ it("reports TypeScript diagnostics with their source location", async () => {
1592
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-error-"));
1593
+ fs.writeFileSync(path.join(projectDir, "main.ts"), ['const value: number = "wrong";', "const TIC = () => print(value);"].join("\n"), "utf-8");
1594
+ const project = createProject(projectDir, [
1595
+ { name: "main", path: "main.ts", kind: "TypeScriptCode" },
1596
+ ]);
1597
+ try {
1598
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1599
+ await expect((0, importResources_1.loadAllImports)(project, reporter))
1600
+ .rejects
1601
+ .toThrow(/TypeScript transpilation failed:[\s\S]*main\.ts:1:7[\s\S]*not assignable to type 'number'/);
1602
+ }
1603
+ finally {
1604
+ fs.rmSync(projectDir, { recursive: true, force: true });
1605
+ }
1606
+ });
1607
+ it("loads extended tsconfig paths and ambient declarations as watched dependencies", async () => {
1608
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-config-"));
1609
+ const sourceDir = path.join(projectDir, "src");
1610
+ const helperDir = path.join(sourceDir, "helpers");
1611
+ fs.mkdirSync(helperDir, { recursive: true });
1612
+ const entryPath = path.join(sourceDir, "main.ts");
1613
+ const helperPath = path.join(helperDir, "helper.ts");
1614
+ const declarationsPath = path.join(sourceDir, "globals.d.ts");
1615
+ const baseConfigPath = path.join(projectDir, "tsconfig.base.json");
1616
+ const configPath = path.join(projectDir, "tsconfig.json");
1617
+ fs.writeFileSync(baseConfigPath, JSON.stringify({
1618
+ compilerOptions: {
1619
+ baseUrl: ".",
1620
+ paths: { "@helpers/*": ["src/helpers/*"] },
1621
+ strict: true,
1622
+ types: [],
1623
+ },
1624
+ }), "utf-8");
1625
+ fs.writeFileSync(configPath, JSON.stringify({ extends: "./tsconfig.base.json", include: ["src/**/*.d.ts"] }), "utf-8");
1626
+ fs.writeFileSync(declarationsPath, "declare const PROJECT_LABEL: string;\n", "utf-8");
1627
+ fs.writeFileSync(helperPath, 'export const helper = "configured";\n', "utf-8");
1628
+ fs.writeFileSync(entryPath, [
1629
+ 'import { helper } from "@helpers/helper";',
1630
+ "export function configuredTick() { print(PROJECT_LABEL + helper); }",
1631
+ ].join("\n"), "utf-8");
1632
+ const project = createProject(projectDir, [
1633
+ {
1634
+ name: "main",
1635
+ path: "src/main.ts",
1636
+ kind: "TypeScriptCode",
1637
+ typescript: { tsconfig: "tsconfig.json" },
1638
+ },
1639
+ ]);
1640
+ try {
1641
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1642
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1643
+ const resource = getTypeScriptResource(resources, "main");
1644
+ const preprocessedSource = resource.getCodeArtifacts(project).preprocessedSource;
1645
+ expect(preprocessedSource).toContain("function configuredTick()");
1646
+ expect(preprocessedSource).toContain('helper = "configured"');
1647
+ expect(resource.getDependencyList()).toEqual(expect.arrayContaining([
1648
+ { path: entryPath, reason: "Imported TypeScript code file" },
1649
+ { path: helperPath, reason: "TypeScript compiler dependency" },
1650
+ { path: declarationsPath, reason: "TypeScript compiler dependency" },
1651
+ { path: (0, projectFiles_1.getProjectTic80DeclarationsPath)(projectDir), reason: "TypeScript compiler dependency" },
1652
+ { path: configPath, reason: "TypeScript project configuration" },
1653
+ { path: baseConfigPath, reason: "TypeScript project configuration" },
1654
+ ]));
1655
+ }
1656
+ finally {
1657
+ fs.rmSync(projectDir, { recursive: true, force: true });
1658
+ }
1659
+ });
1660
+ it.each([
1661
+ { include: ["src/**/*.ts", "src/**/*.d.ts"] },
1662
+ { include: ["src/**/*.ts", "src/**/*.d.ts", ".ticbuild/declarations/**/*.d.ts"] },
1663
+ { files: [] },
1664
+ ])("builds a Lua entrypoint with external TypeScript and an empty config file list: %j", async (fileSelection) => {
1665
+ await withDeclarationProject({
1666
+ "project/src/main.lua": '--#include "import:engine"\nfunction TIC() print(engineTick()) end',
1667
+ "engine/index.ts": 'import { value } from "./value"; export function engineTick() { print(value); return value; }',
1668
+ "engine/value.ts": 'export const value: number = 42;',
1669
+ "project/tsconfig.json": JSON.stringify({ compilerOptions: { strict: true, types: [] }, ...fileSelection }),
1670
+ }, [{ name: "main", path: "project/src/main.lua", kind: "LuaCode" }], async (_, dir) => //
1671
+ {
1672
+ const projectDir = path.join(dir, "project");
1673
+ const project = createProject(projectDir, [
1674
+ { name: "main", path: "src/main.lua", kind: "LuaCode" },
1675
+ { name: "engine", path: "../engine/index.ts", kind: "TypeScriptCode", typescript: { tsconfig: "tsconfig.json" } },
1676
+ ]);
1677
+ fs.unlinkSync((0, projectFiles_1.getProjectTic80DeclarationsPath)(projectDir));
1678
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1679
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1680
+ const source = resources.items.get("main").getCodeArtifacts(project).preprocessedSource;
1681
+ expect(source).toContain("function engineTick()");
1682
+ expect(source).toContain("function TIC()");
1683
+ expect(fs.existsSync((0, projectFiles_1.getProjectTic80DeclarationsPath)(projectDir))).toBe(false);
1684
+ expect(resources.getDependencyList().map(dependency => dependency.path)).toEqual(expect.arrayContaining([
1685
+ path.join(dir, "engine", "value.ts"), path.join(projectDir, "tsconfig.json"),
1686
+ ]));
1687
+ fs.writeFileSync(path.join(dir, "engine", "value.ts"), 'export const value: number = "wrong";');
1688
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Type 'string' is not assignable to type 'number'");
1689
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify({
1690
+ compilerOptions: { strict: "wrong", types: [] }, ...fileSelection,
1691
+ }));
1692
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("Compiler option 'strict' requires a value of type boolean");
1693
+ });
1694
+ });
1695
+ it("ignores tsconfig emission settings owned by ticbuild", async () => {
1696
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-config-owned-"));
1697
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify({
1698
+ compilerOptions: {
1699
+ target: "ES5",
1700
+ noEmit: true,
1701
+ declaration: true,
1702
+ outDir: "dist",
1703
+ types: [],
1704
+ },
1705
+ tstl: {
1706
+ luaTarget: "5.1",
1707
+ noHeader: false,
1708
+ },
1709
+ }), "utf-8");
1710
+ fs.writeFileSync(path.join(projectDir, "main.ts"), "export function tick() {}\n", "utf-8");
1711
+ const project = createProject(projectDir, [
1712
+ {
1713
+ name: "main",
1714
+ path: "main.ts",
1715
+ kind: "TypeScriptCode",
1716
+ typescript: { tsconfig: "tsconfig.json" },
1717
+ },
1718
+ ]);
1719
+ const warningSpy = jest.spyOn(cons, "warning").mockImplementation(() => undefined);
1720
+ try {
1721
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1722
+ const resources = await (0, importResources_1.loadAllImports)(project, reporter);
1723
+ const source = getTypeScriptResource(resources, "main").getCodeArtifacts(project).inputSource;
1724
+ expect(source).toContain("function tick()");
1725
+ expect(source).not.toContain("TypeScriptToLua");
1726
+ expect(warningSpy).toHaveBeenCalledWith(expect.stringContaining("compilerOptions.noEmit"));
1727
+ expect(warningSpy).toHaveBeenCalledWith(expect.stringContaining("tstl.luaTarget"));
1728
+ }
1729
+ finally {
1730
+ warningSpy.mockRestore();
1731
+ fs.rmSync(projectDir, { recursive: true, force: true });
1732
+ }
1733
+ });
1734
+ it("reports malformed tsconfig diagnostics with their source location", async () => {
1735
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-config-error-"));
1736
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), '{ "compilerOptions": { "strict": tru } }', "utf-8");
1737
+ fs.writeFileSync(path.join(projectDir, "main.ts"), "export function tick() {}\n", "utf-8");
1738
+ const project = createProject(projectDir, [
1739
+ {
1740
+ name: "main",
1741
+ path: "main.ts",
1742
+ kind: "TypeScriptCode",
1743
+ typescript: { tsconfig: "tsconfig.json" },
1744
+ },
1745
+ ]);
1746
+ try {
1747
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1748
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow(/TypeScript configuration failed:[\s\S]*tsconfig\.json:1:/);
1749
+ }
1750
+ finally {
1751
+ fs.rmSync(projectDir, { recursive: true, force: true });
1752
+ }
1753
+ });
1754
+ it("rejects tsconfig project references before transpilation", async () => {
1755
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-config-reference-"));
1756
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify({ compilerOptions: { types: [] }, references: [{ path: "./library" }] }), "utf-8");
1757
+ fs.writeFileSync(path.join(projectDir, "main.ts"), "export function tick() {}\n", "utf-8");
1758
+ const project = createProject(projectDir, [
1759
+ {
1760
+ name: "main",
1761
+ path: "main.ts",
1762
+ kind: "TypeScriptCode",
1763
+ typescript: { tsconfig: "tsconfig.json" },
1764
+ },
1765
+ ]);
1766
+ try {
1767
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1768
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("TypeScript project references are not supported yet");
1769
+ }
1770
+ finally {
1771
+ fs.rmSync(projectDir, { recursive: true, force: true });
1772
+ }
1773
+ });
1774
+ it("rejects TypeScriptToLua plugins before they can execute", async () => {
1775
+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "ticbuild-typescript-config-plugin-"));
1776
+ fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify({ compilerOptions: { types: [] }, tstl: { luaPlugins: [{ name: "not-installed" }] } }), "utf-8");
1777
+ fs.writeFileSync(path.join(projectDir, "main.ts"), "export function tick() {}\n", "utf-8");
1778
+ const project = createProject(projectDir, [
1779
+ {
1780
+ name: "main",
1781
+ path: "main.ts",
1782
+ kind: "TypeScriptCode",
1783
+ typescript: { tsconfig: "tsconfig.json" },
1784
+ },
1785
+ ]);
1786
+ try {
1787
+ const reporter = (0, buildReporter_1.createBuildReporter)("human");
1788
+ await expect((0, importResources_1.loadAllImports)(project, reporter)).rejects.toThrow("TypeScriptToLua plugins are not supported yet");
1789
+ }
1790
+ finally {
1791
+ fs.rmSync(projectDir, { recursive: true, force: true });
1792
+ }
1793
+ });
1794
+ });
1795
+ //# sourceMappingURL=TypeScriptCodeImporter.test.js.map