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,1143 +33,43 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.LuaPrinter = void 0;
37
- exports.unparseLua = unparseLua;
36
+ exports.unparseLua = exports.LuaPrinter = void 0;
37
+ exports.parseLuaQuiet = parseLuaQuiet;
38
38
  exports.parseLua = parseLua;
39
39
  exports.processLuaWithReport = processLuaWithReport;
40
40
  exports.processLua = processLua;
41
41
  const luaparse = __importStar(require("luaparse"));
42
- const lua_renamer_1 = require("./lua_renamer");
43
- const lua_alias_literals_1 = require("./lua_alias_literals");
44
- const lua_alias_expressions_1 = require("./lua_alias_expressions");
45
42
  const lua_alias_shared_1 = require("./lua_alias_shared");
46
- const lua_pack_locals_1 = require("./lua_pack_locals");
47
- const lua_simplify_1 = require("./lua_simplify");
48
- const lua_remove_unused_locals_1 = require("./lua_remove_unused_locals");
49
- const lua_remove_unused_functions_1 = require("./lua_remove_unused_functions");
50
- const lua_rename_table_fields_1 = require("./lua_rename_table_fields");
51
- const lua_rename_allowed_table_keys_1 = require("./lua_rename_allowed_table_keys");
52
- const lua_rename_allowed_globals_1 = require("./lua_rename_allowed_globals");
53
43
  const lua_fundamentals_1 = require("./lua_fundamentals");
54
- // Precedence tables, low → high
55
- const LOGICAL_PRECEDENCE = {
56
- or: 1,
57
- and: 2,
58
- };
59
- const BINARY_PRECEDENCE = {
60
- "<": 3,
61
- ">": 3,
62
- "<=": 3,
63
- ">=": 3,
64
- "~=": 3,
65
- "==": 3,
66
- "|": 4,
67
- "~": 5,
68
- "&": 6,
69
- "<<": 7,
70
- ">>": 7,
71
- "..": 8, // right associative
72
- "+": 9,
73
- "-": 9,
74
- "*": 10,
75
- "/": 10,
76
- "//": 10,
77
- "%": 10,
78
- };
79
- const UNARY_PRECEDENCE = 11; // not, #, -, ~
80
- const POW_PRECEDENCE = 12; // ^
81
- function getPrecedence(node) {
82
- switch (node.type) {
83
- case "LogicalExpression":
84
- return LOGICAL_PRECEDENCE[node.operator];
85
- case "BinaryExpression": {
86
- const op = node.operator;
87
- if (op === "^")
88
- return POW_PRECEDENCE;
89
- return BINARY_PRECEDENCE[op];
90
- }
91
- case "UnaryExpression":
92
- return UNARY_PRECEDENCE;
93
- default:
94
- // Primary expressions (literals, identifiers, calls, table ctors, etc.)
95
- return 100;
96
- }
44
+ const lua_ast_provenance_1 = require("./lua_ast_provenance");
45
+ const lua_optimizer_1 = require("./lua_optimizer");
46
+ const lua_print_trace_1 = require("./lua_print_trace");
47
+ const lua_printer_1 = require("./lua_printer");
48
+ Object.defineProperty(exports, "unparseLua", { enumerable: true, get: function () { return lua_printer_1.unparseLua; } });
49
+ const traceProfiler_1 = require("../traceProfiler");
50
+ const lua_transform_map_1 = require("./lua_transform_map");
51
+ var lua_printer_2 = require("./lua_printer");
52
+ Object.defineProperty(exports, "LuaPrinter", { enumerable: true, get: function () { return lua_printer_2.LuaPrinter; } });
53
+ function parseLuaOrThrow(code) {
54
+ return luaparse.parse(code, {
55
+ luaVersion: "5.3", // TIC-80 is 5.3-ish
56
+ comments: true,
57
+ locations: true,
58
+ ranges: true,
59
+ });
97
60
  }
98
- class LuaPrinter {
99
- constructor(options, blockComments) {
100
- this.buf = [];
101
- this.indentLevel = 0;
102
- this.indentUnit = " "; // only used if !minified
103
- this.currentLine = "";
104
- this.inlineMode = false; // When true, render everything on single lines without packing
105
- this.options = options;
106
- this.blockComments = blockComments || new Map();
107
- }
108
- print(chunk) {
109
- const mode = this.options.lineBehavior || "pretty";
110
- // For tight mode, use the token-stream approach
111
- if (mode === "tight") {
112
- return this.printTightMode(chunk);
113
- }
114
- // For pretty and single-line-blocks, use structured approach
115
- this.buf = [];
116
- this.currentLine = "";
117
- this.indentLevel = 0;
118
- this.printBlock(chunk.body);
119
- if (this.currentLine.length > 0)
120
- this.flushLine();
121
- return this.buf.join("");
122
- }
123
- // ===== TIGHT MODE: Token-stream based packing =====
124
- // Renders everything to space-separated tokens, then packs into lines
125
- printTightMode(chunk) {
126
- const tokens = this.collectTokens(chunk.body);
127
- return this.packTokensIntoLines(tokens);
128
- }
129
- // Collect all tokens from a block of statements
130
- collectTokens(body) {
131
- const comments = [...(this.blockComments.get(body) || [])];
132
- const items = [];
133
- let ci = 0;
134
- for (const stmt of body) {
135
- while (ci < comments.length && this.startPos(comments[ci]) <= this.startPos(stmt)) {
136
- items.push(comments[ci]);
137
- ci++;
138
- }
139
- items.push(stmt);
140
- }
141
- while (ci < comments.length) {
142
- items.push(comments[ci]);
143
- ci++;
144
- }
145
- const tokens = [];
146
- for (const node of items) {
147
- if (node.type === "Comment") {
148
- // Comments get special handling - they force a line break
149
- tokens.push("\n" + this.renderComment(node));
150
- }
151
- else {
152
- const stmtTokens = this.statementToTokens(node);
153
- tokens.push(...stmtTokens);
154
- }
155
- }
156
- return tokens;
157
- }
158
- // Convert a statement to tokens (space-separated pieces)
159
- // For maximum packing flexibility, we separate keywords from their arguments
160
- statementToTokens(stmt) {
161
- const tokens = [];
162
- switch (stmt.type) {
163
- case "AssignmentStatement": {
164
- const st = stmt;
165
- const vars = st.variables.map((v) => this.expr(v)).join(",");
166
- const vals = st.init.map((v) => this.expr(v)).join(",");
167
- tokens.push(vars + "=" + vals);
168
- break;
169
- }
170
- case "LocalStatement": {
171
- const st = stmt;
172
- const vars = st.variables.map((v) => this.expr(v)).join(",");
173
- let s = "local " + vars;
174
- if (st.init && st.init.length > 0) {
175
- s += "=" + st.init.map((v) => this.expr(v)).join(",");
176
- }
177
- tokens.push(s);
178
- break;
179
- }
180
- case "CallStatement": {
181
- const st = stmt;
182
- tokens.push(this.expr(st.expression));
183
- break;
184
- }
185
- case "ReturnStatement": {
186
- const st = stmt;
187
- if (st.arguments.length > 0) {
188
- // Keep return with all its comma-separated arguments as one token
189
- // to preserve required commas between multiple return values
190
- tokens.push("return " + st.arguments.map((a) => this.expr(a)).join(","));
191
- }
192
- else {
193
- tokens.push("return");
194
- }
195
- break;
196
- }
197
- case "BreakStatement":
198
- tokens.push("break");
199
- break;
200
- case "FunctionDeclaration": {
201
- const fn = stmt;
202
- let s = fn.isLocal ? "local function " : "function ";
203
- if (fn.identifier) {
204
- s += this.expr(fn.identifier);
205
- }
206
- s += "(" + fn.parameters.map((p) => this.expr(p)).join(",") + ")";
207
- tokens.push(s);
208
- tokens.push(...this.collectTokens(fn.body));
209
- tokens.push("end");
210
- break;
211
- }
212
- case "IfStatement": {
213
- const ifs = stmt;
214
- for (const clause of ifs.clauses) {
215
- if (clause.type === "IfClause") {
216
- tokens.push("if " + this.expr(clause.condition) + " then");
217
- }
218
- else if (clause.type === "ElseifClause") {
219
- tokens.push("elseif " + this.expr(clause.condition) + " then");
220
- }
221
- else {
222
- tokens.push("else");
223
- }
224
- tokens.push(...this.collectTokens(clause.body));
225
- }
226
- tokens.push("end");
227
- break;
228
- }
229
- case "WhileStatement": {
230
- const st = stmt;
231
- tokens.push("while " + this.expr(st.condition) + " do");
232
- tokens.push(...this.collectTokens(st.body));
233
- tokens.push("end");
234
- break;
235
- }
236
- case "RepeatStatement": {
237
- const st = stmt;
238
- tokens.push("repeat");
239
- tokens.push(...this.collectTokens(st.body));
240
- tokens.push("until " + this.expr(st.condition));
241
- break;
242
- }
243
- case "ForNumericStatement": {
244
- const st = stmt;
245
- let s = "for " + this.expr(st.variable) + "=" + this.expr(st.start) + "," + this.expr(st.end);
246
- if (st.step) {
247
- s += "," + this.expr(st.step);
248
- }
249
- s += " do";
250
- tokens.push(s);
251
- tokens.push(...this.collectTokens(st.body));
252
- tokens.push("end");
253
- break;
254
- }
255
- case "ForGenericStatement": {
256
- const st = stmt;
257
- const vars = st.variables.map((v) => this.expr(v)).join(",");
258
- const iters = st.iterators.map((it) => this.expr(it)).join(",");
259
- tokens.push("for " + vars + " in " + iters + " do");
260
- tokens.push(...this.collectTokens(st.body));
261
- tokens.push("end");
262
- break;
263
- }
264
- case "DoStatement": {
265
- const st = stmt;
266
- tokens.push("do");
267
- tokens.push(...this.collectTokens(st.body));
268
- tokens.push("end");
269
- break;
270
- }
271
- default:
272
- break;
273
- }
274
- return tokens;
275
- }
276
- // Pack tokens into lines respecting maxLineLength
277
- packTokensIntoLines(tokens) {
278
- const maxLen = this.options.maxLineLength || 120;
279
- const lines = [];
280
- let currentLine = "";
281
- for (const token of tokens) {
282
- // Special case: comment tokens start with \n and force a new line
283
- if (token.startsWith("\n")) {
284
- if (currentLine.length > 0) {
285
- lines.push(currentLine);
286
- currentLine = "";
287
- }
288
- lines.push(token.slice(1)); // Remove the leading \n marker
289
- continue;
290
- }
291
- if (currentLine.length === 0) {
292
- currentLine = token;
293
- }
294
- else {
295
- const candidate = currentLine + " " + token;
296
- // Use <= to allow filling lines up to exactly maxLen
297
- // EXCEPT: if the token is 'end', use < to prefer wrapping
298
- // This avoids packing 'end' to fill exactly maxLen
299
- const isEndToken = token === "end";
300
- const fits = isEndToken ? candidate.length < maxLen : candidate.length <= maxLen;
301
- if (fits) {
302
- currentLine = candidate;
303
- }
304
- else {
305
- lines.push(currentLine);
306
- currentLine = token;
307
- }
308
- }
309
- }
310
- if (currentLine.length > 0) {
311
- lines.push(currentLine);
312
- }
313
- return lines.join("\n") + (lines.length > 0 ? "\n" : "");
314
- }
315
- // Render a comment for tight mode
316
- renderComment(comment) {
317
- if (comment.raw) {
318
- return comment.raw.trim();
319
- }
320
- return "--" + comment.value;
321
- }
322
- // --- low-level emit helpers ---
323
- emit(s) {
324
- this.currentLine += s;
325
- }
326
- newline() {
327
- this.flushLine();
328
- }
329
- flushLine() {
330
- this.buf.push(this.currentLine + "\n");
331
- this.currentLine = "";
332
- }
333
- emitKeyword(s) {
334
- this.emit(s);
335
- }
336
- startPos(node) {
337
- if (node && Array.isArray(node.range) && node.range.length > 0) {
338
- return node.range[0];
339
- }
340
- return 0;
341
- }
342
- printIndent() {
343
- const indentLevel = Math.min(this.indentLevel, this.options.maxIndentLevel);
344
- this.buf.push(this.indentUnit.repeat(indentLevel));
345
- // if (!this.options.stripWhitespace) {
346
- // this.buf.push(this.indentUnit.repeat(this.indentLevel));
347
- // }
348
- }
349
- printBlock(body) {
350
- const comments = [...(this.blockComments.get(body) || [])];
351
- const items = [];
352
- let ci = 0;
353
- for (const stmt of body) {
354
- while (ci < comments.length && this.startPos(comments[ci]) <= this.startPos(stmt)) {
355
- items.push(comments[ci]);
356
- ci++;
357
- }
358
- items.push(stmt);
359
- }
360
- while (ci < comments.length) {
361
- items.push(comments[ci]);
362
- ci++;
363
- }
364
- const mode = this.options.lineBehavior || "pretty";
365
- const maxLen = this.options.maxLineLength || 120;
366
- // In inline mode, render all statements space-separated on one line (no newlines)
367
- if (this.inlineMode) {
368
- for (let i = 0; i < items.length; i++) {
369
- const node = items[i];
370
- if (i > 0)
371
- this.emit(" ");
372
- this.printStatementInline(node);
373
- }
374
- return;
375
- }
376
- // In pretty mode, print each statement on its own line
377
- if (mode === "pretty") {
378
- for (const node of items) {
379
- this.printIndent();
380
- this.printStatement(node);
381
- }
382
- return;
383
- }
384
- // single-line-blocks mode: blocks are either entirely single-line or multi-line
385
- // (tight mode is handled separately via printTightMode)
386
- const flushLineIfAny = () => {
387
- if (this.currentLine.length > 0)
388
- this.flushLine();
389
- };
390
- for (const node of items) {
391
- // Comments always get their own line
392
- if (node.type === "Comment") {
393
- flushLineIfAny();
394
- this.printIndent();
395
- this.printStatement(node);
396
- continue;
397
- }
398
- const stmt = node;
399
- const inline = this.renderInlineStatement(stmt, maxLen);
400
- const indent = this.indentUnit.repeat(Math.min(this.indentLevel, this.options.maxIndentLevel));
401
- // Check if inline version fits on its own line (with indent)
402
- const inlineWithIndent = inline !== null ? indent + inline : null;
403
- const inlineFits = inlineWithIndent !== null && inlineWithIndent.length < maxLen;
404
- if (inlineFits) {
405
- // Try to pack onto current line
406
- const sep = this.currentLine.length === 0 ? "" : " ";
407
- const prefix = this.currentLine.length === 0 ? indent : this.currentLine;
408
- const candidate = prefix + sep + inline;
409
- if (candidate.length < maxLen || this.currentLine.length === 0) {
410
- if (this.currentLine.length === 0) {
411
- this.currentLine = indent + inline;
412
- }
413
- else {
414
- this.currentLine = this.currentLine + " " + inline;
415
- }
416
- continue;
417
- }
418
- // Doesn't fit on current line, but inline exists - start new line with inline
419
- flushLineIfAny();
420
- this.currentLine = indent + inline;
421
- continue;
422
- }
423
- // Fallback to normal multi-line printing for this statement
424
- flushLineIfAny();
425
- this.printIndent();
426
- this.printStatement(node);
427
- }
428
- // Ensure any buffered inline statements inside this block are flushed before exiting it.
429
- flushLineIfAny();
430
- }
431
- // Print a statement without any newline at the end (for inline mode)
432
- printStatementInline(node) {
433
- switch (node.type) {
434
- case "AssignmentStatement": {
435
- const st = node;
436
- const vars = st.variables.map((v) => this.expr(v)).join(",");
437
- const vals = st.init.map((v) => this.expr(v)).join(",");
438
- this.emit(vars + "=" + vals);
439
- break;
440
- }
441
- case "LocalStatement": {
442
- const st = node;
443
- const vars = st.variables.map((v) => this.expr(v)).join(",");
444
- let s = "local " + vars;
445
- if (st.init && st.init.length > 0) {
446
- s += "=" + st.init.map((v) => this.expr(v)).join(",");
447
- }
448
- this.emit(s);
449
- break;
450
- }
451
- case "CallStatement": {
452
- const st = node;
453
- this.emit(this.expr(st.expression));
454
- break;
455
- }
456
- case "FunctionDeclaration": {
457
- const fn = node;
458
- let s = fn.isLocal ? "local function " : "function ";
459
- if (fn.identifier) {
460
- s += this.expr(fn.identifier);
461
- }
462
- s += "(" + fn.parameters.map((p) => this.expr(p)).join(",") + ") ";
463
- this.emit(s);
464
- this.printBlock(fn.body);
465
- this.emit(" end");
466
- break;
467
- }
468
- case "IfStatement": {
469
- const ifs = node;
470
- for (let i = 0; i < ifs.clauses.length; i++) {
471
- const clause = ifs.clauses[i];
472
- if (clause.type === "IfClause") {
473
- this.emit("if " + this.expr(clause.condition) + " then ");
474
- }
475
- else if (clause.type === "ElseifClause") {
476
- this.emit(" elseif " + this.expr(clause.condition) + " then ");
477
- }
478
- else {
479
- this.emit(" else ");
480
- }
481
- this.printBlock(clause.body);
482
- }
483
- this.emit(" end");
484
- break;
485
- }
486
- case "WhileStatement": {
487
- const st = node;
488
- this.emit("while " + this.expr(st.condition) + " do ");
489
- this.printBlock(st.body);
490
- this.emit(" end");
491
- break;
492
- }
493
- case "RepeatStatement": {
494
- const st = node;
495
- this.emit("repeat ");
496
- this.printBlock(st.body);
497
- this.emit(" until " + this.expr(st.condition));
498
- break;
499
- }
500
- case "ForNumericStatement": {
501
- const st = node;
502
- let s = "for " + this.expr(st.variable) + "=" + this.expr(st.start) + "," + this.expr(st.end);
503
- if (st.step) {
504
- s += "," + this.expr(st.step);
505
- }
506
- s += " do ";
507
- this.emit(s);
508
- this.printBlock(st.body);
509
- this.emit(" end");
510
- break;
511
- }
512
- case "ForGenericStatement": {
513
- const st = node;
514
- const vars = st.variables.map((v) => this.expr(v)).join(",");
515
- const iters = st.iterators.map((it) => this.expr(it)).join(",");
516
- this.emit("for " + vars + " in " + iters + " do ");
517
- this.printBlock(st.body);
518
- this.emit(" end");
519
- break;
520
- }
521
- case "ReturnStatement": {
522
- const st = node;
523
- if (st.arguments.length > 0) {
524
- this.emit("return " + st.arguments.map((a) => this.expr(a)).join(","));
525
- }
526
- else {
527
- this.emit("return");
528
- }
529
- break;
530
- }
531
- case "BreakStatement":
532
- this.emit("break");
533
- break;
534
- case "DoStatement": {
535
- const st = node;
536
- this.emit("do ");
537
- this.printBlock(st.body);
538
- this.emit(" end");
539
- break;
540
- }
541
- case "Comment":
542
- // Skip comments in inline mode
543
- break;
544
- default:
545
- break;
546
- }
547
- }
548
- // --- statement printer ---
549
- printStatement(node) {
550
- switch (node.type) {
551
- case "AssignmentStatement": {
552
- const st = node;
553
- const vars = st.variables.map((v) => this.expr(v)).join(",");
554
- const vals = st.init.map((v) => this.expr(v)).join(",");
555
- this.emit(vars);
556
- this.emit("=");
557
- this.emit(vals);
558
- this.newline();
559
- break;
560
- }
561
- case "LocalStatement": {
562
- const st = node;
563
- const vars = st.variables.map((v) => this.expr(v)).join(",");
564
- this.emitKeyword("local");
565
- this.emit(" ");
566
- this.emit(vars);
567
- if (st.init && st.init.length > 0) {
568
- const vals = st.init.map((v) => this.expr(v)).join(",");
569
- this.emit("=");
570
- this.emit(vals);
571
- }
572
- this.newline();
573
- break;
574
- }
575
- case "CallStatement": {
576
- const st = node;
577
- this.emit(this.expr(st.expression));
578
- this.newline();
579
- break;
580
- }
581
- case "FunctionDeclaration": {
582
- const fn = node;
583
- if (fn.isLocal) {
584
- this.emitKeyword("local");
585
- this.emit(" ");
586
- }
587
- this.emitKeyword("function");
588
- this.emit(" ");
589
- if (fn.identifier) {
590
- this.emit(this.expr(fn.identifier));
591
- }
592
- this.emit("(");
593
- this.emit(fn.parameters.map((p) => this.expr(p)).join(","));
594
- this.emit(")");
595
- this.newline();
596
- this.indentLevel++;
597
- this.printBlock(fn.body);
598
- this.indentLevel--;
599
- this.printIndent();
600
- this.emitKeyword("end");
601
- this.newline();
602
- break;
603
- }
604
- case "IfStatement": {
605
- const ifs = node;
606
- ifs.clauses.forEach((clause, idx) => {
607
- // The enclosing block printer (`printBlock`) emits indentation only once for the
608
- // top-level statement. Subsequent clauses need to re-emit indentation explicitly,
609
- // otherwise `elseif`/`else` start at column 0.
610
- if (idx > 0) {
611
- this.printIndent();
612
- }
613
- if (clause.type === "IfClause") {
614
- this.emitKeyword("if");
615
- this.emit(" ");
616
- this.emit(this.expr(clause.condition));
617
- this.emitKeyword(" then");
618
- }
619
- else if (clause.type === "ElseifClause") {
620
- this.emitKeyword("elseif");
621
- this.emit(" ");
622
- this.emit(this.expr(clause.condition));
623
- this.emitKeyword(" then");
624
- }
625
- else {
626
- this.emitKeyword("else");
627
- }
628
- this.newline();
629
- this.indentLevel++;
630
- this.printBlock(clause.body);
631
- this.indentLevel--;
632
- });
633
- this.printIndent();
634
- this.emitKeyword("end");
635
- this.newline();
636
- break;
637
- }
638
- case "WhileStatement": {
639
- const st = node;
640
- this.emitKeyword("while");
641
- this.emit(" ");
642
- this.emit(this.expr(st.condition));
643
- this.emitKeyword(" do");
644
- this.newline();
645
- this.indentLevel++;
646
- this.printBlock(st.body);
647
- this.indentLevel--;
648
- this.printIndent();
649
- this.emitKeyword("end");
650
- this.newline();
651
- break;
652
- }
653
- case "RepeatStatement": {
654
- const st = node;
655
- this.emitKeyword("repeat");
656
- this.newline();
657
- this.indentLevel++;
658
- this.printBlock(st.body);
659
- this.indentLevel--;
660
- this.emitKeyword("until");
661
- this.emit(" ");
662
- this.emit(this.expr(st.condition));
663
- this.newline();
664
- break;
665
- }
666
- case "ForNumericStatement": {
667
- const st = node;
668
- this.emitKeyword("for");
669
- this.emit(" ");
670
- this.emit(this.expr(st.variable));
671
- this.emit("=");
672
- this.emit(this.expr(st.start));
673
- this.emit(",");
674
- this.emit(this.expr(st.end));
675
- if (st.step) {
676
- this.emit(",");
677
- this.emit(this.expr(st.step));
678
- }
679
- this.emitKeyword(" do");
680
- this.newline();
681
- this.indentLevel++;
682
- this.printBlock(st.body);
683
- this.indentLevel--;
684
- this.printIndent();
685
- this.emitKeyword("end");
686
- this.newline();
687
- break;
688
- }
689
- case "ForGenericStatement": {
690
- const st = node;
691
- this.emitKeyword("for");
692
- this.emit(" ");
693
- this.emit(st.variables.map((v) => this.expr(v)).join(","));
694
- this.emitKeyword(" in ");
695
- this.emit(st.iterators.map((it) => this.expr(it)).join(","));
696
- this.emitKeyword(" do");
697
- this.newline();
698
- this.indentLevel++;
699
- this.printBlock(st.body);
700
- this.indentLevel--;
701
- this.printIndent();
702
- this.emitKeyword("end");
703
- this.newline();
704
- break;
705
- }
706
- case "ReturnStatement": {
707
- const st = node;
708
- this.emitKeyword("return");
709
- if (st.arguments.length > 0) {
710
- this.emit(" ");
711
- this.emit(st.arguments.map((a) => this.expr(a)).join(","));
712
- }
713
- this.newline();
714
- break;
715
- }
716
- case "BreakStatement": {
717
- this.emitKeyword("break");
718
- this.newline();
719
- break;
720
- }
721
- case "DoStatement": {
722
- const st = node;
723
- this.emitKeyword("do");
724
- this.newline();
725
- this.indentLevel++;
726
- this.printBlock(st.body);
727
- this.indentLevel--;
728
- this.printIndent();
729
- this.emitKeyword("end");
730
- this.newline();
731
- break;
732
- }
733
- case "Comment":
734
- this.printComment(node);
735
- break;
736
- default:
737
- // console.warn("Unimplemented statement type:", node.type);
738
- break;
739
- }
740
- }
741
- // Try to render a statement as a single-line string.
742
- // For single-line-blocks mode: only return non-null if the entire statement (including nested blocks) fits on one line.
743
- // Returns null if the statement cannot be rendered inline under the given constraints.
744
- renderInlineStatement(stmt, maxLen) {
745
- // Use a temporary printer in inline mode to render everything on one line
746
- const temp = new LuaPrinter(this.options, this.blockComments);
747
- temp.inlineMode = true;
748
- temp.buf = [];
749
- temp.currentLine = "";
750
- temp.printStatementInline(stmt);
751
- const out = temp.currentLine.trim();
752
- // If it exceeds maxLen, cannot inline
753
- if (out.length > maxLen) {
754
- return null;
755
- }
756
- return out;
757
- }
758
- // Check if statement contains nested blocks
759
- isBlockStatement(stmt) {
760
- switch (stmt.type) {
761
- case "IfStatement":
762
- case "WhileStatement":
763
- case "RepeatStatement":
764
- case "ForNumericStatement":
765
- case "ForGenericStatement":
766
- case "FunctionDeclaration":
767
- case "DoStatement":
768
- return true;
769
- default:
770
- return false;
771
- }
772
- }
773
- // --- expression printer ---
774
- expr(node, parentPrec = 0) {
775
- if (!node)
776
- return "";
777
- switch (node.type) {
778
- case "Identifier":
779
- return node.name;
780
- case "StringLiteral":
781
- return this.stringLiteral(node);
782
- case "NumericLiteral":
783
- return this.numericLiteral(node);
784
- case "BooleanLiteral":
785
- return node.value ? "true" : "false";
786
- case "NilLiteral":
787
- return "nil";
788
- case "VarargLiteral":
789
- return "...";
790
- case "TableConstructorExpression":
791
- return this.tableConstructor(node);
792
- case "UnaryExpression":
793
- return this.unaryExpr(node, parentPrec);
794
- case "BinaryExpression":
795
- return this.binaryExpr(node, parentPrec);
796
- case "LogicalExpression":
797
- return this.logicalExpr(node, parentPrec);
798
- case "MemberExpression":
799
- return this.memberExpr(node);
800
- case "IndexExpression":
801
- return this.indexExpr(node);
802
- case "CallExpression":
803
- return this.callExpr(node);
804
- case "TableCallExpression":
805
- return this.tableCallExpr(node);
806
- case "StringCallExpression":
807
- return this.stringCallExpr(node);
808
- case "FunctionDeclaration":
809
- return this.functionExpr(node);
810
- default:
811
- return `<${node.type}>`;
812
- }
813
- }
814
- stringLiteral(node) {
815
- if (node.raw)
816
- return node.raw;
817
- return (0, lua_fundamentals_1.toLuaStringLiteral)(node.value);
818
- }
819
- numericLiteral(node, options) {
820
- const value = node.value;
821
- const decimalStr = Number.isFinite(value) ? value.toString(10) : String(value);
822
- const candidates = [decimalStr];
823
- const expStr = Number.isFinite(value) ? this.normalizeExponential(value.toExponential()) : null;
824
- if (expStr)
825
- candidates.push(expStr);
826
- const altExpStr = Number.isFinite(value) ? this.exponentialFromDecimalString(decimalStr) : null;
827
- if (altExpStr)
828
- candidates.push(altExpStr);
829
- let best = candidates[0];
830
- for (const cand of candidates) {
831
- if (cand.length < best.length)
832
- best = cand;
833
- }
834
- if (/^-?0\.\d/.test(best)) {
835
- const compact = best.replace(/^(-?)0\./, "$1.");
836
- if (options?.forceLeadingZero && /^-?\./.test(compact)) {
837
- return compact.replace(/^(-?)\./, "$10.");
838
- }
839
- return compact;
840
- }
841
- if (options?.forceLeadingZero && /^-?\./.test(best)) {
842
- return best.replace(/^(-?)\./, "$10.");
843
- }
844
- return best;
845
- }
846
- normalizeExponential(text) {
847
- const parts = text.split("e");
848
- if (parts.length !== 2)
849
- return text;
850
- let mantissa = parts[0];
851
- let exponent = parts[1];
852
- if (exponent.startsWith("+"))
853
- exponent = exponent.slice(1);
854
- if (mantissa.includes(".")) {
855
- mantissa = mantissa.replace(/0+$/, "").replace(/\.$/, "");
856
- }
857
- return `${mantissa}e${exponent}`;
61
+ function parseLuaQuiet(code) {
62
+ try {
63
+ return parseLuaOrThrow(code);
858
64
  }
859
- exponentialFromDecimalString(text) {
860
- const match = text.match(/^(-?)(\d+)(?:\.(\d+))?$/);
861
- if (!match)
862
- return null;
863
- const sign = match[1];
864
- const intPart = match[2];
865
- const fracPart = match[3] || "";
866
- if (fracPart.length === 0) {
867
- const trimmed = intPart.replace(/0+$/, "");
868
- const zeros = intPart.length - trimmed.length;
869
- if (zeros <= 0 || trimmed.length === 0)
870
- return null;
871
- return `${sign}${trimmed}e${zeros}`;
872
- }
873
- if (/^0+$/.test(intPart)) {
874
- const leadingZeros = fracPart.match(/^0+/)?.[0].length ?? 0;
875
- const digits = fracPart.slice(leadingZeros);
876
- if (digits.length === 0)
877
- return null;
878
- const exponent = -(leadingZeros + 1);
879
- const mantissa = digits.length === 1 ? digits : `${digits[0]}.${digits.slice(1)}`;
880
- return `${sign}${mantissa}e${exponent}`;
881
- }
65
+ catch {
882
66
  return null;
883
67
  }
884
- tableConstructor(node) {
885
- if (node.fields.length === 0)
886
- return "{}";
887
- const parts = [];
888
- for (const f of node.fields) {
889
- if (f.type === "TableKey") {
890
- parts.push(`[${this.expr(f.key)}]=${this.expr(f.value)}`);
891
- }
892
- else if (f.type === "TableKeyString") {
893
- // luaparse gives key as an Identifier or StringLiteral
894
- parts.push(`${this.expr(f.key)}=${this.expr(f.value)}`);
895
- }
896
- else {
897
- // TableValue
898
- parts.push(this.expr(f.value));
899
- }
900
- }
901
- return `{${parts.join(",")}}`;
902
- }
903
- unaryExpr(node, parentPrec) {
904
- const prec = getPrecedence(node);
905
- const arg = this.expr(node.argument, prec);
906
- const op = node.operator;
907
- let s;
908
- if (op === "not") {
909
- s = `not ${arg}`;
910
- }
911
- else {
912
- s = op + arg;
913
- }
914
- if (prec < parentPrec)
915
- s = `(${s})`;
916
- return s;
917
- }
918
- binaryExpr(node, parentPrec) {
919
- const prec = getPrecedence(node);
920
- const isRightAssociative = this.isRightAssociativeOperator(node.operator);
921
- const leftRaw = node.operator === ".." ? this.concatLeftExpr(node.left, prec) : this.expr(node.left, prec);
922
- const left = isRightAssociative && getPrecedence(node.left) === prec ? `(${leftRaw})` : leftRaw;
923
- const rightRaw = node.operator === ".." ? this.concatRightExpr(node.right, prec) : this.expr(node.right, prec);
924
- const rightSafe = node.operator === ".." ? this.ensureConcatSafeRight(rightRaw) : rightRaw;
925
- const right = !isRightAssociative && getPrecedence(node.right) === prec ? `(${rightSafe})` : rightSafe;
926
- let s = `${left}${node.operator}${right}`;
927
- if (prec < parentPrec)
928
- s = `(${s})`;
929
- return s;
930
- }
931
- concatLeftExpr(node, parentPrec) {
932
- if (node.type === "NumericLiteral") {
933
- return `(${this.numericLiteral(node)})`;
934
- }
935
- if (node.type === "UnaryExpression") {
936
- const unary = node;
937
- if (unary.operator === "-" && unary.argument.type === "NumericLiteral") {
938
- const arg = this.numericLiteral(unary.argument);
939
- return `(-${arg})`;
940
- }
941
- }
942
- if (node.type === "BinaryExpression") {
943
- const bin = node;
944
- const prec = getPrecedence(bin);
945
- const left = this.expr(bin.left, prec);
946
- let right = this.expr(bin.right, prec);
947
- if (this.isNumericLiteralLike(bin.right)) {
948
- right = `(${right})`;
949
- }
950
- let s = `${left}${bin.operator}${right}`;
951
- if (prec < parentPrec)
952
- s = `(${s})`;
953
- return s;
954
- }
955
- return this.expr(node, parentPrec);
956
- }
957
- concatRightExpr(node, parentPrec) {
958
- if (node.type === "NumericLiteral") {
959
- return this.numericLiteral(node, { forceLeadingZero: true });
960
- }
961
- if (node.type === "UnaryExpression") {
962
- const unary = node;
963
- if (unary.operator === "-" && unary.argument.type === "NumericLiteral") {
964
- const arg = this.numericLiteral(unary.argument, { forceLeadingZero: true });
965
- let s = `-${arg}`;
966
- if (getPrecedence(unary) < parentPrec)
967
- s = `(${s})`;
968
- return s;
969
- }
970
- }
971
- return this.expr(node, parentPrec);
972
- }
973
- ensureConcatSafeRight(text) {
974
- if (text.startsWith("-.")) {
975
- return "-0" + text.slice(1);
976
- }
977
- if (text.startsWith(".")) {
978
- return "0" + text;
979
- }
980
- return text;
981
- }
982
- logicalExpr(node, parentPrec) {
983
- const prec = getPrecedence(node);
984
- const left = this.expr(node.left, prec);
985
- const rightRaw = this.expr(node.right, prec);
986
- const right = getPrecedence(node.right) === prec ? `(${rightRaw})` : rightRaw;
987
- let s = `${left} ${node.operator} ${right}`;
988
- if (prec < parentPrec)
989
- s = `(${s})`;
990
- return s;
991
- }
992
- memberExpr(node) {
993
- // luaparse usually gives . or : in node.indexer
994
- const base = this.prefixBase(node.base);
995
- const id = this.expr(node.identifier);
996
- const indexer = node.indexer || ".";
997
- return `${base}${indexer}${id}`;
998
- }
999
- indexExpr(node) {
1000
- const base = this.prefixBase(node.base);
1001
- return `${base}[${this.expr(node.index)}]`;
1002
- }
1003
- callExpr(node) {
1004
- const base = this.prefixBase(node.base);
1005
- const args = node.arguments.map((a) => this.expr(a)).join(",");
1006
- return `${base}(${args})`;
1007
- }
1008
- tableCallExpr(node) {
1009
- // sugar: f{...} → f({ ... })
1010
- const base = this.prefixBase(node.base);
1011
- const arg = this.expr(node.arguments);
1012
- return `${base}(${arg})`;
1013
- }
1014
- stringCallExpr(node) {
1015
- // sugar: f"str" → f("str")
1016
- const base = this.prefixBase(node.base);
1017
- const arg = this.stringLiteral(node.argument);
1018
- return `${base}(${arg})`;
1019
- }
1020
- isRightAssociativeOperator(op) {
1021
- return op === "^" || op === "..";
1022
- }
1023
- isPrefixExpression(node) {
1024
- switch (node.type) {
1025
- case "Identifier":
1026
- case "MemberExpression":
1027
- case "IndexExpression":
1028
- case "CallExpression":
1029
- case "TableCallExpression":
1030
- case "StringCallExpression":
1031
- return true;
1032
- default:
1033
- return false;
1034
- }
1035
- }
1036
- prefixBase(node) {
1037
- const base = this.expr(node, 100);
1038
- if (this.isPrefixExpression(node))
1039
- return base;
1040
- return this.isParenthesized(base) ? base : `(${base})`;
1041
- }
1042
- isNumericLiteralLike(node) {
1043
- if (node.type === "NumericLiteral")
1044
- return true;
1045
- if (node.type === "UnaryExpression") {
1046
- const unary = node;
1047
- return unary.operator === "-" && unary.argument.type === "NumericLiteral";
1048
- }
1049
- return false;
1050
- }
1051
- isParenthesized(text) {
1052
- return text.length >= 2 && text.startsWith("(") && text.endsWith(")");
1053
- }
1054
- functionExpr(node) {
1055
- // function used as expression: "function(a,b) ... end"
1056
- const params = node.parameters.map((p) => this.expr(p)).join(",");
1057
- const bodyPrinter = new LuaPrinter(this.options, this.blockComments);
1058
- // reuse statement printer but avoid duplicating indent handling:
1059
- const innerChunk = {
1060
- type: "Chunk",
1061
- body: node.body,
1062
- comments: [],
1063
- //globals: [],
1064
- };
1065
- const bodyCode = bodyPrinter.print(innerChunk).trimEnd();
1066
- return `function(${params})\n${bodyCode}\nend`;
1067
- }
1068
- printComment(node) {
1069
- if (node.raw) {
1070
- this.emit(node.raw);
1071
- }
1072
- else {
1073
- this.emit("--" + node.value);
1074
- }
1075
- this.newline();
1076
- }
1077
- }
1078
- exports.LuaPrinter = LuaPrinter;
1079
- function nodeRange(node) {
1080
- if (node && Array.isArray(node.range) && node.range.length > 1) {
1081
- return node.range;
1082
- }
1083
- return [0, Number.MAX_SAFE_INTEGER];
1084
- }
1085
- function rangeContains(outer, inner) {
1086
- return inner[0] >= outer[0] && inner[1] <= outer[1];
1087
- }
1088
- // Collect all statement blocks (function bodies, if/else bodies, loops, etc.)
1089
- function collectBlocksFromStatement(node, blocks) {
1090
- switch (node.type) {
1091
- case "FunctionDeclaration": {
1092
- const fn = node;
1093
- blocks.push({ body: fn.body, range: nodeRange(fn) });
1094
- fn.body.forEach((st) => collectBlocksFromStatement(st, blocks));
1095
- break;
1096
- }
1097
- case "IfStatement": {
1098
- const ifs = node;
1099
- ifs.clauses.forEach((clause) => {
1100
- blocks.push({ body: clause.body, range: nodeRange(clause) });
1101
- clause.body.forEach((st) => collectBlocksFromStatement(st, blocks));
1102
- });
1103
- break;
1104
- }
1105
- case "WhileStatement":
1106
- case "RepeatStatement":
1107
- case "ForNumericStatement":
1108
- case "ForGenericStatement":
1109
- case "DoStatement": {
1110
- const body = node.body;
1111
- blocks.push({ body, range: nodeRange(node) });
1112
- body.forEach((st) => collectBlocksFromStatement(st, blocks));
1113
- break;
1114
- }
1115
- default:
1116
- break;
1117
- }
1118
- }
1119
- function collectAllStatementBlocks(chunk) {
1120
- const blocks = [
1121
- { body: chunk.body, range: nodeRange(chunk) },
1122
- ];
1123
- for (const st of chunk.body) {
1124
- collectBlocksFromStatement(st, blocks);
1125
- }
1126
- return blocks;
1127
- }
1128
- // Build a map from statement blocks to comments contained within them
1129
- // why is this needed?
1130
- // luaparse gives comments attached to the root chunk only, not to inner blocks
1131
- // so we have to manually assign them to the correct blocks
1132
- function buildCommentMap(ast) {
1133
- const blocks = collectAllStatementBlocks(ast);
1134
- const map = new Map();
1135
- blocks.forEach((b) => map.set(b.body, []));
1136
- const comments = ast.comments || [];
1137
- for (const c of comments) {
1138
- const cr = nodeRange(c);
1139
- let target = blocks[0];
1140
- for (const blk of blocks) {
1141
- if (rangeContains(blk.range, cr)) {
1142
- const widthCurrent = target ? target.range[1] - target.range[0] : Number.MAX_SAFE_INTEGER;
1143
- const widthCandidate = blk.range[1] - blk.range[0];
1144
- if (widthCandidate <= widthCurrent) {
1145
- target = blk;
1146
- }
1147
- }
1148
- }
1149
- const list = map.get(target.body) || [];
1150
- list.push(c);
1151
- map.set(target.body, list);
1152
- }
1153
- for (const [body, list] of map.entries()) {
1154
- list.sort((a, b) => nodeRange(a)[0] - nodeRange(b)[0]);
1155
- }
1156
- return map;
1157
- }
1158
- // Generate Lua code from an AST
1159
- function unparseLua(ast, ruleOptions) {
1160
- const generator = new LuaPrinter(ruleOptions, buildCommentMap(ast));
1161
- return generator.print(ast);
1162
68
  }
1163
69
  function parseLua(code) {
1164
70
  //console.log(code);
1165
71
  try {
1166
- const ast = luaparse.parse(code, {
1167
- luaVersion: "5.3", // TIC-80 is 5.3-ish
1168
- comments: true,
1169
- locations: true,
1170
- ranges: true,
1171
- });
1172
- return ast;
72
+ return parseLuaOrThrow(code);
1173
73
  }
1174
74
  catch (error) {
1175
75
  console.error("Error parsing Lua code:", error);
@@ -1177,102 +77,174 @@ function parseLua(code) {
1177
77
  }
1178
78
  return null;
1179
79
  }
1180
- function processLuaWithReport(code, ruleOptions) {
1181
- // Apply optimization rules
1182
- //const options = {...DEFAULT_OPTIMIZATION_RULES, ...ruleOptions};
1183
- // Strip debug blocks and lines before parsing (line-based string matching)
1184
- let processedCode = code;
1185
- processedCode = disambiguateNumericConcat(processedCode);
1186
- // if (ruleOptions.stripDebugBlocks) {
1187
- // // Strip debug blocks
1188
- // processedCode = replaceLuaBlock(processedCode, "-- BEGIN_DEBUG_ONLY", "-- END_DEBUG_ONLY", "");
1189
- // // Strip individual lines marked with -- DEBUG_ONLY
1190
- // const eol = processedCode.includes("\r\n") ? "\r\n" : "\n";
1191
- // const lines = processedCode.split(eol);
1192
- // const filteredLines = lines.filter(line => !line.includes("-- DEBUG_ONLY"));
1193
- // processedCode = filteredLines.join(eol);
1194
- // }
1195
- // Honor explicit directives to keep certain regions verbatim
1196
- // doing this at text level for simplification and because the printer can reformat everything.
1197
- const disableMinify = (0, lua_fundamentals_1.extractLuaBlocks)(processedCode, "-- MINIFICATION OFF", "-- MINIFICATION ON", (i) => `__SOMATIC_DISABLED_MINIFICATION_BLOCK_${i}__()`, { strict: false });
1198
- processedCode = disableMinify.code;
1199
- let ast = parseLua(processedCode);
1200
- if (!ast) {
80
+ function processLuaWithReport(code, ruleOptions, processOptions = {}, profileTrack) {
81
+ const prepared = (0, traceProfiler_1.profileSync)(profileTrack, "Prepare Lua source", { category: "Lua minification" }, () => {
82
+ const preparationMap = lua_transform_map_1.LuaTransformMapBuilder.identity(code.length);
83
+ const processedCode = disambiguateNumericConcat(code, preparationMap);
84
+ // Hide verbatim regions because every AST printer is allowed to reformat them.
85
+ const disableMinify = (0, lua_fundamentals_1.extractLuaBlocks)(processedCode, "-- MINIFICATION OFF", "-- MINIFICATION ON", (i) => `__SOMATIC_DISABLED_MINIFICATION_BLOCK_${i}__()`, { strict: false });
86
+ const disabledBlockOrigins = new Map(disableMinify.blocks.map((block) => [
87
+ block.placeholder,
88
+ preparationMap.mapOffset(block.sourceContentBegin, "right")?.offset ?? 0,
89
+ ]));
90
+ for (const block of [...disableMinify.blocks].sort((a, b) => b.sourceBegin - a.sourceBegin)) {
91
+ const origin = preparationMap.mapOffset(block.sourceBegin, "right");
92
+ preparationMap.spliceRange(block.sourceBegin, block.sourceEnd, block.replacementLength, origin, "anchor");
93
+ }
94
+ return {
95
+ processedCode: disableMinify.code,
96
+ preparationMap,
97
+ disableMinify,
98
+ disabledBlockOrigins,
99
+ };
100
+ });
101
+ const parsedAst = (0, traceProfiler_1.profileSync)(profileTrack, "Parse Lua", { category: "Lua minification" }, () => processOptions.parseFailure === "throw"
102
+ ? parseLuaOrThrow(prepared.processedCode)
103
+ : parseLua(prepared.processedCode));
104
+ if (!parsedAst) {
1201
105
  console.error("Failed to parse Lua code; returning original code.");
1202
- return { code, report: (0, lua_alias_shared_1.createEmptyAliasPassReport)() };
1203
- }
1204
- //console.log("Parsed Lua AST:", ast);
1205
- if (ruleOptions.stripComments) {
1206
- ast.comments = [];
1207
- }
1208
- if (ruleOptions.simplifyExpressions) {
1209
- ast = (0, lua_simplify_1.simplifyExpressionsInAST)(ast);
1210
- }
1211
- if (ruleOptions.removeUnusedLocals) {
1212
- ast = (0, lua_remove_unused_locals_1.removeUnusedLocalsInAST)(ast);
1213
- }
1214
- if (ruleOptions.removeUnusedFunctions) {
1215
- ast = (0, lua_remove_unused_functions_1.removeUnusedFunctionsInAST)(ast, {
1216
- functionNamesToKeep: ruleOptions.functionNamesToKeep,
1217
- });
1218
- }
1219
- const aliasStrategies = [];
1220
- if (ruleOptions.aliasLiterals)
1221
- aliasStrategies.push(lua_alias_literals_1.literalAliasStrategy);
1222
- if (ruleOptions.aliasRepeatedExpressions)
1223
- aliasStrategies.push(lua_alias_expressions_1.repeatedExpressionAliasStrategy);
1224
- const aliasResult = (0, lua_alias_shared_1.runAliasPasses)(ast, aliasStrategies);
1225
- ast = aliasResult.ast;
1226
- if (ruleOptions.packLocalDeclarations) {
1227
- ast = (0, lua_pack_locals_1.packLocalDeclarationsInAST)(ast);
1228
- }
1229
- if (ruleOptions.renameLocalVariables) {
1230
- ast = (0, lua_renamer_1.renameLocalVariablesInAST)(ast);
1231
- }
1232
- if (ruleOptions.renameSpecifiedGlobalSymbols !== false &&
1233
- ruleOptions.globalSymbolsToRename &&
1234
- ruleOptions.globalSymbolsToRename.length > 0) {
1235
- ast = (0, lua_rename_allowed_globals_1.renameAllowedGlobalsInAST)(ast, {
1236
- namesToRename: ruleOptions.globalSymbolsToRename,
1237
- namesToKeep: ruleOptions.functionNamesToKeep,
1238
- });
1239
- }
1240
- if (ruleOptions.tableEntryKeysToRename && ruleOptions.tableEntryKeysToRename.length > 0) {
1241
- ast = (0, lua_rename_allowed_table_keys_1.renameAllowedTableKeysInAST)(ast, ruleOptions.tableEntryKeysToRename);
1242
- }
1243
- if (ruleOptions.renameTableFields) {
1244
- ast = (0, lua_rename_table_fields_1.renameTableFieldsInAST)(ast);
106
+ return {
107
+ code,
108
+ report: (0, lua_alias_shared_1.createEmptyAliasPassReport)(),
109
+ transformMap: lua_transform_map_1.LuaTransformMapBuilder.identity(code.length).toMap(),
110
+ };
1245
111
  }
1246
- const minified = unparseLua(ast, ruleOptions);
112
+ (0, lua_ast_provenance_1.annotateLuaAstOrigins)(parsedAst, prepared.preparationMap.toMap(), code);
113
+ const optimizationResult = (0, traceProfiler_1.profileSync)(profileTrack, "Optimize Lua AST", { category: "Lua minification" }, () => (0, lua_optimizer_1.optimizeLuaAst)(parsedAst, ruleOptions));
114
+ const restored = (0, traceProfiler_1.profileSync)(profileTrack, "Print and map Lua", { category: "Lua minification" }, (scope) => {
115
+ const minified = (0, lua_printer_1.unparseLua)(optimizationResult.ast, ruleOptions);
116
+ const emittedAst = parseLua(minified);
117
+ if (!emittedAst) {
118
+ throw new Error("Lua printer produced output that could not be parsed for source mapping");
119
+ }
120
+ const printedMap = (0, lua_print_trace_1.createLuaPrintTransformMap)(optimizationResult.ast, emittedAst, code, minified);
121
+ const restored = reinsertDisableMinificationBlocksWithMap(minified, printedMap, prepared.disableMinify.blocks.map((block) => ({
122
+ placeholder: block.placeholder,
123
+ content: block.content,
124
+ inputContentBegin: prepared.disabledBlockOrigins.get(block.placeholder) ?? 0,
125
+ })));
126
+ scope?.setArgs({ outputCharacters: restored.code.length });
127
+ return restored;
128
+ });
1247
129
  return {
1248
- code: reinsertDisableMinificationBlocks(minified, disableMinify.blocks),
1249
- report: aliasResult.report,
130
+ code: restored.code,
131
+ report: optimizationResult.report,
132
+ transformMap: restored.transformMap,
1250
133
  };
1251
134
  }
1252
135
  function processLua(code, ruleOptions) {
1253
136
  return processLuaWithReport(code, ruleOptions).code;
1254
137
  }
1255
- function disambiguateNumericConcat(code) {
138
+ function disambiguateNumericConcat(code, transformMap) {
1256
139
  // Insert a space before concatenation when a numeric literal is immediately followed by `..`.
1257
140
  // Examples: `15.."x"` -> `15 .."x"`, `.15.."x"` -> `.15 .."x"`
1258
- return code.replace(/(\d(?:\.\d+)?|\.\d+)\.\./g, "$1 ..");
141
+ const insertions = [];
142
+ const pattern = /(\d(?:\.\d+)?|\.\d+)\.\./y;
143
+ const longBracket = /\[(=*)\[/y;
144
+ // This runs before parsing, since an adjacent numeric literal and concat
145
+ // operator can be invalid Lua. Skip strings and comments without changing
146
+ // their contents, including long brackets with arbitrary delimiter depth.
147
+ for (let index = 0; index < code.length;) {
148
+ const character = code[index];
149
+ if (character === '"' || character === "'") {
150
+ index++;
151
+ while (index < code.length && code[index] !== character) {
152
+ index += code[index] === "\\" ? 2 : 1;
153
+ }
154
+ index++;
155
+ continue;
156
+ }
157
+ const isComment = code.startsWith("--", index);
158
+ longBracket.lastIndex = isComment ? index + 2 : index;
159
+ const opening = longBracket.exec(code);
160
+ if (opening) {
161
+ const closing = `]${opening[1]}]`;
162
+ const end = code.indexOf(closing, longBracket.lastIndex);
163
+ index = end < 0 ? code.length : end + closing.length;
164
+ continue;
165
+ }
166
+ if (isComment) {
167
+ while (index < code.length && code[index] !== "\n" && code[index] !== "\r") {
168
+ index++;
169
+ }
170
+ continue;
171
+ }
172
+ pattern.lastIndex = index;
173
+ const match = pattern.exec(code);
174
+ if (match) {
175
+ insertions.push(index + match[1].length);
176
+ index = pattern.lastIndex;
177
+ }
178
+ else {
179
+ index++;
180
+ }
181
+ }
182
+ let output = code;
183
+ for (const offset of insertions.sort((a, b) => b - a)) {
184
+ const origin = transformMap.mapOffset(offset, "right");
185
+ output = output.slice(0, offset) + " " + output.slice(offset);
186
+ transformMap.spliceRange(offset, offset, 1, origin, "anchor");
187
+ }
188
+ return output;
1259
189
  }
1260
190
  // Escape special characters in a string for use in a RegExp
1261
191
  function escapeRegExp(s) {
1262
192
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1263
193
  }
1264
- function reinsertDisableMinificationBlocks(src, blocks) {
1265
- if (blocks.length === 0)
1266
- return src;
1267
- let out = src;
1268
- for (const b of blocks) {
1269
- // normalize line endings and trim trailing newlines from the block content
1270
- const normalized = b.content.replace(/\r?\n/g, "\n").replace(/\n+$/g, "");
1271
- const replacement = `\n${normalized}\n`;
1272
- // remove surrounding whitespace introduced by tight packing.
1273
- const re = new RegExp(`[\\t ]*${escapeRegExp(b.placeholder)}[\\t ]*`, "g");
1274
- out = out.replace(re, replacement);
1275
- }
1276
- return out;
194
+ function appendNormalizedBlock(builder, content, inputContentBegin) {
195
+ const normalized = content.replace(/\r?\n/g, "\n").replace(/\n+$/g, "");
196
+ builder.appendAnchor(1, inputContentBegin);
197
+ let sourceOffset = 0;
198
+ const lines = normalized.split("\n");
199
+ for (let i = 0; i < lines.length; i++) {
200
+ const line = lines[i];
201
+ builder.appendIdentity(line.length, inputContentBegin + sourceOffset);
202
+ sourceOffset += line.length;
203
+ if (i < lines.length - 1) {
204
+ builder.appendAnchor(1, inputContentBegin + sourceOffset);
205
+ if (content.startsWith("\r\n", sourceOffset)) {
206
+ sourceOffset += 2;
207
+ }
208
+ else if (content[sourceOffset] === "\n" || content[sourceOffset] === "\r") {
209
+ sourceOffset++;
210
+ }
211
+ }
212
+ }
213
+ builder.appendAnchor(1, inputContentBegin + sourceOffset);
214
+ return `\n${normalized}\n`;
215
+ }
216
+ function reinsertDisableMinificationBlocksWithMap(source, transformMap, blocks) {
217
+ if (blocks.length === 0) {
218
+ return { code: source, transformMap };
219
+ }
220
+ const replacements = blocks.flatMap((block) => {
221
+ const placeholderIdentifier = block.placeholder.endsWith("()")
222
+ ? block.placeholder.slice(0, -2)
223
+ : null;
224
+ const placeholderPattern = placeholderIdentifier
225
+ // Printer modes may place whitespace between the placeholder call tokens.
226
+ // Match the token sequence as one placeholder statement in every mode.
227
+ ? `${escapeRegExp(placeholderIdentifier)}\\s*\\(\\s*\\)`
228
+ : escapeRegExp(block.placeholder);
229
+ const pattern = new RegExp(`[\\t ]*${placeholderPattern}[\\t ]*`, "g");
230
+ const match = pattern.exec(source);
231
+ return match
232
+ ? [{ start: match.index, end: match.index + match[0].length, block }]
233
+ : [];
234
+ }).sort((a, b) => a.start - b.start);
235
+ const builder = new lua_transform_map_1.LuaTransformMapBuilder(transformMap.inputLength);
236
+ let output = "";
237
+ let cursor = 0;
238
+ for (const replacement of replacements) {
239
+ const prefix = source.slice(cursor, replacement.start);
240
+ output += prefix;
241
+ builder.appendMappedSlice(prefix.length, transformMap, cursor);
242
+ output += appendNormalizedBlock(builder, replacement.block.content, replacement.block.inputContentBegin);
243
+ cursor = replacement.end;
244
+ }
245
+ const suffix = source.slice(cursor);
246
+ output += suffix;
247
+ builder.appendMappedSlice(suffix.length, transformMap, cursor);
248
+ return { code: output, transformMap: builder.toMap() };
1277
249
  }
1278
250
  //# sourceMappingURL=lua_processor.js.map