funkscript 0.0.0-stage → 0.2.3

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 (631) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -2
  3. package/dist/Widget.tsx +9 -0
  4. package/dist/ast/types.d.ts +513 -0
  5. package/dist/ast/types.d.ts.map +1 -0
  6. package/dist/ast/types.js +5 -0
  7. package/dist/ast/types.js.map +1 -0
  8. package/dist/ast/walk.d.ts +8 -0
  9. package/dist/ast/walk.d.ts.map +1 -0
  10. package/dist/ast/walk.js +23 -0
  11. package/dist/ast/walk.js.map +1 -0
  12. package/dist/cli/build-bun.d.ts +24 -0
  13. package/dist/cli/build-bun.d.ts.map +1 -0
  14. package/dist/cli/build-bun.js +190 -0
  15. package/dist/cli/build-bun.js.map +1 -0
  16. package/dist/cli/build-watch.d.ts +21 -0
  17. package/dist/cli/build-watch.d.ts.map +1 -0
  18. package/dist/cli/build-watch.js +244 -0
  19. package/dist/cli/build-watch.js.map +1 -0
  20. package/dist/cli/build.d.ts +4 -0
  21. package/dist/cli/build.d.ts.map +1 -0
  22. package/dist/cli/build.js +338 -0
  23. package/dist/cli/build.js.map +1 -0
  24. package/dist/cli/check.d.ts +4 -0
  25. package/dist/cli/check.d.ts.map +1 -0
  26. package/dist/cli/check.js +278 -0
  27. package/dist/cli/check.js.map +1 -0
  28. package/dist/cli/commands.d.ts +13 -0
  29. package/dist/cli/commands.d.ts.map +1 -0
  30. package/dist/cli/commands.js +262 -0
  31. package/dist/cli/commands.js.map +1 -0
  32. package/dist/cli/doc.d.ts +3 -0
  33. package/dist/cli/doc.d.ts.map +1 -0
  34. package/dist/cli/doc.js +71 -0
  35. package/dist/cli/doc.js.map +1 -0
  36. package/dist/cli/doctor.d.ts +3 -0
  37. package/dist/cli/doctor.d.ts.map +1 -0
  38. package/dist/cli/doctor.js +121 -0
  39. package/dist/cli/doctor.js.map +1 -0
  40. package/dist/cli/emit.d.ts +4 -0
  41. package/dist/cli/emit.d.ts.map +1 -0
  42. package/dist/cli/emit.js +87 -0
  43. package/dist/cli/emit.js.map +1 -0
  44. package/dist/cli/explain.d.ts +3 -0
  45. package/dist/cli/explain.d.ts.map +1 -0
  46. package/dist/cli/explain.js +103 -0
  47. package/dist/cli/explain.js.map +1 -0
  48. package/dist/cli/fmt.d.ts +3 -0
  49. package/dist/cli/fmt.d.ts.map +1 -0
  50. package/dist/cli/fmt.js +146 -0
  51. package/dist/cli/fmt.js.map +1 -0
  52. package/dist/cli/index.d.ts +3 -0
  53. package/dist/cli/index.d.ts.map +1 -0
  54. package/dist/cli/index.js +186 -0
  55. package/dist/cli/index.js.map +1 -0
  56. package/dist/cli/init.d.ts +10 -0
  57. package/dist/cli/init.d.ts.map +1 -0
  58. package/dist/cli/init.js +412 -0
  59. package/dist/cli/init.js.map +1 -0
  60. package/dist/cli/io.d.ts +9 -0
  61. package/dist/cli/io.d.ts.map +1 -0
  62. package/dist/cli/io.js +113 -0
  63. package/dist/cli/io.js.map +1 -0
  64. package/dist/cli/output-collisions.d.ts +2 -0
  65. package/dist/cli/output-collisions.d.ts.map +1 -0
  66. package/dist/cli/output-collisions.js +39 -0
  67. package/dist/cli/output-collisions.js.map +1 -0
  68. package/dist/cli/pipeline-style.d.ts +3 -0
  69. package/dist/cli/pipeline-style.d.ts.map +1 -0
  70. package/dist/cli/pipeline-style.js +45 -0
  71. package/dist/cli/pipeline-style.js.map +1 -0
  72. package/dist/cli/repl.d.ts +37 -0
  73. package/dist/cli/repl.d.ts.map +1 -0
  74. package/dist/cli/repl.js +334 -0
  75. package/dist/cli/repl.js.map +1 -0
  76. package/dist/cli/run.d.ts +4 -0
  77. package/dist/cli/run.d.ts.map +1 -0
  78. package/dist/cli/run.js +185 -0
  79. package/dist/cli/run.js.map +1 -0
  80. package/dist/cli/test.d.ts +3 -0
  81. package/dist/cli/test.d.ts.map +1 -0
  82. package/dist/cli/test.js +124 -0
  83. package/dist/cli/test.js.map +1 -0
  84. package/dist/cli/tsc.d.ts +3 -0
  85. package/dist/cli/tsc.d.ts.map +1 -0
  86. package/dist/cli/tsc.js +143 -0
  87. package/dist/cli/tsc.js.map +1 -0
  88. package/dist/cli/typecheck.d.ts +23 -0
  89. package/dist/cli/typecheck.d.ts.map +1 -0
  90. package/dist/cli/typecheck.js +65 -0
  91. package/dist/cli/typecheck.js.map +1 -0
  92. package/dist/compiler/ast-inspection.d.ts +18 -0
  93. package/dist/compiler/ast-inspection.d.ts.map +1 -0
  94. package/dist/compiler/ast-inspection.js +96 -0
  95. package/dist/compiler/ast-inspection.js.map +1 -0
  96. package/dist/compiler/boolean-operators.d.ts +8 -0
  97. package/dist/compiler/boolean-operators.d.ts.map +1 -0
  98. package/dist/compiler/boolean-operators.js +84 -0
  99. package/dist/compiler/boolean-operators.js.map +1 -0
  100. package/dist/compiler/check.d.ts +87 -0
  101. package/dist/compiler/check.d.ts.map +1 -0
  102. package/dist/compiler/check.js +1830 -0
  103. package/dist/compiler/check.js.map +1 -0
  104. package/dist/compiler/diagnostics.d.ts +6 -0
  105. package/dist/compiler/diagnostics.d.ts.map +1 -0
  106. package/dist/compiler/diagnostics.js +136 -0
  107. package/dist/compiler/diagnostics.js.map +1 -0
  108. package/dist/compiler/effect-mutation-rule.d.ts +4 -0
  109. package/dist/compiler/effect-mutation-rule.d.ts.map +1 -0
  110. package/dist/compiler/effect-mutation-rule.js +348 -0
  111. package/dist/compiler/effect-mutation-rule.js.map +1 -0
  112. package/dist/compiler/entry-rules.d.ts +5 -0
  113. package/dist/compiler/entry-rules.d.ts.map +1 -0
  114. package/dist/compiler/entry-rules.js +89 -0
  115. package/dist/compiler/entry-rules.js.map +1 -0
  116. package/dist/compiler/imported-record-functions.d.ts +4 -0
  117. package/dist/compiler/imported-record-functions.d.ts.map +1 -0
  118. package/dist/compiler/imported-record-functions.js +706 -0
  119. package/dist/compiler/imported-record-functions.js.map +1 -0
  120. package/dist/compiler/imported-schemas.d.ts +21 -0
  121. package/dist/compiler/imported-schemas.d.ts.map +1 -0
  122. package/dist/compiler/imported-schemas.js +461 -0
  123. package/dist/compiler/imported-schemas.js.map +1 -0
  124. package/dist/compiler/incremental-build.d.ts +23 -0
  125. package/dist/compiler/incremental-build.d.ts.map +1 -0
  126. package/dist/compiler/incremental-build.js +90 -0
  127. package/dist/compiler/incremental-build.js.map +1 -0
  128. package/dist/compiler/incremental-dependencies.d.ts +7 -0
  129. package/dist/compiler/incremental-dependencies.d.ts.map +1 -0
  130. package/dist/compiler/incremental-dependencies.js +190 -0
  131. package/dist/compiler/incremental-dependencies.js.map +1 -0
  132. package/dist/compiler/js-interop-nullability.d.ts +9 -0
  133. package/dist/compiler/js-interop-nullability.d.ts.map +1 -0
  134. package/dist/compiler/js-interop-nullability.js +57 -0
  135. package/dist/compiler/js-interop-nullability.js.map +1 -0
  136. package/dist/compiler/module-resolution.d.ts +6 -0
  137. package/dist/compiler/module-resolution.d.ts.map +1 -0
  138. package/dist/compiler/module-resolution.js +44 -0
  139. package/dist/compiler/module-resolution.js.map +1 -0
  140. package/dist/compiler/modules/output-collisions.d.ts +2 -0
  141. package/dist/compiler/modules/output-collisions.d.ts.map +1 -0
  142. package/dist/compiler/modules/output-collisions.js +39 -0
  143. package/dist/compiler/modules/output-collisions.js.map +1 -0
  144. package/dist/compiler/modules/output-plan.d.ts +7 -0
  145. package/dist/compiler/modules/output-plan.d.ts.map +1 -0
  146. package/dist/compiler/modules/output-plan.js +37 -0
  147. package/dist/compiler/modules/output-plan.js.map +1 -0
  148. package/dist/compiler/modules/resolution.d.ts +8 -0
  149. package/dist/compiler/modules/resolution.d.ts.map +1 -0
  150. package/dist/compiler/modules/resolution.js +48 -0
  151. package/dist/compiler/modules/resolution.js.map +1 -0
  152. package/dist/compiler/numeric-comparisons.d.ts +9 -0
  153. package/dist/compiler/numeric-comparisons.d.ts.map +1 -0
  154. package/dist/compiler/numeric-comparisons.js +153 -0
  155. package/dist/compiler/numeric-comparisons.js.map +1 -0
  156. package/dist/compiler/optional-arguments.d.ts +11 -0
  157. package/dist/compiler/optional-arguments.d.ts.map +1 -0
  158. package/dist/compiler/optional-arguments.js +246 -0
  159. package/dist/compiler/optional-arguments.js.map +1 -0
  160. package/dist/compiler/package-fingerprint.d.ts +7 -0
  161. package/dist/compiler/package-fingerprint.d.ts.map +1 -0
  162. package/dist/compiler/package-fingerprint.js +178 -0
  163. package/dist/compiler/package-fingerprint.js.map +1 -0
  164. package/dist/compiler/package-record-contracts.d.ts +5 -0
  165. package/dist/compiler/package-record-contracts.d.ts.map +1 -0
  166. package/dist/compiler/package-record-contracts.js +126 -0
  167. package/dist/compiler/package-record-contracts.js.map +1 -0
  168. package/dist/compiler/pipeline-companions.d.ts +18 -0
  169. package/dist/compiler/pipeline-companions.d.ts.map +1 -0
  170. package/dist/compiler/pipeline-companions.js +1042 -0
  171. package/dist/compiler/pipeline-companions.js.map +1 -0
  172. package/dist/compiler/pipelines/catalog.d.ts +15 -0
  173. package/dist/compiler/pipelines/catalog.d.ts.map +1 -0
  174. package/dist/compiler/pipelines/catalog.js +55 -0
  175. package/dist/compiler/pipelines/catalog.js.map +1 -0
  176. package/dist/compiler/pipelines/companions.d.ts +18 -0
  177. package/dist/compiler/pipelines/companions.d.ts.map +1 -0
  178. package/dist/compiler/pipelines/companions.js +1042 -0
  179. package/dist/compiler/pipelines/companions.js.map +1 -0
  180. package/dist/compiler/pipelines/resolution.d.ts +38 -0
  181. package/dist/compiler/pipelines/resolution.d.ts.map +1 -0
  182. package/dist/compiler/pipelines/resolution.js +571 -0
  183. package/dist/compiler/pipelines/resolution.js.map +1 -0
  184. package/dist/compiler/project-config.d.ts +28 -0
  185. package/dist/compiler/project-config.d.ts.map +1 -0
  186. package/dist/compiler/project-config.js +155 -0
  187. package/dist/compiler/project-config.js.map +1 -0
  188. package/dist/compiler/providers.d.ts +4 -0
  189. package/dist/compiler/providers.d.ts.map +1 -0
  190. package/dist/compiler/providers.js +101 -0
  191. package/dist/compiler/providers.js.map +1 -0
  192. package/dist/compiler/record-contracts.d.ts +6 -0
  193. package/dist/compiler/record-contracts.d.ts.map +1 -0
  194. package/dist/compiler/record-contracts.js +41 -0
  195. package/dist/compiler/record-contracts.js.map +1 -0
  196. package/dist/compiler/rules/control-flow.d.ts +10 -0
  197. package/dist/compiler/rules/control-flow.d.ts.map +1 -0
  198. package/dist/compiler/rules/control-flow.js +19 -0
  199. package/dist/compiler/rules/control-flow.js.map +1 -0
  200. package/dist/compiler/rules/diagnostic.d.ts +4 -0
  201. package/dist/compiler/rules/diagnostic.d.ts.map +1 -0
  202. package/dist/compiler/rules/diagnostic.js +2 -0
  203. package/dist/compiler/rules/diagnostic.js.map +1 -0
  204. package/dist/compiler/rules/module-scope-refs.d.ts +5 -0
  205. package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -0
  206. package/dist/compiler/rules/module-scope-refs.js +47 -0
  207. package/dist/compiler/rules/module-scope-refs.js.map +1 -0
  208. package/dist/compiler/schemas/analysis.d.ts +13 -0
  209. package/dist/compiler/schemas/analysis.d.ts.map +1 -0
  210. package/dist/compiler/schemas/analysis.js +24 -0
  211. package/dist/compiler/schemas/analysis.js.map +1 -0
  212. package/dist/compiler/schemas/imported-record-functions.d.ts +4 -0
  213. package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -0
  214. package/dist/compiler/schemas/imported-record-functions.js +706 -0
  215. package/dist/compiler/schemas/imported-record-functions.js.map +1 -0
  216. package/dist/compiler/schemas/imported-schemas.d.ts +21 -0
  217. package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -0
  218. package/dist/compiler/schemas/imported-schemas.js +461 -0
  219. package/dist/compiler/schemas/imported-schemas.js.map +1 -0
  220. package/dist/compiler/source-map.d.ts +6 -0
  221. package/dist/compiler/source-map.d.ts.map +1 -0
  222. package/dist/compiler/source-map.js +127 -0
  223. package/dist/compiler/source-map.js.map +1 -0
  224. package/dist/compiler/typescript-context.d.ts +33 -0
  225. package/dist/compiler/typescript-context.d.ts.map +1 -0
  226. package/dist/compiler/typescript-context.js +200 -0
  227. package/dist/compiler/typescript-context.js.map +1 -0
  228. package/dist/compiler.d.ts +77 -0
  229. package/dist/compiler.d.ts.map +1 -0
  230. package/dist/compiler.js +497 -0
  231. package/dist/compiler.js.map +1 -0
  232. package/dist/emitter/assemblyscript.d.ts +5 -0
  233. package/dist/emitter/assemblyscript.d.ts.map +1 -0
  234. package/dist/emitter/assemblyscript.js +979 -0
  235. package/dist/emitter/assemblyscript.js.map +1 -0
  236. package/dist/emitter/declarations.d.ts +46 -0
  237. package/dist/emitter/declarations.d.ts.map +1 -0
  238. package/dist/emitter/declarations.js +739 -0
  239. package/dist/emitter/declarations.js.map +1 -0
  240. package/dist/emitter/emitter.d.ts +165 -0
  241. package/dist/emitter/emitter.d.ts.map +1 -0
  242. package/dist/emitter/emitter.js +2448 -0
  243. package/dist/emitter/emitter.js.map +1 -0
  244. package/dist/emitter/imports.d.ts +6 -0
  245. package/dist/emitter/imports.d.ts.map +1 -0
  246. package/dist/emitter/imports.js +73 -0
  247. package/dist/emitter/imports.js.map +1 -0
  248. package/dist/emitter/indent.d.ts +3 -0
  249. package/dist/emitter/indent.d.ts.map +1 -0
  250. package/dist/emitter/indent.js +31 -0
  251. package/dist/emitter/indent.js.map +1 -0
  252. package/dist/emitter/jsx.d.ts +20 -0
  253. package/dist/emitter/jsx.d.ts.map +1 -0
  254. package/dist/emitter/jsx.js +82 -0
  255. package/dist/emitter/jsx.js.map +1 -0
  256. package/dist/emitter/local-bindings.d.ts +6 -0
  257. package/dist/emitter/local-bindings.d.ts.map +1 -0
  258. package/dist/emitter/local-bindings.js +32 -0
  259. package/dist/emitter/local-bindings.js.map +1 -0
  260. package/dist/emitter/match.d.ts +56 -0
  261. package/dist/emitter/match.d.ts.map +1 -0
  262. package/dist/emitter/match.js +1287 -0
  263. package/dist/emitter/match.js.map +1 -0
  264. package/dist/emitter/pipeline-catalog.d.ts +15 -0
  265. package/dist/emitter/pipeline-catalog.d.ts.map +1 -0
  266. package/dist/emitter/pipeline-catalog.js +55 -0
  267. package/dist/emitter/pipeline-catalog.js.map +1 -0
  268. package/dist/emitter/pipeline-resolution.d.ts +38 -0
  269. package/dist/emitter/pipeline-resolution.d.ts.map +1 -0
  270. package/dist/emitter/pipeline-resolution.js +571 -0
  271. package/dist/emitter/pipeline-resolution.js.map +1 -0
  272. package/dist/emitter/runtime-helpers.d.ts +10 -0
  273. package/dist/emitter/runtime-helpers.d.ts.map +1 -0
  274. package/dist/emitter/runtime-helpers.js +22 -0
  275. package/dist/emitter/runtime-helpers.js.map +1 -0
  276. package/dist/emitter/schemas.d.ts +36 -0
  277. package/dist/emitter/schemas.d.ts.map +1 -0
  278. package/dist/emitter/schemas.js +766 -0
  279. package/dist/emitter/schemas.js.map +1 -0
  280. package/dist/emitter/statements.d.ts +23 -0
  281. package/dist/emitter/statements.d.ts.map +1 -0
  282. package/dist/emitter/statements.js +216 -0
  283. package/dist/emitter/statements.js.map +1 -0
  284. package/dist/emitter/tagged-match.d.ts +23 -0
  285. package/dist/emitter/tagged-match.d.ts.map +1 -0
  286. package/dist/emitter/tagged-match.js +109 -0
  287. package/dist/emitter/tagged-match.js.map +1 -0
  288. package/dist/emitter/types.d.ts +22 -0
  289. package/dist/emitter/types.d.ts.map +1 -0
  290. package/dist/emitter/types.js +231 -0
  291. package/dist/emitter/types.js.map +1 -0
  292. package/dist/errors.d.ts +39 -0
  293. package/dist/errors.d.ts.map +1 -0
  294. package/dist/errors.js +98 -0
  295. package/dist/errors.js.map +1 -0
  296. package/dist/formatter/comments.d.ts +25 -0
  297. package/dist/formatter/comments.d.ts.map +1 -0
  298. package/dist/formatter/comments.js +283 -0
  299. package/dist/formatter/comments.js.map +1 -0
  300. package/dist/formatter/index.d.ts +71 -0
  301. package/dist/formatter/index.d.ts.map +1 -0
  302. package/dist/formatter/index.js +1113 -0
  303. package/dist/formatter/index.js.map +1 -0
  304. package/dist/formatter/operator-precedence.d.ts +3 -0
  305. package/dist/formatter/operator-precedence.d.ts.map +1 -0
  306. package/dist/formatter/operator-precedence.js +27 -0
  307. package/dist/formatter/operator-precedence.js.map +1 -0
  308. package/dist/formatter/prettier.d.ts +7 -0
  309. package/dist/formatter/prettier.d.ts.map +1 -0
  310. package/dist/formatter/prettier.js +51 -0
  311. package/dist/formatter/prettier.js.map +1 -0
  312. package/dist/index.d.ts +17 -0
  313. package/dist/index.d.ts.map +1 -0
  314. package/dist/index.js +17 -0
  315. package/dist/index.js.map +1 -0
  316. package/dist/interop/callback.d.ts +38 -0
  317. package/dist/interop/callback.d.ts.map +1 -0
  318. package/dist/interop/callback.js +130 -0
  319. package/dist/interop/callback.js.map +1 -0
  320. package/dist/interop/index.d.ts +6 -0
  321. package/dist/interop/index.d.ts.map +1 -0
  322. package/dist/interop/index.js +6 -0
  323. package/dist/interop/index.js.map +1 -0
  324. package/dist/interop/js.d.ts +16 -0
  325. package/dist/interop/js.d.ts.map +1 -0
  326. package/dist/interop/js.js +35 -0
  327. package/dist/interop/js.js.map +1 -0
  328. package/dist/interop/record.d.ts +9 -0
  329. package/dist/interop/record.d.ts.map +1 -0
  330. package/dist/interop/record.js +18 -0
  331. package/dist/interop/record.js.map +1 -0
  332. package/dist/interop/valibot.d.ts +9 -0
  333. package/dist/interop/valibot.d.ts.map +1 -0
  334. package/dist/interop/valibot.js +94 -0
  335. package/dist/interop/valibot.js.map +1 -0
  336. package/dist/interop/zod.d.ts +45 -0
  337. package/dist/interop/zod.d.ts.map +1 -0
  338. package/dist/interop/zod.js +143 -0
  339. package/dist/interop/zod.js.map +1 -0
  340. package/dist/lexer/lexer.d.ts +65 -0
  341. package/dist/lexer/lexer.d.ts.map +1 -0
  342. package/dist/lexer/lexer.js +1335 -0
  343. package/dist/lexer/lexer.js.map +1 -0
  344. package/dist/lexer/tokens.d.ts +96 -0
  345. package/dist/lexer/tokens.d.ts.map +1 -0
  346. package/dist/lexer/tokens.js +150 -0
  347. package/dist/lexer/tokens.js.map +1 -0
  348. package/dist/lsp/code-action-worker.d.ts +2 -0
  349. package/dist/lsp/code-action-worker.d.ts.map +1 -0
  350. package/dist/lsp/code-action-worker.js +17 -0
  351. package/dist/lsp/code-action-worker.js.map +1 -0
  352. package/dist/lsp/completion.d.ts +11 -0
  353. package/dist/lsp/completion.d.ts.map +1 -0
  354. package/dist/lsp/completion.js +260 -0
  355. package/dist/lsp/completion.js.map +1 -0
  356. package/dist/lsp/definition.d.ts +42 -0
  357. package/dist/lsp/definition.d.ts.map +1 -0
  358. package/dist/lsp/definition.js +1074 -0
  359. package/dist/lsp/definition.js.map +1 -0
  360. package/dist/lsp/diagnostics-worker.d.ts +2 -0
  361. package/dist/lsp/diagnostics-worker.d.ts.map +1 -0
  362. package/dist/lsp/diagnostics-worker.js +169 -0
  363. package/dist/lsp/diagnostics-worker.js.map +1 -0
  364. package/dist/lsp/docs.d.ts +37 -0
  365. package/dist/lsp/docs.d.ts.map +1 -0
  366. package/dist/lsp/docs.js +830 -0
  367. package/dist/lsp/docs.js.map +1 -0
  368. package/dist/lsp/error-channel.d.ts +3 -0
  369. package/dist/lsp/error-channel.d.ts.map +1 -0
  370. package/dist/lsp/error-channel.js +48 -0
  371. package/dist/lsp/error-channel.js.map +1 -0
  372. package/dist/lsp/hover.d.ts +5 -0
  373. package/dist/lsp/hover.d.ts.map +1 -0
  374. package/dist/lsp/hover.js +651 -0
  375. package/dist/lsp/hover.js.map +1 -0
  376. package/dist/lsp/imports.d.ts +5 -0
  377. package/dist/lsp/imports.d.ts.map +1 -0
  378. package/dist/lsp/imports.js +317 -0
  379. package/dist/lsp/imports.js.map +1 -0
  380. package/dist/lsp/index.d.ts +16 -0
  381. package/dist/lsp/index.d.ts.map +1 -0
  382. package/dist/lsp/index.js +17 -0
  383. package/dist/lsp/index.js.map +1 -0
  384. package/dist/lsp/inlay-hints.d.ts +3 -0
  385. package/dist/lsp/inlay-hints.d.ts.map +1 -0
  386. package/dist/lsp/inlay-hints.js +236 -0
  387. package/dist/lsp/inlay-hints.js.map +1 -0
  388. package/dist/lsp/interop-rename.d.ts +26 -0
  389. package/dist/lsp/interop-rename.d.ts.map +1 -0
  390. package/dist/lsp/interop-rename.js +346 -0
  391. package/dist/lsp/interop-rename.js.map +1 -0
  392. package/dist/lsp/match-arms.d.ts +3 -0
  393. package/dist/lsp/match-arms.d.ts.map +1 -0
  394. package/dist/lsp/match-arms.js +341 -0
  395. package/dist/lsp/match-arms.js.map +1 -0
  396. package/dist/lsp/navigation.d.ts +23 -0
  397. package/dist/lsp/navigation.d.ts.map +1 -0
  398. package/dist/lsp/navigation.js +430 -0
  399. package/dist/lsp/navigation.js.map +1 -0
  400. package/dist/lsp/parsed-documents.d.ts +25 -0
  401. package/dist/lsp/parsed-documents.d.ts.map +1 -0
  402. package/dist/lsp/parsed-documents.js +47 -0
  403. package/dist/lsp/parsed-documents.js.map +1 -0
  404. package/dist/lsp/rename-worker.d.ts +2 -0
  405. package/dist/lsp/rename-worker.d.ts.map +1 -0
  406. package/dist/lsp/rename-worker.js +27 -0
  407. package/dist/lsp/rename-worker.js.map +1 -0
  408. package/dist/lsp/server.d.ts +78 -0
  409. package/dist/lsp/server.d.ts.map +1 -0
  410. package/dist/lsp/server.js +1098 -0
  411. package/dist/lsp/server.js.map +1 -0
  412. package/dist/lsp/thunk-pipeline.d.ts +4 -0
  413. package/dist/lsp/thunk-pipeline.d.ts.map +1 -0
  414. package/dist/lsp/thunk-pipeline.js +95 -0
  415. package/dist/lsp/thunk-pipeline.js.map +1 -0
  416. package/dist/lsp/validation.d.ts +8 -0
  417. package/dist/lsp/validation.d.ts.map +1 -0
  418. package/dist/lsp/validation.js +124 -0
  419. package/dist/lsp/validation.js.map +1 -0
  420. package/dist/lsp/workspace.d.ts +8 -0
  421. package/dist/lsp/workspace.d.ts.map +1 -0
  422. package/dist/lsp/workspace.js +70 -0
  423. package/dist/lsp/workspace.js.map +1 -0
  424. package/dist/math.ts +1 -0
  425. package/dist/parser/declarations.d.ts +21 -0
  426. package/dist/parser/declarations.d.ts.map +1 -0
  427. package/dist/parser/declarations.js +626 -0
  428. package/dist/parser/declarations.js.map +1 -0
  429. package/dist/parser/errors.d.ts +9 -0
  430. package/dist/parser/errors.d.ts.map +1 -0
  431. package/dist/parser/errors.js +11 -0
  432. package/dist/parser/errors.js.map +1 -0
  433. package/dist/parser/index.d.ts +9 -0
  434. package/dist/parser/index.d.ts.map +1 -0
  435. package/dist/parser/index.js +9 -0
  436. package/dist/parser/index.js.map +1 -0
  437. package/dist/parser/jsx.d.ts +5 -0
  438. package/dist/parser/jsx.d.ts.map +1 -0
  439. package/dist/parser/jsx.js +188 -0
  440. package/dist/parser/jsx.js.map +1 -0
  441. package/dist/parser/operator-expressions.d.ts +16 -0
  442. package/dist/parser/operator-expressions.d.ts.map +1 -0
  443. package/dist/parser/operator-expressions.js +146 -0
  444. package/dist/parser/operator-expressions.js.map +1 -0
  445. package/dist/parser/parser.d.ts +104 -0
  446. package/dist/parser/parser.d.ts.map +1 -0
  447. package/dist/parser/parser.js +1216 -0
  448. package/dist/parser/parser.js.map +1 -0
  449. package/dist/parser/patterns.d.ts +9 -0
  450. package/dist/parser/patterns.d.ts.map +1 -0
  451. package/dist/parser/patterns.js +292 -0
  452. package/dist/parser/patterns.js.map +1 -0
  453. package/dist/parser/pipeline-expressions.d.ts +10 -0
  454. package/dist/parser/pipeline-expressions.d.ts.map +1 -0
  455. package/dist/parser/pipeline-expressions.js +57 -0
  456. package/dist/parser/pipeline-expressions.js.map +1 -0
  457. package/dist/parser/scope.d.ts +17 -0
  458. package/dist/parser/scope.d.ts.map +1 -0
  459. package/dist/parser/scope.js +56 -0
  460. package/dist/parser/scope.js.map +1 -0
  461. package/dist/parser/statements.d.ts +13 -0
  462. package/dist/parser/statements.d.ts.map +1 -0
  463. package/dist/parser/statements.js +737 -0
  464. package/dist/parser/statements.js.map +1 -0
  465. package/dist/parser/types.d.ts +13 -0
  466. package/dist/parser/types.d.ts.map +1 -0
  467. package/dist/parser/types.js +371 -0
  468. package/dist/parser/types.js.map +1 -0
  469. package/dist/plugins/bun-preload.d.ts +4 -0
  470. package/dist/plugins/bun-preload.d.ts.map +1 -0
  471. package/dist/plugins/bun-preload.js +18 -0
  472. package/dist/plugins/bun-preload.js.map +1 -0
  473. package/dist/plugins/bun.d.ts +115 -0
  474. package/dist/plugins/bun.d.ts.map +1 -0
  475. package/dist/plugins/bun.js +240 -0
  476. package/dist/plugins/bun.js.map +1 -0
  477. package/dist/plugins/esbuild.d.ts +45 -0
  478. package/dist/plugins/esbuild.d.ts.map +1 -0
  479. package/dist/plugins/esbuild.js +184 -0
  480. package/dist/plugins/esbuild.js.map +1 -0
  481. package/dist/plugins/type-view.d.ts +30 -0
  482. package/dist/plugins/type-view.d.ts.map +1 -0
  483. package/dist/plugins/type-view.js +245 -0
  484. package/dist/plugins/type-view.js.map +1 -0
  485. package/dist/plugins/vite.d.ts +56 -0
  486. package/dist/plugins/vite.d.ts.map +1 -0
  487. package/dist/plugins/vite.js +182 -0
  488. package/dist/plugins/vite.js.map +1 -0
  489. package/dist/service.ts +3 -0
  490. package/dist/service.ts.map +1 -0
  491. package/dist/testing/index.d.ts +24 -0
  492. package/dist/testing/index.d.ts.map +1 -0
  493. package/dist/testing/index.js +56 -0
  494. package/dist/testing/index.js.map +1 -0
  495. package/dist/tooling/doc.d.ts +82 -0
  496. package/dist/tooling/doc.d.ts.map +1 -0
  497. package/dist/tooling/doc.js +624 -0
  498. package/dist/tooling/doc.js.map +1 -0
  499. package/dist/tooling/idiomatic.d.ts +20 -0
  500. package/dist/tooling/idiomatic.d.ts.map +1 -0
  501. package/dist/tooling/idiomatic.js +154 -0
  502. package/dist/tooling/idiomatic.js.map +1 -0
  503. package/dist/tooling/migrate.d.ts +62 -0
  504. package/dist/tooling/migrate.d.ts.map +1 -0
  505. package/dist/tooling/migrate.js +608 -0
  506. package/dist/tooling/migrate.js.map +1 -0
  507. package/dist/tooling/pipeline-style.d.ts +12 -0
  508. package/dist/tooling/pipeline-style.d.ts.map +1 -0
  509. package/dist/tooling/pipeline-style.js +208 -0
  510. package/dist/tooling/pipeline-style.js.map +1 -0
  511. package/dist/version.d.ts +2 -0
  512. package/dist/version.d.ts.map +1 -0
  513. package/dist/version.js +25 -0
  514. package/dist/version.js.map +1 -0
  515. package/package.json +128 -4
  516. package/src/ast/types.ts +753 -0
  517. package/src/ast/walk.ts +35 -0
  518. package/src/cli/build-bun.ts +249 -0
  519. package/src/cli/build-watch.ts +299 -0
  520. package/src/cli/build.ts +450 -0
  521. package/src/cli/check.ts +342 -0
  522. package/src/cli/commands.ts +301 -0
  523. package/src/cli/doc.ts +81 -0
  524. package/src/cli/doctor.ts +173 -0
  525. package/src/cli/emit.ts +138 -0
  526. package/src/cli/explain.ts +127 -0
  527. package/src/cli/fmt.ts +170 -0
  528. package/src/cli/index.ts +227 -0
  529. package/src/cli/init.ts +491 -0
  530. package/src/cli/io.ts +150 -0
  531. package/src/cli/pipeline-style.ts +55 -0
  532. package/src/cli/repl.ts +443 -0
  533. package/src/cli/run.ts +238 -0
  534. package/src/cli/test.ts +148 -0
  535. package/src/cli/tsc.ts +207 -0
  536. package/src/cli/typecheck.ts +100 -0
  537. package/src/compiler/ast-inspection.ts +121 -0
  538. package/src/compiler/boolean-operators.ts +108 -0
  539. package/src/compiler/check.ts +2763 -0
  540. package/src/compiler/diagnostics.ts +179 -0
  541. package/src/compiler/effect-mutation-rule.ts +407 -0
  542. package/src/compiler/entry-rules.ts +116 -0
  543. package/src/compiler/incremental-build.ts +131 -0
  544. package/src/compiler/incremental-dependencies.ts +200 -0
  545. package/src/compiler/js-interop-nullability.ts +67 -0
  546. package/src/compiler/modules/output-collisions.ts +48 -0
  547. package/src/compiler/modules/output-plan.ts +46 -0
  548. package/src/compiler/modules/resolution.ts +56 -0
  549. package/src/compiler/numeric-comparisons.ts +213 -0
  550. package/src/compiler/optional-arguments.ts +335 -0
  551. package/src/compiler/package-fingerprint.ts +216 -0
  552. package/src/compiler/package-record-contracts.ts +156 -0
  553. package/src/compiler/pipelines/catalog.ts +1128 -0
  554. package/src/compiler/pipelines/companions.ts +1279 -0
  555. package/src/compiler/pipelines/resolution.ts +684 -0
  556. package/src/compiler/project-config.ts +221 -0
  557. package/src/compiler/record-contracts.ts +46 -0
  558. package/src/compiler/rules/control-flow.ts +57 -0
  559. package/src/compiler/rules/diagnostic.ts +11 -0
  560. package/src/compiler/rules/module-scope-refs.ts +63 -0
  561. package/src/compiler/schemas/analysis.ts +45 -0
  562. package/src/compiler/schemas/imported-record-functions.ts +984 -0
  563. package/src/compiler/schemas/imported-schemas.ts +761 -0
  564. package/src/compiler/source-map.ts +165 -0
  565. package/src/compiler/typescript-context.ts +250 -0
  566. package/src/compiler.ts +865 -0
  567. package/src/emitter/assemblyscript.ts +1220 -0
  568. package/src/emitter/declarations.ts +916 -0
  569. package/src/emitter/emitter.ts +3128 -0
  570. package/src/emitter/imports.ts +89 -0
  571. package/src/emitter/indent.ts +39 -0
  572. package/src/emitter/jsx.ts +122 -0
  573. package/src/emitter/local-bindings.ts +40 -0
  574. package/src/emitter/match.ts +1631 -0
  575. package/src/emitter/runtime-helpers.ts +31 -0
  576. package/src/emitter/schemas.ts +969 -0
  577. package/src/emitter/statements.ts +310 -0
  578. package/src/emitter/tagged-match.ts +171 -0
  579. package/src/emitter/types.ts +289 -0
  580. package/src/errors.ts +115 -0
  581. package/src/formatter/comments.ts +350 -0
  582. package/src/formatter/index.ts +1457 -0
  583. package/src/formatter/operator-precedence.ts +36 -0
  584. package/src/formatter/prettier.ts +61 -0
  585. package/src/index.ts +16 -0
  586. package/src/interop/callback.ts +188 -0
  587. package/src/interop/js.ts +66 -0
  588. package/src/interop/record.ts +36 -0
  589. package/src/interop/valibot.ts +141 -0
  590. package/src/interop/zod.ts +219 -0
  591. package/src/lexer/lexer.ts +1521 -0
  592. package/src/lexer/tokens.ts +174 -0
  593. package/src/lsp/code-action-worker.ts +31 -0
  594. package/src/lsp/completion.ts +343 -0
  595. package/src/lsp/definition.ts +1165 -0
  596. package/src/lsp/diagnostics-worker.ts +198 -0
  597. package/src/lsp/docs.ts +864 -0
  598. package/src/lsp/error-channel.ts +63 -0
  599. package/src/lsp/hover.ts +803 -0
  600. package/src/lsp/imports.ts +380 -0
  601. package/src/lsp/index.ts +55 -0
  602. package/src/lsp/inlay-hints.ts +308 -0
  603. package/src/lsp/interop-rename.ts +454 -0
  604. package/src/lsp/match-arms.ts +400 -0
  605. package/src/lsp/navigation.ts +553 -0
  606. package/src/lsp/parsed-documents.ts +64 -0
  607. package/src/lsp/rename-worker.ts +40 -0
  608. package/src/lsp/server.ts +1437 -0
  609. package/src/lsp/thunk-pipeline.ts +117 -0
  610. package/src/lsp/validation.ts +147 -0
  611. package/src/lsp/workspace.ts +74 -0
  612. package/src/parser/declarations.ts +808 -0
  613. package/src/parser/errors.ts +18 -0
  614. package/src/parser/jsx.ts +253 -0
  615. package/src/parser/operator-expressions.ts +170 -0
  616. package/src/parser/parser.ts +1565 -0
  617. package/src/parser/patterns.ts +342 -0
  618. package/src/parser/pipeline-expressions.ts +77 -0
  619. package/src/parser/scope.ts +69 -0
  620. package/src/parser/statements.ts +831 -0
  621. package/src/parser/types.ts +453 -0
  622. package/src/plugins/bun-preload.ts +25 -0
  623. package/src/plugins/bun.ts +448 -0
  624. package/src/plugins/esbuild.ts +308 -0
  625. package/src/plugins/type-view.ts +326 -0
  626. package/src/plugins/vite.ts +294 -0
  627. package/src/testing/index.ts +72 -0
  628. package/src/tooling/doc.ts +786 -0
  629. package/src/tooling/idiomatic.ts +202 -0
  630. package/src/tooling/pipeline-style.ts +248 -0
  631. package/src/version.ts +27 -0
@@ -0,0 +1,1335 @@
1
+ import { FunScriptError } from "../errors.js";
2
+ import { BANNED_KEYWORDS, BANNED_SYMBOLS, KEYWORDS, TokenType, } from "./tokens.js";
3
+ export class LexerError extends FunScriptError {
4
+ constructor(message, span) {
5
+ super(message, span);
6
+ this.name = "LexerError";
7
+ }
8
+ }
9
+ export class Lexer {
10
+ source;
11
+ filename;
12
+ offset = 0;
13
+ line = 1;
14
+ column = 1;
15
+ indentStack = [0];
16
+ parenLevel = 0;
17
+ bracketLevel = 0;
18
+ braceStack = [];
19
+ isBlockBrace() {
20
+ const lastToken = this.tokens[this.tokens.length - 1];
21
+ if (!lastToken)
22
+ return false;
23
+ if (lastToken.type === TokenType.EFFECT ||
24
+ lastToken.type === TokenType.PAR ||
25
+ lastToken.type === TokenType.ARROW ||
26
+ lastToken.type === TokenType.RPAREN) {
27
+ return true;
28
+ }
29
+ for (let i = this.tokens.length - 1; i >= 0; i--) {
30
+ const t = this.tokens[i].type;
31
+ if (t === TokenType.NEWLINE ||
32
+ t === TokenType.INDENT ||
33
+ t === TokenType.DEDENT ||
34
+ t === TokenType.LBRACE) {
35
+ break;
36
+ }
37
+ if (t === TokenType.WHEN) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ jsxStack = [];
44
+ isFunx;
45
+ tokens = [];
46
+ atLineStart = true;
47
+ constructor(source, filename = "<anonymous>", options) {
48
+ this.source = source;
49
+ this.filename = filename;
50
+ if (typeof options === "boolean") {
51
+ this.isFunx = options;
52
+ }
53
+ else if (options && typeof options.jsx === "boolean") {
54
+ this.isFunx = options.jsx;
55
+ }
56
+ else {
57
+ this.isFunx = this.filename.endsWith(".funx");
58
+ }
59
+ }
60
+ tokenize() {
61
+ // Handle first-line shebang (e.g. `#!/usr/bin/env bun`)
62
+ if (this.offset === 0 && this.source.startsWith("#!")) {
63
+ while (!this.isAtEnd() && this.peek() !== "\n") {
64
+ this.advance();
65
+ }
66
+ if (!this.isAtEnd() && this.peek() === "\n") {
67
+ this.advance();
68
+ this.line++;
69
+ this.column = 1;
70
+ this.atLineStart = true;
71
+ }
72
+ }
73
+ while (!this.isAtEnd()) {
74
+ if (this.atLineStart) {
75
+ this.handleIndentation();
76
+ }
77
+ if (this.isAtEnd())
78
+ break;
79
+ if (this.isFunx &&
80
+ this.jsxStack.length > 0 &&
81
+ !this.braceStack.includes("interpolation")) {
82
+ const top = this.jsxStack[this.jsxStack.length - 1];
83
+ if (top.kind === "children") {
84
+ this.readJsxChildren();
85
+ continue;
86
+ }
87
+ else if (top.kind === "tag" || top.kind === "closing_tag") {
88
+ this.readJsxTag(top);
89
+ continue;
90
+ }
91
+ }
92
+ const char = this.peek();
93
+ // Whitespace (inline)
94
+ if (char === " " || char === "\t") {
95
+ if (char === "\t") {
96
+ throw new LexerError("Tabs are not allowed for indentation or spacing; use 2 spaces", this.currentSpan(1));
97
+ }
98
+ this.advance();
99
+ continue;
100
+ }
101
+ // Newlines
102
+ if (char === "\r" || char === "\n") {
103
+ this.advanceNewline();
104
+ continue;
105
+ }
106
+ // Banned multi-character operators check
107
+ if (this.matchAhead("&&")) {
108
+ throw new LexerError(BANNED_SYMBOLS["&&"], this.currentSpan(2));
109
+ }
110
+ if (this.matchAhead("||")) {
111
+ throw new LexerError(BANNED_SYMBOLS["||"], this.currentSpan(2));
112
+ }
113
+ // Equality operators must precede comments: '#' starts a comment unless
114
+ // it is immediately followed by '=' or '!'.
115
+ if (this.matchAhead("#=")) {
116
+ this.emitToken(TokenType.VALUE_EQ, "#=", 2);
117
+ continue;
118
+ }
119
+ if (this.matchAhead("#!")) {
120
+ this.emitToken(TokenType.VALUE_NEQ, "#!", 2);
121
+ continue;
122
+ }
123
+ if (this.matchAhead("@=")) {
124
+ this.emitToken(TokenType.REF_EQ, "@=", 2);
125
+ continue;
126
+ }
127
+ if (this.matchAhead("@!")) {
128
+ this.emitToken(TokenType.REF_NEQ, "@!", 2);
129
+ continue;
130
+ }
131
+ if (this.matchAhead("===") || this.matchAhead("!==")) {
132
+ const op = this.source.slice(this.offset, this.offset + 3);
133
+ throw new LexerError(BANNED_SYMBOLS[op], this.currentSpan(3));
134
+ }
135
+ if (this.matchAhead("==") || this.matchAhead("!=")) {
136
+ const op = this.source.slice(this.offset, this.offset + 2);
137
+ throw new LexerError(BANNED_SYMBOLS[op], this.currentSpan(2));
138
+ }
139
+ // TypeScript-style line comments
140
+ if (this.matchAhead("//")) {
141
+ this.skipComment();
142
+ continue;
143
+ }
144
+ // Multi-character operators
145
+ if (this.matchAhead("???")) {
146
+ this.emitToken(TokenType.TYPED_HOLE, "???", 3);
147
+ continue;
148
+ }
149
+ if (this.matchAhead("...")) {
150
+ this.emitToken(TokenType.DOTDOTDOT, "...", 3);
151
+ continue;
152
+ }
153
+ if (this.matchAhead("=>")) {
154
+ this.emitToken(TokenType.ARROW, "=>", 2);
155
+ continue;
156
+ }
157
+ if (this.matchAhead("<-")) {
158
+ this.emitToken(TokenType.LARROW, "<-", 2);
159
+ continue;
160
+ }
161
+ if (this.matchAhead("|>>")) {
162
+ this.emitToken(TokenType.THUNK_PIPE, "|>>", 3);
163
+ continue;
164
+ }
165
+ if (this.matchAhead("|>")) {
166
+ this.emitToken(TokenType.PIPE, "|>", 2);
167
+ continue;
168
+ }
169
+ if (this.matchAhead("**")) {
170
+ this.emitToken(TokenType.STARSTAR, "**", 2);
171
+ continue;
172
+ }
173
+ if (this.matchAhead("??")) {
174
+ throw new LexerError(BANNED_SYMBOLS["??"], this.currentSpan(2));
175
+ }
176
+ // Strings
177
+ if (char === '"') {
178
+ this.readString();
179
+ continue;
180
+ }
181
+ // Template Literals
182
+ if (char === "`") {
183
+ this.readTemplateString();
184
+ continue;
185
+ }
186
+ // Numbers
187
+ if (this.isDigit(char)) {
188
+ this.readNumber();
189
+ continue;
190
+ }
191
+ // Identifiers / Keywords
192
+ if (this.isAlpha(char) || char === "_") {
193
+ this.readIdentifierOrKeyword();
194
+ continue;
195
+ }
196
+ // Single-character symbols
197
+ switch (char) {
198
+ case "=":
199
+ this.emitToken(TokenType.EQ, "=", 1);
200
+ break;
201
+ case "|":
202
+ this.emitToken(TokenType.BAR, "|", 1);
203
+ break;
204
+ case "&":
205
+ this.emitToken(TokenType.AMP, "&", 1);
206
+ break;
207
+ case "+":
208
+ this.emitToken(TokenType.PLUS, "+", 1);
209
+ break;
210
+ case "-":
211
+ this.emitToken(TokenType.MINUS, "-", 1);
212
+ break;
213
+ case "*":
214
+ this.emitToken(TokenType.STAR, "*", 1);
215
+ break;
216
+ case "/":
217
+ this.emitToken(TokenType.SLASH, "/", 1);
218
+ break;
219
+ case "%":
220
+ this.emitToken(TokenType.PERCENT, "%", 1);
221
+ break;
222
+ case "?":
223
+ this.emitToken(TokenType.QUESTION, "?", 1);
224
+ break;
225
+ case ":":
226
+ this.emitToken(TokenType.COLON, ":", 1);
227
+ break;
228
+ case ",":
229
+ this.emitToken(TokenType.COMMA, ",", 1);
230
+ break;
231
+ case ".":
232
+ this.emitToken(TokenType.DOT, ".", 1);
233
+ break;
234
+ case "(":
235
+ this.parenLevel++;
236
+ this.emitToken(TokenType.LPAREN, "(", 1);
237
+ break;
238
+ case ")":
239
+ if (this.parenLevel > 0)
240
+ this.parenLevel--;
241
+ this.emitToken(TokenType.RPAREN, ")", 1);
242
+ break;
243
+ case "[":
244
+ this.bracketLevel++;
245
+ this.emitToken(TokenType.LBRACKET, "[", 1);
246
+ break;
247
+ case "]":
248
+ if (this.bracketLevel > 0)
249
+ this.bracketLevel--;
250
+ this.emitToken(TokenType.RBRACKET, "]", 1);
251
+ break;
252
+ case "{":
253
+ this.braceStack.push(this.isBlockBrace() ? "block" : "record");
254
+ this.emitToken(TokenType.LBRACE, "{", 1);
255
+ break;
256
+ case "}":
257
+ if (this.braceStack.length > 0 &&
258
+ this.braceStack[this.braceStack.length - 1] ===
259
+ "template_interpolation") {
260
+ this.braceStack.pop();
261
+ this.emitToken(TokenType.INTERPOLATION_END, "}", 1);
262
+ this.continueTemplateAfterInterpolation();
263
+ }
264
+ else if (this.braceStack.length > 0 &&
265
+ this.braceStack[this.braceStack.length - 1] === "interpolation") {
266
+ this.braceStack.pop();
267
+ this.emitToken(TokenType.INTERPOLATION_END, "}", 1);
268
+ this.continueStringAfterInterpolation();
269
+ }
270
+ else if (this.braceStack.length > 0 &&
271
+ this.braceStack[this.braceStack.length - 1] === "jsx_expr") {
272
+ this.braceStack.pop();
273
+ if (this.jsxStack.length > 0 &&
274
+ this.jsxStack[this.jsxStack.length - 1].kind === "expr") {
275
+ this.jsxStack.pop();
276
+ }
277
+ this.emitToken(TokenType.RBRACE, "}", 1);
278
+ }
279
+ else {
280
+ if (this.braceStack.length > 0)
281
+ this.braceStack.pop();
282
+ this.emitToken(TokenType.RBRACE, "}", 1);
283
+ }
284
+ break;
285
+ case "<":
286
+ if (this.isFunx && this.matchAhead("</")) {
287
+ this.emitToken(TokenType.JSX_CLOSING_TAG_OPEN, "</", 2);
288
+ this.jsxStack.push({ kind: "closing_tag", hasTagName: false });
289
+ }
290
+ else if (this.isJsxTagStart()) {
291
+ this.emitToken(TokenType.JSX_TAG_OPEN, "<", 1);
292
+ this.jsxStack.push({ kind: "tag", hasTagName: false });
293
+ }
294
+ else {
295
+ const isEqual = this.matchAhead("<=");
296
+ this.emitToken(isEqual ? TokenType.LTE : TokenType.LT, isEqual ? "<=" : "<", isEqual ? 2 : 1);
297
+ }
298
+ break;
299
+ case ">":
300
+ const isEqual = this.matchAhead(">=");
301
+ this.emitToken(isEqual ? TokenType.GTE : TokenType.GT, isEqual ? ">=" : ">", isEqual ? 2 : 1);
302
+ break;
303
+ case "!":
304
+ throw new LexerError(BANNED_SYMBOLS["!"], this.currentSpan(1));
305
+ default:
306
+ throw new LexerError(`Unexpected character '${char}'`, this.currentSpan(1));
307
+ }
308
+ }
309
+ // Flush remaining indentation
310
+ while (this.indentStack.length > 1) {
311
+ this.indentStack.pop();
312
+ this.tokens.push({
313
+ type: TokenType.DEDENT,
314
+ value: "",
315
+ span: this.currentSpan(0),
316
+ });
317
+ }
318
+ // Final EOF token
319
+ this.tokens.push({
320
+ type: TokenType.EOF,
321
+ value: "",
322
+ span: this.currentSpan(0),
323
+ });
324
+ return this.tokens;
325
+ }
326
+ handleIndentation() {
327
+ if (this.bracketLevel > 0 || this.isInJsxChildrenOrTag()) {
328
+ this.atLineStart = false;
329
+ return;
330
+ }
331
+ let spaces = 0;
332
+ const startPos = this.currentPosition();
333
+ while (!this.isAtEnd()) {
334
+ const c = this.peek();
335
+ if (c === " ") {
336
+ spaces++;
337
+ this.advance();
338
+ }
339
+ else if (c === "\t") {
340
+ throw new LexerError("Tabs are not allowed for indentation; use 2 spaces", this.currentSpan(1));
341
+ }
342
+ else {
343
+ break;
344
+ }
345
+ }
346
+ // If entire line is blank or a comment, ignore indentation.
347
+ if (this.peek() === "\r" ||
348
+ this.peek() === "\n" ||
349
+ this.matchAhead("//") ||
350
+ this.isAtEnd()) {
351
+ this.atLineStart = false;
352
+ return;
353
+ }
354
+ this.atLineStart = false;
355
+ const currentIndent = this.indentStack[this.indentStack.length - 1];
356
+ if (spaces > currentIndent) {
357
+ this.indentStack.push(spaces);
358
+ this.tokens.push({
359
+ type: TokenType.INDENT,
360
+ value: " ".repeat(spaces),
361
+ span: { start: startPos, end: this.currentPosition() },
362
+ });
363
+ }
364
+ else if (spaces < currentIndent) {
365
+ while (this.indentStack.length > 1 &&
366
+ this.indentStack[this.indentStack.length - 1] > spaces) {
367
+ this.indentStack.pop();
368
+ this.tokens.push({
369
+ type: TokenType.DEDENT,
370
+ value: "",
371
+ span: { start: startPos, end: this.currentPosition() },
372
+ });
373
+ }
374
+ if (this.indentStack[this.indentStack.length - 1] !== spaces) {
375
+ throw new LexerError(`Inconsistent indentation: unindent does not match any outer indentation level (expected ${this.indentStack.join(", ")}, got ${spaces})`, { start: startPos, end: this.currentPosition() });
376
+ }
377
+ }
378
+ }
379
+ advanceNewline() {
380
+ const startPos = this.currentPosition();
381
+ if (this.peek() === "\r")
382
+ this.advance();
383
+ if (this.peek() === "\n")
384
+ this.advance();
385
+ this.line++;
386
+ this.column = 1;
387
+ this.atLineStart = true;
388
+ const lastToken = this.tokens[this.tokens.length - 1];
389
+ if (lastToken &&
390
+ lastToken.type !== TokenType.NEWLINE &&
391
+ lastToken.type !== TokenType.INDENT) {
392
+ this.tokens.push({
393
+ type: TokenType.NEWLINE,
394
+ value: "\n",
395
+ span: { start: startPos, end: this.currentPosition() },
396
+ });
397
+ }
398
+ }
399
+ readString() {
400
+ const startPos = this.currentPosition();
401
+ this.advance(); // consume opening '"'
402
+ let buffer = "";
403
+ while (!this.isAtEnd() && this.peek() !== '"') {
404
+ const c = this.peek();
405
+ if (c === "\n" || c === "\r") {
406
+ throw new LexerError("Unterminated string literal (newline in string)", {
407
+ start: startPos,
408
+ end: this.currentPosition(),
409
+ });
410
+ }
411
+ if (c === "\\") {
412
+ this.advance();
413
+ if (this.isAtEnd())
414
+ break;
415
+ const esc = this.advance();
416
+ if (esc === "n")
417
+ buffer += "\n";
418
+ else if (esc === "t")
419
+ buffer += "\t";
420
+ else if (esc === "r")
421
+ buffer += "\r";
422
+ else if (esc === '"')
423
+ buffer += '"';
424
+ else if (esc === "\\")
425
+ buffer += "\\";
426
+ else if (esc === "{")
427
+ buffer += "{";
428
+ else
429
+ buffer += "\\" + esc;
430
+ continue;
431
+ }
432
+ if (c === "{") {
433
+ // Start of interpolation
434
+ const inJsxTag = this.isFunx &&
435
+ this.jsxStack.length > 0 &&
436
+ this.jsxStack[this.jsxStack.length - 1].kind === "tag";
437
+ if (inJsxTag && buffer.endsWith("$")) {
438
+ buffer = buffer.slice(0, -1);
439
+ }
440
+ if (buffer.length > 0) {
441
+ this.tokens.push({
442
+ type: TokenType.STRING_PART,
443
+ value: buffer,
444
+ span: { start: startPos, end: this.currentPosition() },
445
+ });
446
+ buffer = "";
447
+ }
448
+ this.advance(); // consume '{'
449
+ this.braceStack.push("interpolation");
450
+ this.tokens.push({
451
+ type: TokenType.INTERPOLATION_START,
452
+ value: "{",
453
+ span: this.currentSpan(1),
454
+ });
455
+ return; // transition to normal tokenizing for expression inside
456
+ }
457
+ buffer += this.advance();
458
+ }
459
+ if (this.isAtEnd()) {
460
+ throw new LexerError("Unterminated string literal", {
461
+ start: startPos,
462
+ end: this.currentPosition(),
463
+ });
464
+ }
465
+ this.advance(); // consume closing '"'
466
+ this.tokens.push({
467
+ type: TokenType.STRING,
468
+ value: buffer,
469
+ span: { start: startPos, end: this.currentPosition() },
470
+ });
471
+ }
472
+ readTemplateString() {
473
+ const startPos = this.currentPosition();
474
+ this.advance(); // consume opening '`'
475
+ let buffer = "";
476
+ while (!this.isAtEnd() && this.peek() !== "`") {
477
+ const c = this.peek();
478
+ if (c === "\\") {
479
+ this.advance();
480
+ if (this.isAtEnd())
481
+ break;
482
+ const esc = this.advance();
483
+ if (esc === "`")
484
+ buffer += "\\`";
485
+ else if (esc === "\\")
486
+ buffer += "\\\\";
487
+ else if (esc === "$")
488
+ buffer += "\\$";
489
+ else if (esc === "{")
490
+ buffer += "\\{";
491
+ else
492
+ buffer += "\\" + esc;
493
+ continue;
494
+ }
495
+ if (c === "$" && this.peekAhead(1) === "{") {
496
+ if (buffer.length > 0) {
497
+ this.tokens.push({
498
+ type: TokenType.TEMPLATE_PART,
499
+ value: buffer,
500
+ span: { start: startPos, end: this.currentPosition() },
501
+ });
502
+ buffer = "";
503
+ }
504
+ this.advance(); // consume '$'
505
+ this.advance(); // consume '{'
506
+ this.braceStack.push("template_interpolation");
507
+ this.tokens.push({
508
+ type: TokenType.INTERPOLATION_START,
509
+ value: "{",
510
+ span: this.currentSpan(2),
511
+ });
512
+ return;
513
+ }
514
+ if (c === "{") {
515
+ if (buffer.length > 0) {
516
+ this.tokens.push({
517
+ type: TokenType.TEMPLATE_PART,
518
+ value: buffer,
519
+ span: { start: startPos, end: this.currentPosition() },
520
+ });
521
+ buffer = "";
522
+ }
523
+ this.advance(); // consume '{'
524
+ this.braceStack.push("template_interpolation");
525
+ this.tokens.push({
526
+ type: TokenType.INTERPOLATION_START,
527
+ value: "{",
528
+ span: this.currentSpan(1),
529
+ });
530
+ return;
531
+ }
532
+ const ch = this.advance();
533
+ if (ch === "\n") {
534
+ this.line++;
535
+ this.column = 1;
536
+ }
537
+ buffer += ch;
538
+ }
539
+ if (this.isAtEnd()) {
540
+ throw new LexerError("Unterminated template literal", {
541
+ start: startPos,
542
+ end: this.currentPosition(),
543
+ });
544
+ }
545
+ this.advance(); // consume closing '`'
546
+ this.tokens.push({
547
+ type: TokenType.TEMPLATE_STRING,
548
+ value: buffer,
549
+ span: { start: startPos, end: this.currentPosition() },
550
+ });
551
+ }
552
+ continueTemplateAfterInterpolation() {
553
+ const startPos = this.currentPosition();
554
+ let buffer = "";
555
+ while (!this.isAtEnd() && this.peek() !== "`") {
556
+ const c = this.peek();
557
+ if (c === "\\") {
558
+ this.advance();
559
+ if (this.isAtEnd())
560
+ break;
561
+ const esc = this.advance();
562
+ if (esc === "`")
563
+ buffer += "\\`";
564
+ else if (esc === "\\")
565
+ buffer += "\\\\";
566
+ else if (esc === "$")
567
+ buffer += "\\$";
568
+ else if (esc === "{")
569
+ buffer += "\\{";
570
+ else
571
+ buffer += "\\" + esc;
572
+ continue;
573
+ }
574
+ if (c === "$" && this.peekAhead(1) === "{") {
575
+ if (buffer.length > 0) {
576
+ this.tokens.push({
577
+ type: TokenType.TEMPLATE_PART,
578
+ value: buffer,
579
+ span: { start: startPos, end: this.currentPosition() },
580
+ });
581
+ buffer = "";
582
+ }
583
+ this.advance(); // consume '$'
584
+ this.advance(); // consume '{'
585
+ this.braceStack.push("template_interpolation");
586
+ this.tokens.push({
587
+ type: TokenType.INTERPOLATION_START,
588
+ value: "{",
589
+ span: this.currentSpan(2),
590
+ });
591
+ return;
592
+ }
593
+ if (c === "{") {
594
+ if (buffer.length > 0) {
595
+ this.tokens.push({
596
+ type: TokenType.TEMPLATE_PART,
597
+ value: buffer,
598
+ span: { start: startPos, end: this.currentPosition() },
599
+ });
600
+ buffer = "";
601
+ }
602
+ this.advance(); // consume '{'
603
+ this.braceStack.push("template_interpolation");
604
+ this.tokens.push({
605
+ type: TokenType.INTERPOLATION_START,
606
+ value: "{",
607
+ span: this.currentSpan(1),
608
+ });
609
+ return;
610
+ }
611
+ const ch = this.advance();
612
+ if (ch === "\n") {
613
+ this.line++;
614
+ this.column = 1;
615
+ }
616
+ buffer += ch;
617
+ }
618
+ if (this.isAtEnd()) {
619
+ throw new LexerError("Unterminated template literal", {
620
+ start: startPos,
621
+ end: this.currentPosition(),
622
+ });
623
+ }
624
+ this.advance(); // consume closing '`'
625
+ this.tokens.push({
626
+ type: TokenType.TEMPLATE_PART,
627
+ value: buffer,
628
+ span: { start: startPos, end: this.currentPosition() },
629
+ });
630
+ }
631
+ /**
632
+ * Reads the verbatim TypeScript payload that follows the 'ts' keyword.
633
+ *
634
+ * The sole form is a balanced brace block. Its contents are verbatim TypeScript:
635
+ * ts { Record<string, { a: number }> }
636
+ * ts { interface Foo { a: number } }
637
+ */
638
+ readTsCode(language = "ts") {
639
+ while (this.peek() === " " || this.peek() === "\t")
640
+ this.advance();
641
+ const startPos = this.currentPosition();
642
+ if (this.peek() !== "{") {
643
+ throw new LexerError(`Expected '{ ... }' after '${language}'`, this.currentSpan(1));
644
+ }
645
+ this.advance(); // opening '{'
646
+ let depth = 1;
647
+ let code = "";
648
+ let quote = null;
649
+ let lineComment = false;
650
+ let blockComment = false;
651
+ while (!this.isAtEnd() && depth > 0) {
652
+ const c = this.advance();
653
+ const next = this.peek();
654
+ if (c === "\n") {
655
+ this.line++;
656
+ this.column = 1;
657
+ lineComment = false;
658
+ }
659
+ if (lineComment) {
660
+ code += c;
661
+ continue;
662
+ }
663
+ if (blockComment) {
664
+ code += c;
665
+ if (c === "*" && next === "/") {
666
+ code += this.advance();
667
+ blockComment = false;
668
+ }
669
+ continue;
670
+ }
671
+ if (quote) {
672
+ code += c;
673
+ if (c === "\\") {
674
+ code += this.advance();
675
+ continue;
676
+ }
677
+ if (c === quote)
678
+ quote = null;
679
+ continue;
680
+ }
681
+ if (c === "/" && next === "/") {
682
+ code += c + this.advance();
683
+ lineComment = true;
684
+ continue;
685
+ }
686
+ if (c === "/" && next === "*") {
687
+ code += c + this.advance();
688
+ blockComment = true;
689
+ continue;
690
+ }
691
+ if (c === '"' || c === "'" || c === "`") {
692
+ quote = c;
693
+ code += c;
694
+ continue;
695
+ }
696
+ if (c === "{") {
697
+ depth++;
698
+ code += c;
699
+ continue;
700
+ }
701
+ if (c === "}") {
702
+ depth--;
703
+ if (depth > 0)
704
+ code += c;
705
+ continue;
706
+ }
707
+ code += c;
708
+ }
709
+ if (depth !== 0)
710
+ throw new LexerError(`Unterminated '${language} { ... }' block`, {
711
+ start: startPos,
712
+ end: this.currentPosition(),
713
+ });
714
+ if (code.trim() === "")
715
+ throw new LexerError(`Empty '${language} { ... }' block`, {
716
+ start: startPos,
717
+ end: this.currentPosition(),
718
+ });
719
+ const leading = code.slice(0, code.search(/\S/));
720
+ const lines = leading.split("\n");
721
+ const contentStart = {
722
+ offset: startPos.offset + 1 + leading.length,
723
+ line: startPos.line + lines.length - 1,
724
+ column: lines.length === 1
725
+ ? startPos.column + 1 + leading.length
726
+ : lines[lines.length - 1].length + 1,
727
+ };
728
+ this.tokens.push({
729
+ type: language === "ts" ? TokenType.TS_CODE : TokenType.AS_CODE,
730
+ value: code.trim(),
731
+ contentStart,
732
+ span: { start: startPos, end: this.currentPosition() },
733
+ });
734
+ }
735
+ continueStringAfterInterpolation() {
736
+ const startPos = this.currentPosition();
737
+ let buffer = "";
738
+ while (!this.isAtEnd() && this.peek() !== '"') {
739
+ const c = this.peek();
740
+ if (c === "\n" || c === "\r") {
741
+ throw new LexerError("Unterminated string literal (newline in string)", {
742
+ start: startPos,
743
+ end: this.currentPosition(),
744
+ });
745
+ }
746
+ if (c === "{" && this.peekPrev() !== "\\") {
747
+ const inJsxTag = this.isFunx &&
748
+ this.jsxStack.length > 0 &&
749
+ this.jsxStack[this.jsxStack.length - 1].kind === "tag";
750
+ if (inJsxTag && buffer.endsWith("$")) {
751
+ buffer = buffer.slice(0, -1);
752
+ }
753
+ if (buffer.length > 0) {
754
+ this.tokens.push({
755
+ type: TokenType.STRING_PART,
756
+ value: buffer,
757
+ span: { start: startPos, end: this.currentPosition() },
758
+ });
759
+ buffer = "";
760
+ }
761
+ this.advance();
762
+ this.braceStack.push("interpolation");
763
+ this.tokens.push({
764
+ type: TokenType.INTERPOLATION_START,
765
+ value: "{",
766
+ span: this.currentSpan(1),
767
+ });
768
+ return;
769
+ }
770
+ buffer += this.advance();
771
+ }
772
+ if (this.isAtEnd()) {
773
+ throw new LexerError("Unterminated string literal", {
774
+ start: startPos,
775
+ end: this.currentPosition(),
776
+ });
777
+ }
778
+ this.advance(); // consume closing '"'
779
+ if (buffer.length > 0) {
780
+ this.tokens.push({
781
+ type: TokenType.STRING_PART,
782
+ value: buffer,
783
+ span: { start: startPos, end: this.currentPosition() },
784
+ });
785
+ }
786
+ }
787
+ readNumber() {
788
+ const startPos = this.currentPosition();
789
+ let raw = "";
790
+ raw += this.readDigitsWithSeparators();
791
+ if (!this.isAtEnd() &&
792
+ this.peek() === "." &&
793
+ this.isDigit(this.peekAhead(1))) {
794
+ raw += this.advance(); // consume '.'
795
+ raw += this.readDigitsWithSeparators();
796
+ }
797
+ else if (!this.isAtEnd() &&
798
+ this.peek() === "." &&
799
+ this.peekAhead(1) === "_") {
800
+ throw new LexerError("Numeric separator must appear between two digits", this.currentSpan(2));
801
+ }
802
+ this.tokens.push({
803
+ type: TokenType.NUMBER,
804
+ value: raw,
805
+ span: { start: startPos, end: this.currentPosition() },
806
+ });
807
+ }
808
+ /** Reads decimal digits, allowing `_` only between two digits. */
809
+ readDigitsWithSeparators() {
810
+ let raw = "";
811
+ while (!this.isAtEnd() && this.isDigit(this.peek()))
812
+ raw += this.advance();
813
+ while (!this.isAtEnd() && this.peek() === "_") {
814
+ if (!this.isDigit(this.peekAhead(1))) {
815
+ throw new LexerError("Numeric separator must appear between two digits", this.currentSpan(1));
816
+ }
817
+ raw += this.advance();
818
+ while (!this.isAtEnd() && this.isDigit(this.peek()))
819
+ raw += this.advance();
820
+ }
821
+ return raw;
822
+ }
823
+ readIdentifierOrKeyword() {
824
+ const startPos = this.currentPosition();
825
+ let raw = "";
826
+ while (!this.isAtEnd() &&
827
+ (this.isAlphaNumeric(this.peek()) || this.peek() === "_")) {
828
+ raw += this.advance();
829
+ }
830
+ const span = { start: startPos, end: this.currentPosition() };
831
+ // Check banned keywords
832
+ if (BANNED_KEYWORDS[raw]) {
833
+ const lastToken = this.tokens[this.tokens.length - 1];
834
+ let previousIndex = this.tokens.length - 1;
835
+ while (previousIndex >= 0 &&
836
+ this.tokens[previousIndex].type === TokenType.NEWLINE)
837
+ previousIndex--;
838
+ if (raw === "try" &&
839
+ this.tokens[previousIndex]?.type === TokenType.THUNK_PIPE) {
840
+ this.tokens.push({ type: TokenType.IDENTIFIER, value: raw, span });
841
+ return;
842
+ }
843
+ if (lastToken && lastToken.type === TokenType.DOT) {
844
+ this.tokens.push({
845
+ type: TokenType.IDENTIFIER,
846
+ value: raw,
847
+ span,
848
+ });
849
+ return;
850
+ }
851
+ if (raw === "type" || raw === "data") {
852
+ if ((lastToken && lastToken.type === TokenType.IMPORT) ||
853
+ (raw === "type" &&
854
+ lastToken?.type === TokenType.EXPORT &&
855
+ /^[ \t]*\{/.test(this.source.slice(this.offset))) ||
856
+ this.braceStack[this.braceStack.length - 1] === "record") {
857
+ this.tokens.push({
858
+ type: TokenType.IDENTIFIER,
859
+ value: raw,
860
+ span,
861
+ });
862
+ return;
863
+ }
864
+ if (lastToken &&
865
+ (lastToken.type === TokenType.LBRACE ||
866
+ lastToken.type === TokenType.COMMA)) {
867
+ for (let j = this.tokens.length - 1; j >= 0; j--) {
868
+ if (this.tokens[j].type === TokenType.NEWLINE)
869
+ break;
870
+ if (this.tokens[j].type === TokenType.IMPORT) {
871
+ this.tokens.push({
872
+ type: TokenType.IDENTIFIER,
873
+ value: raw,
874
+ span,
875
+ });
876
+ return;
877
+ }
878
+ }
879
+ }
880
+ }
881
+ throw new LexerError(BANNED_KEYWORDS[raw], span);
882
+ }
883
+ // Keep import aliases named `as` compatible; only recognize a block here.
884
+ if (raw === "as" && /^[ \t]*\{/.test(this.source.slice(this.offset))) {
885
+ this.tokens.push({ type: TokenType.AS, value: raw, span });
886
+ this.readTsCode("as");
887
+ return;
888
+ }
889
+ // Check active keywords
890
+ if (KEYWORDS[raw]) {
891
+ this.tokens.push({
892
+ type: KEYWORDS[raw],
893
+ value: raw,
894
+ span,
895
+ });
896
+ if (raw === "ts") {
897
+ let prevIdx = this.tokens.length - 2;
898
+ while (prevIdx >= 0 &&
899
+ (this.tokens[prevIdx].type === TokenType.NEWLINE ||
900
+ this.tokens[prevIdx].type === TokenType.INDENT)) {
901
+ prevIdx--;
902
+ }
903
+ const prev = prevIdx >= 0 ? this.tokens[prevIdx] : undefined;
904
+ if (prev?.type === TokenType.FROM) {
905
+ return;
906
+ }
907
+ let p = this.offset;
908
+ while (p < this.source.length &&
909
+ (this.source[p] === " " || this.source[p] === "\t")) {
910
+ p++;
911
+ }
912
+ if (this.source.slice(p, p + 6) === "schema" &&
913
+ (p + 6 >= this.source.length ||
914
+ !/[a-zA-Z0-9_]/.test(this.source[p + 6]))) {
915
+ return;
916
+ }
917
+ this.readTsCode();
918
+ return;
919
+ }
920
+ return;
921
+ }
922
+ // Placeholder '_'
923
+ if (raw === "_") {
924
+ this.tokens.push({
925
+ type: TokenType.UNDERSCORE,
926
+ value: "_",
927
+ span,
928
+ });
929
+ return;
930
+ }
931
+ // UpperCamel vs lowerCamel
932
+ if (raw[0] >= "A" && raw[0] <= "Z") {
933
+ this.tokens.push({
934
+ type: TokenType.UPPER_IDENTIFIER,
935
+ value: raw,
936
+ span,
937
+ });
938
+ }
939
+ else {
940
+ this.tokens.push({
941
+ type: TokenType.IDENTIFIER,
942
+ value: raw,
943
+ span,
944
+ });
945
+ }
946
+ }
947
+ skipComment() {
948
+ while (!this.isAtEnd() && this.peek() !== "\n" && this.peek() !== "\r") {
949
+ this.advance();
950
+ }
951
+ }
952
+ isAtEnd() {
953
+ return this.offset >= this.source.length;
954
+ }
955
+ peek() {
956
+ return this.source[this.offset] || "\0";
957
+ }
958
+ peekPrev() {
959
+ return this.source[this.offset - 1] || "\0";
960
+ }
961
+ peekAhead(n) {
962
+ return this.source[this.offset + n] || "\0";
963
+ }
964
+ matchAhead(str) {
965
+ if (this.source.slice(this.offset, this.offset + str.length) === str) {
966
+ return true;
967
+ }
968
+ return false;
969
+ }
970
+ advance() {
971
+ const c = this.source[this.offset++];
972
+ this.column++;
973
+ return c;
974
+ }
975
+ emitToken(type, value, length) {
976
+ const start = this.currentPosition();
977
+ for (let i = 0; i < length; i++) {
978
+ this.advance();
979
+ }
980
+ this.tokens.push({
981
+ type,
982
+ value,
983
+ span: { start, end: this.currentPosition() },
984
+ });
985
+ }
986
+ isDigit(c) {
987
+ return c >= "0" && c <= "9";
988
+ }
989
+ isAlpha(c) {
990
+ return (c >= "a" && c <= "z") || (c >= "A" && c <= "Z");
991
+ }
992
+ isAlphaNumeric(c) {
993
+ return this.isAlpha(c) || this.isDigit(c);
994
+ }
995
+ currentPosition() {
996
+ return {
997
+ line: this.line,
998
+ column: this.column,
999
+ offset: this.offset,
1000
+ };
1001
+ }
1002
+ currentSpan(length) {
1003
+ return {
1004
+ start: this.currentPosition(),
1005
+ end: {
1006
+ line: this.line,
1007
+ column: this.column + length,
1008
+ offset: this.offset + length,
1009
+ },
1010
+ };
1011
+ }
1012
+ isInJsxChildrenOrTag() {
1013
+ if (this.jsxStack.length === 0)
1014
+ return false;
1015
+ const top = this.jsxStack[this.jsxStack.length - 1];
1016
+ return (top.kind === "tag" ||
1017
+ top.kind === "closing_tag" ||
1018
+ top.kind === "children");
1019
+ }
1020
+ isGenericFunctionStart() {
1021
+ if (this.peek() !== "<")
1022
+ return false;
1023
+ let angleDepth = 1;
1024
+ let i = 1;
1025
+ while (i < 4096) {
1026
+ const c = this.peekAhead(i);
1027
+ if (c === "\0" || c === "\n" || c === "\r")
1028
+ return false;
1029
+ if (c === '"' || c === "'" || c === "`") {
1030
+ const quote = c;
1031
+ i++;
1032
+ while (i < 4096) {
1033
+ const inner = this.peekAhead(i);
1034
+ if (inner === "\0" || inner === "\n" || inner === "\r")
1035
+ return false;
1036
+ if (inner === "\\") {
1037
+ i += 2;
1038
+ continue;
1039
+ }
1040
+ if (inner === quote) {
1041
+ i++;
1042
+ break;
1043
+ }
1044
+ i++;
1045
+ }
1046
+ continue;
1047
+ }
1048
+ if (c === "<") {
1049
+ angleDepth++;
1050
+ i++;
1051
+ continue;
1052
+ }
1053
+ if (c === ">") {
1054
+ // Ignore the `>` in function-type arrows inside a constraint.
1055
+ if (this.peekAhead(i - 1) === "=") {
1056
+ i++;
1057
+ continue;
1058
+ }
1059
+ angleDepth--;
1060
+ if (angleDepth === 0) {
1061
+ let j = i + 1;
1062
+ while (this.peekAhead(j) === " ")
1063
+ j++;
1064
+ if (this.peekAhead(j) !== "(")
1065
+ return false;
1066
+ let parenDepth = 1;
1067
+ let k = j + 1;
1068
+ while (k < 4096) {
1069
+ const param = this.peekAhead(k);
1070
+ if (param === "\0" || param === "\n" || param === "\r")
1071
+ return false;
1072
+ if (param === '"' || param === "'" || param === "`") {
1073
+ const quote = param;
1074
+ k++;
1075
+ while (k < 4096) {
1076
+ const inner = this.peekAhead(k);
1077
+ if (inner === "\0" || inner === "\n" || inner === "\r")
1078
+ return false;
1079
+ if (inner === "\\") {
1080
+ k += 2;
1081
+ continue;
1082
+ }
1083
+ if (inner === quote) {
1084
+ k++;
1085
+ break;
1086
+ }
1087
+ k++;
1088
+ }
1089
+ continue;
1090
+ }
1091
+ if (param === "(")
1092
+ parenDepth++;
1093
+ else if (param === ")") {
1094
+ parenDepth--;
1095
+ if (parenDepth === 0) {
1096
+ let after = k + 1;
1097
+ while (this.peekAhead(after) === " ")
1098
+ after++;
1099
+ return (this.peekAhead(after) === ":" ||
1100
+ (this.peekAhead(after) === "=" &&
1101
+ this.peekAhead(after + 1) === ">"));
1102
+ }
1103
+ }
1104
+ k++;
1105
+ }
1106
+ return false;
1107
+ }
1108
+ }
1109
+ i++;
1110
+ }
1111
+ return false;
1112
+ }
1113
+ isJsxTagStart() {
1114
+ if (!this.isFunx)
1115
+ return false;
1116
+ if (this.peek() !== "<")
1117
+ return false;
1118
+ // `<T>(value: T) => ...` is a generic function, not a JSX tag. Check the
1119
+ // full prefix because `.funx` files otherwise tokenize the parameters as
1120
+ // JSX attributes.
1121
+ if (this.isGenericFunctionStart())
1122
+ return false;
1123
+ // Followed by tag name start, or / for closing tag, or > for fragment
1124
+ const next = this.peekAhead(1);
1125
+ if (!this.isAlpha(next) && next !== "_" && next !== "/" && next !== ">") {
1126
+ return false;
1127
+ }
1128
+ if (next === "/")
1129
+ return true;
1130
+ // Disambiguate from comparison operator (<) and generics
1131
+ const prevToken = this.tokens.length > 0 ? this.tokens[this.tokens.length - 1] : null;
1132
+ if (!prevToken) {
1133
+ return true;
1134
+ }
1135
+ const exprEndingTokens = new Set([
1136
+ TokenType.IDENTIFIER,
1137
+ TokenType.UPPER_IDENTIFIER,
1138
+ TokenType.NUMBER,
1139
+ TokenType.STRING,
1140
+ TokenType.STRING_PART,
1141
+ TokenType.INTERPOLATION_END,
1142
+ TokenType.TEMPLATE_STRING,
1143
+ TokenType.TEMPLATE_PART,
1144
+ TokenType.RPAREN,
1145
+ TokenType.RBRACKET,
1146
+ TokenType.RBRACE,
1147
+ TokenType.TRUE,
1148
+ TokenType.FALSE,
1149
+ TokenType.UNDERSCORE,
1150
+ ]);
1151
+ if (exprEndingTokens.has(prevToken.type)) {
1152
+ return false;
1153
+ }
1154
+ return true;
1155
+ }
1156
+ advanceWhitespaceNewline() {
1157
+ if (this.peek() === "\r")
1158
+ this.advance();
1159
+ if (this.peek() === "\n")
1160
+ this.advance();
1161
+ this.line++;
1162
+ this.column = 1;
1163
+ this.atLineStart = true;
1164
+ }
1165
+ readJsxChildren() {
1166
+ const char = this.peek();
1167
+ if (char === "<") {
1168
+ if (this.matchAhead("</")) {
1169
+ this.emitToken(TokenType.JSX_CLOSING_TAG_OPEN, "</", 2);
1170
+ this.jsxStack.push({ kind: "closing_tag", hasTagName: false });
1171
+ }
1172
+ else {
1173
+ this.emitToken(TokenType.JSX_TAG_OPEN, "<", 1);
1174
+ this.jsxStack.push({ kind: "tag", hasTagName: false });
1175
+ }
1176
+ return;
1177
+ }
1178
+ if (char === "{") {
1179
+ this.emitToken(TokenType.LBRACE, "{", 1);
1180
+ this.braceStack.push("jsx_expr");
1181
+ this.jsxStack.push({ kind: "expr" });
1182
+ return;
1183
+ }
1184
+ const startPos = this.currentPosition();
1185
+ let text = "";
1186
+ while (!this.isAtEnd() && this.peek() !== "<" && this.peek() !== "{") {
1187
+ const c = this.advance();
1188
+ if (c === "\r") {
1189
+ if (this.peek() === "\n") {
1190
+ this.advance();
1191
+ }
1192
+ this.line++;
1193
+ this.column = 1;
1194
+ text += "\n";
1195
+ }
1196
+ else if (c === "\n") {
1197
+ this.line++;
1198
+ this.column = 1;
1199
+ text += "\n";
1200
+ }
1201
+ else {
1202
+ text += c;
1203
+ }
1204
+ }
1205
+ if (text.length > 0) {
1206
+ this.tokens.push({
1207
+ type: TokenType.JSX_TEXT,
1208
+ value: text,
1209
+ span: { start: startPos, end: this.currentPosition() },
1210
+ });
1211
+ }
1212
+ }
1213
+ readJsxTag(top) {
1214
+ const char = this.peek();
1215
+ // Whitespace (inline)
1216
+ if (char === " " || char === "\t") {
1217
+ this.advance();
1218
+ return;
1219
+ }
1220
+ // Newlines within tags
1221
+ if (char === "\r" || char === "\n") {
1222
+ this.advanceWhitespaceNewline();
1223
+ return;
1224
+ }
1225
+ // Comments within tags
1226
+ if (this.matchAhead("//")) {
1227
+ this.skipComment();
1228
+ return;
1229
+ }
1230
+ // Tag name
1231
+ if (!top.hasTagName) {
1232
+ if (char === ">") {
1233
+ // Empty fragment tag: <> or </>
1234
+ this.emitToken(TokenType.JSX_TAG_CLOSE, ">", 1);
1235
+ if (top.kind === "tag") {
1236
+ top.kind = "children";
1237
+ }
1238
+ else {
1239
+ this.jsxStack.pop();
1240
+ if (this.jsxStack.length > 0 &&
1241
+ this.jsxStack[this.jsxStack.length - 1].kind === "children") {
1242
+ this.jsxStack.pop();
1243
+ }
1244
+ }
1245
+ return;
1246
+ }
1247
+ if (this.isAlpha(char) || char === "_") {
1248
+ const startPos = this.currentPosition();
1249
+ let name = "";
1250
+ while (!this.isAtEnd() &&
1251
+ (this.isAlphaNumeric(this.peek()) ||
1252
+ this.peek() === "_" ||
1253
+ this.peek() === "-")) {
1254
+ name += this.advance();
1255
+ }
1256
+ top.hasTagName = true;
1257
+ const type = name[0] >= "A" && name[0] <= "Z"
1258
+ ? TokenType.UPPER_IDENTIFIER
1259
+ : TokenType.IDENTIFIER;
1260
+ this.tokens.push({
1261
+ type,
1262
+ value: name,
1263
+ span: { start: startPos, end: this.currentPosition() },
1264
+ });
1265
+ return;
1266
+ }
1267
+ const prefix = top.kind === "closing_tag" ? "</" : "<";
1268
+ throw new LexerError(`Expected tag name after '${prefix}', found '${char}'`, this.currentSpan(1));
1269
+ }
1270
+ // Member access in tag name (e.g. <Namespace.Component />)
1271
+ if (char === ".") {
1272
+ this.emitToken(TokenType.DOT, ".", 1);
1273
+ top.hasTagName = false;
1274
+ return;
1275
+ }
1276
+ // Self-closing slash close: '/>'
1277
+ if (this.matchAhead("/>")) {
1278
+ this.emitToken(TokenType.JSX_SLASH_CLOSE, "/>", 2);
1279
+ this.jsxStack.pop();
1280
+ return;
1281
+ }
1282
+ // Tag close: '>'
1283
+ if (char === ">") {
1284
+ this.emitToken(TokenType.JSX_TAG_CLOSE, ">", 1);
1285
+ if (top.kind === "tag") {
1286
+ top.kind = "children";
1287
+ }
1288
+ else {
1289
+ this.jsxStack.pop();
1290
+ if (this.jsxStack.length > 0 &&
1291
+ this.jsxStack[this.jsxStack.length - 1].kind === "children") {
1292
+ this.jsxStack.pop();
1293
+ }
1294
+ }
1295
+ return;
1296
+ }
1297
+ // Equals: '='
1298
+ if (char === "=") {
1299
+ this.emitToken(TokenType.EQ, "=", 1);
1300
+ return;
1301
+ }
1302
+ // String attribute value: '"..."'
1303
+ if (char === '"') {
1304
+ this.readString();
1305
+ return;
1306
+ }
1307
+ // Embedded expression attribute value: '{...}'
1308
+ if (char === "{") {
1309
+ this.emitToken(TokenType.LBRACE, "{", 1);
1310
+ this.braceStack.push("jsx_expr");
1311
+ this.jsxStack.push({ kind: "expr" });
1312
+ return;
1313
+ }
1314
+ // Attribute name
1315
+ if (this.isAlpha(char) || char === "_" || char === "-") {
1316
+ const startPos = this.currentPosition();
1317
+ let attrName = "";
1318
+ while (!this.isAtEnd() &&
1319
+ (this.isAlphaNumeric(this.peek()) ||
1320
+ this.peek() === "_" ||
1321
+ this.peek() === "-" ||
1322
+ this.peek() === ":")) {
1323
+ attrName += this.advance();
1324
+ }
1325
+ this.tokens.push({
1326
+ type: TokenType.JSX_ATTRIBUTE_NAME,
1327
+ value: attrName,
1328
+ span: { start: startPos, end: this.currentPosition() },
1329
+ });
1330
+ return;
1331
+ }
1332
+ throw new LexerError(`Unexpected character '${char}' in JSX tag`, this.currentSpan(1));
1333
+ }
1334
+ }
1335
+ //# sourceMappingURL=lexer.js.map