funkscript 0.2.4 → 0.2.7

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 (447) hide show
  1. package/README.md +23 -5
  2. package/dist/ast/types.d.ts.map +1 -1
  3. package/dist/ast/types.js.map +1 -1
  4. package/dist/ast/walk.d.ts.map +1 -1
  5. package/dist/ast/walk.js.map +1 -1
  6. package/dist/cli/build-bun.d.ts.map +1 -1
  7. package/dist/cli/build-bun.js.map +1 -1
  8. package/dist/cli/build-watch.d.ts.map +1 -1
  9. package/dist/cli/build-watch.js +9 -27
  10. package/dist/cli/build-watch.js.map +1 -1
  11. package/dist/cli/build.d.ts +1 -1
  12. package/dist/cli/build.d.ts.map +1 -1
  13. package/dist/cli/build.js +3 -58
  14. package/dist/cli/build.js.map +1 -1
  15. package/dist/cli/check-policy.d.ts +9 -0
  16. package/dist/cli/check-policy.d.ts.map +1 -0
  17. package/dist/cli/check-policy.js +39 -0
  18. package/dist/cli/check-policy.js.map +1 -0
  19. package/dist/cli/check.d.ts.map +1 -1
  20. package/dist/cli/check.js +16 -30
  21. package/dist/cli/check.js.map +1 -1
  22. package/dist/cli/commands.d.ts.map +1 -1
  23. package/dist/cli/commands.js +11 -0
  24. package/dist/cli/commands.js.map +1 -1
  25. package/dist/cli/doc.d.ts.map +1 -1
  26. package/dist/cli/doc.js.map +1 -1
  27. package/dist/cli/doctor.d.ts.map +1 -1
  28. package/dist/cli/doctor.js +5 -7
  29. package/dist/cli/doctor.js.map +1 -1
  30. package/dist/cli/emit.d.ts +1 -1
  31. package/dist/cli/emit.d.ts.map +1 -1
  32. package/dist/cli/emit.js.map +1 -1
  33. package/dist/cli/explain.d.ts.map +1 -1
  34. package/dist/cli/explain.js.map +1 -1
  35. package/dist/cli/fmt.d.ts.map +1 -1
  36. package/dist/cli/fmt.js.map +1 -1
  37. package/dist/cli/index.d.ts.map +1 -1
  38. package/dist/cli/index.js +3 -0
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/init.d.ts +1 -1
  41. package/dist/cli/init.d.ts.map +1 -1
  42. package/dist/cli/init.js +66 -21
  43. package/dist/cli/init.js.map +1 -1
  44. package/dist/cli/io.d.ts.map +1 -1
  45. package/dist/cli/io.js.map +1 -1
  46. package/dist/cli/pipeline-style.d.ts.map +1 -1
  47. package/dist/cli/pipeline-style.js.map +1 -1
  48. package/dist/cli/query.d.ts +3 -0
  49. package/dist/cli/query.d.ts.map +1 -0
  50. package/dist/cli/query.js +152 -0
  51. package/dist/cli/query.js.map +1 -0
  52. package/dist/cli/repl.d.ts.map +1 -1
  53. package/dist/cli/repl.js.map +1 -1
  54. package/dist/cli/run.d.ts.map +1 -1
  55. package/dist/cli/run.js +2 -29
  56. package/dist/cli/run.js.map +1 -1
  57. package/dist/cli/test.d.ts +1 -1
  58. package/dist/cli/test.d.ts.map +1 -1
  59. package/dist/cli/test.js.map +1 -1
  60. package/dist/cli/tsc.d.ts.map +1 -1
  61. package/dist/cli/tsc.js +6 -8
  62. package/dist/cli/tsc.js.map +1 -1
  63. package/dist/cli/typecheck.d.ts.map +1 -1
  64. package/dist/cli/typecheck.js.map +1 -1
  65. package/dist/compiler/ast-inspection.d.ts.map +1 -1
  66. package/dist/compiler/ast-inspection.js.map +1 -1
  67. package/dist/compiler/boolean-operators.d.ts.map +1 -1
  68. package/dist/compiler/boolean-operators.js +12 -2
  69. package/dist/compiler/boolean-operators.js.map +1 -1
  70. package/dist/compiler/check.d.ts.map +1 -1
  71. package/dist/compiler/check.js +113 -131
  72. package/dist/compiler/check.js.map +1 -1
  73. package/dist/compiler/diagnostics-json.d.ts +73 -0
  74. package/dist/compiler/diagnostics-json.d.ts.map +1 -0
  75. package/dist/compiler/diagnostics-json.js +957 -0
  76. package/dist/compiler/diagnostics-json.js.map +1 -0
  77. package/dist/compiler/diagnostics.d.ts.map +1 -1
  78. package/dist/compiler/diagnostics.js.map +1 -1
  79. package/dist/compiler/effect-mutation-rule.d.ts.map +1 -1
  80. package/dist/compiler/effect-mutation-rule.js.map +1 -1
  81. package/dist/compiler/entry-rules.d.ts.map +1 -1
  82. package/dist/compiler/entry-rules.js.map +1 -1
  83. package/dist/compiler/escape-audit.d.ts +46 -0
  84. package/dist/compiler/escape-audit.d.ts.map +1 -0
  85. package/dist/compiler/escape-audit.js +682 -0
  86. package/dist/compiler/escape-audit.js.map +1 -0
  87. package/dist/compiler/incremental-build.d.ts.map +1 -1
  88. package/dist/compiler/incremental-build.js.map +1 -1
  89. package/dist/compiler/incremental-dependencies.d.ts.map +1 -1
  90. package/dist/compiler/incremental-dependencies.js.map +1 -1
  91. package/dist/compiler/js-interop-nullability.d.ts.map +1 -1
  92. package/dist/compiler/js-interop-nullability.js.map +1 -1
  93. package/dist/compiler/modules/output-collisions.d.ts.map +1 -1
  94. package/dist/compiler/modules/output-collisions.js.map +1 -1
  95. package/dist/compiler/modules/output-plan.d.ts.map +1 -1
  96. package/dist/compiler/modules/output-plan.js +10 -5
  97. package/dist/compiler/modules/output-plan.js.map +1 -1
  98. package/dist/compiler/modules/resolution.d.ts.map +1 -1
  99. package/dist/compiler/modules/resolution.js +2 -1
  100. package/dist/compiler/modules/resolution.js.map +1 -1
  101. package/dist/compiler/modules/source-files.d.ts +5 -0
  102. package/dist/compiler/modules/source-files.d.ts.map +1 -0
  103. package/dist/compiler/modules/source-files.js +13 -0
  104. package/dist/compiler/modules/source-files.js.map +1 -0
  105. package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
  106. package/dist/compiler/numeric-comparisons.js +13 -7
  107. package/dist/compiler/numeric-comparisons.js.map +1 -1
  108. package/dist/compiler/optional-arguments.d.ts.map +1 -1
  109. package/dist/compiler/optional-arguments.js.map +1 -1
  110. package/dist/compiler/package-fingerprint.d.ts.map +1 -1
  111. package/dist/compiler/package-fingerprint.js.map +1 -1
  112. package/dist/compiler/package-record-contracts.d.ts.map +1 -1
  113. package/dist/compiler/package-record-contracts.js.map +1 -1
  114. package/dist/compiler/pipelines/catalog.d.ts.map +1 -1
  115. package/dist/compiler/pipelines/catalog.js.map +1 -1
  116. package/dist/compiler/pipelines/companions.d.ts.map +1 -1
  117. package/dist/compiler/pipelines/companions.js.map +1 -1
  118. package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
  119. package/dist/compiler/pipelines/resolution.js +24 -23
  120. package/dist/compiler/pipelines/resolution.js.map +1 -1
  121. package/dist/compiler/project-config.d.ts.map +1 -1
  122. package/dist/compiler/project-config.js +29 -19
  123. package/dist/compiler/project-config.js.map +1 -1
  124. package/dist/compiler/query.d.ts +53 -0
  125. package/dist/compiler/query.d.ts.map +1 -0
  126. package/dist/compiler/query.js +781 -0
  127. package/dist/compiler/query.js.map +1 -0
  128. package/dist/compiler/record-contracts.d.ts.map +1 -1
  129. package/dist/compiler/record-contracts.js.map +1 -1
  130. package/dist/compiler/rules/control-flow.d.ts.map +1 -1
  131. package/dist/compiler/rules/control-flow.js.map +1 -1
  132. package/dist/compiler/rules/diagnostic.d.ts.map +1 -1
  133. package/dist/compiler/rules/diagnostic.js.map +1 -1
  134. package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -1
  135. package/dist/compiler/rules/module-scope-refs.js.map +1 -1
  136. package/dist/compiler/rules/resource-escape.d.ts +7 -0
  137. package/dist/compiler/rules/resource-escape.d.ts.map +1 -0
  138. package/dist/compiler/rules/resource-escape.js +146 -0
  139. package/dist/compiler/rules/resource-escape.js.map +1 -0
  140. package/dist/compiler/rules/resource-providers.d.ts +19 -0
  141. package/dist/compiler/rules/resource-providers.d.ts.map +1 -0
  142. package/dist/compiler/rules/resource-providers.js +222 -0
  143. package/dist/compiler/rules/resource-providers.js.map +1 -0
  144. package/dist/compiler/schemas/analysis.d.ts.map +1 -1
  145. package/dist/compiler/schemas/analysis.js.map +1 -1
  146. package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -1
  147. package/dist/compiler/schemas/imported-record-functions.js.map +1 -1
  148. package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -1
  149. package/dist/compiler/schemas/imported-schemas.js.map +1 -1
  150. package/dist/compiler/source-map.d.ts.map +1 -1
  151. package/dist/compiler/source-map.js +2 -7
  152. package/dist/compiler/source-map.js.map +1 -1
  153. package/dist/compiler/type-view-paths.d.ts +6 -0
  154. package/dist/compiler/type-view-paths.d.ts.map +1 -0
  155. package/dist/compiler/type-view-paths.js +12 -0
  156. package/dist/compiler/type-view-paths.js.map +1 -0
  157. package/dist/compiler/typescript-context.d.ts.map +1 -1
  158. package/dist/compiler/typescript-context.js +5 -7
  159. package/dist/compiler/typescript-context.js.map +1 -1
  160. package/dist/compiler.d.ts.map +1 -1
  161. package/dist/compiler.js.map +1 -1
  162. package/dist/emitter/assemblyscript.d.ts.map +1 -1
  163. package/dist/emitter/assemblyscript.js +120 -136
  164. package/dist/emitter/assemblyscript.js.map +1 -1
  165. package/dist/emitter/declarations.d.ts.map +1 -1
  166. package/dist/emitter/declarations.js.map +1 -1
  167. package/dist/emitter/emitter.d.ts +3 -1
  168. package/dist/emitter/emitter.d.ts.map +1 -1
  169. package/dist/emitter/emitter.js +10 -1
  170. package/dist/emitter/emitter.js.map +1 -1
  171. package/dist/emitter/imports.d.ts.map +1 -1
  172. package/dist/emitter/imports.js.map +1 -1
  173. package/dist/emitter/indent.d.ts.map +1 -1
  174. package/dist/emitter/indent.js.map +1 -1
  175. package/dist/emitter/jsx.d.ts.map +1 -1
  176. package/dist/emitter/jsx.js.map +1 -1
  177. package/dist/emitter/local-bindings.d.ts.map +1 -1
  178. package/dist/emitter/local-bindings.js.map +1 -1
  179. package/dist/emitter/match.d.ts.map +1 -1
  180. package/dist/emitter/match.js.map +1 -1
  181. package/dist/emitter/runtime-helpers.d.ts.map +1 -1
  182. package/dist/emitter/runtime-helpers.js.map +1 -1
  183. package/dist/emitter/schemas.d.ts.map +1 -1
  184. package/dist/emitter/schemas.js.map +1 -1
  185. package/dist/emitter/statements.d.ts +1 -0
  186. package/dist/emitter/statements.d.ts.map +1 -1
  187. package/dist/emitter/statements.js +1 -0
  188. package/dist/emitter/statements.js.map +1 -1
  189. package/dist/emitter/tagged-match.d.ts.map +1 -1
  190. package/dist/emitter/tagged-match.js.map +1 -1
  191. package/dist/emitter/types.d.ts.map +1 -1
  192. package/dist/emitter/types.js.map +1 -1
  193. package/dist/errors.d.ts.map +1 -1
  194. package/dist/errors.js.map +1 -1
  195. package/dist/formatter/comments.d.ts.map +1 -1
  196. package/dist/formatter/comments.js +13 -0
  197. package/dist/formatter/comments.js.map +1 -1
  198. package/dist/formatter/index.d.ts +9 -0
  199. package/dist/formatter/index.d.ts.map +1 -1
  200. package/dist/formatter/index.js +215 -5
  201. package/dist/formatter/index.js.map +1 -1
  202. package/dist/formatter/operator-precedence.d.ts.map +1 -1
  203. package/dist/formatter/operator-precedence.js.map +1 -1
  204. package/dist/formatter/prettier.d.ts.map +1 -1
  205. package/dist/formatter/prettier.js.map +1 -1
  206. package/dist/index.d.ts +3 -0
  207. package/dist/index.d.ts.map +1 -1
  208. package/dist/index.js +3 -0
  209. package/dist/index.js.map +1 -1
  210. package/dist/interop/callback.d.ts.map +1 -1
  211. package/dist/interop/callback.js.map +1 -1
  212. package/dist/interop/js.d.ts.map +1 -1
  213. package/dist/interop/js.js.map +1 -1
  214. package/dist/interop/record.d.ts.map +1 -1
  215. package/dist/interop/record.js.map +1 -1
  216. package/dist/interop/valibot.d.ts.map +1 -1
  217. package/dist/interop/valibot.js.map +1 -1
  218. package/dist/interop/zod.d.ts.map +1 -1
  219. package/dist/interop/zod.js.map +1 -1
  220. package/dist/lexer/lexer.d.ts +1 -0
  221. package/dist/lexer/lexer.d.ts.map +1 -1
  222. package/dist/lexer/lexer.js +26 -10
  223. package/dist/lexer/lexer.js.map +1 -1
  224. package/dist/lexer/tokens.d.ts.map +1 -1
  225. package/dist/lexer/tokens.js.map +1 -1
  226. package/dist/lsp/code-action-worker.d.ts.map +1 -1
  227. package/dist/lsp/code-action-worker.js.map +1 -1
  228. package/dist/lsp/completion.d.ts +25 -0
  229. package/dist/lsp/completion.d.ts.map +1 -1
  230. package/dist/lsp/completion.js +1114 -51
  231. package/dist/lsp/completion.js.map +1 -1
  232. package/dist/lsp/definition.d.ts +2 -0
  233. package/dist/lsp/definition.d.ts.map +1 -1
  234. package/dist/lsp/definition.js +52 -58
  235. package/dist/lsp/definition.js.map +1 -1
  236. package/dist/lsp/diagnostics-worker.d.ts.map +1 -1
  237. package/dist/lsp/diagnostics-worker.js +1 -1
  238. package/dist/lsp/diagnostics-worker.js.map +1 -1
  239. package/dist/lsp/docs.d.ts +1 -1
  240. package/dist/lsp/docs.d.ts.map +1 -1
  241. package/dist/lsp/docs.js +4 -3
  242. package/dist/lsp/docs.js.map +1 -1
  243. package/dist/lsp/error-channel.d.ts.map +1 -1
  244. package/dist/lsp/error-channel.js.map +1 -1
  245. package/dist/lsp/hover.d.ts +5 -1
  246. package/dist/lsp/hover.d.ts.map +1 -1
  247. package/dist/lsp/hover.js +1016 -46
  248. package/dist/lsp/hover.js.map +1 -1
  249. package/dist/lsp/imports.d.ts +2 -0
  250. package/dist/lsp/imports.d.ts.map +1 -1
  251. package/dist/lsp/imports.js +45 -21
  252. package/dist/lsp/imports.js.map +1 -1
  253. package/dist/lsp/index.d.ts.map +1 -1
  254. package/dist/lsp/index.js.map +1 -1
  255. package/dist/lsp/inlay-hints.d.ts.map +1 -1
  256. package/dist/lsp/inlay-hints.js.map +1 -1
  257. package/dist/lsp/interop-rename.d.ts.map +1 -1
  258. package/dist/lsp/interop-rename.js.map +1 -1
  259. package/dist/lsp/match-arms.d.ts.map +1 -1
  260. package/dist/lsp/match-arms.js.map +1 -1
  261. package/dist/lsp/navigation.d.ts +1 -1
  262. package/dist/lsp/navigation.d.ts.map +1 -1
  263. package/dist/lsp/navigation.js +30 -12
  264. package/dist/lsp/navigation.js.map +1 -1
  265. package/dist/lsp/parsed-documents.d.ts.map +1 -1
  266. package/dist/lsp/parsed-documents.js.map +1 -1
  267. package/dist/lsp/range-format.d.ts +4 -0
  268. package/dist/lsp/range-format.d.ts.map +1 -0
  269. package/dist/lsp/range-format.js +88 -0
  270. package/dist/lsp/range-format.js.map +1 -0
  271. package/dist/lsp/rename-worker.d.ts.map +1 -1
  272. package/dist/lsp/rename-worker.js.map +1 -1
  273. package/dist/lsp/schema-import-hover.d.ts +8 -0
  274. package/dist/lsp/schema-import-hover.d.ts.map +1 -0
  275. package/dist/lsp/schema-import-hover.js +52 -0
  276. package/dist/lsp/schema-import-hover.js.map +1 -0
  277. package/dist/lsp/server.d.ts +3 -1
  278. package/dist/lsp/server.d.ts.map +1 -1
  279. package/dist/lsp/server.js +73 -48
  280. package/dist/lsp/server.js.map +1 -1
  281. package/dist/lsp/signature-help.d.ts +6 -0
  282. package/dist/lsp/signature-help.d.ts.map +1 -0
  283. package/dist/lsp/signature-help.js +183 -0
  284. package/dist/lsp/signature-help.js.map +1 -0
  285. package/dist/lsp/thunk-pipeline.d.ts.map +1 -1
  286. package/dist/lsp/thunk-pipeline.js.map +1 -1
  287. package/dist/lsp/validation.d.ts.map +1 -1
  288. package/dist/lsp/validation.js +3 -2
  289. package/dist/lsp/validation.js.map +1 -1
  290. package/dist/lsp/workspace.d.ts +3 -1
  291. package/dist/lsp/workspace.d.ts.map +1 -1
  292. package/dist/lsp/workspace.js +66 -10
  293. package/dist/lsp/workspace.js.map +1 -1
  294. package/dist/parser/declarations.d.ts.map +1 -1
  295. package/dist/parser/declarations.js +22 -1
  296. package/dist/parser/declarations.js.map +1 -1
  297. package/dist/parser/errors.d.ts.map +1 -1
  298. package/dist/parser/errors.js.map +1 -1
  299. package/dist/parser/jsx.d.ts.map +1 -1
  300. package/dist/parser/jsx.js.map +1 -1
  301. package/dist/parser/operator-expressions.d.ts.map +1 -1
  302. package/dist/parser/operator-expressions.js.map +1 -1
  303. package/dist/parser/parser.d.ts.map +1 -1
  304. package/dist/parser/parser.js.map +1 -1
  305. package/dist/parser/patterns.d.ts.map +1 -1
  306. package/dist/parser/patterns.js.map +1 -1
  307. package/dist/parser/pipeline-expressions.d.ts.map +1 -1
  308. package/dist/parser/pipeline-expressions.js.map +1 -1
  309. package/dist/parser/scope.d.ts.map +1 -1
  310. package/dist/parser/scope.js.map +1 -1
  311. package/dist/parser/statements.d.ts.map +1 -1
  312. package/dist/parser/statements.js.map +1 -1
  313. package/dist/parser/types.d.ts.map +1 -1
  314. package/dist/parser/types.js.map +1 -1
  315. package/dist/plugins/bun-preload.d.ts.map +1 -1
  316. package/dist/plugins/bun-preload.js.map +1 -1
  317. package/dist/plugins/bun.d.ts +2 -18
  318. package/dist/plugins/bun.d.ts.map +1 -1
  319. package/dist/plugins/bun.js +5 -30
  320. package/dist/plugins/bun.js.map +1 -1
  321. package/dist/plugins/esbuild.d.ts +1 -1
  322. package/dist/plugins/esbuild.d.ts.map +1 -1
  323. package/dist/plugins/esbuild.js +10 -36
  324. package/dist/plugins/esbuild.js.map +1 -1
  325. package/dist/plugins/server-boundary.d.ts +14 -0
  326. package/dist/plugins/server-boundary.d.ts.map +1 -0
  327. package/dist/plugins/server-boundary.js +25 -0
  328. package/dist/plugins/server-boundary.js.map +1 -0
  329. package/dist/plugins/type-view.d.ts.map +1 -1
  330. package/dist/plugins/type-view.js +5 -3
  331. package/dist/plugins/type-view.js.map +1 -1
  332. package/dist/plugins/vite.d.ts +2 -18
  333. package/dist/plugins/vite.d.ts.map +1 -1
  334. package/dist/plugins/vite.js +4 -29
  335. package/dist/plugins/vite.js.map +1 -1
  336. package/dist/testing/index.d.ts.map +1 -1
  337. package/dist/testing/index.js.map +1 -1
  338. package/dist/tooling/doc.d.ts.map +1 -1
  339. package/dist/tooling/doc.js.map +1 -1
  340. package/dist/tooling/idiomatic.d.ts.map +1 -1
  341. package/dist/tooling/idiomatic.js.map +1 -1
  342. package/dist/tooling/pipeline-style.d.ts.map +1 -1
  343. package/dist/tooling/pipeline-style.js.map +1 -1
  344. package/dist/version.d.ts.map +1 -1
  345. package/dist/version.js.map +1 -1
  346. package/package.json +13 -6
  347. package/src/cli/build-watch.ts +10 -29
  348. package/src/cli/build.ts +9 -60
  349. package/src/cli/check-policy.ts +54 -0
  350. package/src/cli/check.ts +19 -31
  351. package/src/cli/commands.ts +13 -0
  352. package/src/cli/doctor.ts +10 -7
  353. package/src/cli/index.ts +3 -0
  354. package/src/cli/init.ts +66 -21
  355. package/src/cli/query.ts +191 -0
  356. package/src/cli/run.ts +5 -30
  357. package/src/cli/tsc.ts +10 -8
  358. package/src/compiler/boolean-operators.ts +11 -2
  359. package/src/compiler/check.ts +152 -180
  360. package/src/compiler/diagnostics-json.ts +1205 -0
  361. package/src/compiler/escape-audit.ts +913 -0
  362. package/src/compiler/modules/output-plan.ts +11 -9
  363. package/src/compiler/modules/resolution.ts +2 -1
  364. package/src/compiler/modules/source-files.ts +13 -0
  365. package/src/compiler/numeric-comparisons.ts +14 -8
  366. package/src/compiler/pipelines/resolution.ts +30 -26
  367. package/src/compiler/project-config.ts +30 -19
  368. package/src/compiler/query.ts +1177 -0
  369. package/src/compiler/rules/resource-escape.ts +223 -0
  370. package/src/compiler/rules/resource-providers.ts +293 -0
  371. package/src/compiler/source-map.ts +3 -7
  372. package/src/compiler/type-view-paths.ts +10 -0
  373. package/src/compiler/typescript-context.ts +6 -7
  374. package/src/emitter/assemblyscript.ts +101 -147
  375. package/src/emitter/emitter.ts +13 -1
  376. package/src/emitter/statements.ts +2 -0
  377. package/src/formatter/comments.ts +14 -0
  378. package/src/formatter/index.ts +299 -4
  379. package/src/index.ts +3 -0
  380. package/src/lexer/lexer.ts +39 -20
  381. package/src/lsp/completion.ts +1452 -66
  382. package/src/lsp/definition.ts +50 -58
  383. package/src/lsp/diagnostics-worker.ts +1 -4
  384. package/src/lsp/docs.ts +4 -3
  385. package/src/lsp/hover.ts +1465 -44
  386. package/src/lsp/imports.ts +75 -22
  387. package/src/lsp/navigation.ts +41 -22
  388. package/src/lsp/range-format.ts +102 -0
  389. package/src/lsp/schema-import-hover.ts +76 -0
  390. package/src/lsp/server.ts +99 -69
  391. package/src/lsp/signature-help.ts +226 -0
  392. package/src/lsp/validation.ts +3 -2
  393. package/src/lsp/workspace.ts +63 -9
  394. package/src/parser/declarations.ts +27 -1
  395. package/src/plugins/bun.ts +14 -66
  396. package/src/plugins/esbuild.ts +16 -55
  397. package/src/plugins/server-boundary.ts +41 -0
  398. package/src/plugins/type-view.ts +11 -3
  399. package/src/plugins/vite.ts +12 -62
  400. package/dist/Widget.tsx +0 -9
  401. package/dist/cli/output-collisions.d.ts +0 -2
  402. package/dist/cli/output-collisions.d.ts.map +0 -1
  403. package/dist/cli/output-collisions.js +0 -39
  404. package/dist/cli/output-collisions.js.map +0 -1
  405. package/dist/compiler/imported-record-functions.d.ts +0 -4
  406. package/dist/compiler/imported-record-functions.d.ts.map +0 -1
  407. package/dist/compiler/imported-record-functions.js +0 -706
  408. package/dist/compiler/imported-record-functions.js.map +0 -1
  409. package/dist/compiler/imported-schemas.d.ts +0 -21
  410. package/dist/compiler/imported-schemas.d.ts.map +0 -1
  411. package/dist/compiler/imported-schemas.js +0 -461
  412. package/dist/compiler/imported-schemas.js.map +0 -1
  413. package/dist/compiler/module-resolution.d.ts +0 -6
  414. package/dist/compiler/module-resolution.d.ts.map +0 -1
  415. package/dist/compiler/module-resolution.js +0 -44
  416. package/dist/compiler/module-resolution.js.map +0 -1
  417. package/dist/compiler/pipeline-companions.d.ts +0 -18
  418. package/dist/compiler/pipeline-companions.d.ts.map +0 -1
  419. package/dist/compiler/pipeline-companions.js +0 -1042
  420. package/dist/compiler/pipeline-companions.js.map +0 -1
  421. package/dist/compiler/providers.d.ts +0 -4
  422. package/dist/compiler/providers.d.ts.map +0 -1
  423. package/dist/compiler/providers.js +0 -101
  424. package/dist/compiler/providers.js.map +0 -1
  425. package/dist/emitter/pipeline-catalog.d.ts +0 -15
  426. package/dist/emitter/pipeline-catalog.d.ts.map +0 -1
  427. package/dist/emitter/pipeline-catalog.js +0 -55
  428. package/dist/emitter/pipeline-catalog.js.map +0 -1
  429. package/dist/emitter/pipeline-resolution.d.ts +0 -38
  430. package/dist/emitter/pipeline-resolution.d.ts.map +0 -1
  431. package/dist/emitter/pipeline-resolution.js +0 -571
  432. package/dist/emitter/pipeline-resolution.js.map +0 -1
  433. package/dist/interop/index.d.ts +0 -6
  434. package/dist/interop/index.d.ts.map +0 -1
  435. package/dist/interop/index.js +0 -6
  436. package/dist/interop/index.js.map +0 -1
  437. package/dist/math.ts +0 -1
  438. package/dist/parser/index.d.ts +0 -9
  439. package/dist/parser/index.d.ts.map +0 -1
  440. package/dist/parser/index.js +0 -9
  441. package/dist/parser/index.js.map +0 -1
  442. package/dist/service.ts +0 -3
  443. package/dist/service.ts.map +0 -1
  444. package/dist/tooling/migrate.d.ts +0 -62
  445. package/dist/tooling/migrate.d.ts.map +0 -1
  446. package/dist/tooling/migrate.js +0 -608
  447. package/dist/tooling/migrate.js.map +0 -1
@@ -0,0 +1,223 @@
1
+ import ts from "typescript";
2
+ import {
3
+ asRecord,
4
+ astChild,
5
+ astChildren,
6
+ astName,
7
+ collectPatternVars,
8
+ isAstNode,
9
+ type AstInspectNode,
10
+ } from "../ast-inspection.js";
11
+
12
+ /** Find resources flowing into a block's result, including through aliases and closures. */
13
+ export function findResourceEscape(
14
+ effectBlock: AstInspectNode,
15
+ finalExpr: AstInspectNode,
16
+ followsAcquire: (expr: AstInspectNode, seen: Set<string>) => boolean,
17
+ isIndependentProperty: (expr: AstInspectNode) => boolean,
18
+ ): AstInspectNode | undefined {
19
+ const resolveReturned = (
20
+ name: string | undefined,
21
+ seen: Set<string>,
22
+ ): AstInspectNode | undefined => {
23
+ if (!name || seen.has(name)) return undefined;
24
+ const stmts = astChildren(effectBlock, "body");
25
+ const bind = stmts.find(
26
+ (stmt) =>
27
+ stmt.kind === "EffectBindStatement" &&
28
+ astName(astChild(stmt, "id")) === name,
29
+ );
30
+ if (bind) return bind;
31
+ const alias = stmts.find(
32
+ (stmt) =>
33
+ stmt.kind === "BindingDeclaration" &&
34
+ astName(astChild(stmt, "id")) === name,
35
+ );
36
+ const init = astChild(alias, "init");
37
+ return init?.kind === "Identifier"
38
+ ? resolveReturned(astName(init), new Set([...seen, name]))
39
+ : undefined;
40
+ };
41
+ const findEscapedResource = (
42
+ expr: AstInspectNode | null,
43
+ hidden: Set<string>,
44
+ seen: Set<string>,
45
+ inClosure: boolean,
46
+ matched: ReadonlyMap<string, AstInspectNode> = new Map(),
47
+ ): AstInspectNode | undefined => {
48
+ if (!expr) return undefined;
49
+ if (
50
+ expr.kind === "StringLiteral" ||
51
+ expr.kind === "TemplateLiteral" ||
52
+ expr.kind === "NumberLiteral" ||
53
+ expr.kind === "BooleanLiteral"
54
+ )
55
+ return undefined;
56
+ if (expr.kind === "Identifier") {
57
+ const name = astName(expr);
58
+ if (!name || seen.has(name)) return undefined;
59
+ if (matched.has(name)) return matched.get(name);
60
+ if (hidden.has(name)) return undefined;
61
+ const bind = resolveReturned(name, new Set());
62
+ const source = astChild(bind, "effect");
63
+ if (source && followsAcquire(source, new Set())) return source;
64
+ const local = astChildren(effectBlock, "body").find(
65
+ (stmt) =>
66
+ stmt.kind === "BindingDeclaration" &&
67
+ astName(astChild(stmt, "id")) === name,
68
+ );
69
+ return findEscapedResource(
70
+ astChild(local, "init"),
71
+ hidden,
72
+ new Set([...seen, name]),
73
+ inClosure,
74
+ matched,
75
+ );
76
+ }
77
+ if (expr.kind === "MemberExpression" || expr.kind === "IndexExpression") {
78
+ return inClosure || !isIndependentProperty(expr)
79
+ ? findEscapedResource(
80
+ astChild(expr, "object"),
81
+ hidden,
82
+ seen,
83
+ true,
84
+ matched,
85
+ )
86
+ : undefined;
87
+ }
88
+ if (expr.kind === "MatchExpression") {
89
+ const subject = findEscapedResource(
90
+ astChild(expr, "scrutinee"),
91
+ hidden,
92
+ seen,
93
+ false,
94
+ matched,
95
+ );
96
+ for (const arm of astChildren(expr, "arms")) {
97
+ const nestedHidden = new Set(hidden);
98
+ const nestedMatched = new Map(matched);
99
+ for (const name of collectPatternVars(astChild(arm, "pattern"))) {
100
+ nestedHidden.add(name);
101
+ if (subject) nestedMatched.set(name, subject);
102
+ else nestedMatched.delete(name);
103
+ }
104
+ const found = findEscapedResource(
105
+ astChild(arm, "body"),
106
+ nestedHidden,
107
+ seen,
108
+ inClosure,
109
+ nestedMatched,
110
+ );
111
+ if (found) return found;
112
+ }
113
+ return undefined;
114
+ }
115
+ if (expr.kind === "FunctionExpression") {
116
+ const nestedHidden = new Set(hidden);
117
+ const nestedMatched = new Map(matched);
118
+ for (const param of astChildren(expr, "params")) {
119
+ for (const name of collectPatternVars(astChild(param, "name"))) {
120
+ nestedHidden.add(name);
121
+ nestedMatched.delete(name);
122
+ }
123
+ }
124
+ const body = astChild(expr, "body");
125
+ if (body?.kind === "BlockStatement") {
126
+ for (const stmt of astChildren(body, "statements")) {
127
+ if (stmt.kind === "BindingDeclaration") {
128
+ for (const name of collectPatternVars(astChild(stmt, "id"))) {
129
+ nestedHidden.add(name);
130
+ nestedMatched.delete(name);
131
+ }
132
+ }
133
+ }
134
+ }
135
+ return findEscapedResource(body, nestedHidden, seen, true, nestedMatched);
136
+ }
137
+ if (expr.kind === "FieldEntry" || expr.kind === "DotPathEntry")
138
+ return findEscapedResource(
139
+ astChild(expr, "value"),
140
+ hidden,
141
+ seen,
142
+ inClosure,
143
+ matched,
144
+ );
145
+ if (expr.kind === "ShorthandEntry")
146
+ return findEscapedResource(
147
+ astChild(expr, "key"),
148
+ hidden,
149
+ seen,
150
+ inClosure,
151
+ matched,
152
+ );
153
+ for (const [key, value] of Object.entries(asRecord(expr))) {
154
+ if (key === "span" || key === "typeAnnotation") continue;
155
+ const children = Array.isArray(value) ? value : [value];
156
+ for (const child of children) {
157
+ if (!isAstNode(child)) continue;
158
+ const found = findEscapedResource(
159
+ child,
160
+ hidden,
161
+ seen,
162
+ inClosure,
163
+ matched,
164
+ );
165
+ if (found) return found;
166
+ }
167
+ }
168
+ return undefined;
169
+ };
170
+ return findEscapedResource(finalExpr, new Set(), new Set(), false);
171
+ }
172
+
173
+ /** Check a scoped result using TypeScript types to recognize independent values. */
174
+ export function findScopedResourceEscape(
175
+ effectBlock: AstInspectNode,
176
+ finalExpr: AstInspectNode,
177
+ sourceFile: ts.SourceFile,
178
+ checker: ts.TypeChecker,
179
+ followsAcquire: (expr: AstInspectNode, seen: Set<string>) => boolean,
180
+ ): AstInspectNode | undefined {
181
+ const isIndependentProperty = (expr: AstInspectNode): boolean => {
182
+ if (expr.kind !== "MemberExpression") return false;
183
+ const object = astName(astChild(expr, "object"));
184
+ const property = astName(astChild(expr, "property"));
185
+ if (!object || !property) return false;
186
+ const isPrimitive = (type: ts.Type): boolean =>
187
+ type.isUnion()
188
+ ? type.types.every(isPrimitive)
189
+ : !!(
190
+ type.flags &
191
+ (ts.TypeFlags.StringLike |
192
+ ts.TypeFlags.NumberLike |
193
+ ts.TypeFlags.BooleanLike |
194
+ ts.TypeFlags.BigIntLike |
195
+ ts.TypeFlags.ESSymbolLike |
196
+ ts.TypeFlags.Null |
197
+ ts.TypeFlags.Undefined)
198
+ );
199
+ let found = false;
200
+ let independent = true;
201
+ const visit = (candidate: ts.Node): void => {
202
+ if (
203
+ ts.isPropertyAccessExpression(candidate) &&
204
+ ts.isIdentifier(candidate.expression) &&
205
+ candidate.expression.text === object &&
206
+ candidate.name.text === property
207
+ ) {
208
+ found = true;
209
+ if (!isPrimitive(checker.getTypeAtLocation(candidate)))
210
+ independent = false;
211
+ }
212
+ ts.forEachChild(candidate, visit);
213
+ };
214
+ visit(sourceFile);
215
+ return found && independent;
216
+ };
217
+ return findResourceEscape(
218
+ effectBlock,
219
+ finalExpr,
220
+ followsAcquire,
221
+ isIndependentProperty,
222
+ );
223
+ }
@@ -0,0 +1,293 @@
1
+ import * as fs from "node:fs";
2
+ import type { Program } from "../../ast/types.js";
3
+ import { FunScriptError, isFileNotFoundError } from "../../errors.js";
4
+ import { Lexer } from "../../lexer/lexer.js";
5
+ import { Parser } from "../../parser/parser.js";
6
+ import {
7
+ astBool,
8
+ astChild,
9
+ astChildren,
10
+ astName,
11
+ collectPatternVars,
12
+ getMemberNames,
13
+ type AstInspectNode,
14
+ } from "../ast-inspection.js";
15
+ import { resolveFunModule } from "../modules/resolution.js";
16
+ import { findResourceEscape } from "./resource-escape.js";
17
+
18
+ const scopedEffectProviders = new Set([
19
+ "acquireRelease",
20
+ "makeSpanScoped",
21
+ "forkScoped",
22
+ ]);
23
+
24
+ export function effectImportNames(program: Program | undefined) {
25
+ const effect = new Set(["Effect"]);
26
+ const scope = new Set(["Scope"]);
27
+ const acquire = new Set(["acquireRelease"]);
28
+ const finalizer = new Set(["addFinalizer"]);
29
+ for (const item of program?.body ?? []) {
30
+ if (item.kind !== "ImportDeclaration" || item.isTypeOnly) continue;
31
+ const source = item.source.parts
32
+ .map((part) => (part.kind === "StringRawPart" ? part.value : ""))
33
+ .join("");
34
+ if (source === "effect") {
35
+ for (const spec of item.specifiers) {
36
+ if (spec.isTypeOnly) continue;
37
+ if (spec.imported.name === "Effect") effect.add(spec.local.name);
38
+ if (spec.imported.name === "Scope") scope.add(spec.local.name);
39
+ }
40
+ }
41
+ if (source === "effect/Effect" || source === "effect/Scope") {
42
+ if (item.namespaceBinding)
43
+ (source === "effect/Effect" ? effect : scope).add(
44
+ item.namespaceBinding.name,
45
+ );
46
+ for (const spec of item.specifiers) {
47
+ if (spec.isTypeOnly) continue;
48
+ if (
49
+ source === "effect/Effect" &&
50
+ scopedEffectProviders.has(spec.imported.name)
51
+ )
52
+ acquire.add(spec.local.name);
53
+ if (spec.imported.name === "addFinalizer")
54
+ finalizer.add(spec.local.name);
55
+ }
56
+ }
57
+ }
58
+ for (const item of program?.body ?? []) {
59
+ const declaration =
60
+ item.kind === "ExportDeclaration" ? item.declaration : item;
61
+ if (
62
+ declaration.kind !== "BindingDeclaration" ||
63
+ declaration.id.kind !== "Identifier"
64
+ )
65
+ continue;
66
+ effect.delete(declaration.id.name);
67
+ scope.delete(declaration.id.name);
68
+ acquire.delete(declaration.id.name);
69
+ finalizer.delete(declaration.id.name);
70
+ }
71
+ return { effect, scope, acquire, finalizer };
72
+ }
73
+
74
+ type Ref = { target: string; name: string };
75
+ type Module = {
76
+ file: string;
77
+ ast: Program;
78
+ bindings: Map<string, AstInspectNode>;
79
+ named: Map<string, Ref>;
80
+ namespaces: Map<string, string>;
81
+ imports: ReturnType<typeof effectImportNames>;
82
+ };
83
+
84
+ /** Resolve resource acquisition through inspected FunkScript modules only. */
85
+ export function createResourceProviderResolver(options: {
86
+ rootFile: string;
87
+ rootAst: Program;
88
+ rootBindings: Map<string, AstInspectNode>;
89
+ rootImports: ReturnType<typeof effectImportNames>;
90
+ shadowed: ReadonlySet<string>;
91
+ sources: ReadonlyMap<string, string>;
92
+ programs: ReadonlyMap<string, Program>;
93
+ }): (expr: AstInspectNode, seen: Set<string>) => boolean {
94
+ const modules = new Map<string, Module>();
95
+ const resolveTarget = (file: string, specifier: string) =>
96
+ resolveFunModule(
97
+ file,
98
+ specifier,
99
+ (name) => options.sources.has(name) || fs.existsSync(name),
100
+ { directories: true },
101
+ );
102
+ const moduleFor = (file: string, ast?: Program): Module | undefined => {
103
+ const cached = modules.get(file);
104
+ if (cached) return cached;
105
+ if (!ast) {
106
+ ast = options.programs.get(file);
107
+ if (!ast) {
108
+ try {
109
+ const source =
110
+ options.sources.get(file) ?? fs.readFileSync(file, "utf8");
111
+ ast = new Parser(
112
+ new Lexer(source, file).tokenize(),
113
+ file,
114
+ source,
115
+ ).parse();
116
+ } catch (error) {
117
+ if (!(error instanceof FunScriptError) && !isFileNotFoundError(error))
118
+ throw error;
119
+ return undefined;
120
+ }
121
+ }
122
+ }
123
+ const root = file === options.rootFile;
124
+ const context: Module = {
125
+ file,
126
+ ast,
127
+ bindings: root ? options.rootBindings : new Map<string, AstInspectNode>(),
128
+ imports: root ? options.rootImports : effectImportNames(ast),
129
+ named: new Map(),
130
+ namespaces: new Map(),
131
+ };
132
+ modules.set(file, context);
133
+ for (const entry of ast.body) {
134
+ const binding =
135
+ entry.kind === "ExportDeclaration" ? entry.declaration : entry;
136
+ if (
137
+ !root &&
138
+ binding.kind === "BindingDeclaration" &&
139
+ binding.id.kind === "Identifier"
140
+ )
141
+ context.bindings.set(binding.id.name, binding.init);
142
+ if (entry.kind !== "ImportDeclaration" || entry.isTypeOnly) continue;
143
+ const specifier = entry.source.parts
144
+ .map((part) => (part.kind === "StringRawPart" ? part.value : ""))
145
+ .join("");
146
+ const target = resolveTarget(file, specifier);
147
+ if (!target) continue;
148
+ if (
149
+ entry.namespaceBinding &&
150
+ !(root && options.shadowed.has(entry.namespaceBinding.name))
151
+ )
152
+ context.namespaces.set(entry.namespaceBinding.name, target);
153
+ for (const spec of entry.specifiers) {
154
+ if (
155
+ !spec.isTypeOnly &&
156
+ !(root && options.shadowed.has(spec.local.name))
157
+ )
158
+ context.named.set(spec.local.name, {
159
+ target,
160
+ name: spec.imported.name,
161
+ });
162
+ }
163
+ }
164
+ return context;
165
+ };
166
+ const root = moduleFor(options.rootFile, options.rootAst)!;
167
+ const exported = (
168
+ file: string,
169
+ name: string,
170
+ seen: Set<string>,
171
+ ): { expression: AstInspectNode; context: Module } | undefined => {
172
+ const key = `export:${file}:${name}`;
173
+ if (seen.has(key)) return undefined;
174
+ const nextSeen = new Set([...seen, key]);
175
+ const context = moduleFor(file);
176
+ if (!context) return undefined;
177
+ for (const entry of context.ast.body) {
178
+ if (
179
+ entry.kind === "ExportDeclaration" &&
180
+ entry.declaration.kind === "BindingDeclaration" &&
181
+ entry.declaration.id.kind === "Identifier" &&
182
+ entry.declaration.id.name === name
183
+ )
184
+ return { expression: entry.declaration.init, context };
185
+ if (entry.kind === "ExportFromDeclaration" && !entry.isTypeOnly) {
186
+ const spec = entry.specifiers.find(
187
+ (item) => !item.isTypeOnly && item.local.name === name,
188
+ );
189
+ if (!spec) continue;
190
+ const source = entry.source.parts
191
+ .map((part) => (part.kind === "StringRawPart" ? part.value : ""))
192
+ .join("");
193
+ const target = resolveTarget(file, source);
194
+ if (target) return exported(target, spec.imported.name, nextSeen);
195
+ }
196
+ }
197
+ return undefined;
198
+ };
199
+ // Function parameters shadow names only in their own module. Keep graph
200
+ // cycle markers when following an import, but not lexical shadowing names.
201
+ const acrossModule = (seen: Set<string>) =>
202
+ new Set(
203
+ [...seen].filter(
204
+ (key) =>
205
+ key.startsWith("binding:") ||
206
+ key.startsWith("namespace:") ||
207
+ key.startsWith("export:"),
208
+ ),
209
+ );
210
+ const follows = (
211
+ expr: AstInspectNode | null,
212
+ seen: Set<string>,
213
+ context: Module,
214
+ ): boolean => {
215
+ if (!expr) return false;
216
+ if (expr.kind === "Identifier") {
217
+ const name = astName(expr);
218
+ if (!name || seen.has(name)) return false;
219
+ const key = `binding:${context.file}:${name}`;
220
+ if (seen.has(key)) return false;
221
+ const nextSeen = new Set([...seen, key]);
222
+ const local = context.bindings.get(name);
223
+ if (local) return follows(local, nextSeen, context);
224
+ const imported = context.named.get(name);
225
+ const target =
226
+ imported && exported(imported.target, imported.name, nextSeen);
227
+ return target
228
+ ? follows(target.expression, acrossModule(nextSeen), target.context)
229
+ : false;
230
+ }
231
+ if (expr.kind === "FunctionExpression") {
232
+ const nestedSeen = new Set(seen);
233
+ for (const param of astChildren(expr, "params"))
234
+ for (const name of collectPatternVars(astChild(param, "name")))
235
+ nestedSeen.add(name);
236
+ return follows(astChild(expr, "body"), nestedSeen, context);
237
+ }
238
+ if (expr.kind === "BlockStatement")
239
+ return follows(astChild(expr, "finalExpression"), seen, context);
240
+ if (expr.kind === "EffectBlockExpression" && astBool(expr, "unscoped")) {
241
+ const result = astChild(expr, "finalExpression");
242
+ return !!(
243
+ result &&
244
+ findResourceEscape(
245
+ expr,
246
+ result,
247
+ (source, localSeen) =>
248
+ follows(source, new Set([...seen, ...localSeen]), context),
249
+ () => true,
250
+ )
251
+ );
252
+ }
253
+ if (expr.kind === "CallExpression") {
254
+ const callee = astChild(expr, "callee");
255
+ const member = getMemberNames(callee);
256
+ const name = astName(callee);
257
+ if (
258
+ (member?.object &&
259
+ !seen.has(member.object) &&
260
+ context.imports.effect.has(member.object) &&
261
+ !!member.property &&
262
+ scopedEffectProviders.has(member.property)) ||
263
+ (callee?.kind === "Identifier" &&
264
+ name &&
265
+ !seen.has(name) &&
266
+ context.imports.acquire.has(name))
267
+ )
268
+ return true;
269
+ if (callee?.kind === "Identifier") return follows(callee, seen, context);
270
+ if (
271
+ member?.object &&
272
+ member.property &&
273
+ !seen.has(member.object) &&
274
+ !context.bindings.has(member.object)
275
+ ) {
276
+ const key = `namespace:${context.file}:${member.object}.${member.property}`;
277
+ if (seen.has(key)) return false;
278
+ const nextSeen = new Set([...seen, key]);
279
+ const namespace = context.namespaces.get(member.object);
280
+ const target =
281
+ namespace && exported(namespace, member.property, nextSeen);
282
+ if (target)
283
+ return follows(
284
+ target.expression,
285
+ acrossModule(nextSeen),
286
+ target.context,
287
+ );
288
+ }
289
+ }
290
+ return false;
291
+ };
292
+ return (expr, seen) => follows(expr, seen, root);
293
+ }
@@ -2,6 +2,7 @@ import MagicString, { Bundle, type SourceMap } from "magic-string";
2
2
  import ts from "typescript";
3
3
  import type { Program } from "../ast/types.js";
4
4
  import { Emitter, type EmitterOptions } from "../emitter/emitter.js";
5
+ import { funSourceToTypeScriptFile } from "./modules/source-files.js";
5
6
 
6
7
  /** Map generated TypeScript back to declarations in the original source. */
7
8
  export function generateSourceMap(
@@ -12,13 +13,8 @@ export function generateSourceMap(
12
13
  emitterOptions: EmitterOptions,
13
14
  outputFile?: string,
14
15
  ): SourceMap {
15
- const outTarget = outputFile
16
- ? outputFile
17
- : filename.endsWith(".funx")
18
- ? `${filename.slice(0, -5)}.tsx`
19
- : filename.endsWith(".fun")
20
- ? `${filename.slice(0, -4)}.ts`
21
- : `${filename}.ts`;
16
+ const outTarget =
17
+ outputFile || funSourceToTypeScriptFile(filename) || `${filename}.ts`;
22
18
 
23
19
  const s = new MagicString(source);
24
20
  const movedImports: Array<{
@@ -0,0 +1,10 @@
1
+ /** Default location and manifest shared by the type-view writer and readers. */
2
+ export const DEFAULT_TYPE_VIEW_DIR = ".funscript/types";
3
+ export const TYPE_VIEW_MANIFEST = ".funscript-type-view.json";
4
+
5
+ /** Read source names from the current manifest or its legacy array format. */
6
+ export function typeViewManifestSources(manifest: unknown): unknown[] {
7
+ if (Array.isArray(manifest)) return manifest;
8
+ if (manifest && typeof manifest === "object") return Object.keys(manifest);
9
+ return [];
10
+ }
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import ts from "typescript";
4
4
  import { isFileNotFoundError } from "../errors.js";
5
+ import { funSourceToTypeScriptFile } from "./modules/source-files.js";
5
6
 
6
7
  // Declaration files are immutable for the lifetime of a process in the common
7
8
  // case. Share parsed ASTs between compilation contexts, while checking file
@@ -174,13 +175,11 @@ export class TypeScriptCompilationContext {
174
175
  }
175
176
 
176
177
  setFilename(filename: string, reuseProgram = false): void {
177
- const nextFile = filename.endsWith(".funx")
178
- ? filename.slice(0, -5) + ".tsx"
179
- : filename.endsWith(".fun")
180
- ? filename.slice(0, -4) + ".ts"
181
- : filename.endsWith(".ts") || filename.endsWith(".tsx")
182
- ? filename
183
- : filename + ".ts";
178
+ const nextFile =
179
+ funSourceToTypeScriptFile(filename) ??
180
+ (filename.endsWith(".ts") || filename.endsWith(".tsx")
181
+ ? filename
182
+ : `${filename}.ts`);
184
183
  if (this.virtualFile && this.virtualFile !== nextFile && !reuseProgram)
185
184
  this.program = undefined;
186
185
  // Directory tooling can opt into using the old Program as an incremental