funkscript 0.2.3 → 0.2.6

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 (359) 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 +5 -3
  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.map +1 -1
  14. package/dist/cli/check.d.ts.map +1 -1
  15. package/dist/cli/check.js.map +1 -1
  16. package/dist/cli/commands.d.ts.map +1 -1
  17. package/dist/cli/commands.js.map +1 -1
  18. package/dist/cli/doc.d.ts.map +1 -1
  19. package/dist/cli/doc.js.map +1 -1
  20. package/dist/cli/doctor.d.ts.map +1 -1
  21. package/dist/cli/doctor.js +4 -2
  22. package/dist/cli/doctor.js.map +1 -1
  23. package/dist/cli/emit.d.ts +1 -1
  24. package/dist/cli/emit.d.ts.map +1 -1
  25. package/dist/cli/emit.js.map +1 -1
  26. package/dist/cli/explain.d.ts.map +1 -1
  27. package/dist/cli/explain.js.map +1 -1
  28. package/dist/cli/fmt.d.ts.map +1 -1
  29. package/dist/cli/fmt.js.map +1 -1
  30. package/dist/cli/index.d.ts.map +1 -1
  31. package/dist/cli/index.js +0 -0
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/init.d.ts +1 -1
  34. package/dist/cli/init.d.ts.map +1 -1
  35. package/dist/cli/init.js +66 -21
  36. package/dist/cli/init.js.map +1 -1
  37. package/dist/cli/io.d.ts.map +1 -1
  38. package/dist/cli/io.js.map +1 -1
  39. package/dist/cli/pipeline-style.d.ts.map +1 -1
  40. package/dist/cli/pipeline-style.js.map +1 -1
  41. package/dist/cli/repl.d.ts.map +1 -1
  42. package/dist/cli/repl.js.map +1 -1
  43. package/dist/cli/run.d.ts.map +1 -1
  44. package/dist/cli/run.js.map +1 -1
  45. package/dist/cli/test.d.ts +1 -1
  46. package/dist/cli/test.d.ts.map +1 -1
  47. package/dist/cli/test.js.map +1 -1
  48. package/dist/cli/tsc.d.ts.map +1 -1
  49. package/dist/cli/tsc.js +5 -3
  50. package/dist/cli/tsc.js.map +1 -1
  51. package/dist/cli/typecheck.d.ts.map +1 -1
  52. package/dist/cli/typecheck.js.map +1 -1
  53. package/dist/compiler/ast-inspection.d.ts.map +1 -1
  54. package/dist/compiler/ast-inspection.js.map +1 -1
  55. package/dist/compiler/boolean-operators.d.ts.map +1 -1
  56. package/dist/compiler/boolean-operators.js +12 -2
  57. package/dist/compiler/boolean-operators.js.map +1 -1
  58. package/dist/compiler/check.d.ts.map +1 -1
  59. package/dist/compiler/check.js +95 -103
  60. package/dist/compiler/check.js.map +1 -1
  61. package/dist/compiler/diagnostics.d.ts.map +1 -1
  62. package/dist/compiler/diagnostics.js.map +1 -1
  63. package/dist/compiler/effect-mutation-rule.d.ts.map +1 -1
  64. package/dist/compiler/effect-mutation-rule.js.map +1 -1
  65. package/dist/compiler/entry-rules.d.ts.map +1 -1
  66. package/dist/compiler/entry-rules.js.map +1 -1
  67. package/dist/compiler/incremental-build.d.ts.map +1 -1
  68. package/dist/compiler/incremental-build.js.map +1 -1
  69. package/dist/compiler/incremental-dependencies.d.ts.map +1 -1
  70. package/dist/compiler/incremental-dependencies.js.map +1 -1
  71. package/dist/compiler/js-interop-nullability.d.ts.map +1 -1
  72. package/dist/compiler/js-interop-nullability.js.map +1 -1
  73. package/dist/compiler/modules/output-collisions.d.ts.map +1 -1
  74. package/dist/compiler/modules/output-collisions.js.map +1 -1
  75. package/dist/compiler/modules/output-plan.d.ts.map +1 -1
  76. package/dist/compiler/modules/output-plan.js.map +1 -1
  77. package/dist/compiler/modules/resolution.d.ts.map +1 -1
  78. package/dist/compiler/modules/resolution.js +2 -1
  79. package/dist/compiler/modules/resolution.js.map +1 -1
  80. package/dist/compiler/modules/source-files.d.ts +3 -0
  81. package/dist/compiler/modules/source-files.d.ts.map +1 -0
  82. package/dist/compiler/modules/source-files.js +5 -0
  83. package/dist/compiler/modules/source-files.js.map +1 -0
  84. package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
  85. package/dist/compiler/numeric-comparisons.js.map +1 -1
  86. package/dist/compiler/optional-arguments.d.ts.map +1 -1
  87. package/dist/compiler/optional-arguments.js.map +1 -1
  88. package/dist/compiler/package-fingerprint.d.ts.map +1 -1
  89. package/dist/compiler/package-fingerprint.js.map +1 -1
  90. package/dist/compiler/package-record-contracts.d.ts.map +1 -1
  91. package/dist/compiler/package-record-contracts.js.map +1 -1
  92. package/dist/compiler/pipelines/catalog.d.ts.map +1 -1
  93. package/dist/compiler/pipelines/catalog.js.map +1 -1
  94. package/dist/compiler/pipelines/companions.d.ts.map +1 -1
  95. package/dist/compiler/pipelines/companions.js.map +1 -1
  96. package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
  97. package/dist/compiler/pipelines/resolution.js.map +1 -1
  98. package/dist/compiler/project-config.d.ts.map +1 -1
  99. package/dist/compiler/project-config.js +29 -19
  100. package/dist/compiler/project-config.js.map +1 -1
  101. package/dist/compiler/record-contracts.d.ts.map +1 -1
  102. package/dist/compiler/record-contracts.js.map +1 -1
  103. package/dist/compiler/rules/control-flow.d.ts.map +1 -1
  104. package/dist/compiler/rules/control-flow.js.map +1 -1
  105. package/dist/compiler/rules/diagnostic.d.ts.map +1 -1
  106. package/dist/compiler/rules/diagnostic.js.map +1 -1
  107. package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -1
  108. package/dist/compiler/rules/module-scope-refs.js.map +1 -1
  109. package/dist/compiler/rules/resource-escape.d.ts +7 -0
  110. package/dist/compiler/rules/resource-escape.d.ts.map +1 -0
  111. package/dist/compiler/rules/resource-escape.js +146 -0
  112. package/dist/compiler/rules/resource-escape.js.map +1 -0
  113. package/dist/compiler/rules/resource-providers.d.ts +19 -0
  114. package/dist/compiler/rules/resource-providers.d.ts.map +1 -0
  115. package/dist/compiler/rules/resource-providers.js +222 -0
  116. package/dist/compiler/rules/resource-providers.js.map +1 -0
  117. package/dist/compiler/schemas/analysis.d.ts.map +1 -1
  118. package/dist/compiler/schemas/analysis.js.map +1 -1
  119. package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -1
  120. package/dist/compiler/schemas/imported-record-functions.js.map +1 -1
  121. package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -1
  122. package/dist/compiler/schemas/imported-schemas.js.map +1 -1
  123. package/dist/compiler/source-map.d.ts.map +1 -1
  124. package/dist/compiler/source-map.js.map +1 -1
  125. package/dist/compiler/type-view-paths.d.ts +4 -0
  126. package/dist/compiler/type-view-paths.d.ts.map +1 -0
  127. package/dist/compiler/type-view-paths.js +4 -0
  128. package/dist/compiler/type-view-paths.js.map +1 -0
  129. package/dist/compiler/typescript-context.d.ts.map +1 -1
  130. package/dist/compiler/typescript-context.js.map +1 -1
  131. package/dist/compiler.d.ts.map +1 -1
  132. package/dist/compiler.js.map +1 -1
  133. package/dist/emitter/assemblyscript.d.ts.map +1 -1
  134. package/dist/emitter/assemblyscript.js.map +1 -1
  135. package/dist/emitter/declarations.d.ts.map +1 -1
  136. package/dist/emitter/declarations.js.map +1 -1
  137. package/dist/emitter/emitter.d.ts +3 -1
  138. package/dist/emitter/emitter.d.ts.map +1 -1
  139. package/dist/emitter/emitter.js +10 -1
  140. package/dist/emitter/emitter.js.map +1 -1
  141. package/dist/emitter/imports.d.ts.map +1 -1
  142. package/dist/emitter/imports.js.map +1 -1
  143. package/dist/emitter/indent.d.ts.map +1 -1
  144. package/dist/emitter/indent.js.map +1 -1
  145. package/dist/emitter/jsx.d.ts.map +1 -1
  146. package/dist/emitter/jsx.js.map +1 -1
  147. package/dist/emitter/local-bindings.d.ts.map +1 -1
  148. package/dist/emitter/local-bindings.js.map +1 -1
  149. package/dist/emitter/match.d.ts.map +1 -1
  150. package/dist/emitter/match.js.map +1 -1
  151. package/dist/emitter/runtime-helpers.d.ts.map +1 -1
  152. package/dist/emitter/runtime-helpers.js.map +1 -1
  153. package/dist/emitter/schemas.d.ts.map +1 -1
  154. package/dist/emitter/schemas.js.map +1 -1
  155. package/dist/emitter/statements.d.ts +1 -0
  156. package/dist/emitter/statements.d.ts.map +1 -1
  157. package/dist/emitter/statements.js +1 -0
  158. package/dist/emitter/statements.js.map +1 -1
  159. package/dist/emitter/tagged-match.d.ts.map +1 -1
  160. package/dist/emitter/tagged-match.js.map +1 -1
  161. package/dist/emitter/types.d.ts.map +1 -1
  162. package/dist/emitter/types.js.map +1 -1
  163. package/dist/errors.d.ts.map +1 -1
  164. package/dist/errors.js.map +1 -1
  165. package/dist/formatter/comments.d.ts.map +1 -1
  166. package/dist/formatter/comments.js +13 -0
  167. package/dist/formatter/comments.js.map +1 -1
  168. package/dist/formatter/index.d.ts.map +1 -1
  169. package/dist/formatter/index.js +57 -3
  170. package/dist/formatter/index.js.map +1 -1
  171. package/dist/formatter/operator-precedence.d.ts.map +1 -1
  172. package/dist/formatter/operator-precedence.js.map +1 -1
  173. package/dist/formatter/prettier.d.ts.map +1 -1
  174. package/dist/formatter/prettier.js.map +1 -1
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js.map +1 -1
  177. package/dist/interop/callback.d.ts.map +1 -1
  178. package/dist/interop/callback.js.map +1 -1
  179. package/dist/interop/js.d.ts.map +1 -1
  180. package/dist/interop/js.js.map +1 -1
  181. package/dist/interop/record.d.ts.map +1 -1
  182. package/dist/interop/record.js.map +1 -1
  183. package/dist/interop/valibot.d.ts.map +1 -1
  184. package/dist/interop/valibot.js.map +1 -1
  185. package/dist/interop/zod.d.ts.map +1 -1
  186. package/dist/interop/zod.js.map +1 -1
  187. package/dist/lexer/lexer.d.ts +1 -0
  188. package/dist/lexer/lexer.d.ts.map +1 -1
  189. package/dist/lexer/lexer.js +26 -10
  190. package/dist/lexer/lexer.js.map +1 -1
  191. package/dist/lexer/tokens.d.ts.map +1 -1
  192. package/dist/lexer/tokens.js.map +1 -1
  193. package/dist/lsp/code-action-worker.d.ts.map +1 -1
  194. package/dist/lsp/code-action-worker.js.map +1 -1
  195. package/dist/lsp/completion.d.ts.map +1 -1
  196. package/dist/lsp/completion.js.map +1 -1
  197. package/dist/lsp/definition.d.ts.map +1 -1
  198. package/dist/lsp/definition.js.map +1 -1
  199. package/dist/lsp/diagnostics-worker.d.ts.map +1 -1
  200. package/dist/lsp/diagnostics-worker.js +1 -1
  201. package/dist/lsp/diagnostics-worker.js.map +1 -1
  202. package/dist/lsp/docs.d.ts +1 -1
  203. package/dist/lsp/docs.d.ts.map +1 -1
  204. package/dist/lsp/docs.js +4 -3
  205. package/dist/lsp/docs.js.map +1 -1
  206. package/dist/lsp/error-channel.d.ts.map +1 -1
  207. package/dist/lsp/error-channel.js.map +1 -1
  208. package/dist/lsp/hover.d.ts.map +1 -1
  209. package/dist/lsp/hover.js +16 -5
  210. package/dist/lsp/hover.js.map +1 -1
  211. package/dist/lsp/imports.d.ts.map +1 -1
  212. package/dist/lsp/imports.js +10 -1
  213. package/dist/lsp/imports.js.map +1 -1
  214. package/dist/lsp/index.d.ts.map +1 -1
  215. package/dist/lsp/index.js.map +1 -1
  216. package/dist/lsp/inlay-hints.d.ts.map +1 -1
  217. package/dist/lsp/inlay-hints.js.map +1 -1
  218. package/dist/lsp/interop-rename.d.ts.map +1 -1
  219. package/dist/lsp/interop-rename.js.map +1 -1
  220. package/dist/lsp/match-arms.d.ts.map +1 -1
  221. package/dist/lsp/match-arms.js.map +1 -1
  222. package/dist/lsp/navigation.d.ts.map +1 -1
  223. package/dist/lsp/navigation.js.map +1 -1
  224. package/dist/lsp/parsed-documents.d.ts.map +1 -1
  225. package/dist/lsp/parsed-documents.js.map +1 -1
  226. package/dist/lsp/rename-worker.d.ts.map +1 -1
  227. package/dist/lsp/rename-worker.js.map +1 -1
  228. package/dist/lsp/server.d.ts +2 -1
  229. package/dist/lsp/server.d.ts.map +1 -1
  230. package/dist/lsp/server.js +20 -0
  231. package/dist/lsp/server.js.map +1 -1
  232. package/dist/lsp/signature-help.d.ts +6 -0
  233. package/dist/lsp/signature-help.d.ts.map +1 -0
  234. package/dist/lsp/signature-help.js +183 -0
  235. package/dist/lsp/signature-help.js.map +1 -0
  236. package/dist/lsp/thunk-pipeline.d.ts.map +1 -1
  237. package/dist/lsp/thunk-pipeline.js.map +1 -1
  238. package/dist/lsp/validation.d.ts.map +1 -1
  239. package/dist/lsp/validation.js +3 -2
  240. package/dist/lsp/validation.js.map +1 -1
  241. package/dist/lsp/workspace.d.ts.map +1 -1
  242. package/dist/lsp/workspace.js.map +1 -1
  243. package/dist/parser/declarations.d.ts.map +1 -1
  244. package/dist/parser/declarations.js +22 -1
  245. package/dist/parser/declarations.js.map +1 -1
  246. package/dist/parser/errors.d.ts.map +1 -1
  247. package/dist/parser/errors.js.map +1 -1
  248. package/dist/parser/jsx.d.ts.map +1 -1
  249. package/dist/parser/jsx.js.map +1 -1
  250. package/dist/parser/operator-expressions.d.ts.map +1 -1
  251. package/dist/parser/operator-expressions.js.map +1 -1
  252. package/dist/parser/parser.d.ts.map +1 -1
  253. package/dist/parser/parser.js.map +1 -1
  254. package/dist/parser/patterns.d.ts.map +1 -1
  255. package/dist/parser/patterns.js.map +1 -1
  256. package/dist/parser/pipeline-expressions.d.ts.map +1 -1
  257. package/dist/parser/pipeline-expressions.js.map +1 -1
  258. package/dist/parser/scope.d.ts.map +1 -1
  259. package/dist/parser/scope.js.map +1 -1
  260. package/dist/parser/statements.d.ts.map +1 -1
  261. package/dist/parser/statements.js.map +1 -1
  262. package/dist/parser/types.d.ts.map +1 -1
  263. package/dist/parser/types.js.map +1 -1
  264. package/dist/plugins/bun-preload.d.ts.map +1 -1
  265. package/dist/plugins/bun-preload.js.map +1 -1
  266. package/dist/plugins/bun.d.ts.map +1 -1
  267. package/dist/plugins/bun.js.map +1 -1
  268. package/dist/plugins/esbuild.d.ts.map +1 -1
  269. package/dist/plugins/esbuild.js.map +1 -1
  270. package/dist/plugins/type-view.d.ts.map +1 -1
  271. package/dist/plugins/type-view.js +5 -3
  272. package/dist/plugins/type-view.js.map +1 -1
  273. package/dist/plugins/vite.d.ts.map +1 -1
  274. package/dist/plugins/vite.js.map +1 -1
  275. package/dist/testing/index.d.ts.map +1 -1
  276. package/dist/testing/index.js.map +1 -1
  277. package/dist/tooling/doc.d.ts.map +1 -1
  278. package/dist/tooling/doc.js.map +1 -1
  279. package/dist/tooling/idiomatic.d.ts.map +1 -1
  280. package/dist/tooling/idiomatic.js.map +1 -1
  281. package/dist/tooling/pipeline-style.d.ts.map +1 -1
  282. package/dist/tooling/pipeline-style.js.map +1 -1
  283. package/dist/version.d.ts.map +1 -1
  284. package/dist/version.js.map +1 -1
  285. package/package.json +13 -6
  286. package/src/cli/build-watch.ts +6 -3
  287. package/src/cli/doctor.ts +8 -2
  288. package/src/cli/init.ts +66 -21
  289. package/src/cli/tsc.ts +8 -3
  290. package/src/compiler/boolean-operators.ts +11 -2
  291. package/src/compiler/check.ts +124 -132
  292. package/src/compiler/modules/resolution.ts +2 -1
  293. package/src/compiler/modules/source-files.ts +4 -0
  294. package/src/compiler/project-config.ts +30 -19
  295. package/src/compiler/rules/resource-escape.ts +223 -0
  296. package/src/compiler/rules/resource-providers.ts +293 -0
  297. package/src/compiler/type-view-paths.ts +3 -0
  298. package/src/emitter/emitter.ts +13 -1
  299. package/src/emitter/statements.ts +2 -0
  300. package/src/formatter/comments.ts +14 -0
  301. package/src/formatter/index.ts +70 -2
  302. package/src/lexer/lexer.ts +39 -20
  303. package/src/lsp/diagnostics-worker.ts +1 -4
  304. package/src/lsp/docs.ts +4 -3
  305. package/src/lsp/hover.ts +23 -4
  306. package/src/lsp/imports.ts +20 -1
  307. package/src/lsp/server.ts +30 -0
  308. package/src/lsp/signature-help.ts +226 -0
  309. package/src/lsp/validation.ts +3 -2
  310. package/src/parser/declarations.ts +27 -1
  311. package/src/plugins/type-view.ts +11 -3
  312. package/dist/Widget.tsx +0 -9
  313. package/dist/cli/output-collisions.d.ts +0 -2
  314. package/dist/cli/output-collisions.d.ts.map +0 -1
  315. package/dist/cli/output-collisions.js +0 -39
  316. package/dist/cli/output-collisions.js.map +0 -1
  317. package/dist/compiler/imported-record-functions.d.ts +0 -4
  318. package/dist/compiler/imported-record-functions.d.ts.map +0 -1
  319. package/dist/compiler/imported-record-functions.js +0 -706
  320. package/dist/compiler/imported-record-functions.js.map +0 -1
  321. package/dist/compiler/imported-schemas.d.ts +0 -21
  322. package/dist/compiler/imported-schemas.d.ts.map +0 -1
  323. package/dist/compiler/imported-schemas.js +0 -461
  324. package/dist/compiler/imported-schemas.js.map +0 -1
  325. package/dist/compiler/module-resolution.d.ts +0 -6
  326. package/dist/compiler/module-resolution.d.ts.map +0 -1
  327. package/dist/compiler/module-resolution.js +0 -44
  328. package/dist/compiler/module-resolution.js.map +0 -1
  329. package/dist/compiler/pipeline-companions.d.ts +0 -18
  330. package/dist/compiler/pipeline-companions.d.ts.map +0 -1
  331. package/dist/compiler/pipeline-companions.js +0 -1042
  332. package/dist/compiler/pipeline-companions.js.map +0 -1
  333. package/dist/compiler/providers.d.ts +0 -4
  334. package/dist/compiler/providers.d.ts.map +0 -1
  335. package/dist/compiler/providers.js +0 -101
  336. package/dist/compiler/providers.js.map +0 -1
  337. package/dist/emitter/pipeline-catalog.d.ts +0 -15
  338. package/dist/emitter/pipeline-catalog.d.ts.map +0 -1
  339. package/dist/emitter/pipeline-catalog.js +0 -55
  340. package/dist/emitter/pipeline-catalog.js.map +0 -1
  341. package/dist/emitter/pipeline-resolution.d.ts +0 -38
  342. package/dist/emitter/pipeline-resolution.d.ts.map +0 -1
  343. package/dist/emitter/pipeline-resolution.js +0 -571
  344. package/dist/emitter/pipeline-resolution.js.map +0 -1
  345. package/dist/interop/index.d.ts +0 -6
  346. package/dist/interop/index.d.ts.map +0 -1
  347. package/dist/interop/index.js +0 -6
  348. package/dist/interop/index.js.map +0 -1
  349. package/dist/math.ts +0 -1
  350. package/dist/parser/index.d.ts +0 -9
  351. package/dist/parser/index.d.ts.map +0 -1
  352. package/dist/parser/index.js +0 -9
  353. package/dist/parser/index.js.map +0 -1
  354. package/dist/service.ts +0 -3
  355. package/dist/service.ts.map +0 -1
  356. package/dist/tooling/migrate.d.ts +0 -62
  357. package/dist/tooling/migrate.d.ts.map +0 -1
  358. package/dist/tooling/migrate.js +0 -608
  359. package/dist/tooling/migrate.js.map +0 -1
@@ -1,5 +1,10 @@
1
1
  import { checkControlFlowRules } from "./rules/control-flow.js";
2
2
  import { checkModuleScopeRefs } from "./rules/module-scope-refs.js";
3
+ import { findScopedResourceEscape } from "./rules/resource-escape.js";
4
+ import {
5
+ createResourceProviderResolver,
6
+ effectImportNames,
7
+ } from "./rules/resource-providers.js";
3
8
  import { isEntryModule, getEffectRunnerName } from "./entry-rules.js";
4
9
  export { isEntryModule } from "./entry-rules.js";
5
10
  import { checkCapturedMutInEffect } from "./effect-mutation-rule.js";
@@ -2100,8 +2105,85 @@ export const typeCheckVirtualFiles = (
2100
2105
  (finalExpr?.kind === "Identifier" ||
2101
2106
  finalExpr?.kind === "UpperIdentifier") &&
2102
2107
  astName(finalExpr) === "Void";
2108
+ const isIndependentLiteral = (
2109
+ expr: AstInspectNode | null,
2110
+ ): boolean => {
2111
+ if (!expr) return false;
2112
+ if (
2113
+ [
2114
+ "NumberLiteral",
2115
+ "StringLiteral",
2116
+ "BooleanLiteral",
2117
+ "TemplateLiteral",
2118
+ ].includes(expr.kind)
2119
+ )
2120
+ return true;
2121
+ if (expr.kind === "ArrayExpression")
2122
+ return astChildren(expr, "elements").every(
2123
+ isIndependentLiteral,
2124
+ );
2125
+ if (expr.kind === "RecordExpression")
2126
+ return astChildren(expr, "entries").every(
2127
+ (entry) =>
2128
+ (entry.kind === "FieldEntry" ||
2129
+ entry.kind === "DotPathEntry") &&
2130
+ isIndependentLiteral(astChild(entry, "value")),
2131
+ );
2132
+ return false;
2133
+ };
2103
2134
 
2104
- if (!isUnit) {
2135
+ if (!isUnit && !isIndependentLiteral(finalExpr)) {
2136
+ // Function parameters shadow module bindings, including
2137
+ // inside nested functions. Never follow a shadowed name.
2138
+ const shadowed = new Set<string>();
2139
+ const collectEnclosingParams = (
2140
+ candidate: AstInspectNode,
2141
+ ): void => {
2142
+ if (
2143
+ !candidate.span ||
2144
+ !node.span ||
2145
+ candidate.span.start.offset > node.span.start.offset ||
2146
+ candidate.span.end.offset < node.span.end.offset
2147
+ )
2148
+ return;
2149
+ if (candidate.kind === "FunctionExpression") {
2150
+ for (const param of astChildren(candidate, "params")) {
2151
+ for (const name of collectPatternVars(
2152
+ astChild(param, "name"),
2153
+ ))
2154
+ shadowed.add(name);
2155
+ }
2156
+ }
2157
+ for (const [key, value] of Object.entries(
2158
+ asRecord(candidate),
2159
+ )) {
2160
+ if (key === "span") continue;
2161
+ if (Array.isArray(value)) {
2162
+ for (const item of value)
2163
+ if (isAstNode(item)) collectEnclosingParams(item);
2164
+ } else if (isAstNode(value))
2165
+ collectEnclosingParams(value);
2166
+ }
2167
+ };
2168
+ if (meta.ast) collectEnclosingParams(meta.ast);
2169
+ for (const statement of astChildren(node, "body")) {
2170
+ if (
2171
+ statement.kind === "BindingDeclaration" ||
2172
+ statement.kind === "EffectBindStatement"
2173
+ ) {
2174
+ for (const name of collectPatternVars(
2175
+ astChild(statement, "id"),
2176
+ ))
2177
+ shadowed.add(name);
2178
+ }
2179
+ }
2180
+ const imports = effectImportNames(meta.ast);
2181
+ for (const name of shadowed) {
2182
+ imports.effect.delete(name);
2183
+ imports.scope.delete(name);
2184
+ imports.acquire.delete(name);
2185
+ imports.finalizer.delete(name);
2186
+ }
2105
2187
  const findFinalizer = (
2106
2188
  n: unknown,
2107
2189
  allowAcquire: boolean,
@@ -2121,7 +2203,8 @@ export const typeCheckVirtualFiles = (
2121
2203
  callee.property as { name?: string } | undefined
2122
2204
  )?.name;
2123
2205
  if (
2124
- (obj === "Effect" || obj === "Scope") &&
2206
+ !!obj &&
2207
+ (imports.effect.has(obj) || imports.scope.has(obj)) &&
2125
2208
  (prop === "addFinalizer" ||
2126
2209
  (allowAcquire && prop === "acquireRelease"))
2127
2210
  ) {
@@ -2133,8 +2216,10 @@ export const typeCheckVirtualFiles = (
2133
2216
  } else if (callee?.kind === "Identifier") {
2134
2217
  const calleeName = (callee as { name?: string }).name;
2135
2218
  if (
2136
- calleeName === "addFinalizer" ||
2137
- (allowAcquire && calleeName === "acquireRelease")
2219
+ (!!calleeName && imports.finalizer.has(calleeName)) ||
2220
+ (allowAcquire &&
2221
+ !!calleeName &&
2222
+ imports.acquire.has(calleeName))
2138
2223
  ) {
2139
2224
  return {
2140
2225
  name: calleeName,
@@ -2175,10 +2260,11 @@ export const typeCheckVirtualFiles = (
2175
2260
  detectedCall = findFinalizer(finalExpr, false);
2176
2261
  }
2177
2262
 
2178
- // Follow simple local aliases and providers only
2179
- // when the acquired value itself is returned from this scope.
2180
- // Derived values (e.g. resource.fd) remain valid consumers.
2181
- if (!detectedCall && finalExpr?.kind === "Identifier") {
2263
+ // Follow resources through aliases, returned containers and
2264
+ // captured closures. An eagerly read property can be an
2265
+ // independent value, but a closure reading it captures the
2266
+ // resource itself for later use.
2267
+ if (!detectedCall && finalExpr) {
2182
2268
  const bindings = new Map<string, AstInspectNode>();
2183
2269
  for (const item of meta.ast?.body ?? []) {
2184
2270
  const decl =
@@ -2192,39 +2278,6 @@ export const typeCheckVirtualFiles = (
2192
2278
  bindings.set(decl.id.name, decl.init);
2193
2279
  }
2194
2280
  }
2195
- // Function parameters shadow module bindings, including
2196
- // inside nested functions. Never follow a shadowed name.
2197
- const shadowed = new Set<string>();
2198
- const collectEnclosingParams = (
2199
- candidate: AstInspectNode,
2200
- ): void => {
2201
- if (
2202
- !candidate.span ||
2203
- !node.span ||
2204
- candidate.span.start.offset > node.span.start.offset ||
2205
- candidate.span.end.offset < node.span.end.offset
2206
- )
2207
- return;
2208
- if (candidate.kind === "FunctionExpression") {
2209
- for (const param of astChildren(candidate, "params")) {
2210
- for (const name of collectPatternVars(
2211
- astChild(param, "name"),
2212
- ))
2213
- shadowed.add(name);
2214
- }
2215
- }
2216
- for (const [key, value] of Object.entries(
2217
- asRecord(candidate),
2218
- )) {
2219
- if (key === "span") continue;
2220
- if (Array.isArray(value)) {
2221
- for (const item of value)
2222
- if (isAstNode(item)) collectEnclosingParams(item);
2223
- } else if (isAstNode(value))
2224
- collectEnclosingParams(value);
2225
- }
2226
- };
2227
- if (meta.ast) collectEnclosingParams(meta.ast);
2228
2281
  for (const name of shadowed) bindings.delete(name);
2229
2282
  for (const stmt of astChildren(node, "body")) {
2230
2283
  if (stmt.kind === "BindingDeclaration") {
@@ -2233,96 +2286,33 @@ export const typeCheckVirtualFiles = (
2233
2286
  if (name && init) bindings.set(name, init);
2234
2287
  }
2235
2288
  }
2236
- const resolveReturned = (
2237
- name: string | undefined,
2238
- seen: Set<string>,
2239
- ): AstInspectNode | undefined => {
2240
- if (!name || seen.has(name)) return undefined;
2241
- const stmts = astChildren(node, "body");
2242
- const bind = stmts.find(
2243
- (stmt) =>
2244
- stmt.kind === "EffectBindStatement" &&
2245
- astName(astChild(stmt, "id")) === name,
2246
- );
2247
- if (bind) return bind;
2248
- const alias = stmts.find(
2249
- (stmt) =>
2250
- stmt.kind === "BindingDeclaration" &&
2251
- astName(astChild(stmt, "id")) === name,
2252
- );
2253
- const init = astChild(alias, "init");
2254
- return init?.kind === "Identifier"
2255
- ? resolveReturned(
2256
- astName(init),
2257
- new Set([...seen, name]),
2258
- )
2259
- : undefined;
2260
- };
2261
- const bind = resolveReturned(astName(finalExpr), new Set());
2262
- const source = astChild(bind, "effect");
2263
- const followsAcquire = (
2264
- expr: AstInspectNode | null,
2265
- seen: Set<string>,
2266
- ): boolean => {
2267
- if (!expr) return false;
2268
- if (expr.kind === "Identifier") {
2269
- const name = astName(expr);
2270
- if (!name || seen.has(name)) return false;
2271
- const next = bindings.get(name);
2272
- if (!next) return false;
2273
- return followsAcquire(next, new Set([...seen, name]));
2274
- }
2275
- if (expr.kind === "FunctionExpression") {
2276
- const nestedSeen = new Set(seen);
2277
- for (const param of astChildren(expr, "params")) {
2278
- for (const name of collectPatternVars(
2279
- astChild(param, "name"),
2280
- ))
2281
- nestedSeen.add(name);
2282
- }
2283
- return followsAcquire(
2284
- astChild(expr, "body"),
2285
- nestedSeen,
2289
+ const programs = new Map<string, Program>();
2290
+ for (const entry of virtualSourceMap.values()) {
2291
+ if (entry.ast)
2292
+ programs.set(
2293
+ path.resolve(cwd, entry.funPath),
2294
+ entry.ast,
2286
2295
  );
2287
- }
2288
- if (expr.kind === "BlockStatement") {
2289
- return followsAcquire(
2290
- astChild(expr, "finalExpression"),
2291
- seen,
2292
- );
2293
- }
2294
- if (
2295
- expr.kind === "EffectBlockExpression" &&
2296
- astBool(expr, "unscoped")
2297
- ) {
2298
- const result = astChild(expr, "finalExpression");
2299
- if (result?.kind !== "Identifier") return false;
2300
- const bind = astChildren(expr, "body").find(
2301
- (stmt) =>
2302
- stmt.kind === "EffectBindStatement" &&
2303
- astName(astChild(stmt, "id")) === astName(result),
2304
- );
2305
- return followsAcquire(astChild(bind, "effect"), seen);
2306
- }
2307
- if (expr.kind === "CallExpression") {
2308
- const callee = astChild(expr, "callee");
2309
- const member = getMemberNames(callee);
2310
- if (
2311
- (member?.object === "Effect" &&
2312
- member.property === "acquireRelease") ||
2313
- (callee?.kind === "Identifier" &&
2314
- astName(callee) === "acquireRelease")
2315
- )
2316
- return true;
2317
- if (callee?.kind === "Identifier") {
2318
- return followsAcquire(callee, seen);
2319
- }
2320
- }
2321
- return false;
2322
- };
2323
- if (source && followsAcquire(source, new Set())) {
2296
+ }
2297
+ const followsAcquire = createResourceProviderResolver({
2298
+ rootFile: path.resolve(cwd, meta.funPath),
2299
+ rootAst: meta.ast!,
2300
+ rootBindings: bindings,
2301
+ rootImports: imports,
2302
+ shadowed,
2303
+ sources: virtualSources,
2304
+ programs,
2305
+ });
2306
+ const source = findScopedResourceEscape(
2307
+ node,
2308
+ finalExpr,
2309
+ sf,
2310
+ checker,
2311
+ followsAcquire,
2312
+ );
2313
+ if (source) {
2324
2314
  detectedCall = {
2325
- name: "Effect.acquireRelease (through an alias)",
2315
+ name: "a scope-bound provider",
2326
2316
  span: source.span ?? node.span!,
2327
2317
  };
2328
2318
  }
@@ -2333,10 +2323,12 @@ export const typeCheckVirtualFiles = (
2333
2323
  addAstDiag(
2334
2324
  callInfo.span,
2335
2325
  "PREMATURE_FINALIZER_CLOSE",
2336
- `Finalizer registered with '${callInfo.name}' in a scoped effect block will execute immediately when this function returns, closing the returned resource.`,
2326
+ callInfo.name === "a scope-bound provider"
2327
+ ? "A scope-bound resource escapes this effect through the returned value. Its scope closes before the caller can use it."
2328
+ : `Finalizer registered with '${callInfo.name}' in a scoped effect block will execute immediately when this function returns, closing the returned resource or a resource it captures.`,
2337
2329
  "error",
2338
- "By default, 'effect' blocks create a scoped boundary ('Effect.scoped'). Any finalizer registered via 'Effect.addFinalizer' or 'Effect.acquireRelease' executes as soon as the block returns, tearing down the resource before the caller can use it.",
2339
- "Change 'effect' to 'effect (unscoped)' so the resource's lifetime is bound to the caller's scope, or return 'Void' if all work is completed inside this block.",
2330
+ "By default, 'effect' blocks create a scoped boundary ('Effect.scoped'). Scope-bound resources are finalized as soon as the block returns, before the caller can use them.",
2331
+ "Change 'effect' to 'effect (unscoped)' so the resource's lifetime is bound to the caller's scope, or finish using the resource inside this block and return an independent value.",
2340
2332
  );
2341
2333
  }
2342
2334
  }
@@ -1,6 +1,7 @@
1
1
  import * as path from "node:path";
2
2
  import * as fs from "node:fs";
3
3
  import { isFileNotFoundError } from "../../errors.js";
4
+ import { isFunSourceFile } from "./source-files.js";
4
5
 
5
6
  /** Source module specifiers become JavaScript paths in emitted TypeScript. */
6
7
  export function emittedModuleSource(source: string): string {
@@ -28,7 +29,7 @@ export function resolveFunModule(
28
29
  ): string | undefined {
29
30
  if (!specifier.startsWith(".")) return undefined;
30
31
  const requested = path.resolve(path.dirname(importer), specifier);
31
- if (/\.funx?$/.test(requested))
32
+ if (isFunSourceFile(requested))
32
33
  return exists(requested) ? requested : undefined;
33
34
  // Explicit TypeScript paths identify TypeScript files, even if absent.
34
35
  if (/\.(?:ts|tsx)$/.test(requested)) return undefined;
@@ -0,0 +1,4 @@
1
+ /** Recognize FunkScript source files using the compiler's case-sensitive extensions. */
2
+ export function isFunSourceFile(filename: string): boolean {
3
+ return /\.funx?$/.test(filename);
4
+ }
@@ -17,6 +17,25 @@ export interface FunScriptProjectConfig {
17
17
  allowEarlyReturns?: boolean | string[];
18
18
  }
19
19
 
20
+ const CONFIG_FIELDS = [
21
+ "noTs",
22
+ "noGlobalThis",
23
+ "barePipelines",
24
+ "effectOnly",
25
+ "format",
26
+ "modularEffectImports",
27
+ "noDeepDestructure",
28
+ "maxDestructureDepth",
29
+ "allowHoles",
30
+ "allowEarlyReturns",
31
+ ];
32
+ const MIN_DESTRUCTURE_DEPTH = 1;
33
+ const MAX_DESTRUCTURE_DEPTH = 10;
34
+ const FORMAT_BOUNDS = {
35
+ indentSize: { min: 1, max: 8 },
36
+ lineWidth: { min: 40, max: 240 },
37
+ } as const;
38
+
20
39
  /** Read a literal FunkScript record without compiling or executing project code. */
21
40
  export function loadProjectConfig(cwd: string): FunScriptProjectConfig {
22
41
  const file = path.resolve(cwd, "funscript.config.fun");
@@ -49,21 +68,12 @@ export function loadProjectConfig(cwd: string): FunScriptProjectConfig {
49
68
  for (const entry of binding.init.entries) {
50
69
  if (
51
70
  entry.kind !== "FieldEntry" ||
52
- ![
53
- "noTs",
54
- "noGlobalThis",
55
- "barePipelines",
56
- "effectOnly",
57
- "format",
58
- "modularEffectImports",
59
- "noDeepDestructure",
60
- "maxDestructureDepth",
61
- "allowHoles",
62
- "allowEarlyReturns",
63
- ].includes(entry.key.name)
71
+ !CONFIG_FIELDS.includes(entry.key.name)
64
72
  ) {
65
73
  throw new Error(
66
- "config accepts only 'noTs', 'noGlobalThis', 'barePipelines', 'effectOnly', 'format', 'modularEffectImports', 'noDeepDestructure', 'maxDestructureDepth', 'allowHoles', and 'allowEarlyReturns'",
74
+ `config accepts only ${CONFIG_FIELDS.slice(0, -1)
75
+ .map((field) => `'${field}'`)
76
+ .join(", ")}, and '${CONFIG_FIELDS.at(-1)}'`,
67
77
  );
68
78
  }
69
79
  const name = entry.key.name;
@@ -73,11 +83,11 @@ export function loadProjectConfig(cwd: string): FunScriptProjectConfig {
73
83
  if (
74
84
  entry.value.kind !== "NumberLiteral" ||
75
85
  !Number.isInteger(entry.value.value) ||
76
- entry.value.value < 1 ||
77
- entry.value.value > 10
86
+ entry.value.value < MIN_DESTRUCTURE_DEPTH ||
87
+ entry.value.value > MAX_DESTRUCTURE_DEPTH
78
88
  ) {
79
89
  throw new Error(
80
- "maxDestructureDepth must be an integer between 1 and 10",
90
+ `maxDestructureDepth must be an integer between ${MIN_DESTRUCTURE_DEPTH} and ${MAX_DESTRUCTURE_DEPTH}`,
81
91
  );
82
92
  }
83
93
  config.maxDestructureDepth = entry.value.value;
@@ -94,14 +104,15 @@ export function loadProjectConfig(cwd: string): FunScriptProjectConfig {
94
104
  const key = field.key.name as "indentSize" | "lineWidth";
95
105
  if (format[key] !== undefined)
96
106
  throw new Error(`duplicate format field '${key}'`);
107
+ const { min, max } = FORMAT_BOUNDS[key];
97
108
  if (
98
109
  field.value.kind !== "NumberLiteral" ||
99
110
  !Number.isInteger(field.value.value) ||
100
- field.value.value < (key === "indentSize" ? 1 : 40) ||
101
- field.value.value > (key === "indentSize" ? 8 : 240)
111
+ field.value.value < min ||
112
+ field.value.value > max
102
113
  )
103
114
  throw new Error(
104
- `${key} must be an integer between ${key === "indentSize" ? "1 and 8" : "40 and 240"}`,
115
+ `${key} must be an integer between ${min} and ${max}`,
105
116
  );
106
117
  format[key] = field.value.value;
107
118
  }
@@ -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
+ }