ticbuild 1.0.22 → 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 +7 -4
  290. package/dist/buildInfo.d.ts.map +1 -1
  291. package/dist/buildInfo.js +7 -4
  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
@@ -33,61 +33,113 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.preprocessTypeScriptDeclarationDirectives = preprocessTypeScriptDeclarationDirectives;
36
37
  exports.preprocessLuaCode = preprocessLuaCode;
38
+ const luaparse = __importStar(require("luaparse"));
37
39
  const path = __importStar(require("node:path"));
38
40
  const fileSystem_1 = require("../utils/fileSystem");
39
41
  const lua_fundamentals_1 = require("../utils/lua/lua_fundamentals");
40
42
  const lua_utils_1 = require("../utils/lua/lua_utils");
41
43
  const cartLoader_1 = require("../utils/tic80/cartLoader");
42
- const importUtils_1 = require("./importUtils");
44
+ const importReference_1 = require("./importReference");
45
+ const tic80CartImporter_1 = require("./importers/tic80CartImporter");
43
46
  const manifestTypes_1 = require("./manifestTypes");
44
47
  const lua_processor_1 = require("../utils/lua/lua_processor");
45
- const lua_doc_1 = require("../utils/lua/lua_doc");
48
+ const LuaCATS_1 = require("../utils/lua/LuaCATS");
46
49
  const cons = __importStar(require("../utils/console"));
50
+ const errorHandling_1 = require("../utils/errorHandling");
47
51
  const sourceMap_1 = require("./sourceMap");
48
52
  const luaEncode_1 = require("./luaEncode");
49
- async function preprocessLuaCode(project, source, filePath) {
50
- const manifestDefines = getManifestPreprocessorDefines(project);
53
+ const importSources_1 = require("./importSources");
54
+ const traceProfiler_1 = require("../utils/traceProfiler");
55
+ const preprocessorDefines_1 = require("./preprocessorDefines");
56
+ const luaPreprocessorSyntax_1 = require("./luaPreprocessorSyntax");
57
+ /** Resolve active includes from TypeScript directive comments before Lua exists. */
58
+ async function preprocessTypeScriptDeclarationDirectives(project, source, filePath, options) {
59
+ const directives = (0, luaPreprocessorSyntax_1.extractTypeScriptDeclarationDirectives)(source);
60
+ if (directives.trim())
61
+ await preprocessLuaCode(project, directives, filePath, options);
62
+ }
63
+ async function preprocessLuaCode(project, source, filePath, options = {}) {
64
+ const manifestDefines = (0, preprocessorDefines_1.getResolvedPreprocessorDefines)(project);
65
+ const fallbackImportSources = new Map();
66
+ const resolveImportSource = options.resolveImportSource ?? (async (importName) => {
67
+ const importDef = project.manifest.imports.find((candidate) => candidate.name === importName);
68
+ if (!importDef) {
69
+ return undefined;
70
+ }
71
+ let source = fallbackImportSources.get(importName);
72
+ if (!source) {
73
+ source = (0, importSources_1.materializeImportSource)(project, importDef);
74
+ fallbackImportSources.set(importName, source);
75
+ }
76
+ return await source;
77
+ });
51
78
  const state = {
52
79
  defines: new Map(Object.entries(manifestDefines)),
53
80
  dependencies: new Set(),
54
81
  pragmaOnceKeys: new Set(),
55
82
  includeStack: [],
56
- macros: new Map(),
57
83
  macroSymbols: [],
58
84
  minifyAllowedGlobalNames: [],
85
+ minifyGlobalNamesToKeep: [],
86
+ resolveCodeImport: options.resolveCodeImport,
87
+ resolveImportSource,
88
+ diagnostics: {
89
+ sourcesProcessed: 0,
90
+ sourceCharacters: 0,
91
+ includeDirectives: 0,
92
+ fileIncludes: 0,
93
+ codeImportIncludes: 0,
94
+ cartridgeCodeIncludes: 0,
95
+ pragmaOnceSkips: 0,
96
+ },
59
97
  };
60
98
  const includeKey = makeIncludeKey(filePath, {});
61
- const rawResult = await processSource(project, source, filePath, includeKey, state, {});
62
- const expandedResult = expandMacros(project, rawResult, state.macros, filePath);
63
- const finalResult = await expandPreprocessorCalls(project, expandedResult, filePath, state);
99
+ const inputSourceMap = options.sourceMap ?? (0, sourceMap_1.createIdentitySourceMap)(source, filePath);
100
+ (0, sourceMap_1.assertSourceMapMatchesSource)(inputSourceMap, source);
101
+ const rawResult = await (0, traceProfiler_1.profileAsync)(options.profileScope, "Resolve Lua includes and directives", {
102
+ category: "Lua preprocessing",
103
+ args: { inputCharacters: source.length },
104
+ }, async (scope) => {
105
+ const result = await processSource(project, source, inputSourceMap, filePath, includeKey, state, {});
106
+ scope?.setArgs({
107
+ outputCharacters: result.code.length,
108
+ sourceMapSegments: result.map.getSegments().length,
109
+ macroDefinitions: result.macroDefinitions.length,
110
+ ...state.diagnostics,
111
+ });
112
+ return result;
113
+ });
114
+ const expandedResult = expandMacros(rawResult, filePath, options.profileScope);
115
+ const finalResult = await expandPreprocessorCalls(project, expandedResult, filePath, state, options.quietParseFailures ?? false, options.profileScope);
116
+ const sourceMap = (0, traceProfiler_1.profileSync)(options.profileScope, "Finalize Lua source map", {
117
+ category: "Lua preprocessing",
118
+ args: {
119
+ outputCharacters: finalResult.code.length,
120
+ sourceMapSegments: finalResult.map.getSegments().length,
121
+ },
122
+ }, () => finalResult.map.toSourceMap(finalResult.code));
64
123
  return {
65
124
  code: finalResult.code,
66
125
  dependencies: Array.from(state.dependencies.values()),
67
- sourceMap: finalResult.map.toSourceMap(finalResult.code),
126
+ sourceMap,
68
127
  preprocessorSymbols: state.macroSymbols,
69
128
  minifyAllowedGlobalNames: Array.from(new Set(state.minifyAllowedGlobalNames)),
129
+ minifyGlobalNamesToKeep: Array.from(new Set(state.minifyGlobalNamesToKeep)),
70
130
  };
71
131
  }
72
- function getManifestPreprocessorDefines(project) {
73
- const defines = project.manifest.preprocessor?.defines;
74
- if (!defines) {
75
- return {};
76
- }
77
- const resolved = {};
78
- for (const [key, value] of Object.entries(defines)) {
79
- resolved[key] = typeof value === "string" ? project.substituteVariables(value) : value;
80
- }
81
- return resolved;
82
- }
83
- async function processSource(project, source, filePath, includeKey, state, inputOverrides, trackDependency = true) {
132
+ async function processSource(project, source, inputSourceMap, filePath, includeKey, state, inputOverrides, trackDependency = true) {
84
133
  if (state.pragmaOnceKeys.has(includeKey)) {
85
- return { code: "", map: new sourceMap_1.SourceMapBuilder() };
134
+ state.diagnostics.pragmaOnceSkips++;
135
+ return { code: "", map: new sourceMap_1.SourceMapBuilder(), macroDefinitions: [] };
86
136
  }
87
137
  if (state.includeStack.includes(includeKey)) {
88
138
  const cycle = [...state.includeStack, includeKey].join(" -> ");
89
139
  throw new Error(`Lua preprocessor include cycle detected: ${cycle}`);
90
140
  }
141
+ state.diagnostics.sourcesProcessed++;
142
+ state.diagnostics.sourceCharacters += source.length;
91
143
  state.includeStack.push(includeKey);
92
144
  if (trackDependency) {
93
145
  state.dependencies.add(filePath);
@@ -101,9 +153,10 @@ async function processSource(project, source, filePath, includeKey, state, input
101
153
  }
102
154
  const conditionalStack = [];
103
155
  const builder = new sourceMap_1.SourceMapBuilder();
156
+ const macroDefinitions = [];
104
157
  let output = "";
105
158
  let lastEmittedOrigin = null;
106
- let pendingMinifyAllowRename = null;
159
+ let pendingMinifyRename = null;
107
160
  // helper to check if current line is in active conditional block
108
161
  const isActive = () => {
109
162
  if (conditionalStack.length === 0) {
@@ -117,71 +170,77 @@ async function processSource(project, source, filePath, includeKey, state, input
117
170
  const lineInfo = lines[i];
118
171
  const line = lineInfo.text;
119
172
  const lineNumber = i + 1;
120
- const directiveMatch = line.match(/^\s*--#\s*(\w+)\s*(.*)$/);
173
+ const authoredLineLocation = (0, sourceMap_1.mapPreprocessedOffsetToLineColumn)(inputSourceMap, lineInfo.startOffset, "right");
174
+ const authoredFilePath = authoredLineLocation?.file ?? filePath;
175
+ const authoredLineNumber = authoredLineLocation?.line ?? lineNumber;
176
+ const directiveMatch = (0, luaPreprocessorSyntax_1.parseLuaPreprocessorDirective)(line);
121
177
  if (!directiveMatch) {
122
178
  if (isActive()) {
123
- if (pendingMinifyAllowRename && !isIgnorableMinifyTargetLine(line)) {
124
- const targetName = parseMinifyAllowRenameTarget(line);
179
+ if (pendingMinifyRename && !isIgnorableMinifyTargetLine(line)) {
180
+ const targetName = parseMinifyRenameTarget(line);
125
181
  if (!targetName) {
126
- throw new Error(formatError(pendingMinifyAllowRename.filePath, pendingMinifyAllowRename.lineNumber, `--#minify allow_rename must be followed by a simple global function or assignment`));
182
+ throw new Error(formatError(pendingMinifyRename.filePath, pendingMinifyRename.lineNumber, minifyTargetError(pendingMinifyRename.option)));
127
183
  }
128
- state.minifyAllowedGlobalNames.push(targetName);
129
- pendingMinifyAllowRename = null;
184
+ if (pendingMinifyRename.option === "allow_rename") {
185
+ state.minifyAllowedGlobalNames.push(targetName);
186
+ }
187
+ else {
188
+ state.minifyGlobalNamesToKeep.push(targetName);
189
+ }
190
+ pendingMinifyRename = null;
130
191
  }
131
192
  if (output.length > 0) {
132
193
  output += "\n";
133
- const newlineOrigin = lastEmittedOrigin ?? { file: filePath, offset: lineInfo.startOffset };
134
- builder.appendOriginal("\n", newlineOrigin.file, newlineOrigin.offset);
194
+ const newlineOrigin = lastEmittedOrigin ?? (0, sourceMap_1.mapPreprocessedOffset)(inputSourceMap, lineInfo.startOffset, "right");
195
+ builder.appendGenerated("\n", newlineOrigin);
135
196
  }
136
197
  output += line;
137
- builder.appendOriginal(line, filePath, lineInfo.startOffset);
138
- lastEmittedOrigin = { file: filePath, offset: lineInfo.endOffset };
198
+ builder.appendMappedSlice(line, inputSourceMap, lineInfo.startOffset);
199
+ lastEmittedOrigin = (0, sourceMap_1.mapPreprocessedOffset)(inputSourceMap, lineInfo.endOffset, "left");
139
200
  }
140
201
  continue;
141
202
  }
142
- const directive = directiveMatch[1];
143
- const rest = directiveMatch[2] || "";
203
+ const { name: directive, arguments: rest } = directiveMatch;
144
204
  switch (directive) {
145
205
  case "macro": {
146
- const macroHeader = parseMacroHeader(rest, filePath, lineNumber);
206
+ const macroHeader = parseMacroHeader(rest, authoredFilePath, authoredLineNumber);
147
207
  const nameOffset = findMacroNameOffset(line, lineInfo.startOffset, macroHeader.name);
148
- const docLines = (0, lua_doc_1.collectDocCommentAbove)(lineTexts, i);
208
+ const nameOrigin = (0, sourceMap_1.mapPreprocessedOffset)(inputSourceMap, nameOffset, "right");
209
+ const docLines = (0, LuaCATS_1.collectDocCommentAbove)(lineTexts, i);
149
210
  if (macroHeader.inlineBody !== undefined) {
150
211
  if (isActive()) {
151
- state.macros.set(macroHeader.name, {
152
- name: macroHeader.name,
153
- params: macroHeader.params,
154
- body: macroHeader.inlineBody,
155
- sourceFile: filePath,
156
- lineNumber,
212
+ const definition = createMacroDefinition(macroHeader, macroHeader.inlineBody, authoredFilePath, authoredLineNumber);
213
+ macroDefinitions.push({
214
+ offset: output.length,
215
+ definition,
157
216
  });
158
217
  state.macroSymbols.push({
159
218
  name: macroHeader.name,
160
219
  kind: "macro",
161
- sourceFile: filePath,
162
- offset: nameOffset,
220
+ invocationStyle: macroHeader.invocationStyle,
221
+ sourceFile: nameOrigin?.file ?? authoredFilePath,
222
+ offset: nameOrigin?.offset ?? nameOffset,
163
223
  params: macroHeader.params,
164
224
  docLines,
165
225
  });
166
226
  }
167
227
  break;
168
228
  }
169
- const bodyResult = readMacroBody(lineTexts, i + 1, filePath, lineNumber);
229
+ const bodyResult = readMacroBody(lineTexts, i + 1, authoredFilePath, authoredLineNumber);
170
230
  i = bodyResult.endIndex;
171
231
  if (isActive()) {
172
232
  const strippedBody = stripLuaCommentsPreserveNewlines(bodyResult.body);
173
- state.macros.set(macroHeader.name, {
174
- name: macroHeader.name,
175
- params: macroHeader.params,
176
- body: strippedBody,
177
- sourceFile: filePath,
178
- lineNumber,
233
+ const definition = createMacroDefinition(macroHeader, strippedBody, authoredFilePath, authoredLineNumber);
234
+ macroDefinitions.push({
235
+ offset: output.length,
236
+ definition,
179
237
  });
180
238
  state.macroSymbols.push({
181
239
  name: macroHeader.name,
182
240
  kind: "macro",
183
- sourceFile: filePath,
184
- offset: nameOffset,
241
+ invocationStyle: macroHeader.invocationStyle,
242
+ sourceFile: nameOrigin?.file ?? authoredFilePath,
243
+ offset: nameOrigin?.offset ?? nameOffset,
185
244
  params: macroHeader.params,
186
245
  docLines,
187
246
  });
@@ -189,20 +248,24 @@ async function processSource(project, source, filePath, includeKey, state, input
189
248
  break;
190
249
  }
191
250
  case "endmacro": {
192
- throw new Error(formatError(filePath, lineNumber, `--#endmacro without matching --#macro`));
251
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `--#endmacro without matching --#macro`));
193
252
  }
194
253
  case "minify": {
195
254
  if (!isActive()) {
196
255
  break;
197
256
  }
198
257
  const minifyOption = stripTrailingLineComment(rest).trim();
199
- if (minifyOption !== "allow_rename") {
200
- throw new Error(formatError(filePath, lineNumber, `Unsupported --#minify option: ${minifyOption}`));
258
+ if (minifyOption !== "allow_rename" && minifyOption !== "no_rename") {
259
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Unsupported --#minify option: ${minifyOption}`));
201
260
  }
202
- if (pendingMinifyAllowRename) {
203
- throw new Error(formatError(filePath, lineNumber, `--#minify allow_rename cannot be repeated before a target declaration`));
261
+ if (pendingMinifyRename) {
262
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `--#minify ${pendingMinifyRename.option} cannot be repeated before a target declaration`));
204
263
  }
205
- pendingMinifyAllowRename = { filePath, lineNumber };
264
+ pendingMinifyRename = {
265
+ option: minifyOption,
266
+ filePath: authoredFilePath,
267
+ lineNumber: authoredLineNumber,
268
+ };
206
269
  break;
207
270
  }
208
271
  case "define": {
@@ -211,7 +274,7 @@ async function processSource(project, source, filePath, includeKey, state, input
211
274
  }
212
275
  const defineMatch = rest.match(/^([A-Za-z_][A-Za-z0-9_]*)(?:\s+(.*))?$/);
213
276
  if (!defineMatch) {
214
- throw new Error(formatError(filePath, lineNumber, `Invalid --#define syntax: ${line}`));
277
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#define syntax: ${line}`));
215
278
  }
216
279
  const name = defineMatch[1];
217
280
  const expr = defineMatch[2];
@@ -219,7 +282,7 @@ async function processSource(project, source, filePath, includeKey, state, input
219
282
  localDefines.set(name, true);
220
283
  }
221
284
  else {
222
- const value = evaluateExpression(parseExpression(expr, filePath, lineNumber), localDefines, filePath, lineNumber);
285
+ const value = evaluateExpression(parseExpression(expr, authoredFilePath, authoredLineNumber), localDefines, authoredFilePath, authoredLineNumber);
223
286
  localDefines.set(name, value);
224
287
  }
225
288
  break;
@@ -230,7 +293,7 @@ async function processSource(project, source, filePath, includeKey, state, input
230
293
  }
231
294
  const undefMatch = rest.match(/^([A-Za-z_][A-Za-z0-9_]*)$/);
232
295
  if (!undefMatch) {
233
- throw new Error(formatError(filePath, lineNumber, `Invalid --#undef syntax: ${line}`));
296
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#undef syntax: ${line}`));
234
297
  }
235
298
  localDefines.delete(undefMatch[1]);
236
299
  break;
@@ -240,9 +303,9 @@ async function processSource(project, source, filePath, includeKey, state, input
240
303
  let conditionMet = false;
241
304
  if (parentActive) {
242
305
  if (!rest || rest.trim() === "") {
243
- throw new Error(formatError(filePath, lineNumber, `Missing expression in --#if`));
306
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Missing expression in --#if`));
244
307
  }
245
- const exprValue = evaluateExpression(parseExpression(rest, filePath, lineNumber), localDefines, filePath, lineNumber);
308
+ const exprValue = evaluateExpression(parseExpression(rest, authoredFilePath, authoredLineNumber), localDefines, authoredFilePath, authoredLineNumber);
246
309
  conditionMet = isTruthy(exprValue);
247
310
  }
248
311
  conditionalStack.push({
@@ -259,7 +322,7 @@ async function processSource(project, source, filePath, includeKey, state, input
259
322
  if (parentActive) {
260
323
  const ifdefMatch = rest.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)$/);
261
324
  if (!ifdefMatch) {
262
- throw new Error(formatError(filePath, lineNumber, `Invalid --#ifdef syntax: ${line}`));
325
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#ifdef syntax: ${line}`));
263
326
  }
264
327
  conditionMet = localDefines.has(ifdefMatch[1]);
265
328
  }
@@ -277,7 +340,7 @@ async function processSource(project, source, filePath, includeKey, state, input
277
340
  if (parentActive) {
278
341
  const ifndefMatch = rest.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)$/);
279
342
  if (!ifndefMatch) {
280
- throw new Error(formatError(filePath, lineNumber, `Invalid --#ifndef syntax: ${line}`));
343
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#ifndef syntax: ${line}`));
281
344
  }
282
345
  conditionMet = !localDefines.has(ifndefMatch[1]);
283
346
  }
@@ -291,11 +354,11 @@ async function processSource(project, source, filePath, includeKey, state, input
291
354
  }
292
355
  case "else": {
293
356
  if (conditionalStack.length === 0) {
294
- throw new Error(formatError(filePath, lineNumber, `--#else without matching --#if`));
357
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `--#else without matching --#if`));
295
358
  }
296
359
  const top = conditionalStack[conditionalStack.length - 1];
297
360
  if (top.hasElse) {
298
- throw new Error(formatError(filePath, lineNumber, `Duplicate --#else for same --#if`));
361
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Duplicate --#else for same --#if`));
299
362
  }
300
363
  top.hasElse = true;
301
364
  top.active = top.parentActive && !top.conditionMet;
@@ -303,7 +366,7 @@ async function processSource(project, source, filePath, includeKey, state, input
303
366
  }
304
367
  case "endif": {
305
368
  if (conditionalStack.length === 0) {
306
- throw new Error(formatError(filePath, lineNumber, `--#endif without matching --#if`));
369
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `--#endif without matching --#if`));
307
370
  }
308
371
  conditionalStack.pop();
309
372
  break;
@@ -314,13 +377,13 @@ async function processSource(project, source, filePath, includeKey, state, input
314
377
  }
315
378
  const pragmaMatch = rest.trim().match(/^(\w+)$/);
316
379
  if (!pragmaMatch) {
317
- throw new Error(formatError(filePath, lineNumber, `Invalid --#pragma syntax: ${line}`));
380
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#pragma syntax: ${line}`));
318
381
  }
319
382
  if (pragmaMatch[1] === "once") {
320
383
  state.pragmaOnceKeys.add(includeKey);
321
384
  }
322
385
  else {
323
- throw new Error(formatError(filePath, lineNumber, `Unknown pragma: ${pragmaMatch[1]}`));
386
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Unknown pragma: ${pragmaMatch[1]}`));
324
387
  }
325
388
  break;
326
389
  }
@@ -328,20 +391,23 @@ async function processSource(project, source, filePath, includeKey, state, input
328
391
  if (!isActive()) {
329
392
  break;
330
393
  }
394
+ state.diagnostics.includeDirectives++;
331
395
  const includeMatch = rest.trim().match(/^"([^"]+)"(.*)$/);
332
396
  if (!includeMatch) {
333
- throw new Error(formatError(filePath, lineNumber, `Invalid --#include syntax: ${line}`));
397
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Invalid --#include syntax: ${line}`));
334
398
  }
335
399
  const includeTarget = includeMatch[1];
336
400
  const remainder = includeMatch[2] || "";
337
- const overrides = parseWithOverrides(remainder, localDefines, filePath, lineNumber);
338
- const included = await resolveInclude(project, includeTarget, filePath, overrides, state, lineNumber);
401
+ const overrides = parseWithOverrides(remainder, localDefines, authoredFilePath, authoredLineNumber);
402
+ const included = await resolveInclude(project, includeTarget, authoredFilePath, overrides, state, authoredLineNumber);
403
+ let includedOffset = output.length;
339
404
  if (included.code) {
340
405
  if (output.length > 0) {
341
406
  output += "\n";
342
- const newlineOrigin = lastEmittedOrigin ?? { file: filePath, offset: 0 };
343
- builder.appendOriginal("\n", newlineOrigin.file, newlineOrigin.offset);
407
+ const newlineOrigin = lastEmittedOrigin ?? { file: authoredFilePath, offset: authoredLineLocation?.offset ?? 0 };
408
+ builder.appendGenerated("\n", newlineOrigin);
344
409
  }
410
+ includedOffset = output.length;
345
411
  output += included.code;
346
412
  builder.appendMap(included.map);
347
413
  const endOrigin = included.map.mapOffset(included.code.length);
@@ -349,6 +415,12 @@ async function processSource(project, source, filePath, includeKey, state, input
349
415
  lastEmittedOrigin = endOrigin;
350
416
  }
351
417
  }
418
+ for (const event of included.macroDefinitions) {
419
+ macroDefinitions.push({
420
+ offset: includedOffset + event.offset,
421
+ definition: event.definition,
422
+ });
423
+ }
352
424
  break;
353
425
  }
354
426
  case "error": {
@@ -357,9 +429,9 @@ async function processSource(project, source, filePath, includeKey, state, input
357
429
  }
358
430
  const message = rest.trim();
359
431
  if (!message) {
360
- throw new Error(formatError(filePath, lineNumber, `--#error encountered`));
432
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `--#error encountered`));
361
433
  }
362
- throw new Error(formatError(filePath, lineNumber, message));
434
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, message));
363
435
  }
364
436
  case "warning": {
365
437
  if (!isActive()) {
@@ -367,24 +439,24 @@ async function processSource(project, source, filePath, includeKey, state, input
367
439
  }
368
440
  const message = rest.trim();
369
441
  if (!message) {
370
- cons.warning(formatError(filePath, lineNumber, `--#warning encountered`));
442
+ cons.warning(formatError(authoredFilePath, authoredLineNumber, `--#warning encountered`));
371
443
  break;
372
444
  }
373
- cons.warning(formatError(filePath, lineNumber, message));
445
+ cons.warning(formatError(authoredFilePath, authoredLineNumber, message));
374
446
  break;
375
447
  }
376
448
  default:
377
- throw new Error(formatError(filePath, lineNumber, `Unknown directive: --#${directive}`));
449
+ throw new Error(formatError(authoredFilePath, authoredLineNumber, `Unknown directive: --#${directive}`));
378
450
  }
379
451
  }
380
452
  if (conditionalStack.length > 0) {
381
453
  throw new Error(formatError(filePath, lines.length, `Unclosed --#if block`));
382
454
  }
383
- if (pendingMinifyAllowRename) {
384
- throw new Error(formatError(pendingMinifyAllowRename.filePath, pendingMinifyAllowRename.lineNumber, `--#minify allow_rename must be followed by a simple global function or assignment`));
455
+ if (pendingMinifyRename) {
456
+ throw new Error(formatError(pendingMinifyRename.filePath, pendingMinifyRename.lineNumber, minifyTargetError(pendingMinifyRename.option)));
385
457
  }
386
458
  state.includeStack.pop();
387
- return { code: output, map: builder };
459
+ return { code: output, map: builder, macroDefinitions };
388
460
  }
389
461
  function isIgnorableMinifyTargetLine(line) {
390
462
  const trimmed = line.trim();
@@ -393,7 +465,10 @@ function isIgnorableMinifyTargetLine(line) {
393
465
  function stripTrailingLineComment(text) {
394
466
  return text.replace(/\s*--.*$/, "");
395
467
  }
396
- function parseMinifyAllowRenameTarget(line) {
468
+ function minifyTargetError(option) {
469
+ return `--#minify ${option} must be followed by a simple global function or assignment`;
470
+ }
471
+ function parseMinifyRenameTarget(line) {
397
472
  const functionMatch = line.match(/^\s*function\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
398
473
  if (functionMatch) {
399
474
  return functionMatch[1];
@@ -408,6 +483,7 @@ async function resolveInclude(project, includeTarget, fromFile, overrides, state
408
483
  if (includeTarget.startsWith("import:")) {
409
484
  return await resolveImportInclude(project, includeTarget, overrides, state, lineNumber);
410
485
  }
486
+ state.diagnostics.fileIncludes++;
411
487
  const substituted = project.substituteVariables(includeTarget);
412
488
  let resolvedPath;
413
489
  const localFound = (0, fileSystem_1.resolveFileWithSearchPaths)(substituted, path.dirname(fromFile));
@@ -419,77 +495,69 @@ async function resolveInclude(project, includeTarget, fromFile, overrides, state
419
495
  resolvedPath = project.resolveIncludePath(substituted);
420
496
  }
421
497
  catch (error) {
422
- const message = error instanceof Error ? error.message : String(error);
498
+ const message = (0, errorHandling_1.getErrorMessage)(error);
423
499
  throw new Error(formatError(fromFile, lineNumber, message));
424
500
  }
425
501
  }
426
502
  const includeKey = makeIncludeKey(resolvedPath, overrides);
427
503
  if (state.pragmaOnceKeys.has(includeKey)) {
428
- return { code: "", map: new sourceMap_1.SourceMapBuilder() };
504
+ state.diagnostics.pragmaOnceSkips++;
505
+ return { code: "", map: new sourceMap_1.SourceMapBuilder(), macroDefinitions: [] };
429
506
  }
430
507
  const source = await (0, fileSystem_1.readTextFileAsync)(resolvedPath);
431
- const included = await processSource(project, source, resolvedPath, includeKey, state, overrides);
508
+ const included = await processSource(project, source, (0, sourceMap_1.createIdentitySourceMap)(source, resolvedPath), resolvedPath, includeKey, state, overrides);
432
509
  return ensureTrailingNewline(included, resolvedPath);
433
510
  }
434
511
  async function resolveImportInclude(project, includeTarget, overrides, state, lineNumber) {
435
- const ref = (0, importUtils_1.parseImportReference)(includeTarget);
436
- const importName = ref.importName;
437
- const chunkSpec = ref.chunkSpec;
512
+ const ref = (0, importReference_1.parseImportReference)(includeTarget);
513
+ const importName = ref.import;
438
514
  const importDef = project.manifest.imports.find((imp) => imp.name === importName);
439
515
  if (!importDef) {
440
516
  throw new Error(formatError("<include>", lineNumber, `Import not found: ${importName}`));
441
517
  }
442
- if (importDef.kind === manifestTypes_1.kImportKind.key.LuaCode) {
443
- const resolvedPath = project.resolveImportPath(importDef);
444
- const includeKey = makeIncludeKey(resolvedPath, overrides);
518
+ const generatedLua = await state.resolveCodeImport?.(importName);
519
+ if (generatedLua) {
520
+ state.diagnostics.codeImportIncludes++;
521
+ if (ref.chunks !== undefined || ref.bank !== undefined) {
522
+ throw new Error(formatError(generatedLua.sourcePath, lineNumber, "generated code imports do not support chunk or bank selectors"));
523
+ }
524
+ for (const dependency of generatedLua.dependencies ?? []) {
525
+ state.dependencies.add(dependency.path);
526
+ }
527
+ const includeKey = makeIncludeKey(generatedLua.sourcePath, overrides);
445
528
  if (state.pragmaOnceKeys.has(includeKey)) {
446
- return { code: "", map: new sourceMap_1.SourceMapBuilder() };
529
+ state.diagnostics.pragmaOnceSkips++;
530
+ return { code: "", map: new sourceMap_1.SourceMapBuilder(), macroDefinitions: [] };
447
531
  }
448
- const source = await (0, fileSystem_1.readTextFileAsync)(resolvedPath);
449
- const included = await processSource(project, source, resolvedPath, includeKey, state, overrides);
450
- return ensureTrailingNewline(included, resolvedPath);
532
+ const included = await processSource(project, generatedLua.source, generatedLua.sourceMap, generatedLua.sourcePath, includeKey, state, overrides, !(generatedLua.generatedOutputs ?? []).some((outputPath) => (0, fileSystem_1.isSameFileLocation)(outputPath, generatedLua.sourcePath)));
533
+ return ensureTrailingNewline(included, generatedLua.sourcePath);
451
534
  }
452
535
  if (importDef.kind === manifestTypes_1.kImportKind.key.Tic80Cartridge) {
453
- const resolvedPath = project.resolveImportPath(importDef);
454
- const data = await (0, fileSystem_1.readBinaryFileAsync)(resolvedPath);
455
- const cart = (0, cartLoader_1.parseTic80Cart)(data);
456
- state.dependencies.add(resolvedPath);
457
- const availableChunks = importDef.chunks && importDef.chunks.length > 0
458
- ? importDef.chunks
459
- : Array.from(new Set(cart.chunks.map((chunk) => chunk.chunkType)));
460
- const hasCode = availableChunks.includes("CODE") || availableChunks.includes("CODE_COMPRESSED");
461
- if (!hasCode) {
462
- throw new Error(formatError(resolvedPath, lineNumber, `No CODE or CODE_COMPRESSED chunk found in cart: ${importName}`));
463
- }
464
- let selectedChunk = availableChunks.includes("CODE") ? "CODE" : "CODE_COMPRESSED";
465
- if (chunkSpec) {
466
- if (chunkSpec !== "CODE" && chunkSpec !== "CODE_COMPRESSED") {
467
- throw new Error(formatError(resolvedPath, lineNumber, `Only CODE or CODE_COMPRESSED chunk is supported for include`));
468
- }
469
- selectedChunk = chunkSpec;
470
- if (!availableChunks.includes(selectedChunk)) {
471
- throw new Error(formatError(resolvedPath, lineNumber, `Requested chunk ${selectedChunk} not available in import`));
472
- }
536
+ state.diagnostics.cartridgeCodeIncludes++;
537
+ const importSource = await state.resolveImportSource(importName);
538
+ if (!importSource) {
539
+ throw new Error(formatError("<include>", lineNumber, `Import source not found: ${importName}`));
473
540
  }
474
- else if (availableChunks.length > 1) {
475
- throw new Error(formatError(resolvedPath, lineNumber, `Import ${importName} contains multiple chunks. Specify :CODE explicitly in include.`));
541
+ const resource = await (0, tic80CartImporter_1.importTic80Cart)(project, importDef, importSource);
542
+ for (const dependency of resource.getDependencyList()) {
543
+ state.dependencies.add(dependency.path);
476
544
  }
477
- const decoder = new TextDecoder("utf-8");
478
- let sourceBytes = null;
479
- if (selectedChunk === "CODE") {
480
- sourceBytes = (0, cartLoader_1.getCombinedCodeBytes)(cart);
481
- }
482
- else {
483
- const compressedChunk = cart.chunks.find((chunk) => chunk.chunkType === "CODE_COMPRESSED");
484
- sourceBytes = compressedChunk ? (0, cartLoader_1.decompressCodeBytes)(compressedChunk.data) : null;
545
+ let source;
546
+ let sourceName;
547
+ try {
548
+ const { chunkType, bank, data } = resource.selectSingleChunk(ref);
549
+ // if you really want to #include a non-CODE chunk, you need to explicitly specify the chunk
550
+ if (ref.chunks === undefined && chunkType !== "CODE" && chunkType !== "CODE_COMPRESSED") {
551
+ throw new Error("Specify a chunk type to include a data chunk as Lua source");
552
+ }
553
+ source = new TextDecoder("utf-8").decode(chunkType === "CODE_COMPRESSED" ? (0, cartLoader_1.decompressCodeBytes)(data) : data);
554
+ sourceName = `import:${importName}:${chunkType}:${bank}`;
485
555
  }
486
- if (!sourceBytes) {
487
- throw new Error(formatError(resolvedPath, lineNumber, `Requested chunk ${selectedChunk} not found in cart`));
556
+ catch (error) {
557
+ throw new Error(formatError(resource.cartPath, lineNumber, (0, errorHandling_1.getErrorMessage)(error)));
488
558
  }
489
- const source = decoder.decode(sourceBytes);
490
- const includeKey = makeIncludeKey(`${includeTarget}:${selectedChunk}`, overrides);
491
- const included = await processSource(project, source, `${includeTarget}:${selectedChunk}`, includeKey, state, overrides, false);
492
- return ensureTrailingNewline(included, `${includeTarget}:${selectedChunk}`);
559
+ const included = await processSource(project, source, (0, sourceMap_1.createIdentitySourceMap)(source, sourceName), sourceName, makeIncludeKey(sourceName, overrides), state, overrides, false);
560
+ return ensureTrailingNewline(included, sourceName);
493
561
  }
494
562
  throw new Error(formatError("<include>", lineNumber, `Unsupported import kind: ${importDef.kind}`));
495
563
  }
@@ -677,7 +745,7 @@ function ensureTrailingNewline(result, filePath) {
677
745
  const map = new sourceMap_1.SourceMapBuilder();
678
746
  map.appendMap(result.map);
679
747
  map.appendGenerated("\n", origin);
680
- return { code: result.code + "\n", map };
748
+ return { code: result.code + "\n", map, macroDefinitions: result.macroDefinitions };
681
749
  }
682
750
  function readLongBracketOpen(text, index) {
683
751
  if (text[index] !== "[") {
@@ -818,6 +886,7 @@ function parseMacroHeader(rest, filePath, lineNumber) {
818
886
  throw new Error(formatError(filePath, lineNumber, `Invalid --#macro syntax: ${rest}`));
819
887
  }
820
888
  const name = headerMatch[1];
889
+ const invocationStyle = headerMatch[2] === undefined ? "object" : "function";
821
890
  const paramList = headerMatch[3];
822
891
  const inlineBody = headerMatch[4];
823
892
  const params = paramList
@@ -829,21 +898,75 @@ function parseMacroHeader(rest, filePath, lineNumber) {
829
898
  const sanitizedInlineBody = inlineBody !== undefined ? stripLuaCommentsPreserveNewlines(inlineBody).trim() : undefined;
830
899
  return {
831
900
  name,
901
+ invocationStyle,
832
902
  params,
833
903
  inlineBody: sanitizedInlineBody,
834
904
  };
835
905
  }
906
+ function createMacroDefinition(header, body, sourceFile, lineNumber) {
907
+ const parsedBody = parseMacroBody(body, sourceFile, lineNumber);
908
+ if (header.invocationStyle === "object" && parsedBody.kind !== "expression") {
909
+ throw new Error(formatError(sourceFile, lineNumber, `Object-like macro ${header.name} must have exactly one Lua expression`));
910
+ }
911
+ return {
912
+ name: header.name,
913
+ invocationStyle: header.invocationStyle,
914
+ params: header.params,
915
+ body,
916
+ bodyKind: parsedBody.kind,
917
+ bodyAst: parsedBody.ast,
918
+ bodyRangeOffset: parsedBody.rangeOffset,
919
+ sourceFile,
920
+ lineNumber,
921
+ };
922
+ }
923
+ function parseMacroBody(body, filePath, lineNumber) {
924
+ if (body.trim().length === 0) {
925
+ return { kind: "empty", ast: null, rangeOffset: 0 };
926
+ }
927
+ const expressionPrefix = "return ";
928
+ try {
929
+ const expressionChunk = parseLuaChunkWithRanges(expressionPrefix + body);
930
+ if (expressionChunk.body.length === 1
931
+ && expressionChunk.body[0].type === "ReturnStatement"
932
+ && expressionChunk.body[0].arguments.length === 1) {
933
+ return {
934
+ kind: "expression",
935
+ ast: expressionChunk.body[0].arguments[0],
936
+ rangeOffset: expressionPrefix.length,
937
+ };
938
+ }
939
+ }
940
+ catch {
941
+ // A statement list is the other supported non-empty body form.
942
+ }
943
+ try {
944
+ return { kind: "statements", ast: parseLuaChunkWithRanges(body), rangeOffset: 0 };
945
+ }
946
+ catch (error) {
947
+ const message = (0, errorHandling_1.getErrorMessage)(error);
948
+ throw new Error(formatError(filePath, lineNumber, `Failed to parse macro body: ${message}`));
949
+ }
950
+ }
951
+ function parseLuaChunkWithRanges(code) {
952
+ return luaparse.parse(code, {
953
+ luaVersion: "5.3",
954
+ comments: true,
955
+ locations: true,
956
+ ranges: true,
957
+ });
958
+ }
836
959
  function readMacroBody(lines, startIndex, filePath, lineNumber) {
837
960
  const bodyLines = [];
838
961
  for (let i = startIndex; i < lines.length; i++) {
839
962
  const line = lines[i];
840
963
  // check for --#endmacro
841
- const match = line.match(/^\s*--#\s*(\w+)\s*(.*)$/);
964
+ const match = (0, luaPreprocessorSyntax_1.parseLuaPreprocessorDirective)(line);
842
965
  if (match) {
843
- if (match[1] === "endmacro") {
966
+ if (match.name === "endmacro") {
844
967
  return { body: bodyLines.join("\n"), endIndex: i };
845
968
  }
846
- if (match[1] === "macro") {
969
+ if (match.name === "macro") {
847
970
  throw new Error(formatError(filePath, lineNumber, `Nested --#macro is not supported`));
848
971
  }
849
972
  }
@@ -851,66 +974,182 @@ function readMacroBody(lines, startIndex, filePath, lineNumber) {
851
974
  }
852
975
  throw new Error(formatError(filePath, lineNumber, `Unclosed --#macro block`));
853
976
  }
854
- function expandMacros(project, result, macros, filePath) {
855
- if (macros.size === 0) {
856
- return result;
857
- }
858
- let current = result;
859
- const maxPasses = 25;
860
- for (let pass = 0; pass < maxPasses; pass++) {
861
- const passResult = applyMacroPass(project, current, macros, filePath);
862
- if (!passResult.changed) {
863
- return current;
977
+ function expandMacros(result, filePath, parentScope) {
978
+ return (0, traceProfiler_1.profileSync)(parentScope, "Expand Lua macros", {
979
+ category: "Lua preprocessing",
980
+ args: {
981
+ inputCharacters: result.code.length,
982
+ inputSourceMapSegments: result.map.getSegments().length,
983
+ macroDefinitions: result.macroDefinitions.length,
984
+ },
985
+ }, (scope) => {
986
+ if (result.macroDefinitions.length === 0) {
987
+ scope?.setArgs({ passesAttempted: 0, expansionPasses: 0, replacements: 0 });
988
+ return result;
864
989
  }
865
- current = { code: passResult.code, map: passResult.map };
866
- }
867
- throw new Error(formatError(filePath, 1, `Macro expansion exceeded ${maxPasses} passes (possible recursion)`));
990
+ let current = result;
991
+ let passesAttempted = 0;
992
+ let expansionPasses = 0;
993
+ let replacementCount = 0;
994
+ const maxPasses = 25;
995
+ for (let pass = 0; pass < maxPasses; pass++) {
996
+ const passResult = (0, traceProfiler_1.profileSync)(scope, "Lua macro expansion pass", {
997
+ category: "Lua preprocessing",
998
+ args: {
999
+ pass: pass + 1,
1000
+ inputCharacters: current.code.length,
1001
+ inputSourceMapSegments: current.map.getSegments().length,
1002
+ },
1003
+ }, (passScope) => {
1004
+ const expanded = applyMacroPass(current, filePath, passScope);
1005
+ passScope?.setArgs({
1006
+ changed: expanded.changed,
1007
+ replacements: expanded.replacementCount,
1008
+ outputCharacters: expanded.code.length,
1009
+ outputSourceMapSegments: expanded.map.getSegments().length,
1010
+ });
1011
+ return expanded;
1012
+ });
1013
+ passesAttempted++;
1014
+ replacementCount += passResult.replacementCount;
1015
+ if (!passResult.changed) {
1016
+ scope?.setArgs({
1017
+ passesAttempted,
1018
+ expansionPasses,
1019
+ replacements: replacementCount,
1020
+ outputCharacters: current.code.length,
1021
+ outputSourceMapSegments: current.map.getSegments().length,
1022
+ });
1023
+ return current;
1024
+ }
1025
+ expansionPasses++;
1026
+ current = {
1027
+ code: passResult.code,
1028
+ map: passResult.map,
1029
+ macroDefinitions: passResult.macroDefinitions,
1030
+ };
1031
+ }
1032
+ scope?.setArgs({
1033
+ passesAttempted,
1034
+ expansionPasses,
1035
+ replacements: replacementCount,
1036
+ outputCharacters: current.code.length,
1037
+ outputSourceMapSegments: current.map.getSegments().length,
1038
+ });
1039
+ throw new Error(formatError(filePath, 1, `Macro expansion exceeded ${maxPasses} passes (possible recursion)`));
1040
+ });
868
1041
  }
869
- function applyMacroPass(project, result, macros, filePath) {
870
- const chunk = (0, lua_processor_1.parseLua)(result.code);
1042
+ function applyMacroPass(result, filePath, parentScope) {
1043
+ const chunk = (0, traceProfiler_1.profileSync)(parentScope, "Parse Lua for macro expansion", {
1044
+ category: "Lua preprocessing",
1045
+ args: { inputCharacters: result.code.length },
1046
+ }, () => parseLuaForMacroExpansion(result.code, filePath));
871
1047
  const replacements = [];
872
- walkLuaAst(chunk, (node, parent) => {
873
- if (node.type !== "CallExpression") {
874
- return;
875
- }
876
- const callNode = node;
877
- if (callNode.base.type !== "Identifier") {
878
- return;
879
- }
880
- const macroDef = macros.get(callNode.base.name);
881
- if (!macroDef) {
882
- return;
883
- }
884
- const range = getRange(callNode, filePath);
885
- const lineNumber = getLineNumber(callNode, 1);
886
- const args = callNode.arguments || [];
887
- if (args.length !== macroDef.params.length) {
888
- throw new Error(formatError(filePath, lineNumber, `Macro ${macroDef.name} expects ${macroDef.params.length} args but got ${args.length}`));
1048
+ let identifierNodes = 0;
1049
+ let callExpressionNodes = 0;
1050
+ let definitionLookups = 0;
1051
+ const filtered = (0, traceProfiler_1.profileSync)(parentScope, "Find Lua macro expansions", {
1052
+ category: "Lua preprocessing",
1053
+ args: { macroDefinitions: result.macroDefinitions.length },
1054
+ }, (scope) => {
1055
+ walkLuaAst(chunk, (node, parent) => {
1056
+ if (node.type === "Identifier") {
1057
+ identifierNodes++;
1058
+ if (isIdentifierKeyPosition(node, parent)) {
1059
+ return;
1060
+ }
1061
+ const range = getRange(node, filePath);
1062
+ definitionLookups++;
1063
+ const macroDef = findMacroDefinitionAtOffset(result.macroDefinitions, node.name, range[0]);
1064
+ if (!macroDef || macroDef.invocationStyle !== "object") {
1065
+ return;
1066
+ }
1067
+ replacements.push({
1068
+ start: range[0],
1069
+ end: range[1],
1070
+ text: expandMacroBody(macroDef, []),
1071
+ });
1072
+ return;
1073
+ }
1074
+ if (node.type !== "CallExpression") {
1075
+ return;
1076
+ }
1077
+ callExpressionNodes++;
1078
+ const callNode = node;
1079
+ if (callNode.base.type !== "Identifier") {
1080
+ return;
1081
+ }
1082
+ const range = getRange(callNode, filePath);
1083
+ definitionLookups++;
1084
+ const macroDef = findMacroDefinitionAtOffset(result.macroDefinitions, callNode.base.name, range[0]);
1085
+ if (!macroDef || macroDef.invocationStyle !== "function") {
1086
+ return;
1087
+ }
1088
+ const lineNumber = getLineNumber(callNode, 1);
1089
+ if (macroDef.bodyKind !== "expression" && parent?.type !== "CallStatement") {
1090
+ const bodyLabel = macroDef.bodyKind === "empty" ? "Empty" : "Statement-list";
1091
+ throw new Error(formatError(filePath, lineNumber, `${bodyLabel} macro ${macroDef.name} can only be used as a standalone call statement`));
1092
+ }
1093
+ const args = callNode.arguments || [];
1094
+ if (args.length !== macroDef.params.length) {
1095
+ throw new Error(formatError(filePath, lineNumber, `Macro ${macroDef.name} expects ${macroDef.params.length} args but got ${args.length}`));
1096
+ }
1097
+ const argTexts = args.map((arg) => stripLuaCommentsPreserveNewlines(sliceRange(result.code, getRange(arg, filePath))));
1098
+ const expanded = expandMacroBody(macroDef, argTexts);
1099
+ replacements.push({ start: range[0], end: range[1], text: expanded });
1100
+ });
1101
+ const sortedByStart = [...replacements].sort((a, b) => a.start - b.start || b.end - a.end);
1102
+ // filter out nested replacements; only keep outermost
1103
+ // this prevents overlapping edits
1104
+ const nonOverlapping = [];
1105
+ let currentOuter = null;
1106
+ for (const rep of sortedByStart) {
1107
+ if (currentOuter && rep.start >= currentOuter.start && rep.end <= currentOuter.end) {
1108
+ continue;
1109
+ }
1110
+ nonOverlapping.push(rep);
1111
+ currentOuter = rep;
889
1112
  }
890
- const argTexts = args.map((arg) => stripLuaCommentsPreserveNewlines(sliceRange(result.code, getRange(arg, filePath))));
891
- const expanded = expandMacroBody(project, macroDef, argTexts, filePath, lineNumber);
892
- replacements.push({ start: range[0], end: range[1], text: expanded });
1113
+ scope?.setArgs({
1114
+ identifierNodes,
1115
+ callExpressionNodes,
1116
+ definitionLookups,
1117
+ replacementsFound: replacements.length,
1118
+ replacementsApplied: nonOverlapping.length,
1119
+ });
1120
+ return nonOverlapping;
893
1121
  });
894
- if (replacements.length === 0) {
895
- return { code: result.code, map: result.map, changed: false };
896
- }
897
- const sortedByStart = [...replacements].sort((a, b) => a.start - b.start || b.end - a.end);
898
- // filter out nested replacements; only keep outermost
899
- // this prevents overlapping edits
900
- const filtered = [];
901
- let currentOuter = null;
902
- for (const rep of sortedByStart) {
903
- if (currentOuter && rep.start >= currentOuter.start && rep.end <= currentOuter.end) {
904
- continue;
905
- }
906
- filtered.push(rep);
907
- currentOuter = rep;
1122
+ if (filtered.length === 0) {
1123
+ return { ...result, changed: false, replacementCount: 0 };
908
1124
  }
909
1125
  const sorted = filtered.sort((a, b) => b.start - a.start);
910
- const updated = applyReplacementsWithMap(result, sorted, filePath);
911
- return { code: updated.code, map: updated.map, changed: true };
1126
+ const updated = applyReplacementsWithMap(result, sorted, filePath, parentScope);
1127
+ return { ...updated, changed: true, replacementCount: sorted.length };
1128
+ }
1129
+ function parseLuaForMacroExpansion(code, filePath) {
1130
+ try {
1131
+ return parseLuaChunkWithRanges(code);
1132
+ }
1133
+ catch (error) {
1134
+ const errorWithLine = error;
1135
+ const lineNumber = typeof errorWithLine.line === "number" ? errorWithLine.line : 1;
1136
+ const message = (0, errorHandling_1.getErrorMessage)(error);
1137
+ throw new Error(formatError(filePath, lineNumber, `Failed to parse Lua while expanding macros: ${message}`));
1138
+ }
912
1139
  }
913
- function expandMacroBody(project, macro, argTexts, filePath, lineNumber) {
1140
+ function findMacroDefinitionAtOffset(events, name, invocationOffset) {
1141
+ let found;
1142
+ for (const event of events) {
1143
+ if (event.offset > invocationOffset) {
1144
+ break;
1145
+ }
1146
+ if (event.definition.name === name) {
1147
+ found = event.definition;
1148
+ }
1149
+ }
1150
+ return found;
1151
+ }
1152
+ function expandMacroBody(macro, argTexts) {
914
1153
  const wrappedBody = wrapMacroBody(macro.body);
915
1154
  if (wrappedBody.length === 0) {
916
1155
  // empty macro bodies should be explicitly supported for things like ASSERT or NOP-like macros.
@@ -919,10 +1158,11 @@ function expandMacroBody(project, macro, argTexts, filePath, lineNumber) {
919
1158
  if (macro.params.length === 0) {
920
1159
  return wrappedBody;
921
1160
  }
922
- const parsed = parseExpressionWithRanges(macro.body, macro.sourceFile, macro.lineNumber);
923
- const offset = "return ".length;
1161
+ if (!macro.bodyAst) {
1162
+ throw new Error(formatError(macro.sourceFile, macro.lineNumber, `Macro ${macro.name} has no parsed body`));
1163
+ }
924
1164
  const replacements = [];
925
- walkLuaAst(parsed, (node, parent) => {
1165
+ walkLuaAst(macro.bodyAst, (node, parent) => {
926
1166
  if (node.type !== "Identifier") {
927
1167
  return;
928
1168
  }
@@ -935,8 +1175,8 @@ function expandMacroBody(project, macro, argTexts, filePath, lineNumber) {
935
1175
  }
936
1176
  const range = getRange(node, macro.sourceFile);
937
1177
  replacements.push({
938
- start: range[0] - offset,
939
- end: range[1] - offset,
1178
+ start: range[0] - macro.bodyRangeOffset,
1179
+ end: range[1] - macro.bodyRangeOffset,
940
1180
  // #14 we don't need overly aggressive parens, but here's where you'd put it if you wanted to (also see other #14 instances)
941
1181
  text: `${argTexts[index]}`,
942
1182
  });
@@ -959,10 +1199,26 @@ function wrapMacroBody(body) {
959
1199
  // #14 we don't need overly aggressive parens, but here's where you'd put it if you wanted to (also see other #14 instances)
960
1200
  return `${trimmed}`;
961
1201
  }
962
- async function expandPreprocessorCalls(project, result, filePath, state) {
963
- const chunk = (0, lua_processor_1.parseLua)(result.code);
1202
+ async function expandPreprocessorCalls(project, result, filePath, state, quietParseFailures, parentScope) {
1203
+ return (0, traceProfiler_1.profileAsync)(parentScope, "Expand Lua preprocessor calls", {
1204
+ category: "Lua preprocessing",
1205
+ args: {
1206
+ inputCharacters: result.code.length,
1207
+ inputSourceMapSegments: result.map.getSegments().length,
1208
+ },
1209
+ }, (scope) => expandPreprocessorCallsCore(project, result, filePath, state, quietParseFailures, scope));
1210
+ }
1211
+ async function expandPreprocessorCallsCore(project, result, filePath, state, quietParseFailures, parentScope) {
1212
+ const chunk = (0, traceProfiler_1.profileSync)(parentScope, "Parse Lua for preprocessor calls", {
1213
+ category: "Lua preprocessing",
1214
+ args: { inputCharacters: result.code.length },
1215
+ }, () => (quietParseFailures ? (0, lua_processor_1.parseLuaQuiet)(result.code) : (0, lua_processor_1.parseLua)(result.code)));
964
1216
  const replacements = [];
965
1217
  const tasks = [];
1218
+ let callExpressionNodes = 0;
1219
+ let expandCalls = 0;
1220
+ let importCalls = 0;
1221
+ let encodeCalls = 0;
966
1222
  const addReplacement = (node, text) => {
967
1223
  const range = getRange(node, filePath);
968
1224
  replacements.push({ start: range[0], end: range[1], text });
@@ -1004,16 +1260,18 @@ async function expandPreprocessorCalls(project, result, filePath, state) {
1004
1260
  }
1005
1261
  return importDef;
1006
1262
  };
1007
- walkLuaAst(chunk, (node) => {
1263
+ const visitCall = (node) => {
1008
1264
  if (node.type !== "CallExpression") {
1009
1265
  return;
1010
1266
  }
1267
+ callExpressionNodes++;
1011
1268
  const callNode = node;
1012
1269
  if (callNode.base.type !== "Identifier") {
1013
1270
  return;
1014
1271
  }
1015
1272
  const fnName = callNode.base.name;
1016
1273
  if (fnName === "__EXPAND") {
1274
+ expandCalls++;
1017
1275
  tasks.push((async () => {
1018
1276
  const lineNumber = getLineNumber(callNode, 1);
1019
1277
  if (callNode.arguments.length !== 1) {
@@ -1027,6 +1285,7 @@ async function expandPreprocessorCalls(project, result, filePath, state) {
1027
1285
  return;
1028
1286
  }
1029
1287
  if (fnName === "__IMPORT") {
1288
+ importCalls++;
1030
1289
  tasks.push((async () => {
1031
1290
  const lineNumber = getLineNumber(callNode, 1);
1032
1291
  if (callNode.arguments.length !== 2) {
@@ -1038,12 +1297,16 @@ async function expandPreprocessorCalls(project, result, filePath, state) {
1038
1297
  if (!importSpec.startsWith("import:")) {
1039
1298
  throw new Error(formatError(filePath, lineNumber, `__IMPORT requires an import reference`));
1040
1299
  }
1041
- const ref = (0, importUtils_1.parseImportReference)(importSpec);
1042
- const importDef = resolveImportDefinition(ref.importName, lineNumber);
1300
+ const ref = (0, importReference_1.parseImportReference)(importSpec);
1301
+ const importDef = resolveImportDefinition(ref.import, lineNumber);
1043
1302
  const pipelineSpec = project.substituteVariables(pipelineArg.value);
1044
1303
  const split = (0, luaEncode_1.splitPipelineSpec)(pipelineSpec, true, filePath, lineNumber, formatError);
1045
1304
  const resolvedSourceSpec = (0, luaEncode_1.normalizeEmptySpec)(project.substituteVariables(split.sourceSpecRaw || ""));
1046
- const bytes = await (0, luaEncode_1.resolveImportBytes)(project, importDef, resolvedSourceSpec, ref.chunkSpec, (dep) => state.dependencies.add(dep), filePath, lineNumber, formatError);
1305
+ const importSource = await state.resolveImportSource(ref.import);
1306
+ if (!importSource) {
1307
+ throw new Error(formatError(filePath, lineNumber, `Import source not found: ${ref.import}`));
1308
+ }
1309
+ const bytes = await (0, luaEncode_1.resolveImportBytes)(project, importDef, importSource, resolvedSourceSpec, ref, (dep) => state.dependencies.add(dep), filePath, lineNumber, formatError);
1047
1310
  const destSpec = project.substituteVariables(split.destSpecRaw);
1048
1311
  const output = (0, luaEncode_1.encodeBytesWithDestSpec)(bytes, destSpec, filePath, lineNumber, formatError);
1049
1312
  addReplacement(callNode, output);
@@ -1051,6 +1314,7 @@ async function expandPreprocessorCalls(project, result, filePath, state) {
1051
1314
  return;
1052
1315
  }
1053
1316
  if (fnName === "__ENCODE") {
1317
+ encodeCalls++;
1054
1318
  tasks.push((async () => {
1055
1319
  const lineNumber = getLineNumber(callNode, 1);
1056
1320
  if (callNode.arguments.length !== 2) {
@@ -1072,25 +1336,131 @@ async function expandPreprocessorCalls(project, result, filePath, state) {
1072
1336
  addReplacement(callNode, output);
1073
1337
  })());
1074
1338
  }
1339
+ };
1340
+ (0, traceProfiler_1.profileSync)(parentScope, "Find Lua preprocessor calls", { category: "Lua preprocessing" }, (scope) => {
1341
+ walkLuaAst(chunk, visitCall);
1342
+ scope?.setArgs({
1343
+ callExpressionNodes,
1344
+ preprocessorCalls: expandCalls + importCalls + encodeCalls,
1345
+ expandCalls,
1346
+ importCalls,
1347
+ encodeCalls,
1348
+ });
1075
1349
  });
1076
1350
  if (tasks.length === 0) {
1351
+ parentScope?.setArgs({
1352
+ callExpressionNodes,
1353
+ preprocessorCalls: 0,
1354
+ expandCalls: 0,
1355
+ importCalls: 0,
1356
+ encodeCalls: 0,
1357
+ replacements: 0,
1358
+ outputCharacters: result.code.length,
1359
+ outputSourceMapSegments: result.map.getSegments().length,
1360
+ });
1077
1361
  return result;
1078
1362
  }
1079
- await Promise.all(tasks);
1363
+ await (0, traceProfiler_1.profileAsync)(parentScope, "Complete Lua preprocessor calls", {
1364
+ category: "Lua preprocessing",
1365
+ args: { preprocessorCalls: tasks.length },
1366
+ }, async (scope) => {
1367
+ await Promise.all(tasks);
1368
+ scope?.setArgs({ replacements: replacements.length });
1369
+ });
1080
1370
  if (replacements.length === 0) {
1371
+ parentScope?.setArgs({
1372
+ callExpressionNodes,
1373
+ preprocessorCalls: expandCalls + importCalls + encodeCalls,
1374
+ expandCalls,
1375
+ importCalls,
1376
+ encodeCalls,
1377
+ replacements: 0,
1378
+ outputCharacters: result.code.length,
1379
+ outputSourceMapSegments: result.map.getSegments().length,
1380
+ });
1081
1381
  return result;
1082
1382
  }
1083
1383
  const sorted = replacements.sort((a, b) => b.start - a.start);
1084
- return applyReplacementsWithMap(result, sorted, filePath);
1384
+ const updated = applyReplacementsWithMap(result, sorted, filePath, parentScope);
1385
+ parentScope?.setArgs({
1386
+ callExpressionNodes,
1387
+ preprocessorCalls: expandCalls + importCalls + encodeCalls,
1388
+ expandCalls,
1389
+ importCalls,
1390
+ encodeCalls,
1391
+ replacements: replacements.length,
1392
+ outputCharacters: updated.code.length,
1393
+ outputSourceMapSegments: updated.map.getSegments().length,
1394
+ });
1395
+ return updated;
1085
1396
  }
1086
- function applyReplacementsWithMap(result, replacements, filePath) {
1087
- let out = result.code;
1088
- for (const rep of replacements) {
1089
- out = out.slice(0, rep.start) + rep.text + out.slice(rep.end);
1090
- const origin = result.map.mapOffset(rep.start) ?? { file: filePath, offset: 0 };
1091
- result.map.spliceRange(rep.start, rep.end, rep.text.length, origin);
1397
+ function applyReplacementsWithMap(result, replacements, filePath, parentScope) {
1398
+ return (0, traceProfiler_1.profileSync)(parentScope, "Apply Lua replacements", {
1399
+ category: "Lua preprocessing",
1400
+ args: {
1401
+ replacements: replacements.length,
1402
+ inputCharacters: result.code.length,
1403
+ inputSourceMapSegments: result.map.getSegments().length,
1404
+ macroDefinitions: result.macroDefinitions.length,
1405
+ replacedCharacters: replacements.reduce((total, rep) => total + rep.end - rep.start, 0),
1406
+ insertedCharacters: replacements.reduce((total, rep) => total + rep.text.length, 0),
1407
+ },
1408
+ }, (scope) => {
1409
+ // original implementation was inefficient:
1410
+ // for each replacement,
1411
+ // {
1412
+ // perform the replacement via (slice begin + text + slice end)
1413
+ // update the source map via mapOffset and result.map.spliceRange()
1414
+ // -> spliceRange visits every segment to update offsets
1415
+ // so every segment is just getting pushed and pushed over and over again.
1416
+ // more efficient to build a map of all replacements, and apply in one sweep.
1417
+ // }
1418
+ const ascending = [...replacements].sort((a, b) => a.start - b.start || a.end - b.end);
1419
+ // build list of origins
1420
+ const mappedReplacements = ascending.map((replacement) => ({
1421
+ start: replacement.start,
1422
+ end: replacement.end,
1423
+ newLength: replacement.text.length,
1424
+ origin: result.map.mapOffset(replacement.start, "right") ?? { file: filePath, offset: 0 },
1425
+ }));
1426
+ // apply replacements in one go, building the output string in a stream of chunks
1427
+ const outputParts = [];
1428
+ let sourceCursor = 0;
1429
+ for (const replacement of ascending) {
1430
+ outputParts.push(result.code.slice(sourceCursor, replacement.start), replacement.text);
1431
+ sourceCursor = replacement.end;
1432
+ }
1433
+ outputParts.push(result.code.slice(sourceCursor));
1434
+ const out = outputParts.join("");
1435
+ // update the map also in one go using all the mapped replacements
1436
+ result.map.spliceRanges(mappedReplacements);
1437
+ // update macro definition offsets based on the replacements
1438
+ const descending = [...ascending].reverse();
1439
+ const macroDefinitions = result.macroDefinitions.map((event) => {
1440
+ let offset = event.offset;
1441
+ for (const replacement of descending) {
1442
+ offset = mapOffsetThroughReplacement(offset, replacement.start, replacement.end, replacement.text.length);
1443
+ }
1444
+ return {
1445
+ offset,
1446
+ definition: event.definition,
1447
+ };
1448
+ });
1449
+ scope?.setArgs({
1450
+ outputCharacters: out.length,
1451
+ outputSourceMapSegments: result.map.getSegments().length,
1452
+ });
1453
+ return { code: out, map: result.map, macroDefinitions };
1454
+ });
1455
+ }
1456
+ function mapOffsetThroughReplacement(offset, start, end, replacementLength) {
1457
+ if (offset <= start) {
1458
+ return offset;
1459
+ }
1460
+ if (offset >= end) {
1461
+ return offset + replacementLength - (end - start);
1092
1462
  }
1093
- return { code: out, map: result.map };
1463
+ return start + replacementLength;
1094
1464
  }
1095
1465
  function splitLinesWithOffsets(source) {
1096
1466
  const lines = [];
@@ -1128,23 +1498,6 @@ function findMacroNameOffset(line, lineStartOffset, name) {
1128
1498
  }
1129
1499
  return lineStartOffset + index;
1130
1500
  }
1131
- function parseExpressionWithRanges(body, filePath, lineNumber) {
1132
- try {
1133
- const chunk = (0, lua_processor_1.parseLua)(`return ${body}`);
1134
- if (chunk.body.length === 0 || chunk.body[0].type !== "ReturnStatement") {
1135
- throw new Error("Invalid expression");
1136
- }
1137
- const returnStmt = chunk.body[0];
1138
- if (returnStmt.arguments.length !== 1) {
1139
- throw new Error("Expected single expression");
1140
- }
1141
- return returnStmt.arguments[0];
1142
- }
1143
- catch (error) {
1144
- const message = error instanceof Error ? error.message : String(error);
1145
- throw new Error(formatError(filePath, lineNumber, `Failed to parse macro body: ${message}`));
1146
- }
1147
- }
1148
1501
  function getRange(node, filePath) {
1149
1502
  const withRange = node;
1150
1503
  if (!withRange.range) {
@@ -1191,10 +1544,6 @@ function isIdentifierKeyPosition(node, parent) {
1191
1544
  const tableKey = parent;
1192
1545
  return tableKey.key === node;
1193
1546
  }
1194
- if (parent.type === "TableKey") {
1195
- const tableKey = parent;
1196
- return tableKey.key === node;
1197
- }
1198
1547
  if (parent.type === "MemberExpression") {
1199
1548
  const member = parent;
1200
1549
  return member.identifier === node;