veryfront 0.1.1237 → 0.1.1239

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 (493) hide show
  1. package/esm/cli/auth/login.d.ts +24 -2
  2. package/esm/cli/auth/login.d.ts.map +1 -1
  3. package/esm/cli/auth/login.js +444 -35
  4. package/esm/cli/commands/build/error-handler.d.ts.map +1 -1
  5. package/esm/cli/commands/build/error-handler.js +41 -3
  6. package/esm/cli/commands/build/handler.d.ts.map +1 -1
  7. package/esm/cli/commands/build/handler.js +1 -1
  8. package/esm/cli/commands/dev/command.d.ts.map +1 -1
  9. package/esm/cli/commands/dev/command.js +14 -1
  10. package/esm/cli/commands/dev/inference-status.d.ts +6 -0
  11. package/esm/cli/commands/dev/inference-status.d.ts.map +1 -1
  12. package/esm/cli/commands/dev/inference-status.js +14 -2
  13. package/esm/cli/commands/generate/command.d.ts.map +1 -1
  14. package/esm/cli/commands/generate/command.js +61 -0
  15. package/esm/cli/commands/init/init-command.d.ts.map +1 -1
  16. package/esm/cli/commands/init/init-command.js +23 -31
  17. package/esm/cli/commands/install/registry.d.ts.map +1 -1
  18. package/esm/cli/commands/install/registry.js +6 -9
  19. package/esm/cli/commands/login/command-help.d.ts.map +1 -1
  20. package/esm/cli/commands/login/command-help.js +3 -1
  21. package/esm/cli/commands/pull/command.d.ts +1 -0
  22. package/esm/cli/commands/pull/command.d.ts.map +1 -1
  23. package/esm/cli/commands/pull/command.js +49 -6
  24. package/esm/cli/commands/push/command-help.d.ts.map +1 -1
  25. package/esm/cli/commands/push/command-help.js +7 -0
  26. package/esm/cli/commands/push/command.d.ts +23 -12
  27. package/esm/cli/commands/push/command.d.ts.map +1 -1
  28. package/esm/cli/commands/push/command.js +461 -44
  29. package/esm/cli/commands/push/plan.d.ts +35 -0
  30. package/esm/cli/commands/push/plan.d.ts.map +1 -0
  31. package/esm/cli/commands/push/plan.js +96 -0
  32. package/esm/cli/commands/schedule/handler.d.ts +21 -2
  33. package/esm/cli/commands/schedule/handler.d.ts.map +1 -1
  34. package/esm/cli/commands/schedule/handler.js +74 -27
  35. package/esm/cli/commands/schema/command-help.js +1 -1
  36. package/esm/cli/commands/up/command.js +1 -1
  37. package/esm/cli/commands/webhook/handler.d.ts.map +1 -1
  38. package/esm/cli/commands/webhook/handler.js +3 -1
  39. package/esm/cli/router.d.ts.map +1 -1
  40. package/esm/cli/router.js +27 -5
  41. package/esm/cli/shared/args.d.ts +15 -1
  42. package/esm/cli/shared/args.d.ts.map +1 -1
  43. package/esm/cli/shared/args.js +56 -3
  44. package/esm/cli/shared/config.d.ts +11 -2
  45. package/esm/cli/shared/config.d.ts.map +1 -1
  46. package/esm/cli/shared/config.js +72 -27
  47. package/esm/cli/shared/project-creation.js +1 -1
  48. package/esm/cli/sync/state.d.ts +20 -0
  49. package/esm/cli/sync/state.d.ts.map +1 -0
  50. package/esm/cli/sync/state.js +193 -0
  51. package/esm/deno.js +2 -2
  52. package/esm/extensions/ext-llm-anthropic/src/anthropic-request-builder.d.ts.map +1 -1
  53. package/esm/extensions/ext-llm-anthropic/src/anthropic-request-builder.js +852 -21
  54. package/esm/extensions/ext-observability-sentry/src/policy.d.ts +2 -0
  55. package/esm/extensions/ext-observability-sentry/src/policy.d.ts.map +1 -1
  56. package/esm/extensions/ext-observability-sentry/src/policy.js +214 -3
  57. package/esm/src/agent/conversation/delegation-policy.d.ts +2 -0
  58. package/esm/src/agent/conversation/delegation-policy.d.ts.map +1 -1
  59. package/esm/src/agent/conversation/delegation-policy.js +13 -3
  60. package/esm/src/agent/conversation/hosted-terminal.d.ts.map +1 -1
  61. package/esm/src/agent/conversation/hosted-terminal.js +6 -2
  62. package/esm/src/agent/conversation/run-chunk-mirror.d.ts.map +1 -1
  63. package/esm/src/agent/conversation/run-chunk-mirror.js +14 -2
  64. package/esm/src/agent/factory.d.ts.map +1 -1
  65. package/esm/src/agent/factory.js +22 -11
  66. package/esm/src/agent/hosted/chat-runtime-tool-assembly.d.ts +2 -0
  67. package/esm/src/agent/hosted/chat-runtime-tool-assembly.d.ts.map +1 -1
  68. package/esm/src/agent/hosted/chat-runtime-tool-assembly.js +6 -1
  69. package/esm/src/agent/hosted/child-fork-execution-runner.d.ts +2 -1
  70. package/esm/src/agent/hosted/child-fork-execution-runner.d.ts.map +1 -1
  71. package/esm/src/agent/hosted/child-fork-execution-runner.js +6 -3
  72. package/esm/src/agent/hosted/child-fork-step-message-preparation.d.ts +12 -3
  73. package/esm/src/agent/hosted/child-fork-step-message-preparation.d.ts.map +1 -1
  74. package/esm/src/agent/hosted/child-fork-step-message-preparation.js +16 -3
  75. package/esm/src/agent/hosted/cloud-agent-chat-execution.d.ts +1 -1
  76. package/esm/src/agent/hosted/cloud-agent-chat-execution.d.ts.map +1 -1
  77. package/esm/src/agent/hosted/cloud-agent-chat-execution.js +3 -3
  78. package/esm/src/agent/hosted/cloud-agent-child-tools.d.ts +11 -0
  79. package/esm/src/agent/hosted/cloud-agent-child-tools.d.ts.map +1 -1
  80. package/esm/src/agent/hosted/cloud-agent-child-tools.js +2 -3
  81. package/esm/src/agent/hosted/cloud-agent-config.d.ts +1 -0
  82. package/esm/src/agent/hosted/cloud-agent-config.d.ts.map +1 -1
  83. package/esm/src/agent/hosted/cloud-runtime-system-messages.d.ts +16 -1
  84. package/esm/src/agent/hosted/cloud-runtime-system-messages.d.ts.map +1 -1
  85. package/esm/src/agent/hosted/cloud-runtime-system-messages.js +13 -3
  86. package/esm/src/agent/hosted/default-chat-runtime.d.ts +2 -1
  87. package/esm/src/agent/hosted/default-chat-runtime.d.ts.map +1 -1
  88. package/esm/src/agent/hosted/default-chat-runtime.js +18 -7
  89. package/esm/src/agent/hosted/default-invoke-agent-tool.d.ts +2 -1
  90. package/esm/src/agent/hosted/default-invoke-agent-tool.d.ts.map +1 -1
  91. package/esm/src/agent/hosted/default-invoke-agent-tool.js +11 -3
  92. package/esm/src/agent/hosted/default-project-steering-refresh.d.ts +2 -1
  93. package/esm/src/agent/hosted/default-project-steering-refresh.d.ts.map +1 -1
  94. package/esm/src/agent/hosted/default-project-steering-refresh.js +4 -1
  95. package/esm/src/agent/hosted/runtime-state-resolver.d.ts +6 -4
  96. package/esm/src/agent/hosted/runtime-state-resolver.d.ts.map +1 -1
  97. package/esm/src/agent/hosted/runtime-state-resolver.js +8 -11
  98. package/esm/src/agent/index.d.ts +3 -3
  99. package/esm/src/agent/index.d.ts.map +1 -1
  100. package/esm/src/agent/project/agent-runtime.d.ts.map +1 -1
  101. package/esm/src/agent/project/agent-runtime.js +6 -3
  102. package/esm/src/agent/runtime/agent-definition.d.ts +68 -66
  103. package/esm/src/agent/runtime/agent-definition.d.ts.map +1 -1
  104. package/esm/src/agent/runtime/agent-definition.js +15 -2
  105. package/esm/src/agent/runtime/agent-invocation-contract.d.ts +2 -0
  106. package/esm/src/agent/runtime/agent-invocation-contract.d.ts.map +1 -1
  107. package/esm/src/agent/runtime/agent-markdown-adapter.js +1 -1
  108. package/esm/src/agent/runtime/agent-runtime-step.d.ts +11 -5
  109. package/esm/src/agent/runtime/agent-runtime-step.d.ts.map +1 -1
  110. package/esm/src/agent/runtime/agent-runtime-step.js +23 -6
  111. package/esm/src/agent/runtime/call-context.d.ts +42 -11
  112. package/esm/src/agent/runtime/call-context.d.ts.map +1 -1
  113. package/esm/src/agent/runtime/call-context.js +480 -42
  114. package/esm/src/agent/runtime/chat-stream-handler.d.ts +18 -0
  115. package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
  116. package/esm/src/agent/runtime/chat-stream-handler.js +38 -18
  117. package/esm/src/agent/runtime/effective-agent-system.d.ts +13 -4
  118. package/esm/src/agent/runtime/effective-agent-system.d.ts.map +1 -1
  119. package/esm/src/agent/runtime/effective-agent-system.js +29 -0
  120. package/esm/src/agent/runtime/index.d.ts +1 -0
  121. package/esm/src/agent/runtime/index.d.ts.map +1 -1
  122. package/esm/src/agent/runtime/index.js +638 -53
  123. package/esm/src/agent/runtime/load-skill-tool.d.ts +33 -3
  124. package/esm/src/agent/runtime/load-skill-tool.d.ts.map +1 -1
  125. package/esm/src/agent/runtime/load-skill-tool.js +152 -21
  126. package/esm/src/agent/runtime/model-resolution.d.ts +3 -0
  127. package/esm/src/agent/runtime/model-resolution.d.ts.map +1 -1
  128. package/esm/src/agent/runtime/model-resolution.js +14 -0
  129. package/esm/src/agent/runtime/model-transport.d.ts +1 -0
  130. package/esm/src/agent/runtime/model-transport.d.ts.map +1 -1
  131. package/esm/src/agent/runtime/model-transport.js +5 -2
  132. package/esm/src/agent/runtime/run-runtime-context.d.ts +4 -0
  133. package/esm/src/agent/runtime/run-runtime-context.d.ts.map +1 -1
  134. package/esm/src/agent/runtime/run-runtime-context.js +9 -3
  135. package/esm/src/agent/runtime/runtime-tool-config.d.ts +1 -0
  136. package/esm/src/agent/runtime/runtime-tool-config.d.ts.map +1 -1
  137. package/esm/src/agent/runtime/skill-prompt.d.ts +3 -0
  138. package/esm/src/agent/runtime/skill-prompt.d.ts.map +1 -1
  139. package/esm/src/agent/runtime/skill-prompt.js +113 -25
  140. package/esm/src/agent/runtime/streamed-assistant-message.d.ts +22 -2
  141. package/esm/src/agent/runtime/streamed-assistant-message.d.ts.map +1 -1
  142. package/esm/src/agent/runtime/streamed-assistant-message.js +26 -5
  143. package/esm/src/agent/runtime/tool-inventory.d.ts.map +1 -1
  144. package/esm/src/agent/runtime/tool-inventory.js +13 -9
  145. package/esm/src/agent/runtime/tool-result-continuation.d.ts +4 -2
  146. package/esm/src/agent/runtime/tool-result-continuation.d.ts.map +1 -1
  147. package/esm/src/agent/runtime/tool-result-continuation.js +24 -20
  148. package/esm/src/agent/schemas/agent.schema.d.ts +2 -2
  149. package/esm/src/agent/service/runtime.js +1 -1
  150. package/esm/src/agent/streaming/fork-runtime-stream.d.ts +5 -4
  151. package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
  152. package/esm/src/agent/types.d.ts +14 -1
  153. package/esm/src/agent/types.d.ts.map +1 -1
  154. package/esm/src/chat/chat-ui-message-helpers.d.ts.map +1 -1
  155. package/esm/src/chat/chat-ui-message-helpers.js +75 -16
  156. package/esm/src/config/loader.d.ts.map +1 -1
  157. package/esm/src/config/loader.js +37 -1
  158. package/esm/src/errors/catalog/build-errors.d.ts.map +1 -1
  159. package/esm/src/errors/catalog/build-errors.js +14 -0
  160. package/esm/src/errors/error-registry/build.d.ts +2 -0
  161. package/esm/src/errors/error-registry/build.d.ts.map +1 -1
  162. package/esm/src/errors/error-registry/build.js +8 -0
  163. package/esm/src/errors/error-registry/deploy.d.ts +4 -0
  164. package/esm/src/errors/error-registry/deploy.d.ts.map +1 -1
  165. package/esm/src/errors/error-registry/deploy.js +16 -0
  166. package/esm/src/errors/error-registry.d.ts +3 -0
  167. package/esm/src/errors/error-registry.d.ts.map +1 -1
  168. package/esm/src/errors/index.d.ts +2 -1
  169. package/esm/src/errors/index.d.ts.map +1 -1
  170. package/esm/src/errors/index.js +4 -3
  171. package/esm/src/errors/tenant-classification.d.ts +25 -0
  172. package/esm/src/errors/tenant-classification.d.ts.map +1 -0
  173. package/esm/src/errors/tenant-classification.js +61 -0
  174. package/esm/src/extensions/builtin-extensions.d.ts +10 -15
  175. package/esm/src/extensions/builtin-extensions.d.ts.map +1 -1
  176. package/esm/src/extensions/builtin-extensions.js +32 -26
  177. package/esm/src/extensions/deferred-extension.d.ts +4 -4
  178. package/esm/src/extensions/deferred-extension.js +4 -4
  179. package/esm/src/extensions/index.d.ts +1 -0
  180. package/esm/src/extensions/index.d.ts.map +1 -1
  181. package/esm/src/extensions/index.js +1 -0
  182. package/esm/src/html/hydration-script-builder/hydration-runtime.generated.js +1 -1
  183. package/esm/src/integrations/_data.d.ts.map +1 -1
  184. package/esm/src/integrations/_data.js +6 -0
  185. package/esm/src/integrations/schema.d.ts +8 -0
  186. package/esm/src/integrations/schema.d.ts.map +1 -1
  187. package/esm/src/integrations/schema.js +3 -0
  188. package/esm/src/integrations/types.d.ts +2 -0
  189. package/esm/src/integrations/types.d.ts.map +1 -1
  190. package/esm/src/internal-agents/run-stream.d.ts.map +1 -1
  191. package/esm/src/internal-agents/run-stream.js +35 -20
  192. package/esm/src/internal-agents/run-system-prompt.d.ts +7 -2
  193. package/esm/src/internal-agents/run-system-prompt.d.ts.map +1 -1
  194. package/esm/src/internal-agents/run-system-prompt.js +19 -13
  195. package/esm/src/internal-agents/schema.d.ts +2 -0
  196. package/esm/src/internal-agents/schema.d.ts.map +1 -1
  197. package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
  198. package/esm/src/modules/react-loader/ssr-module-loader/loader.js +2 -18
  199. package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.d.ts +11 -0
  200. package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.d.ts.map +1 -1
  201. package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.js +53 -6
  202. package/esm/src/observability/application-error-contract.d.ts +4 -0
  203. package/esm/src/observability/application-error-contract.d.ts.map +1 -1
  204. package/esm/src/observability/application-errors.d.ts.map +1 -1
  205. package/esm/src/observability/application-errors.js +64 -3
  206. package/esm/src/platform/adapters/runtime/deno/http-server.d.ts.map +1 -1
  207. package/esm/src/platform/adapters/runtime/deno/http-server.js +2 -10
  208. package/esm/src/platform/adapters/runtime/shared/request-peer.d.ts +14 -0
  209. package/esm/src/platform/adapters/runtime/shared/request-peer.d.ts.map +1 -1
  210. package/esm/src/platform/adapters/runtime/shared/request-peer.js +82 -0
  211. package/esm/src/platform/compat/http/pinned-fetch.d.ts +1 -1
  212. package/esm/src/provider/runtime-loader/provider-http.d.ts +5 -1
  213. package/esm/src/provider/runtime-loader/provider-http.d.ts.map +1 -1
  214. package/esm/src/provider/runtime-loader/provider-http.js +55 -17
  215. package/esm/src/provider/shared/index.d.ts +1 -0
  216. package/esm/src/provider/shared/index.d.ts.map +1 -1
  217. package/esm/src/provider/shared/index.js +2 -0
  218. package/esm/src/provider/types.d.ts +1 -0
  219. package/esm/src/provider/types.d.ts.map +1 -1
  220. package/esm/src/react/components/ui/adapter/builtin/combobox.d.ts +3 -0
  221. package/esm/src/react/components/ui/adapter/builtin/combobox.d.ts.map +1 -0
  222. package/esm/src/react/components/ui/adapter/builtin/combobox.js +204 -0
  223. package/esm/src/react/components/ui/adapter/builtin/dialog.d.ts +3 -0
  224. package/esm/src/react/components/ui/adapter/builtin/dialog.d.ts.map +1 -0
  225. package/esm/src/react/components/ui/adapter/builtin/dialog.js +20 -0
  226. package/esm/src/react/components/ui/adapter/builtin/drawer.d.ts +3 -0
  227. package/esm/src/react/components/ui/adapter/builtin/drawer.d.ts.map +1 -0
  228. package/esm/src/react/components/ui/adapter/builtin/drawer.js +21 -0
  229. package/esm/src/react/components/ui/adapter/builtin/index.d.ts.map +1 -1
  230. package/esm/src/react/components/ui/adapter/builtin/index.js +10 -0
  231. package/esm/src/react/components/ui/adapter/builtin/popover.d.ts +3 -0
  232. package/esm/src/react/components/ui/adapter/builtin/popover.d.ts.map +1 -0
  233. package/esm/src/react/components/ui/adapter/builtin/popover.js +28 -0
  234. package/esm/src/react/components/ui/adapter/builtin/tabs.d.ts +3 -0
  235. package/esm/src/react/components/ui/adapter/builtin/tabs.d.ts.map +1 -0
  236. package/esm/src/react/components/ui/adapter/builtin/tabs.js +73 -0
  237. package/esm/src/react/components/ui/adapter/context.d.ts.map +1 -1
  238. package/esm/src/react/components/ui/adapter/context.js +10 -0
  239. package/esm/src/react/components/ui/adapter/contract.d.ts +212 -0
  240. package/esm/src/react/components/ui/adapter/contract.d.ts.map +1 -1
  241. package/esm/src/react/components/ui/adapter/token-scope.d.ts +24 -0
  242. package/esm/src/react/components/ui/adapter/token-scope.d.ts.map +1 -0
  243. package/esm/src/react/components/ui/adapter/token-scope.js +26 -0
  244. package/esm/src/react/components/ui/alert-dialog.d.ts +101 -0
  245. package/esm/src/react/components/ui/alert-dialog.d.ts.map +1 -0
  246. package/esm/src/react/components/ui/alert-dialog.js +181 -0
  247. package/esm/src/react/components/ui/aspect-ratio.d.ts +18 -0
  248. package/esm/src/react/components/ui/aspect-ratio.d.ts.map +1 -0
  249. package/esm/src/react/components/ui/aspect-ratio.js +13 -0
  250. package/esm/src/react/components/ui/autocomplete.d.ts +67 -0
  251. package/esm/src/react/components/ui/autocomplete.d.ts.map +1 -0
  252. package/esm/src/react/components/ui/autocomplete.js +59 -0
  253. package/esm/src/react/components/ui/breadcrumb.d.ts +86 -0
  254. package/esm/src/react/components/ui/breadcrumb.d.ts.map +1 -0
  255. package/esm/src/react/components/ui/breadcrumb.js +67 -0
  256. package/esm/src/react/components/ui/calendar.d.ts +40 -0
  257. package/esm/src/react/components/ui/calendar.d.ts.map +1 -0
  258. package/esm/src/react/components/ui/calendar.js +170 -0
  259. package/esm/src/react/components/ui/combobox.d.ts +74 -0
  260. package/esm/src/react/components/ui/combobox.d.ts.map +1 -0
  261. package/esm/src/react/components/ui/combobox.js +100 -0
  262. package/esm/src/react/components/ui/context-menu.d.ts +116 -0
  263. package/esm/src/react/components/ui/context-menu.d.ts.map +1 -0
  264. package/esm/src/react/components/ui/context-menu.js +168 -0
  265. package/esm/src/react/components/ui/date-picker.d.ts +69 -0
  266. package/esm/src/react/components/ui/date-picker.d.ts.map +1 -0
  267. package/esm/src/react/components/ui/date-picker.js +96 -0
  268. package/esm/src/react/components/ui/dialog.d.ts +41 -11
  269. package/esm/src/react/components/ui/dialog.d.ts.map +1 -1
  270. package/esm/src/react/components/ui/dialog.js +47 -28
  271. package/esm/src/react/components/ui/drawer.d.ts +31 -8
  272. package/esm/src/react/components/ui/drawer.d.ts.map +1 -1
  273. package/esm/src/react/components/ui/drawer.js +33 -22
  274. package/esm/src/react/components/ui/dropdown-menu.d.ts.map +1 -1
  275. package/esm/src/react/components/ui/dropdown-menu.js +7 -75
  276. package/esm/src/react/components/ui/field.d.ts +70 -0
  277. package/esm/src/react/components/ui/field.d.ts.map +1 -0
  278. package/esm/src/react/components/ui/field.js +161 -0
  279. package/esm/src/react/components/ui/file-type.d.ts +9 -8
  280. package/esm/src/react/components/ui/file-type.d.ts.map +1 -1
  281. package/esm/src/react/components/ui/file-type.js +8 -8
  282. package/esm/src/react/components/ui/hover-card.d.ts +82 -0
  283. package/esm/src/react/components/ui/hover-card.d.ts.map +1 -0
  284. package/esm/src/react/components/ui/hover-card.js +140 -0
  285. package/esm/src/react/components/ui/index.d.ts +23 -2
  286. package/esm/src/react/components/ui/index.d.ts.map +1 -1
  287. package/esm/src/react/components/ui/index.js +21 -0
  288. package/esm/src/react/components/ui/input-otp.d.ts +37 -0
  289. package/esm/src/react/components/ui/input-otp.d.ts.map +1 -0
  290. package/esm/src/react/components/ui/input-otp.js +42 -0
  291. package/esm/src/react/components/ui/menu-keyboard.d.ts +8 -0
  292. package/esm/src/react/components/ui/menu-keyboard.d.ts.map +1 -0
  293. package/esm/src/react/components/ui/menu-keyboard.js +76 -0
  294. package/esm/src/react/components/ui/menubar.d.ts +98 -0
  295. package/esm/src/react/components/ui/menubar.d.ts.map +1 -0
  296. package/esm/src/react/components/ui/menubar.js +173 -0
  297. package/esm/src/react/components/ui/meter.d.ts +45 -0
  298. package/esm/src/react/components/ui/meter.d.ts.map +1 -0
  299. package/esm/src/react/components/ui/meter.js +59 -0
  300. package/esm/src/react/components/ui/modal-surface.d.ts +7 -1
  301. package/esm/src/react/components/ui/modal-surface.d.ts.map +1 -1
  302. package/esm/src/react/components/ui/modal-surface.js +23 -6
  303. package/esm/src/react/components/ui/navigation-menu.d.ts +101 -0
  304. package/esm/src/react/components/ui/navigation-menu.d.ts.map +1 -0
  305. package/esm/src/react/components/ui/navigation-menu.js +195 -0
  306. package/esm/src/react/components/ui/number-field.d.ts +46 -0
  307. package/esm/src/react/components/ui/number-field.d.ts.map +1 -0
  308. package/esm/src/react/components/ui/number-field.js +121 -0
  309. package/esm/src/react/components/ui/pagination.d.ts +77 -0
  310. package/esm/src/react/components/ui/pagination.d.ts.map +1 -0
  311. package/esm/src/react/components/ui/pagination.js +62 -0
  312. package/esm/src/react/components/ui/popover.d.ts +42 -13
  313. package/esm/src/react/components/ui/popover.d.ts.map +1 -1
  314. package/esm/src/react/components/ui/popover.js +25 -12
  315. package/esm/src/react/components/ui/scroll-area.d.ts +38 -0
  316. package/esm/src/react/components/ui/scroll-area.d.ts.map +1 -0
  317. package/esm/src/react/components/ui/scroll-area.js +35 -0
  318. package/esm/src/react/components/ui/separator.d.ts +20 -0
  319. package/esm/src/react/components/ui/separator.d.ts.map +1 -0
  320. package/esm/src/react/components/ui/separator.js +13 -0
  321. package/esm/src/react/components/ui/slider.d.ts +44 -0
  322. package/esm/src/react/components/ui/slider.d.ts.map +1 -0
  323. package/esm/src/react/components/ui/slider.js +46 -0
  324. package/esm/src/react/components/ui/status.d.ts +6 -5
  325. package/esm/src/react/components/ui/status.d.ts.map +1 -1
  326. package/esm/src/react/components/ui/status.js +4 -4
  327. package/esm/src/react/components/ui/tabs.d.ts +32 -9
  328. package/esm/src/react/components/ui/tabs.d.ts.map +1 -1
  329. package/esm/src/react/components/ui/tabs.js +46 -22
  330. package/esm/src/react/components/ui/toggle.d.ts +26 -0
  331. package/esm/src/react/components/ui/toggle.d.ts.map +1 -0
  332. package/esm/src/react/components/ui/toggle.js +29 -0
  333. package/esm/src/react/components/ui/use-isomorphic-layout-effect.d.ts +2 -1
  334. package/esm/src/react/components/ui/use-isomorphic-layout-effect.d.ts.map +1 -1
  335. package/esm/src/react/components/ui/use-isomorphic-layout-effect.js +6 -3
  336. package/esm/src/rendering/chunk-optimizer/source-imports.d.ts.map +1 -1
  337. package/esm/src/rendering/chunk-optimizer/source-imports.js +4 -114
  338. package/esm/src/rendering/orchestrator/css-candidate-manifest.d.ts.map +1 -1
  339. package/esm/src/rendering/orchestrator/css-candidate-manifest.js +30 -1
  340. package/esm/src/rendering/orchestrator/module-loader/build-failure.d.ts +10 -0
  341. package/esm/src/rendering/orchestrator/module-loader/build-failure.d.ts.map +1 -1
  342. package/esm/src/rendering/orchestrator/module-loader/build-failure.js +50 -3
  343. package/esm/src/rendering/orchestrator/module-loader/dependency-resolver.d.ts +2 -0
  344. package/esm/src/rendering/orchestrator/module-loader/dependency-resolver.d.ts.map +1 -1
  345. package/esm/src/rendering/orchestrator/module-loader/dependency-resolver.js +21 -6
  346. package/esm/src/rendering/orchestrator/module-loader/index.d.ts +2 -1
  347. package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
  348. package/esm/src/rendering/orchestrator/module-loader/index.js +190 -7
  349. package/esm/src/rendering/orchestrator/module-loader/module-persistence.d.ts +4 -0
  350. package/esm/src/rendering/orchestrator/module-loader/module-persistence.d.ts.map +1 -1
  351. package/esm/src/rendering/orchestrator/module-loader/module-persistence.js +374 -7
  352. package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
  353. package/esm/src/rendering/orchestrator/pipeline.js +12 -1
  354. package/esm/src/runs/runs-client.d.ts +2 -4
  355. package/esm/src/runs/runs-client.d.ts.map +1 -1
  356. package/esm/src/runs/schemas.d.ts +18 -8
  357. package/esm/src/runs/schemas.d.ts.map +1 -1
  358. package/esm/src/runs/schemas.js +26 -0
  359. package/esm/src/runtime/model-call-context.d.ts +6 -1
  360. package/esm/src/runtime/model-call-context.d.ts.map +1 -1
  361. package/esm/src/runtime/runtime-bridge.d.ts.map +1 -1
  362. package/esm/src/runtime/runtime-bridge.js +133 -15
  363. package/esm/src/schedule/factory.d.ts +8 -2
  364. package/esm/src/schedule/factory.d.ts.map +1 -1
  365. package/esm/src/schedule/factory.js +0 -8
  366. package/esm/src/schedule/index.d.ts +10 -1
  367. package/esm/src/schedule/index.d.ts.map +1 -1
  368. package/esm/src/schedule/index.js +9 -0
  369. package/esm/src/schedule/types.d.ts +30 -11
  370. package/esm/src/schedule/types.d.ts.map +1 -1
  371. package/esm/src/schedule/validation.d.ts +17 -0
  372. package/esm/src/schedule/validation.d.ts.map +1 -1
  373. package/esm/src/schedule/validation.js +93 -5
  374. package/esm/src/security/sandbox/worker-pool.d.ts.map +1 -1
  375. package/esm/src/security/sandbox/worker-pool.js +6 -1
  376. package/esm/src/server/bootstrap.d.ts.map +1 -1
  377. package/esm/src/server/bootstrap.js +6 -0
  378. package/esm/src/server/dev-server/index.d.ts +1 -1
  379. package/esm/src/server/dev-server/index.d.ts.map +1 -1
  380. package/esm/src/server/dev-server/server.d.ts +7 -3
  381. package/esm/src/server/dev-server/server.d.ts.map +1 -1
  382. package/esm/src/server/dev-server/server.js +12 -3
  383. package/esm/src/server/dev-server/types.d.ts +7 -1
  384. package/esm/src/server/dev-server/types.d.ts.map +1 -1
  385. package/esm/src/server/dev-server.d.ts +1 -1
  386. package/esm/src/server/dev-server.d.ts.map +1 -1
  387. package/esm/src/server/handlers/dev/framework-candidates.generated.d.ts.map +1 -1
  388. package/esm/src/server/handlers/dev/framework-candidates.generated.js +2509 -34
  389. package/esm/src/server/handlers/dev/projects/index.d.ts.map +1 -1
  390. package/esm/src/server/handlers/dev/projects/index.js +3 -0
  391. package/esm/src/server/handlers/request/agent-stream.handler.d.ts.map +1 -1
  392. package/esm/src/server/handlers/request/agent-stream.handler.js +29 -24
  393. package/esm/src/server/index.d.ts +3 -3
  394. package/esm/src/server/index.d.ts.map +1 -1
  395. package/esm/src/server/index.js +10 -5
  396. package/esm/src/server/node-handler.d.ts.map +1 -1
  397. package/esm/src/server/node-handler.js +4 -1
  398. package/esm/src/server/production-server.d.ts.map +1 -1
  399. package/esm/src/server/production-server.js +2 -1
  400. package/esm/src/server/project-env/cache.d.ts +17 -0
  401. package/esm/src/server/project-env/cache.d.ts.map +1 -1
  402. package/esm/src/server/project-env/cache.js +78 -2
  403. package/esm/src/server/project-env/fetcher.d.ts.map +1 -1
  404. package/esm/src/server/project-env/fetcher.js +24 -14
  405. package/esm/src/server/project-env/index.d.ts +1 -1
  406. package/esm/src/server/project-env/index.d.ts.map +1 -1
  407. package/esm/src/server/project-env/index.js +1 -1
  408. package/esm/src/server/project-env/internal-authorization.d.ts +7 -0
  409. package/esm/src/server/project-env/internal-authorization.d.ts.map +1 -0
  410. package/esm/src/server/project-env/internal-authorization.js +32 -0
  411. package/esm/src/server/runtime-handler/index.d.ts.map +1 -1
  412. package/esm/src/server/runtime-handler/index.js +1 -1
  413. package/esm/src/server/runtime-handler/projects-handler.d.ts +1 -1
  414. package/esm/src/server/runtime-handler/projects-handler.d.ts.map +1 -1
  415. package/esm/src/server/runtime-handler/projects-handler.js +4 -2
  416. package/esm/src/transforms/esm/http-bundler.d.ts.map +1 -1
  417. package/esm/src/transforms/esm/http-bundler.js +6 -5
  418. package/esm/src/transforms/esm/http-cache-helpers.d.ts +11 -0
  419. package/esm/src/transforms/esm/http-cache-helpers.d.ts.map +1 -1
  420. package/esm/src/transforms/esm/http-cache-helpers.js +35 -0
  421. package/esm/src/transforms/esm/http-cache.d.ts.map +1 -1
  422. package/esm/src/transforms/esm/http-cache.js +16 -10
  423. package/esm/src/transforms/esm/specifier-resolver.d.ts.map +1 -1
  424. package/esm/src/transforms/esm/specifier-resolver.js +87 -7
  425. package/esm/src/transforms/import-rewriter/strategies/alias-strategy.d.ts +2 -0
  426. package/esm/src/transforms/import-rewriter/strategies/alias-strategy.d.ts.map +1 -1
  427. package/esm/src/transforms/import-rewriter/strategies/alias-strategy.js +11 -6
  428. package/esm/src/transforms/md/compiler/md-compiler.d.ts.map +1 -1
  429. package/esm/src/transforms/md/compiler/md-compiler.js +12 -5
  430. package/esm/src/transforms/mdx/compiler/frontmatter-extractor.d.ts +2 -0
  431. package/esm/src/transforms/mdx/compiler/frontmatter-extractor.d.ts.map +1 -1
  432. package/esm/src/transforms/mdx/compiler/frontmatter-extractor.js +33 -1
  433. package/esm/src/transforms/mdx/compiler/mdx-compiler.d.ts.map +1 -1
  434. package/esm/src/transforms/mdx/compiler/mdx-compiler.js +46 -7
  435. package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts.map +1 -1
  436. package/esm/src/transforms/mdx/esm-module-loader/cache/index.js +8 -2
  437. package/esm/src/transforms/mdx/esm-module-loader/cache-format.d.ts +1 -0
  438. package/esm/src/transforms/mdx/esm-module-loader/cache-format.d.ts.map +1 -1
  439. package/esm/src/transforms/mdx/esm-module-loader/cache-format.js +3 -0
  440. package/esm/src/transforms/mdx/esm-module-loader/loader-helpers.d.ts +4 -0
  441. package/esm/src/transforms/mdx/esm-module-loader/loader-helpers.d.ts.map +1 -1
  442. package/esm/src/transforms/mdx/esm-module-loader/loader-helpers.js +44 -8
  443. package/esm/src/transforms/mdx/esm-module-loader/missing-module.d.ts +2 -0
  444. package/esm/src/transforms/mdx/esm-module-loader/missing-module.d.ts.map +1 -1
  445. package/esm/src/transforms/mdx/esm-module-loader/missing-module.js +4 -0
  446. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/http-fallback.d.ts.map +1 -1
  447. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/http-fallback.js +5 -1
  448. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/http-fetcher.d.ts +2 -0
  449. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/http-fetcher.d.ts.map +1 -1
  450. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/http-fetcher.js +50 -11
  451. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.d.ts +24 -12
  452. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.d.ts.map +1 -1
  453. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.js +201 -18
  454. package/esm/src/transforms/mdx/esm-module-loader/types.d.ts +5 -0
  455. package/esm/src/transforms/mdx/esm-module-loader/types.d.ts.map +1 -1
  456. package/esm/src/transforms/mdx/esm-module-loader/utils/source-spans.d.ts +22 -2
  457. package/esm/src/transforms/mdx/esm-module-loader/utils/source-spans.d.ts.map +1 -1
  458. package/esm/src/transforms/mdx/esm-module-loader/utils/source-spans.js +2080 -129
  459. package/esm/src/transforms/mdx/esm-module-loader/utils/stub-module.d.ts +11 -1
  460. package/esm/src/transforms/mdx/esm-module-loader/utils/stub-module.d.ts.map +1 -1
  461. package/esm/src/transforms/mdx/esm-module-loader/utils/stub-module.js +32 -15
  462. package/esm/src/transforms/pipeline/stages/compile.d.ts.map +1 -1
  463. package/esm/src/transforms/pipeline/stages/compile.js +44 -0
  464. package/esm/src/transforms/shared/specifier-suffix.d.ts +25 -0
  465. package/esm/src/transforms/shared/specifier-suffix.d.ts.map +1 -0
  466. package/esm/src/transforms/shared/specifier-suffix.js +43 -0
  467. package/esm/src/trigger/index.d.ts +2 -2
  468. package/esm/src/trigger/index.d.ts.map +1 -1
  469. package/esm/src/trigger/index.js +1 -1
  470. package/esm/src/trigger/local-runner.d.ts +2 -2
  471. package/esm/src/trigger/local-runner.d.ts.map +1 -1
  472. package/esm/src/trigger/local-runner.js +11 -4
  473. package/esm/src/trigger/target.d.ts +97 -5
  474. package/esm/src/trigger/target.d.ts.map +1 -1
  475. package/esm/src/trigger/target.js +175 -5
  476. package/esm/src/utils/version-constant.d.ts +1 -1
  477. package/esm/src/utils/version-constant.js +1 -1
  478. package/esm/src/webhook/types.d.ts +21 -6
  479. package/esm/src/webhook/types.d.ts.map +1 -1
  480. package/esm/src/webhook/validation.d.ts.map +1 -1
  481. package/esm/src/webhook/validation.js +27 -39
  482. package/esm/templates/index.d.ts +1 -1
  483. package/esm/templates/index.d.ts.map +1 -1
  484. package/esm/templates/loader.d.ts +6 -6
  485. package/esm/templates/loader.d.ts.map +1 -1
  486. package/esm/templates/loader.js +34 -18
  487. package/esm/templates/manifest.generated.d.ts +3 -0
  488. package/esm/templates/manifest.generated.d.ts.map +1 -0
  489. package/esm/templates/manifest.generated.js +2 -0
  490. package/package.json +8 -8
  491. package/esm/templates/manifest.d.ts +0 -664
  492. package/esm/templates/manifest.d.ts.map +0 -1
  493. package/esm/templates/manifest.js +0 -662
@@ -1,4 +1,55 @@
1
1
  import { INVALID_ARGUMENT } from "../../../../errors/index.js";
2
+ const MAX_TEMPLATE_LITERAL_DEPTH = 512;
3
+ const MAX_RAW_JSX_TEXT_CLOSING_LOOKAHEAD = 64 * 1024;
4
+ const StringFromCodePoint = String.fromCodePoint;
5
+ const IDENTIFIER_START_PATTERN = /^[$_\p{ID_Start}]$/u;
6
+ const IDENTIFIER_PART_PATTERN = /^[$_\p{ID_Continue}\u200C\u200D]$/u;
7
+ const IDENTIFIER_ESCAPE_SOURCE = String.raw `\\u(?:[0-9A-Fa-f]{4}|\{[0-9A-Fa-f]+\})`;
8
+ const IDENTIFIER_NAME_SOURCE = String
9
+ .raw `(?:[$_\p{ID_Start}]|${IDENTIFIER_ESCAPE_SOURCE})(?:[$\p{ID_Continue}\u200C\u200D]|${IDENTIFIER_ESCAPE_SOURCE})*`;
10
+ const FUNCTION_DECLARATION_PREFIX_PATTERN = new RegExp(String
11
+ .raw `^(?:export\s+(?:default\s+)?)?(?:async\s+)?function(?:\s*\*)?(?:\s+${IDENTIFIER_NAME_SOURCE})?\s*$`, "u");
12
+ const TYPESCRIPT_FUNCTION_DECLARATION_PREFIX_PATTERN = new RegExp(String
13
+ .raw `^(?:export\s+(?:default\s+)?)?(?:async\s+)?function(?:\s*\*)?(?:\s+${IDENTIFIER_NAME_SOURCE})?(?:\s*<[\s\S]*>)?\s*\([\s\S]*\)\s*(?::\s*[\s\S]*\S)?\s*$`, "u");
14
+ const CLASS_DECLARATION_PREFIX_PATTERN = new RegExp(String
15
+ .raw `^(?:@[\s\S]+?\s+)*(?:export\s+(?:default\s+)?)?(?:declare\s+)?(?:abstract\s+)?class(?:\s+${IDENTIFIER_NAME_SOURCE})?(?:\s*<[\s\S]*>)?(?:\s+extends\s+[\s\S]+?)?(?:\s+implements\s+[\s\S]+)?\s*$`, "u");
16
+ const TYPESCRIPT_DECLARATION_PREFIX_PATTERN = new RegExp(String
17
+ .raw `^(?:export\s+(?:default\s+)?)?(?:declare\s+)?(?:(?:interface\s+${IDENTIFIER_NAME_SOURCE}(?:\s*<[\s\S]*>)?(?:\s+extends\s+[\s\S]+)?)|(?:(?:const\s+)?enum\s+${IDENTIFIER_NAME_SOURCE})|(?:global)|(?:(?:namespace|module)\s+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|${IDENTIFIER_NAME_SOURCE}(?:\s*\.\s*${IDENTIFIER_NAME_SOURCE})*)))\s*$`, "u");
18
+ const TYPESCRIPT_TYPE_ALIAS_PREFIX_PATTERN = new RegExp(String.raw `^(?:export\s+)?type\s+${IDENTIFIER_NAME_SOURCE}(?:\s*<[\s\S]*>)?\s*=\s*[\s\S]*\S\s*$`, "u");
19
+ const TYPESCRIPT_AMBIENT_DECLARATION_PREFIX_PATTERN = new RegExp(String
20
+ .raw `^(?:export\s+)?declare\s+(?:(?:(?:const|let|var)\s+${IDENTIFIER_NAME_SOURCE}(?:\s*:\s*[\s\S]*\S)?)|(?:function\s+${IDENTIFIER_NAME_SOURCE}(?:\s*<[\s\S]*>)?\s*\([\s\S]*\)\s*(?::\s*[\s\S]*\S)?)|(?:class\s+${IDENTIFIER_NAME_SOURCE}(?:\s*<[\s\S]*>)?(?:\s+extends\s+[\s\S]+?)?(?:\s+implements\s+[\s\S]+)?))\s*$`, "u");
21
+ const JSX_TEXT_BREAK_STATEMENT_KEYWORDS = new Set([
22
+ "async",
23
+ "await",
24
+ "break",
25
+ "case",
26
+ "class",
27
+ "const",
28
+ "continue",
29
+ "debugger",
30
+ "default",
31
+ "do",
32
+ "else",
33
+ "export",
34
+ "for",
35
+ "function",
36
+ "if",
37
+ "import",
38
+ "let",
39
+ "return",
40
+ "switch",
41
+ "throw",
42
+ "try",
43
+ "var",
44
+ "while",
45
+ "with",
46
+ "yield",
47
+ ]);
48
+ function assertTemplateLiteralDepth(depth) {
49
+ if (depth > MAX_TEMPLATE_LITERAL_DEPTH) {
50
+ throw new RangeError("Template literal nesting exceeds scanner limit");
51
+ }
52
+ }
2
53
  export function replaceSourceSpans(source, replacements) {
3
54
  let result = source;
4
55
  // Sort descending by start so we apply back-to-front and earlier spans stay valid.
@@ -14,123 +65,1635 @@ export function replaceSourceSpans(source, replacements) {
14
65
  throw new RangeError(`Overlapping source replacement spans: [${earlier.start},${earlier.end}) and [${later.start},${later.end})`);
15
66
  }
16
67
  }
17
- for (const { start, end, replacement, expected } of sorted) {
18
- if (start < 0 || end < start || end > source.length) {
19
- throw new RangeError(`Invalid source replacement span: ${start}-${end}`);
68
+ for (const { start, end, replacement, expected } of sorted) {
69
+ if (start < 0 || end < start || end > source.length) {
70
+ throw new RangeError(`Invalid source replacement span: ${start}-${end}`);
71
+ }
72
+ if (expected !== undefined && source.slice(start, end) !== expected) {
73
+ throw INVALID_ARGUMENT.create({
74
+ detail: `Source replacement span did not match expected text: ${expected}`,
75
+ });
76
+ }
77
+ result = result.slice(0, start) + replacement + result.slice(end);
78
+ }
79
+ return result;
80
+ }
81
+ function isIdentifierChar(char) {
82
+ return char !== undefined && IDENTIFIER_PART_PATTERN.test(char);
83
+ }
84
+ function isIdentifierStart(char) {
85
+ return char !== undefined && IDENTIFIER_START_PATTERN.test(char);
86
+ }
87
+ function identifierCharacterAt(source, index) {
88
+ if (index < 0 || index >= source.length)
89
+ return undefined;
90
+ let characterIndex = index;
91
+ const codeUnit = source.charCodeAt(characterIndex);
92
+ if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff && characterIndex > 0) {
93
+ const previousCodeUnit = source.charCodeAt(characterIndex - 1);
94
+ if (previousCodeUnit >= 0xd800 && previousCodeUnit <= 0xdbff)
95
+ characterIndex--;
96
+ }
97
+ const codePoint = source.codePointAt(characterIndex);
98
+ return codePoint === undefined ? undefined : StringFromCodePoint(codePoint);
99
+ }
100
+ function isIdentifierPartAt(source, index) {
101
+ return isIdentifierChar(identifierCharacterAt(source, index));
102
+ }
103
+ function isIdentifierStartAt(source, index) {
104
+ return isIdentifierStart(identifierCharacterAt(source, index));
105
+ }
106
+ function isHexDigit(char) {
107
+ return char !== undefined && /[0-9A-Fa-f]/.test(char);
108
+ }
109
+ function identifierEscapeCodePoint(source, start) {
110
+ if (source[start] !== "\\" || source[start + 1] !== "u")
111
+ return undefined;
112
+ if (source[start + 2] === "{") {
113
+ let cursor = start + 3;
114
+ while (isHexDigit(source[cursor]))
115
+ cursor++;
116
+ if (cursor === start + 3 || source[cursor] !== "}")
117
+ return undefined;
118
+ const codePoint = Number.parseInt(source.slice(start + 3, cursor), 16);
119
+ if (!Number.isSafeInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
120
+ return undefined;
121
+ }
122
+ return { codePoint, end: cursor + 1 };
123
+ }
124
+ for (let offset = 2; offset < 6; offset++) {
125
+ if (!isHexDigit(source[start + offset]))
126
+ return undefined;
127
+ }
128
+ return {
129
+ codePoint: Number.parseInt(source.slice(start + 2, start + 6), 16),
130
+ end: start + 6,
131
+ };
132
+ }
133
+ function isIdentifierEscapeStartingAt(source, index) {
134
+ const escape = identifierEscapeCodePoint(source, index);
135
+ return escape !== undefined && isIdentifierChar(StringFromCodePoint(escape.codePoint));
136
+ }
137
+ function identifierEscapeStartEndingAt(source, end) {
138
+ const fixedStart = end - "\\u0000".length;
139
+ const fixed = identifierEscapeCodePoint(source, fixedStart);
140
+ if (fixed?.end === end &&
141
+ isIdentifierChar(StringFromCodePoint(fixed.codePoint))) {
142
+ return fixedStart;
143
+ }
144
+ if (source[end - 1] !== "}")
145
+ return undefined;
146
+ let cursor = end - 2;
147
+ while (cursor >= 0 && isHexDigit(source[cursor]))
148
+ cursor--;
149
+ if (source[cursor] !== "{" || source[cursor - 1] !== "u" || source[cursor - 2] !== "\\") {
150
+ return undefined;
151
+ }
152
+ const braced = identifierEscapeCodePoint(source, cursor - 2);
153
+ return braced?.end === end && isIdentifierChar(StringFromCodePoint(braced.codePoint))
154
+ ? cursor - 2
155
+ : undefined;
156
+ }
157
+ function isIdentifierEscapeEndingAt(source, end) {
158
+ return identifierEscapeStartEndingAt(source, end) !== undefined;
159
+ }
160
+ function isIdentifierBoundaryBefore(source, index) {
161
+ return isIdentifierPartAt(source, index - 1) || isIdentifierEscapeEndingAt(source, index);
162
+ }
163
+ function isIdentifierBoundaryAfter(source, index) {
164
+ return isIdentifierPartAt(source, index) || isIdentifierEscapeStartingAt(source, index);
165
+ }
166
+ function skipLineComment(source, index) {
167
+ let cursor = index + 2;
168
+ while (cursor < source.length && !isLineTerminator(source[cursor]))
169
+ cursor++;
170
+ if (cursor >= source.length)
171
+ return source.length;
172
+ return source[cursor] === "\r" && source[cursor + 1] === "\n" ? cursor + 2 : cursor + 1;
173
+ }
174
+ function isStatementKeywordAt(source, index, keyword, atStatementStart) {
175
+ if (!atStatementStart)
176
+ return false;
177
+ if (!source.startsWith(keyword, index))
178
+ return false;
179
+ if (isIdentifierBoundaryBefore(source, index) || source[index - 1] === ".")
180
+ return false;
181
+ if (isIdentifierBoundaryAfter(source, index + keyword.length))
182
+ return false;
183
+ return true;
184
+ }
185
+ function skipIgnored(source, index) {
186
+ const char = source[index];
187
+ const next = source[index + 1];
188
+ if (char === "/" && next === "/") {
189
+ return skipLineComment(source, index);
190
+ }
191
+ if (char === "/" && next === "*") {
192
+ const end = source.indexOf("*/", index + 2);
193
+ return end === -1 ? source.length : end + 2;
194
+ }
195
+ if (char === '"' || char === "'" || char === "`") {
196
+ let cursor = index + 1;
197
+ while (cursor < source.length) {
198
+ if (source[cursor] === "\\") {
199
+ cursor += 2;
200
+ continue;
201
+ }
202
+ if (source[cursor] === char)
203
+ return cursor + 1;
204
+ cursor++;
205
+ }
206
+ return source.length;
207
+ }
208
+ return index;
209
+ }
210
+ function skipWhitespace(source, index) {
211
+ let cursor = index;
212
+ while (/\s/.test(source[cursor] ?? ""))
213
+ cursor++;
214
+ return cursor;
215
+ }
216
+ function hasLineTerminatorBetween(source, start, end) {
217
+ for (let cursor = start; cursor < end; cursor++) {
218
+ if (isLineTerminator(source[cursor]))
219
+ return true;
220
+ }
221
+ return false;
222
+ }
223
+ // Comments are legal wherever whitespace is, so a dynamic import can carry a
224
+ // bundler hint between the keyword, the parentheses and the specifier. Treating
225
+ // the comment as an unexpected character would leave the specifier unresolved.
226
+ function skipWhitespaceAndComments(source, index) {
227
+ let cursor = index;
228
+ while (cursor < source.length) {
229
+ const afterWhitespace = skipWhitespace(source, cursor);
230
+ const char = source[afterWhitespace];
231
+ const next = source[afterWhitespace + 1];
232
+ if (char === "/" && (next === "/" || next === "*")) {
233
+ cursor = skipIgnored(source, afterWhitespace);
234
+ continue;
235
+ }
236
+ return afterWhitespace;
237
+ }
238
+ return cursor;
239
+ }
240
+ function nextStatementCursor(source, index) {
241
+ let cursor = index;
242
+ while (cursor < source.length) {
243
+ if (source[cursor] === ";")
244
+ return cursor + 1;
245
+ if (isLineTerminator(source[cursor])) {
246
+ return source[cursor] === "\r" && source[cursor + 1] === "\n" ? cursor + 2 : cursor + 1;
247
+ }
248
+ cursor++;
249
+ }
250
+ return source.length;
251
+ }
252
+ function hexDigitValue(char) {
253
+ if (char === undefined)
254
+ return -1;
255
+ const code = char.charCodeAt(0);
256
+ if (code >= 48 && code <= 57)
257
+ return code - 48;
258
+ if (code >= 65 && code <= 70)
259
+ return code - 55;
260
+ if (code >= 97 && code <= 102)
261
+ return code - 87;
262
+ return -1;
263
+ }
264
+ function decodeHexEscape(source, start, length) {
265
+ let value = 0;
266
+ for (let offset = 0; offset < length; offset++) {
267
+ const digit = hexDigitValue(source[start + offset]);
268
+ if (digit === -1)
269
+ return null;
270
+ value = value * 16 + digit;
271
+ }
272
+ return value;
273
+ }
274
+ function invalidEscapedSpecifier() {
275
+ throw new SyntaxError("Invalid escaped module specifier");
276
+ }
277
+ function isLineTerminator(char) {
278
+ return char === "\r" || char === "\n" || char === "\u2028" || char === "\u2029";
279
+ }
280
+ function decodeLiteralContents(source, start, end, allowLineTerminators) {
281
+ let result = "";
282
+ let cursor = start;
283
+ while (cursor < end) {
284
+ const char = source[cursor];
285
+ if (char !== "\\") {
286
+ if (isLineTerminator(char)) {
287
+ if (!allowLineTerminators)
288
+ invalidEscapedSpecifier();
289
+ if (char === "\r") {
290
+ result += "\n";
291
+ cursor += source[cursor + 1] === "\n" ? 2 : 1;
292
+ continue;
293
+ }
294
+ }
295
+ result += char;
296
+ cursor++;
297
+ continue;
298
+ }
299
+ const escaped = source[cursor + 1];
300
+ if (escaped === undefined || cursor + 1 >= end)
301
+ invalidEscapedSpecifier();
302
+ if (isLineTerminator(escaped)) {
303
+ cursor += escaped === "\r" && source[cursor + 2] === "\n" ? 3 : 2;
304
+ continue;
305
+ }
306
+ const simpleEscape = {
307
+ b: "\b",
308
+ f: "\f",
309
+ n: "\n",
310
+ r: "\r",
311
+ t: "\t",
312
+ v: "\v",
313
+ }[escaped];
314
+ if (simpleEscape !== undefined) {
315
+ result += simpleEscape;
316
+ cursor += 2;
317
+ continue;
318
+ }
319
+ if (escaped === "0") {
320
+ if (/[0-9]/.test(source[cursor + 2] ?? ""))
321
+ invalidEscapedSpecifier();
322
+ result += "\0";
323
+ cursor += 2;
324
+ continue;
325
+ }
326
+ if (/[1-9]/.test(escaped))
327
+ invalidEscapedSpecifier();
328
+ if (escaped === "x") {
329
+ const value = decodeHexEscape(source, cursor + 2, 2);
330
+ if (value === null || cursor + 4 > end)
331
+ invalidEscapedSpecifier();
332
+ result += StringFromCodePoint(value);
333
+ cursor += 4;
334
+ continue;
335
+ }
336
+ if (escaped === "u") {
337
+ if (source[cursor + 2] === "{") {
338
+ let escapeEnd = cursor + 3;
339
+ let value = 0;
340
+ let digitCount = 0;
341
+ while (escapeEnd < end && source[escapeEnd] !== "}") {
342
+ const digit = hexDigitValue(source[escapeEnd]);
343
+ if (digit === -1)
344
+ invalidEscapedSpecifier();
345
+ value = value * 16 + digit;
346
+ digitCount++;
347
+ escapeEnd++;
348
+ }
349
+ if (digitCount === 0 || source[escapeEnd] !== "}" || value > 0x10ffff)
350
+ invalidEscapedSpecifier();
351
+ result += StringFromCodePoint(value);
352
+ cursor = escapeEnd + 1;
353
+ continue;
354
+ }
355
+ const value = decodeHexEscape(source, cursor + 2, 4);
356
+ if (value === null || cursor + 6 > end)
357
+ invalidEscapedSpecifier();
358
+ result += StringFromCodePoint(value);
359
+ cursor += 6;
360
+ continue;
361
+ }
362
+ result += escaped;
363
+ cursor += 2;
364
+ }
365
+ return result;
366
+ }
367
+ function readQuotedSpecifier(source, quoteIndex) {
368
+ const quote = source[quoteIndex];
369
+ if (quote !== '"' && quote !== "'")
370
+ return null;
371
+ let cursor = quoteIndex + 1;
372
+ while (cursor < source.length) {
373
+ if (source[cursor] === "\\") {
374
+ cursor += 2;
375
+ continue;
376
+ }
377
+ if (source[cursor] === quote) {
378
+ const specifier = decodeLiteralContents(source, quoteIndex + 1, cursor, false);
379
+ return {
380
+ end: cursor + 1,
381
+ specifier,
382
+ };
383
+ }
384
+ cursor++;
385
+ }
386
+ return null;
387
+ }
388
+ function readLiteralSpecifier(source, literalIndex) {
389
+ const quote = source[literalIndex];
390
+ if (quote === '"' || quote === "'")
391
+ return readQuotedSpecifier(source, literalIndex);
392
+ if (quote !== "`")
393
+ return null;
394
+ let cursor = literalIndex + 1;
395
+ while (cursor < source.length) {
396
+ if (source[cursor] === "\\") {
397
+ cursor += 2;
398
+ continue;
399
+ }
400
+ if (source[cursor] === "$" && source[cursor + 1] === "{")
401
+ return null;
402
+ if (source[cursor] === "`") {
403
+ const specifier = decodeLiteralContents(source, literalIndex + 1, cursor, true);
404
+ return {
405
+ end: cursor + 1,
406
+ specifier,
407
+ };
408
+ }
409
+ cursor++;
410
+ }
411
+ return null;
412
+ }
413
+ function skipFullTemplateLiteral(source, templateIndex, depth = 0) {
414
+ assertTemplateLiteralDepth(depth);
415
+ let cursor = templateIndex + 1;
416
+ while (cursor < source.length) {
417
+ if (source[cursor] === "\\") {
418
+ cursor += 2;
419
+ continue;
420
+ }
421
+ if (source[cursor] === "`")
422
+ return cursor + 1;
423
+ if (source[cursor] === "$" && source[cursor + 1] === "{") {
424
+ const expressionEnd = findTemplateExpressionEnd(source, cursor + 2, depth + 1);
425
+ if (expressionEnd === null)
426
+ return source.length;
427
+ cursor = expressionEnd + 1;
428
+ continue;
429
+ }
430
+ cursor++;
431
+ }
432
+ return source.length;
433
+ }
434
+ function previousSignificantIndex(source, index) {
435
+ let cursor = index - 1;
436
+ while (cursor >= 0 && /\s/.test(source[cursor] ?? ""))
437
+ cursor--;
438
+ return cursor;
439
+ }
440
+ function lineCommentStart(source, index) {
441
+ let cursor = index;
442
+ while (cursor > 0 && !isLineTerminator(source[cursor - 1] ?? ""))
443
+ cursor--;
444
+ let quote = null;
445
+ for (; cursor <= index; cursor++) {
446
+ const char = source[cursor];
447
+ if (quote !== null) {
448
+ if (char === "\\")
449
+ cursor++;
450
+ else if (char === quote)
451
+ quote = null;
452
+ continue;
453
+ }
454
+ if (char === '"' || char === "'" || char === "`") {
455
+ quote = char;
456
+ continue;
457
+ }
458
+ if (char === "/" && source[cursor + 1] === "/")
459
+ return cursor;
460
+ }
461
+ return null;
462
+ }
463
+ function previousSignificantIndexBeforeIgnored(source, index) {
464
+ let cursor = index;
465
+ while (cursor >= 0) {
466
+ cursor = previousSignificantIndex(source, cursor);
467
+ if (cursor < 0)
468
+ return cursor;
469
+ if (source[cursor] === "/" && source[cursor - 1] === "*") {
470
+ const start = source.lastIndexOf("/*", cursor - 1);
471
+ if (start >= 0) {
472
+ cursor = start;
473
+ continue;
474
+ }
475
+ }
476
+ const lineStart = Math.max(source.lastIndexOf("\n", cursor), source.lastIndexOf("\r", cursor), source.lastIndexOf("\u2028", cursor), source.lastIndexOf("\u2029", cursor)) + 1;
477
+ if (source.lastIndexOf("//", cursor) >= lineStart) {
478
+ const commentStart = lineCommentStart(source, cursor);
479
+ if (commentStart !== null) {
480
+ cursor = commentStart;
481
+ continue;
482
+ }
483
+ }
484
+ return cursor;
485
+ }
486
+ return cursor;
487
+ }
488
+ function keywordBefore(source, index, previousTokenIndex = previousSignificantIndex(source, index)) {
489
+ const end = previousTokenIndex + 1;
490
+ let start = end;
491
+ while (start > 0 && isIdentifierPartAt(source, start - 1))
492
+ start--;
493
+ if (start === end)
494
+ return null;
495
+ return source.slice(start, end);
496
+ }
497
+ /**
498
+ * Whether the word ending at `previousTokenIndex` is a member name, not a keyword.
499
+ *
500
+ * Every keyword the classifier accepts as a regex prefix is also a legal
501
+ * property name in ES5+, so `metrics.in / 2` and `metrics.return / 2` are
502
+ * ordinary code in which the slash divides. Reading the word as a keyword
503
+ * opens a regex literal that never closes, and the scan then swallows the rest
504
+ * of the module — every later import disappears from nested materialization
505
+ * and from dependency collection alike.
506
+ *
507
+ * Covers `.name`, optional chaining `?.name` (the character before the word is
508
+ * `.` either way) and private fields `#name`.
509
+ */
510
+ export function isMemberNameBefore(source, previousTokenIndex) {
511
+ const end = previousTokenIndex + 1;
512
+ let start = end;
513
+ while (start > 0 && isIdentifierPartAt(source, start - 1))
514
+ start--;
515
+ if (start === end)
516
+ return false;
517
+ const immediateBefore = previousSignificantIndex(source, start);
518
+ if (immediateBefore < 0)
519
+ return false;
520
+ // Most keyword-shaped identifiers are ordinary expression operands. Avoid
521
+ // rescanning the whole line for a comment unless the adjacent trivia can
522
+ // actually contain one; doing that for every `of` makes long declarations
523
+ // quadratic under coverage instrumentation.
524
+ if (source[immediateBefore] !== "/" &&
525
+ !hasLineTerminatorBetween(source, immediateBefore + 1, start)) {
526
+ const immediateChar = source[immediateBefore];
527
+ if (immediateChar === "#")
528
+ return true;
529
+ if (immediateChar !== ".")
530
+ return false;
531
+ return source[immediateBefore - 1] !== "." || source[immediateBefore - 2] !== ".";
532
+ }
533
+ const before = previousSignificantIndexBeforeIgnored(source, start);
534
+ if (before < 0)
535
+ return false;
536
+ const char = source[before];
537
+ if (char === "#")
538
+ return true;
539
+ if (char !== ".")
540
+ return false;
541
+ return source[before - 1] !== "." || source[before - 2] !== ".";
542
+ }
543
+ function restrictedStatementKeywordBeforeLabel(source, index, previousTokenIndex, rangeStart) {
544
+ const labelEnd = previousTokenIndex + 1;
545
+ let labelStart = labelEnd;
546
+ while (labelStart > rangeStart && isIdentifierPartAt(source, labelStart - 1))
547
+ labelStart--;
548
+ if (labelStart === labelEnd)
549
+ return null;
550
+ const beforeLabel = previousSignificantIndexBeforeIgnored(source, labelStart);
551
+ const keyword = keywordBefore(source, labelStart, beforeLabel);
552
+ if (keyword !== "break" && keyword !== "continue")
553
+ return null;
554
+ const keywordEnd = beforeLabel + 1;
555
+ if (hasLineTerminatorBetween(source, keywordEnd, labelStart))
556
+ return null;
557
+ if (!hasLineTerminatorBetween(source, labelEnd, index))
558
+ return null;
559
+ return keyword;
560
+ }
561
+ function openParenContext(source, index, previousTokenIndex) {
562
+ const keyword = keywordBefore(source, index, previousTokenIndex);
563
+ const keywordStart = previousTokenIndex - (keyword?.length ?? 0) + 1;
564
+ const previousKeyword = keyword === "await"
565
+ ? keywordBefore(source, keywordStart, previousSignificantIndexBeforeIgnored(source, keywordStart))
566
+ : null;
567
+ const isForAwaitHeader = previousKeyword === "for";
568
+ return {
569
+ index,
570
+ isControlCondition: keyword === "if" || keyword === "while" || keyword === "for" ||
571
+ keyword === "with" || keyword === "switch" || keyword === "catch" || isForAwaitHeader,
572
+ isForHeader: keyword === "for" || isForAwaitHeader,
573
+ hasSemicolon: false,
574
+ };
575
+ }
576
+ function isControlConditionCloseParen(index, rangeStart, matchingOpenParens) {
577
+ const openParen = matchingOpenParens.get(index);
578
+ return openParen !== undefined && openParen.index >= rangeStart &&
579
+ openParen.isControlCondition;
580
+ }
581
+ function isControlBlockCloseBrace(source, index, rangeStart, matchingOpenBraces, matchingOpenParens) {
582
+ const openBrace = matchingOpenBraces.get(index);
583
+ if (openBrace === undefined)
584
+ return false;
585
+ const beforeOpenBrace = openBrace.previousTokenIndex;
586
+ return beforeOpenBrace >= rangeStart &&
587
+ source[beforeOpenBrace] === ")" &&
588
+ isControlConditionCloseParen(beforeOpenBrace, rangeStart, matchingOpenParens);
589
+ }
590
+ function normalizedDeclarationPrefix(source, start, end) {
591
+ return source.slice(start, end).trimStart().replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n\u2028\u2029]*/g, " ");
592
+ }
593
+ function declarationStatementStartBefore(source, index, keywords = [
594
+ "async",
595
+ "export",
596
+ "function",
597
+ ]) {
598
+ const separatorStart = Math.max(source.lastIndexOf(";", index - 1), source.lastIndexOf("{", index - 1), source.lastIndexOf("}", index - 1)) + 1;
599
+ return declarationAsiBoundaryBefore(source, separatorStart, index, keywords) ?? separatorStart;
600
+ }
601
+ function balancedDeclarationStatementStartBefore(source, index, keywords) {
602
+ let cursor = index - 1;
603
+ let parenDepth = 0;
604
+ let braceDepth = 0;
605
+ let bracketDepth = 0;
606
+ while (cursor >= 0) {
607
+ const char = source[cursor];
608
+ if (char === ")")
609
+ parenDepth++;
610
+ else if (char === "(" && parenDepth > 0)
611
+ parenDepth--;
612
+ else if (char === "}")
613
+ braceDepth++;
614
+ else if (char === "{" && braceDepth > 0)
615
+ braceDepth--;
616
+ else if (char === "]")
617
+ bracketDepth++;
618
+ else if (char === "[" && bracketDepth > 0)
619
+ bracketDepth--;
620
+ else if (parenDepth === 0 && braceDepth === 0 && bracketDepth === 0) {
621
+ if (char === ";" || char === "{" || char === "}") {
622
+ const separatorStart = cursor + 1;
623
+ return declarationAsiBoundaryBefore(source, separatorStart, index, keywords) ??
624
+ separatorStart;
625
+ }
626
+ }
627
+ cursor--;
628
+ }
629
+ return declarationAsiBoundaryBefore(source, 0, index, keywords) ?? 0;
630
+ }
631
+ function classDeclarationStatementStartBefore(source, index) {
632
+ return balancedDeclarationStatementStartBefore(source, index, [
633
+ "class",
634
+ "declare",
635
+ "export",
636
+ ]);
637
+ }
638
+ function startsWithDeclarationKeywordAt(source, index, keywords) {
639
+ return keywords.some((keyword) => source.startsWith(keyword, index) &&
640
+ !isIdentifierBoundaryBefore(source, index) &&
641
+ !isIdentifierBoundaryAfter(source, index + keyword.length));
642
+ }
643
+ function hasDeclarationKeywordBefore(source, start, end, keywords) {
644
+ for (const keyword of keywords) {
645
+ let index = source.indexOf(keyword, start);
646
+ while (index >= 0 && index < end) {
647
+ if (!isIdentifierBoundaryBefore(source, index) &&
648
+ !isIdentifierBoundaryAfter(source, index + keyword.length)) {
649
+ return true;
650
+ }
651
+ index = source.indexOf(keyword, index + keyword.length);
652
+ }
653
+ }
654
+ return false;
655
+ }
656
+ function declarationAsiBoundaryBefore(source, start, end, keywords) {
657
+ let boundary = null;
658
+ let cursor = start;
659
+ while (cursor < end) {
660
+ const char = source[cursor];
661
+ if (char !== undefined && isLineTerminator(char)) {
662
+ const afterLine = char === "\r" && source[cursor + 1] === "\n" ? cursor + 2 : cursor + 1;
663
+ const previousTokenIndex = previousSignificantIndexBeforeIgnored(source, cursor);
664
+ const declarationStart = skipWhitespaceAndComments(source, afterLine);
665
+ if (previousTokenIndex >= start &&
666
+ canEndStatementBeforeLineTerminator(source, previousTokenIndex) &&
667
+ declarationStart < end &&
668
+ startsWithDeclarationKeywordAt(source, declarationStart, keywords)) {
669
+ boundary = declarationStart;
670
+ }
671
+ cursor = afterLine;
672
+ continue;
673
+ }
674
+ const skipped = skipIgnored(source, cursor);
675
+ if (skipped !== cursor) {
676
+ cursor = skipped;
677
+ continue;
678
+ }
679
+ cursor++;
680
+ }
681
+ return boundary;
682
+ }
683
+ function isFunctionDeclarationBlockOpenBrace(source, previousTokenIndex, matchingOpenParens) {
684
+ if (source[previousTokenIndex] !== ")")
685
+ return false;
686
+ const openParen = matchingOpenParens.get(previousTokenIndex);
687
+ if (openParen === undefined)
688
+ return false;
689
+ const declarationStart = declarationStatementStartBefore(source, openParen.index);
690
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, openParen.index);
691
+ return FUNCTION_DECLARATION_PREFIX_PATTERN.test(prefix);
692
+ }
693
+ function isTypeScriptFunctionDeclarationBlockOpenBrace(source, index, previousTokenIndex) {
694
+ const previousToken = source[previousTokenIndex];
695
+ if (previousToken !== ")" &&
696
+ previousToken !== "]" &&
697
+ previousToken !== "}" &&
698
+ !isIdentifierPartAt(source, previousTokenIndex) &&
699
+ !isIdentifierEscapeEndingAt(source, previousTokenIndex + 1)) {
700
+ return false;
701
+ }
702
+ const separatorStart = source.lastIndexOf(";", index - 1) + 1;
703
+ if (!hasDeclarationKeywordBefore(source, separatorStart, index, [
704
+ "async",
705
+ "export",
706
+ "function",
707
+ ])) {
708
+ return false;
709
+ }
710
+ const declarationStart = balancedDeclarationStatementStartBefore(source, index, [
711
+ "async",
712
+ "export",
713
+ "function",
714
+ ]);
715
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, index);
716
+ return TYPESCRIPT_FUNCTION_DECLARATION_PREFIX_PATTERN.test(prefix);
717
+ }
718
+ function isClassDeclarationBlockOpenBrace(source, index, previousTokenIndex, currentParen) {
719
+ const previousToken = source[previousTokenIndex];
720
+ if (previousToken !== ")" &&
721
+ previousToken !== "]" &&
722
+ previousToken !== ">" &&
723
+ !isIdentifierPartAt(source, previousTokenIndex) &&
724
+ !isIdentifierEscapeEndingAt(source, previousTokenIndex + 1)) {
725
+ return false;
726
+ }
727
+ const separatorStart = source.lastIndexOf(";", index - 1) + 1;
728
+ if (!hasDeclarationKeywordBefore(source, separatorStart, index, ["class", "export"])) {
729
+ return false;
730
+ }
731
+ const declarationStart = classDeclarationStatementStartBefore(source, index);
732
+ if (currentParen !== undefined && currentParen.index >= declarationStart)
733
+ return false;
734
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, index);
735
+ return CLASS_DECLARATION_PREFIX_PATTERN.test(prefix);
736
+ }
737
+ function isTypeScriptDeclarationBlockOpenBrace(source, index, previousTokenIndex) {
738
+ const previousToken = source[previousTokenIndex];
739
+ if (previousToken !== ">" &&
740
+ previousToken !== '"' &&
741
+ previousToken !== "'" &&
742
+ !isIdentifierPartAt(source, previousTokenIndex) &&
743
+ !isIdentifierEscapeEndingAt(source, previousTokenIndex + 1)) {
744
+ return false;
745
+ }
746
+ const keywords = [
747
+ "const",
748
+ "declare",
749
+ "enum",
750
+ "export",
751
+ "interface",
752
+ "module",
753
+ "namespace",
754
+ ];
755
+ const separatorStart = source.lastIndexOf(";", index - 1) + 1;
756
+ if (!hasDeclarationKeywordBefore(source, separatorStart, index, keywords)) {
757
+ return false;
758
+ }
759
+ const declarationStart = balancedDeclarationStatementStartBefore(source, index, keywords);
760
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, index);
761
+ return TYPESCRIPT_DECLARATION_PREFIX_PATTERN.test(prefix);
762
+ }
763
+ function identifierStartBefore(source, end, rangeStart) {
764
+ let start = end;
765
+ while (start > rangeStart) {
766
+ const escapeStart = identifierEscapeStartEndingAt(source, start);
767
+ if (escapeStart !== undefined && escapeStart >= rangeStart) {
768
+ start = escapeStart;
769
+ continue;
770
+ }
771
+ if (!isIdentifierPartAt(source, start - 1))
772
+ break;
773
+ start--;
774
+ }
775
+ return start;
776
+ }
777
+ function isIdentifierStartOrEscapeAt(source, index) {
778
+ const escape = identifierEscapeCodePoint(source, index);
779
+ if (escape !== undefined)
780
+ return isIdentifierStart(StringFromCodePoint(escape.codePoint));
781
+ return isIdentifierStartAt(source, index);
782
+ }
783
+ function switchClauseStartBeforeColon(source, start, colonIndex) {
784
+ let cursor = start;
785
+ let candidate = null;
786
+ let parenDepth = 0;
787
+ let braceDepth = 0;
788
+ let bracketDepth = 0;
789
+ while (cursor < colonIndex) {
790
+ const skipped = skipIgnored(source, cursor);
791
+ if (skipped !== cursor) {
792
+ cursor = skipped;
793
+ continue;
794
+ }
795
+ const char = source[cursor];
796
+ if (char === "(")
797
+ parenDepth++;
798
+ else if (char === ")" && parenDepth > 0)
799
+ parenDepth--;
800
+ else if (char === "{")
801
+ braceDepth++;
802
+ else if (char === "}" && braceDepth > 0)
803
+ braceDepth--;
804
+ else if (char === "[")
805
+ bracketDepth++;
806
+ else if (char === "]" && bracketDepth > 0)
807
+ bracketDepth--;
808
+ if (parenDepth === 0 && braceDepth === 0 && bracketDepth === 0) {
809
+ if (source.startsWith("case", cursor) &&
810
+ !isIdentifierBoundaryBefore(source, cursor) &&
811
+ !isIdentifierBoundaryAfter(source, cursor + "case".length)) {
812
+ candidate = cursor;
813
+ cursor += "case".length;
814
+ continue;
815
+ }
816
+ if (source.startsWith("default", cursor) &&
817
+ !isIdentifierBoundaryBefore(source, cursor) &&
818
+ !isIdentifierBoundaryAfter(source, cursor + "default".length)) {
819
+ candidate = cursor;
820
+ cursor += "default".length;
821
+ continue;
822
+ }
823
+ }
824
+ cursor++;
825
+ }
826
+ return candidate;
827
+ }
828
+ function isSwitchClauseBlockOpenBrace(source, colonIndex, rangeStart, enclosingOpenBrace) {
829
+ const searchStart = Math.max(rangeStart, (enclosingOpenBrace?.index ?? rangeStart - 1) + 1);
830
+ const clauseStart = switchClauseStartBeforeColon(source, searchStart, colonIndex);
831
+ if (clauseStart === null)
832
+ return false;
833
+ const clausePrefix = normalizedDeclarationPrefix(source, clauseStart, colonIndex).trim();
834
+ return clausePrefix === "default" || /^case\b[\s\S]*\S$/.test(clausePrefix);
835
+ }
836
+ function canEndStatementBeforeLineTerminator(source, previousTokenIndex, completedRegexLiteralEnds) {
837
+ const char = source[previousTokenIndex];
838
+ if (char === ")" || char === "]" || char === "}")
839
+ return true;
840
+ if (char === '"' || char === "'" || char === "`")
841
+ return true;
842
+ if (char === "/") {
843
+ return completedRegexLiteralEnds?.has(previousTokenIndex) === true ||
844
+ isCompletedRegexLiteralEnd(source, previousTokenIndex);
845
+ }
846
+ if (char === "+" && source[previousTokenIndex - 1] === "+")
847
+ return true;
848
+ if (char === "-" && source[previousTokenIndex - 1] === "-")
849
+ return true;
850
+ return isIdentifierPartAt(source, previousTokenIndex) ||
851
+ isIdentifierEscapeEndingAt(source, previousTokenIndex + 1);
852
+ }
853
+ function isTypeAliasDeclarationBeforeRegex(source, regexIndex, previousTokenIndex, rangeStart) {
854
+ if (!hasLineTerminatorBetween(source, previousTokenIndex + 1, regexIndex) ||
855
+ !canEndStatementBeforeLineTerminator(source, previousTokenIndex)) {
856
+ return false;
857
+ }
858
+ const separatorStart = Math.max(source.lastIndexOf(";", regexIndex - 1), source.lastIndexOf("{", regexIndex - 1), source.lastIndexOf("}", regexIndex - 1)) + 1;
859
+ if (!hasDeclarationKeywordBefore(source, separatorStart, regexIndex, ["export", "type"])) {
860
+ return false;
861
+ }
862
+ const declarationStart = balancedDeclarationStatementStartBefore(source, regexIndex, [
863
+ "export",
864
+ "type",
865
+ ]);
866
+ if (declarationStart < rangeStart)
867
+ return false;
868
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, regexIndex);
869
+ return TYPESCRIPT_TYPE_ALIAS_PREFIX_PATTERN.test(prefix);
870
+ }
871
+ function isTypeScriptAmbientDeclarationBeforeRegex(source, regexIndex, previousTokenIndex, rangeStart) {
872
+ if (!hasLineTerminatorBetween(source, previousTokenIndex + 1, regexIndex) ||
873
+ !canEndStatementBeforeLineTerminator(source, previousTokenIndex)) {
874
+ return false;
875
+ }
876
+ const separatorStart = Math.max(source.lastIndexOf(";", regexIndex - 1), source.lastIndexOf("{", regexIndex - 1), source.lastIndexOf("}", regexIndex - 1)) + 1;
877
+ if (!hasDeclarationKeywordBefore(source, separatorStart, regexIndex, ["declare", "export"])) {
878
+ return false;
879
+ }
880
+ const declarationStart = balancedDeclarationStatementStartBefore(source, regexIndex, [
881
+ "declare",
882
+ "export",
883
+ ]);
884
+ if (declarationStart < rangeStart)
885
+ return false;
886
+ const prefix = normalizedDeclarationPrefix(source, declarationStart, regexIndex);
887
+ return TYPESCRIPT_AMBIENT_DECLARATION_PREFIX_PATTERN.test(prefix);
888
+ }
889
+ function isCompletedRegexLiteralEnd(source, endIndex) {
890
+ for (let start = endIndex - 1; start >= 0; start--) {
891
+ if (source[start] !== "/")
892
+ continue;
893
+ const before = previousSignificantIndexBeforeIgnored(source, start);
894
+ const beforeChar = source[before];
895
+ const canStart = before < 0 ||
896
+ (beforeChar !== undefined && "([{=,:;!~?&|+-*%^<>".includes(beforeChar)) ||
897
+ [
898
+ "case",
899
+ "default",
900
+ "delete",
901
+ "do",
902
+ "else",
903
+ "extends",
904
+ "in",
905
+ "instanceof",
906
+ "new",
907
+ "await",
908
+ "break",
909
+ "continue",
910
+ "debugger",
911
+ "return",
912
+ "throw",
913
+ "typeof",
914
+ "void",
915
+ "yield",
916
+ ].includes(keywordBefore(source, start, before) ?? "");
917
+ if (!canStart)
918
+ continue;
919
+ if (skipRegexLiteral(source, start) === endIndex + 1)
920
+ return true;
921
+ }
922
+ return false;
923
+ }
924
+ function isInRawJsxText(textDepth, expressionDepth) {
925
+ return textDepth > expressionDepth;
926
+ }
927
+ function isPlainStatementBlockOpenBrace(source, rangeStart, openBraceIndex, previousTokenIndex, enclosingOpenBrace, completedRegexLiteralEnds) {
928
+ if (previousTokenIndex < rangeStart)
929
+ return true;
930
+ if (source[previousTokenIndex] === ";" || source[previousTokenIndex] === "}")
931
+ return true;
932
+ if (hasLineTerminatorBetween(source, previousTokenIndex + 1, openBraceIndex) &&
933
+ canEndStatementBeforeLineTerminator(source, previousTokenIndex, completedRegexLiteralEnds)) {
934
+ return true;
935
+ }
936
+ if (source[previousTokenIndex] !== ":")
937
+ return false;
938
+ const labelEnd = previousSignificantIndex(source, previousTokenIndex) + 1;
939
+ const labelStart = identifierStartBefore(source, labelEnd, rangeStart);
940
+ if (labelStart < labelEnd &&
941
+ isIdentifierStartOrEscapeAt(source, labelStart)) {
942
+ const beforeLabel = previousSignificantIndex(source, labelStart);
943
+ if (beforeLabel < rangeStart || source[beforeLabel] === ";" || source[beforeLabel] === "}") {
944
+ return true;
945
+ }
946
+ }
947
+ return isSwitchClauseBlockOpenBrace(source, previousTokenIndex, rangeStart, enclosingOpenBrace);
948
+ }
949
+ function openBraceContext(source, rangeStart, index, previousTokenIndex, matchingOpenParens, currentParen, enclosingOpenBrace, completedRegexLiteralEnds) {
950
+ return {
951
+ index,
952
+ previousTokenIndex,
953
+ isDeclarationBlock: isFunctionDeclarationBlockOpenBrace(source, previousTokenIndex, matchingOpenParens) || isTypeScriptFunctionDeclarationBlockOpenBrace(source, index, previousTokenIndex) ||
954
+ isClassDeclarationBlockOpenBrace(source, index, previousTokenIndex, currentParen) ||
955
+ isTypeScriptDeclarationBlockOpenBrace(source, index, previousTokenIndex),
956
+ isPlainStatementBlock: isPlainStatementBlockOpenBrace(source, rangeStart, index, previousTokenIndex, enclosingOpenBrace, completedRegexLiteralEnds),
957
+ };
958
+ }
959
+ function isDeclarationBlockCloseBrace(index, matchingOpenBraces) {
960
+ return matchingOpenBraces.get(index)?.isDeclarationBlock === true;
961
+ }
962
+ function isStatementBlockCloseBrace(source, index, matchingOpenBraces) {
963
+ const openBrace = matchingOpenBraces.get(index);
964
+ if (openBrace === undefined)
965
+ return false;
966
+ const keyword = keywordBefore(source, openBrace.index, openBrace.previousTokenIndex);
967
+ return keyword === "try" || keyword === "catch" || keyword === "finally" ||
968
+ keyword === "do" || keyword === "else";
969
+ }
970
+ function isPlainStatementBlockCloseBrace(index, matchingOpenBraces) {
971
+ return matchingOpenBraces.get(index)?.isPlainStatementBlock === true;
972
+ }
973
+ function isArrowFunctionBodyCloseBraceAtAsiBoundary(source, index, nextTokenIndex, matchingOpenBraces) {
974
+ const openBrace = matchingOpenBraces.get(index);
975
+ if (openBrace === undefined || source[openBrace.previousTokenIndex] !== ">")
976
+ return false;
977
+ const beforeArrow = previousSignificantIndex(source, openBrace.previousTokenIndex);
978
+ return source[beforeArrow] === "=" &&
979
+ hasLineTerminatorBetween(source, index + 1, nextTokenIndex);
980
+ }
981
+ function isForOfKeywordBefore(source, rangeStart, currentParen, previousTokenIndex) {
982
+ const keywordEnd = previousTokenIndex + 1;
983
+ let keywordStart = keywordEnd;
984
+ while (keywordStart > rangeStart && /[A-Za-z_$]/.test(source[keywordStart - 1] ?? "")) {
985
+ keywordStart--;
986
+ }
987
+ if (source.slice(keywordStart, keywordEnd) !== "of")
988
+ return false;
989
+ const beforeKeyword = previousSignificantIndex(source, keywordStart);
990
+ if (beforeKeyword >= rangeStart && source[beforeKeyword] === ".")
991
+ return false;
992
+ const beforeKeywordChar = source[beforeKeyword];
993
+ if (!isIdentifierPartAt(source, beforeKeyword) &&
994
+ beforeKeywordChar !== "]" &&
995
+ beforeKeywordChar !== "}" &&
996
+ beforeKeywordChar !== ")") {
997
+ return false;
998
+ }
999
+ return currentParen?.isForHeader === true && !currentParen.hasSemicolon;
1000
+ }
1001
+ function createModuleDeclarationTracker(source, rangeStart) {
1002
+ let cursor = rangeStart;
1003
+ let atStatementStart = true;
1004
+ let parenDepth = 0;
1005
+ let braceDepth = 0;
1006
+ let bracketDepth = 0;
1007
+ let candidate = null;
1008
+ return (end) => {
1009
+ while (cursor <= end) {
1010
+ const skipped = skipIgnored(source, cursor);
1011
+ if (skipped !== cursor) {
1012
+ if (source[cursor] === "/" && source[cursor + 1] === "/") {
1013
+ atStatementStart = true;
1014
+ }
1015
+ else if (source[cursor] === "/" &&
1016
+ source[cursor + 1] === "*" &&
1017
+ hasLineTerminatorBetween(source, cursor + 2, skipped - 2)) {
1018
+ atStatementStart = true;
1019
+ }
1020
+ else {
1021
+ atStatementStart = false;
1022
+ }
1023
+ cursor = skipped;
1024
+ continue;
1025
+ }
1026
+ const char = source[cursor];
1027
+ if (char === "(")
1028
+ parenDepth++;
1029
+ else if (char === ")" && parenDepth > 0)
1030
+ parenDepth--;
1031
+ else if (char === "{")
1032
+ braceDepth++;
1033
+ else if (char === "}" && braceDepth > 0)
1034
+ braceDepth--;
1035
+ else if (char === "[")
1036
+ bracketDepth++;
1037
+ else if (char === "]" && bracketDepth > 0)
1038
+ bracketDepth--;
1039
+ const atTopLevel = parenDepth === 0 && braceDepth === 0 && bracketDepth === 0;
1040
+ if (atTopLevel && char === ";") {
1041
+ candidate = null;
1042
+ atStatementStart = true;
1043
+ cursor++;
1044
+ continue;
1045
+ }
1046
+ if (atTopLevel && char !== undefined && isLineTerminator(char)) {
1047
+ atStatementStart = true;
1048
+ cursor++;
1049
+ continue;
1050
+ }
1051
+ if (/\s/.test(char ?? "")) {
1052
+ cursor++;
1053
+ continue;
1054
+ }
1055
+ if (atTopLevel && atStatementStart) {
1056
+ if (source.startsWith("import", cursor) &&
1057
+ !isIdentifierBoundaryBefore(source, cursor) &&
1058
+ !isIdentifierBoundaryAfter(source, cursor + "import".length)) {
1059
+ candidate = { keyword: "import", index: cursor };
1060
+ atStatementStart = false;
1061
+ cursor += "import".length;
1062
+ continue;
1063
+ }
1064
+ if (source.startsWith("export", cursor) &&
1065
+ !isIdentifierBoundaryBefore(source, cursor) &&
1066
+ !isIdentifierBoundaryAfter(source, cursor + "export".length)) {
1067
+ candidate = { keyword: "export", index: cursor };
1068
+ atStatementStart = false;
1069
+ cursor += "export".length;
1070
+ continue;
1071
+ }
1072
+ }
1073
+ if (atTopLevel)
1074
+ atStatementStart = false;
1075
+ cursor++;
1076
+ }
1077
+ return candidate;
1078
+ };
1079
+ }
1080
+ function isCompletedModuleDeclarationBeforeRegex(source, index, previousTokenIndex, moduleDeclarationBefore) {
1081
+ if (!hasLineTerminatorBetween(source, previousTokenIndex + 1, index))
1082
+ return false;
1083
+ const declaration = moduleDeclarationBefore(previousTokenIndex);
1084
+ if (declaration === null)
1085
+ return false;
1086
+ const declarationSource = normalizedDeclarationPrefix(source, declaration.index, previousTokenIndex + 1).trim();
1087
+ if (declaration.keyword === "import") {
1088
+ return (/^import\s*["'`][\s\S]*["'`]$/.test(declarationSource) ||
1089
+ /^import\b[\s\S]*\bfrom\s*["'`][\s\S]*["'`]$/.test(declarationSource)) && !/^import\s*[.(]/.test(declarationSource);
1090
+ }
1091
+ return /^export\b[\s\S]*\bfrom\s*["'`][\s\S]*["'`]$/.test(declarationSource) ||
1092
+ /^export\s+(?:type\s+)?\{[\s\S]*\}$/.test(declarationSource);
1093
+ }
1094
+ function isCompletedLocalExportListBeforeRegex(source, index, previousTokenIndex, statementStart) {
1095
+ if (!hasLineTerminatorBetween(source, previousTokenIndex + 1, index))
1096
+ return false;
1097
+ const declarationSource = normalizedDeclarationPrefix(source, statementStart, previousTokenIndex + 1).trim();
1098
+ return /^(?:type\s+)?\{[\s\S]*\}$/.test(declarationSource);
1099
+ }
1100
+ function isPostfixNonNullAssertionBefore(source, index, rangeStart) {
1101
+ const beforeBang = previousSignificantIndexBeforeIgnored(source, index);
1102
+ return beforeBang >= rangeStart &&
1103
+ !hasLineTerminatorBetween(source, beforeBang + 1, index) &&
1104
+ canEndStatementBeforeLineTerminator(source, beforeBang);
1105
+ }
1106
+ function isCompletedTypeArgumentListBefore(source, closeIndex, rangeStart) {
1107
+ let cursor = closeIndex - 1;
1108
+ let angleDepth = 1;
1109
+ let parenDepth = 0;
1110
+ let braceDepth = 0;
1111
+ let bracketDepth = 0;
1112
+ let sawTypeContent = false;
1113
+ while (cursor >= rangeStart) {
1114
+ const char = source[cursor];
1115
+ if (char === ")")
1116
+ parenDepth++;
1117
+ else if (char === "(" && parenDepth > 0)
1118
+ parenDepth--;
1119
+ else if (char === "}")
1120
+ braceDepth++;
1121
+ else if (char === "{" && braceDepth > 0)
1122
+ braceDepth--;
1123
+ else if (char === "]")
1124
+ bracketDepth++;
1125
+ else if (char === "[" && bracketDepth > 0)
1126
+ bracketDepth--;
1127
+ else if (parenDepth === 0 && braceDepth === 0 && bracketDepth === 0) {
1128
+ if (char === ">") {
1129
+ angleDepth++;
1130
+ }
1131
+ else if (char === "<") {
1132
+ angleDepth--;
1133
+ if (angleDepth === 0) {
1134
+ const beforeOpen = previousSignificantIndexBeforeIgnored(source, cursor);
1135
+ const beforeOpenChar = source[beforeOpen];
1136
+ return sawTypeContent && beforeOpen >= rangeStart &&
1137
+ (isIdentifierPartAt(source, beforeOpen) ||
1138
+ isIdentifierEscapeEndingAt(source, beforeOpen + 1) ||
1139
+ beforeOpenChar === ")" ||
1140
+ beforeOpenChar === "]");
1141
+ }
1142
+ }
1143
+ else if (!/\s/.test(char ?? "")) {
1144
+ sawTypeContent = true;
1145
+ }
1146
+ }
1147
+ else if (!/\s/.test(char ?? "")) {
1148
+ sawTypeContent = true;
1149
+ }
1150
+ cursor--;
1151
+ }
1152
+ return false;
1153
+ }
1154
+ function canStartRegexLiteral(source, index, rangeStart, matchingOpenBraces, matchingOpenParens, currentParen, previousTokenIndex, moduleDeclarationBefore) {
1155
+ const previous = previousTokenIndex;
1156
+ if (previous < rangeStart)
1157
+ return true;
1158
+ if (isCompletedModuleDeclarationBeforeRegex(source, index, previous, moduleDeclarationBefore))
1159
+ return true;
1160
+ const char = source[previous];
1161
+ if (char === ")" &&
1162
+ isControlConditionCloseParen(previous, rangeStart, matchingOpenParens))
1163
+ return true;
1164
+ if (char === "}" &&
1165
+ (isControlBlockCloseBrace(source, previous, rangeStart, matchingOpenBraces, matchingOpenParens) ||
1166
+ isDeclarationBlockCloseBrace(previous, matchingOpenBraces) ||
1167
+ isStatementBlockCloseBrace(source, previous, matchingOpenBraces) ||
1168
+ isPlainStatementBlockCloseBrace(previous, matchingOpenBraces) ||
1169
+ isArrowFunctionBodyCloseBraceAtAsiBoundary(source, previous, index, matchingOpenBraces)))
1170
+ return true;
1171
+ if ((char === "+" || char === "-") &&
1172
+ previous - 1 >= rangeStart &&
1173
+ source[previous - 1] === char) {
1174
+ return false;
1175
+ }
1176
+ if (char === "." &&
1177
+ previous - 2 >= rangeStart &&
1178
+ source[previous - 1] === "." &&
1179
+ source[previous - 2] === ".") {
1180
+ return true;
1181
+ }
1182
+ if (char === "!")
1183
+ return !isPostfixNonNullAssertionBefore(source, previous, rangeStart);
1184
+ if (char === ">" && isCompletedTypeArgumentListBefore(source, previous, rangeStart)) {
1185
+ return false;
1186
+ }
1187
+ if (char !== undefined && "([{=,:;~?&|+-*%^<>".includes(char))
1188
+ return true;
1189
+ const keyword = keywordBefore(source, index, previous);
1190
+ // One gate for every keyword in the list below, rather than a guard per
1191
+ // keyword: one added later inherits it automatically.
1192
+ if (keyword !== null && isMemberNameBefore(source, previous))
1193
+ return false;
1194
+ if (keyword === "of") {
1195
+ return isForOfKeywordBefore(source, rangeStart, currentParen, previous);
1196
+ }
1197
+ const isKeywordRegexPrefix = [
1198
+ "case",
1199
+ "default",
1200
+ "delete",
1201
+ "do",
1202
+ "else",
1203
+ "extends",
1204
+ "in",
1205
+ "instanceof",
1206
+ "new",
1207
+ "await",
1208
+ "break",
1209
+ "continue",
1210
+ "debugger",
1211
+ "return",
1212
+ "throw",
1213
+ "typeof",
1214
+ "void",
1215
+ "yield",
1216
+ ].includes(keyword ?? "");
1217
+ if (isKeywordRegexPrefix)
1218
+ return true;
1219
+ if (isTypeAliasDeclarationBeforeRegex(source, index, previous, rangeStart))
1220
+ return true;
1221
+ if (isTypeScriptAmbientDeclarationBeforeRegex(source, index, previous, rangeStart))
1222
+ return true;
1223
+ return restrictedStatementKeywordBeforeLabel(source, index, previous, rangeStart) !== null;
1224
+ }
1225
+ function skipRegexLiteral(source, regexIndex) {
1226
+ let cursor = regexIndex + 1;
1227
+ let inCharacterClass = false;
1228
+ while (cursor < source.length) {
1229
+ const char = source[cursor];
1230
+ if (char === "\\") {
1231
+ cursor += 2;
1232
+ continue;
1233
+ }
1234
+ if (char === "[" && !inCharacterClass) {
1235
+ inCharacterClass = true;
1236
+ cursor++;
1237
+ continue;
1238
+ }
1239
+ if (char === "]" && inCharacterClass) {
1240
+ inCharacterClass = false;
1241
+ cursor++;
1242
+ continue;
1243
+ }
1244
+ if (char === "/" && !inCharacterClass) {
1245
+ cursor++;
1246
+ while (/[A-Za-z]/.test(source[cursor] ?? ""))
1247
+ cursor++;
1248
+ return cursor;
1249
+ }
1250
+ cursor++;
1251
+ }
1252
+ return source.length;
1253
+ }
1254
+ function canStartRawJsxOpeningTag(source, index) {
1255
+ if (source[index - 1] === "<")
1256
+ return false;
1257
+ const previous = previousSignificantIndex(source, index);
1258
+ if (previous < 0)
1259
+ return true;
1260
+ const char = source[previous];
1261
+ if (char !== undefined && "([{=,:;!~?&|+-*%^<>".includes(char))
1262
+ return true;
1263
+ if (char === "}")
1264
+ return true;
1265
+ const keyword = keywordBefore(source, index, previous);
1266
+ return ["case", "default", "return", "throw", "yield"].includes(keyword ?? "");
1267
+ }
1268
+ function rawJsxTagName(source, index) {
1269
+ if (source[index] === ">")
1270
+ return { name: null, end: index };
1271
+ let cursor = index;
1272
+ while (cursor < source.length) {
1273
+ const char = source[cursor];
1274
+ if (char === "." ||
1275
+ char === ":" ||
1276
+ char === "-" ||
1277
+ isIdentifierStartAt(source, cursor) ||
1278
+ IDENTIFIER_PART_PATTERN.test(char ?? "")) {
1279
+ cursor++;
1280
+ continue;
1281
+ }
1282
+ break;
1283
+ }
1284
+ return { name: source.slice(index, cursor), end: cursor };
1285
+ }
1286
+ function findParenEnd(source, index) {
1287
+ let cursor = index + 1;
1288
+ let depth = 1;
1289
+ while (cursor < source.length) {
1290
+ const skipped = skipIgnored(source, cursor);
1291
+ if (skipped !== cursor) {
1292
+ cursor = skipped;
1293
+ continue;
1294
+ }
1295
+ if (source[cursor] === "(")
1296
+ depth++;
1297
+ else if (source[cursor] === ")") {
1298
+ depth--;
1299
+ if (depth === 0)
1300
+ return cursor + 1;
1301
+ }
1302
+ cursor++;
1303
+ }
1304
+ return null;
1305
+ }
1306
+ function createRawJsxLookaheadCache() {
1307
+ return { closingTagsByStatementEnd: new Map(), statementEnds: [], statementEndCursor: 0 };
1308
+ }
1309
+ function statementEndAfter(source, start, cache) {
1310
+ if (cache !== undefined) {
1311
+ const ranges = cache.statementEnds;
1312
+ let rangeIndex = Math.min(cache.statementEndCursor, ranges.length - 1);
1313
+ if (rangeIndex >= 0) {
1314
+ if (start < ranges[rangeIndex].start) {
1315
+ let low = 0;
1316
+ let high = rangeIndex;
1317
+ while (low <= high) {
1318
+ const mid = Math.floor((low + high) / 2);
1319
+ const range = ranges[mid];
1320
+ if (start < range.start)
1321
+ high = mid - 1;
1322
+ else if (start >= range.end)
1323
+ low = mid + 1;
1324
+ else {
1325
+ cache.statementEndCursor = mid;
1326
+ return range.end;
1327
+ }
1328
+ }
1329
+ }
1330
+ else {
1331
+ while (rangeIndex < ranges.length && start >= ranges[rangeIndex].end)
1332
+ rangeIndex++;
1333
+ if (rangeIndex < ranges.length &&
1334
+ start >= ranges[rangeIndex].start &&
1335
+ start < ranges[rangeIndex].end) {
1336
+ cache.statementEndCursor = rangeIndex;
1337
+ return ranges[rangeIndex].end;
1338
+ }
1339
+ }
1340
+ }
1341
+ }
1342
+ const end = nextStatementCursor(source, start);
1343
+ cache?.statementEnds.push({ start, end });
1344
+ if (cache !== undefined)
1345
+ cache.statementEndCursor = cache.statementEnds.length - 1;
1346
+ return end;
1347
+ }
1348
+ function hasRawJsxClosingTagBeforeStatementEnd(source, name, start, cache) {
1349
+ const statementEnd = statementEndAfter(source, start, cache);
1350
+ const cached = cache?.closingTagsByStatementEnd.get(statementEnd);
1351
+ const index = cached !== undefined && start >= cached.start
1352
+ ? cached
1353
+ : indexRawJsxClosingTags(source, start, statementEnd);
1354
+ if (cache !== undefined && index !== cached) {
1355
+ cache.closingTagsByStatementEnd.set(statementEnd, index);
1356
+ }
1357
+ const positions = index.tags.get(name);
1358
+ if (positions !== undefined && hasPositionAtOrAfter(positions, start))
1359
+ return true;
1360
+ return hasRawJsxClosingTagAcrossText(source, name, start, statementEnd);
1361
+ }
1362
+ function indexRawJsxClosingTags(source, start, statementEnd) {
1363
+ const tags = new Map();
1364
+ let closing = source.indexOf("<", start);
1365
+ while (closing >= 0 && closing < statementEnd) {
1366
+ if (source[closing + 1] === "/") {
1367
+ const tag = rawJsxTagName(source, closing + 2);
1368
+ const afterName = source[tag.end];
1369
+ if (tag.name !== null && tag.name !== "" &&
1370
+ (afterName === ">" || afterName === "/" || /\s/.test(afterName ?? ""))) {
1371
+ let positions = tags.get(tag.name);
1372
+ if (positions === undefined) {
1373
+ positions = [];
1374
+ tags.set(tag.name, positions);
1375
+ }
1376
+ positions.push(closing);
1377
+ }
1378
+ }
1379
+ closing = source.indexOf("<", closing + 1);
1380
+ }
1381
+ return { start, tags };
1382
+ }
1383
+ function identifierAt(source, index) {
1384
+ if (!isIdentifierStartAt(source, index))
1385
+ return null;
1386
+ let cursor = index + 1;
1387
+ while (cursor < source.length && isIdentifierPartAt(source, cursor))
1388
+ cursor++;
1389
+ return source.slice(index, cursor);
1390
+ }
1391
+ function looksLikeStatementAfterJsxTextBreak(source, index) {
1392
+ const start = skipWhitespace(source, index);
1393
+ const keyword = identifierAt(source, start);
1394
+ return keyword !== null && JSX_TEXT_BREAK_STATEMENT_KEYWORDS.has(keyword);
1395
+ }
1396
+ function hasRawJsxClosingTagAcrossText(source, name, start, statementEnd) {
1397
+ const limit = Math.min(source.length, start + MAX_RAW_JSX_TEXT_CLOSING_LOOKAHEAD);
1398
+ let cursor = start;
1399
+ while (cursor < limit) {
1400
+ const char = source[cursor];
1401
+ if (char === "<") {
1402
+ if (source[cursor + 1] !== "/")
1403
+ return false;
1404
+ const tag = rawJsxTagName(source, cursor + 2);
1405
+ const afterName = source[tag.end];
1406
+ return tag.name === name &&
1407
+ (afterName === ">" || afterName === "/" || /\s/.test(afterName ?? ""));
1408
+ }
1409
+ if (char === "{") {
1410
+ const expressionEnd = findTemplateExpressionEnd(source, cursor + 1);
1411
+ if (expressionEnd === null)
1412
+ return false;
1413
+ cursor = expressionEnd + 1;
1414
+ continue;
1415
+ }
1416
+ if (char === "}" || char === ")" || char === "]")
1417
+ return false;
1418
+ if (cursor >= statementEnd &&
1419
+ (char === ";" || (char !== undefined && isLineTerminator(char))) &&
1420
+ looksLikeStatementAfterJsxTextBreak(source, cursor + 1)) {
1421
+ return false;
1422
+ }
1423
+ cursor++;
1424
+ }
1425
+ return false;
1426
+ }
1427
+ function hasPositionAtOrAfter(positions, start) {
1428
+ let low = 0;
1429
+ let high = positions.length;
1430
+ while (low < high) {
1431
+ const mid = Math.floor((low + high) / 2);
1432
+ if (positions[mid] < start)
1433
+ low = mid + 1;
1434
+ else
1435
+ high = mid;
1436
+ }
1437
+ return low < positions.length;
1438
+ }
1439
+ function looksLikeTypeScriptAngleConstruct(source, tagStart, tagEnd, name, cache) {
1440
+ if (name === null)
1441
+ return false;
1442
+ const next = skipWhitespaceAndComments(source, tagEnd);
1443
+ if (source[next] === "(") {
1444
+ const parenEnd = findParenEnd(source, next);
1445
+ const afterParen = parenEnd === null ? -1 : skipWhitespaceAndComments(source, parenEnd);
1446
+ if (afterParen >= 0 && source.slice(afterParen, afterParen + 2) === "=>") {
1447
+ return true;
1448
+ }
1449
+ }
1450
+ const quotedValueEnd = source[next] === '"' || source[next] === "'"
1451
+ ? skipIgnored(source, next)
1452
+ : next;
1453
+ if (source[next] !== undefined &&
1454
+ (isIdentifierStartAt(source, next) || source[next] === "(" || quotedValueEnd !== next) &&
1455
+ !hasRawJsxClosingTagBeforeStatementEnd(source, name, quotedValueEnd, cache)) {
1456
+ const before = previousSignificantIndex(source, tagStart);
1457
+ return before >= 0 && "=(:,[!~?&|+-*%^<>".includes(source[before] ?? "");
1458
+ }
1459
+ return false;
1460
+ }
1461
+ function readRawJsxTag(source, index, options = {}) {
1462
+ if (source[index] !== "<")
1463
+ return null;
1464
+ const isClosingTag = source[index + 1] === "/";
1465
+ if (!canStartRawJsxOpeningTag(source, index) &&
1466
+ !(isClosingTag && options.allowClosingTagAfterText === true)) {
1467
+ return null;
1468
+ }
1469
+ const nameStart = isClosingTag ? index + 2 : index + 1;
1470
+ if (source[nameStart] !== ">" && !isIdentifierStartAt(source, nameStart))
1471
+ return null;
1472
+ const name = rawJsxTagName(source, nameStart).name;
1473
+ let cursor = nameStart;
1474
+ let quote = null;
1475
+ const expressionRanges = [];
1476
+ while (cursor < source.length) {
1477
+ const char = source[cursor];
1478
+ if (quote !== null) {
1479
+ if (char === "\\") {
1480
+ cursor += 2;
1481
+ continue;
1482
+ }
1483
+ if (char === quote)
1484
+ quote = null;
1485
+ cursor++;
1486
+ continue;
20
1487
  }
21
- if (expected !== undefined && source.slice(start, end) !== expected) {
22
- throw INVALID_ARGUMENT.create({
23
- detail: `Source replacement span did not match expected text: ${expected}`,
24
- });
1488
+ if (char === '"' || char === "'") {
1489
+ quote = char;
1490
+ cursor++;
1491
+ continue;
25
1492
  }
26
- result = result.slice(0, start) + replacement + result.slice(end);
1493
+ if (char === "{") {
1494
+ const expressionEnd = findTemplateExpressionEnd(source, cursor + 1);
1495
+ if (expressionEnd === null)
1496
+ return null;
1497
+ expressionRanges.push({ start: cursor + 1, end: expressionEnd });
1498
+ cursor = expressionEnd + 1;
1499
+ continue;
1500
+ }
1501
+ if (char === ">") {
1502
+ const beforeClose = previousSignificantIndex(source, cursor);
1503
+ const isSelfClosingTag = !isClosingTag && source[beforeClose] === "/";
1504
+ if (!isClosingTag &&
1505
+ !isSelfClosingTag &&
1506
+ looksLikeTypeScriptAngleConstruct(source, index, cursor + 1, name, options.lookaheadCache)) {
1507
+ return null;
1508
+ }
1509
+ return {
1510
+ end: cursor + 1,
1511
+ expressionRanges,
1512
+ name,
1513
+ isClosingTag,
1514
+ isSelfClosingTag,
1515
+ };
1516
+ }
1517
+ cursor++;
27
1518
  }
28
- return result;
1519
+ return null;
29
1520
  }
30
- function isIdentifierChar(char) {
31
- return char !== undefined && /[A-Za-z0-9_$]/.test(char);
1521
+ function skipRawJsxTag(source, index, lookaheadCache) {
1522
+ return readRawJsxTag(source, index, { lookaheadCache })?.end ?? index;
32
1523
  }
33
- function isStatementKeywordAt(source, index, keyword) {
34
- if (!source.startsWith(keyword, index))
35
- return false;
36
- if (isIdentifierChar(source[index - 1]) || source[index - 1] === ".")
37
- return false;
38
- if (isIdentifierChar(source[index + keyword.length]))
39
- return false;
40
- const lineStart = source.lastIndexOf("\n", index - 1) + 1;
41
- return /^[\t ]*$/.test(source.slice(lineStart, index));
1524
+ function skipRawJsxText(source, index) {
1525
+ const nextTag = source.indexOf("<", index);
1526
+ const nextExpression = source.indexOf("{", index);
1527
+ if (nextTag === -1)
1528
+ return nextExpression === -1 ? source.length : nextExpression;
1529
+ if (nextExpression === -1)
1530
+ return nextTag;
1531
+ return Math.min(nextTag, nextExpression);
42
1532
  }
43
- function skipIgnored(source, index) {
1533
+ function skipExpressionIgnored(source, index, rangeStart, depth, matchingOpenBraces, matchingOpenParens, currentParen, previousTokenIndex, moduleDeclarationBefore, rawJsxLookaheadCache, completedRegexLiteralEnds) {
44
1534
  const char = source[index];
45
1535
  const next = source[index + 1];
1536
+ const jsxTagEnd = skipRawJsxTag(source, index, rawJsxLookaheadCache);
1537
+ if (jsxTagEnd !== index)
1538
+ return jsxTagEnd;
46
1539
  if (char === "/" && next === "/") {
47
- const newline = source.indexOf("\n", index + 2);
48
- return newline === -1 ? source.length : newline + 1;
1540
+ return skipLineComment(source, index);
49
1541
  }
50
1542
  if (char === "/" && next === "*") {
51
1543
  const end = source.indexOf("*/", index + 2);
52
1544
  return end === -1 ? source.length : end + 2;
53
1545
  }
54
- if (char === '"' || char === "'" || char === "`") {
55
- let cursor = index + 1;
56
- while (cursor < source.length) {
57
- if (source[cursor] === "\\") {
58
- cursor += 2;
59
- continue;
60
- }
61
- if (source[cursor] === char)
62
- return cursor + 1;
63
- cursor++;
64
- }
65
- return source.length;
1546
+ if (char === '"' || char === "'")
1547
+ return skipIgnored(source, index);
1548
+ if (char === "`")
1549
+ return skipFullTemplateLiteral(source, index, depth + 1);
1550
+ if (char === "/" &&
1551
+ canStartRegexLiteral(source, index, rangeStart, matchingOpenBraces, matchingOpenParens, currentParen, previousTokenIndex, moduleDeclarationBefore)) {
1552
+ const end = skipRegexLiteral(source, index);
1553
+ completedRegexLiteralEnds?.add(end - 1);
1554
+ return end;
66
1555
  }
67
1556
  return index;
68
1557
  }
69
- function skipWhitespace(source, index) {
70
- let cursor = index;
71
- while (/\s/.test(source[cursor] ?? ""))
72
- cursor++;
73
- return cursor;
1558
+ function tokenIndexAfterIgnored(source, index, skipped, previousTokenIndex) {
1559
+ const isComment = source[index] === "/" &&
1560
+ (source[index + 1] === "/" || source[index + 1] === "*");
1561
+ return isComment ? previousTokenIndex : Math.max(index, skipped - 1);
74
1562
  }
75
- // Comments are legal wherever whitespace is, so a dynamic import can carry a
76
- // bundler hint between the keyword, the parentheses and the specifier. Treating
77
- // the comment as an unexpected character would leave the specifier unresolved.
78
- function skipWhitespaceAndComments(source, index) {
79
- let cursor = index;
1563
+ function isPropertyAccessBeforeImport(source, previousTokenIndex, rangeStart) {
1564
+ const previous = source[previousTokenIndex];
1565
+ if (previous === "#")
1566
+ return true;
1567
+ if (previous !== ".")
1568
+ return false;
1569
+ const isSpread = previousTokenIndex - 2 >= rangeStart &&
1570
+ source[previousTokenIndex - 1] === "." &&
1571
+ source[previousTokenIndex - 2] === ".";
1572
+ return !isSpread;
1573
+ }
1574
+ function findTemplateExpressionEnd(source, expressionIndex, depth = 0) {
1575
+ assertTemplateLiteralDepth(depth);
1576
+ let cursor = expressionIndex;
1577
+ let braceDepth = 1;
1578
+ const openBraces = [];
1579
+ const matchingOpenBraces = new Map();
1580
+ const openParens = [];
1581
+ const matchingOpenParens = new Map();
1582
+ let previousTokenIndex = expressionIndex - 1;
1583
+ const moduleDeclarationBefore = createModuleDeclarationTracker(source, expressionIndex);
1584
+ const rawJsxLookaheadCache = createRawJsxLookaheadCache();
1585
+ const completedRegexLiteralEnds = new Set();
1586
+ let rawJsxTextDepth = 0;
1587
+ let rawJsxExpressionBraceDepth = 0;
1588
+ const rawJsxExpressionBraceStack = [];
80
1589
  while (cursor < source.length) {
81
- const afterWhitespace = skipWhitespace(source, cursor);
82
- const char = source[afterWhitespace];
83
- const next = source[afterWhitespace + 1];
84
- if (char === "/" && (next === "/" || next === "*")) {
85
- cursor = skipIgnored(source, afterWhitespace);
1590
+ const jsxTag = readRawJsxTag(source, cursor, {
1591
+ allowClosingTagAfterText: isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth),
1592
+ lookaheadCache: rawJsxLookaheadCache,
1593
+ });
1594
+ if (jsxTag !== null) {
1595
+ if (jsxTag.isClosingTag) {
1596
+ rawJsxTextDepth = Math.max(0, rawJsxTextDepth - 1);
1597
+ }
1598
+ else if (!jsxTag.isSelfClosingTag) {
1599
+ rawJsxTextDepth++;
1600
+ }
1601
+ previousTokenIndex = jsxTag.end - 1;
1602
+ cursor = jsxTag.end;
86
1603
  continue;
87
1604
  }
88
- return afterWhitespace;
89
- }
90
- return cursor;
91
- }
92
- function nextStatementCursor(source, index) {
93
- const semicolon = source.indexOf(";", index);
94
- const newline = source.indexOf("\n", index);
95
- const candidates = [semicolon, newline].filter((position) => position >= 0);
96
- if (candidates.length === 0)
97
- return source.length;
98
- return Math.min(...candidates) + 1;
99
- }
100
- function readQuotedSpecifier(source, quoteIndex) {
101
- const quote = source[quoteIndex];
102
- if (quote !== '"' && quote !== "'")
103
- return null;
104
- let cursor = quoteIndex + 1;
105
- while (cursor < source.length) {
106
- if (source[cursor] === "\\") {
107
- cursor += 2;
1605
+ if (isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth)) {
1606
+ const textEnd = skipRawJsxText(source, cursor);
1607
+ if (textEnd !== cursor) {
1608
+ cursor = textEnd;
1609
+ continue;
1610
+ }
1611
+ }
1612
+ const skipped = skipExpressionIgnored(source, cursor, expressionIndex, depth, matchingOpenBraces, matchingOpenParens, openParens.at(-1), previousTokenIndex, moduleDeclarationBefore, rawJsxLookaheadCache, completedRegexLiteralEnds);
1613
+ if (skipped !== cursor) {
1614
+ previousTokenIndex = tokenIndexAfterIgnored(source, cursor, skipped, previousTokenIndex);
1615
+ cursor = skipped;
108
1616
  continue;
109
1617
  }
110
- if (source[cursor] === quote) {
111
- return {
112
- end: cursor + 1,
113
- specifier: source.slice(quoteIndex + 1, cursor),
114
- };
1618
+ if (source[cursor] === "{") {
1619
+ const isRawJsxExpressionBrace = isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth);
1620
+ rawJsxExpressionBraceStack.push(isRawJsxExpressionBrace);
1621
+ if (isRawJsxExpressionBrace)
1622
+ rawJsxExpressionBraceDepth++;
1623
+ openBraces.push(openBraceContext(source, expressionIndex, cursor, previousTokenIndex, matchingOpenParens, openParens.at(-1), openBraces.at(-1), completedRegexLiteralEnds));
1624
+ braceDepth++;
1625
+ previousTokenIndex = cursor;
1626
+ cursor++;
1627
+ continue;
115
1628
  }
1629
+ if (source[cursor] === "}") {
1630
+ braceDepth--;
1631
+ if (braceDepth === 0)
1632
+ return cursor;
1633
+ const isRawJsxExpressionBrace = rawJsxExpressionBraceStack.pop();
1634
+ if (isRawJsxExpressionBrace) {
1635
+ rawJsxExpressionBraceDepth = Math.max(0, rawJsxExpressionBraceDepth - 1);
1636
+ }
1637
+ const openBrace = openBraces.pop();
1638
+ if (openBrace !== undefined)
1639
+ matchingOpenBraces.set(cursor, openBrace);
1640
+ previousTokenIndex = cursor;
1641
+ cursor++;
1642
+ continue;
1643
+ }
1644
+ if (source[cursor] === "(") {
1645
+ openParens.push(openParenContext(source, cursor, previousTokenIndex));
1646
+ previousTokenIndex = cursor;
1647
+ cursor++;
1648
+ continue;
1649
+ }
1650
+ if (source[cursor] === ")") {
1651
+ const openParen = openParens.pop();
1652
+ if (openParen !== undefined)
1653
+ matchingOpenParens.set(cursor, openParen);
1654
+ previousTokenIndex = cursor;
1655
+ cursor++;
1656
+ continue;
1657
+ }
1658
+ if (source[cursor] === ";" && openParens.at(-1)?.isForHeader) {
1659
+ openParens.at(-1).hasSemicolon = true;
1660
+ }
1661
+ if (!/\s/.test(source[cursor] ?? ""))
1662
+ previousTokenIndex = cursor;
116
1663
  cursor++;
117
1664
  }
118
1665
  return null;
119
1666
  }
120
- function findFromSpan(source, statementStart, matcher) {
1667
+ function findFromSpan(source, statementStart, matcher, isExportDeclaration) {
121
1668
  let cursor = statementStart;
1669
+ let previousTokenIndex = previousSignificantIndexBeforeIgnored(source, statementStart);
1670
+ const matchingOpenBraces = new Map();
1671
+ const matchingOpenParens = new Map();
1672
+ const moduleDeclarationBefore = () => null;
122
1673
  while (cursor < source.length) {
123
1674
  const skipped = skipIgnored(source, cursor);
124
1675
  if (skipped !== cursor) {
1676
+ previousTokenIndex = tokenIndexAfterIgnored(source, cursor, skipped, previousTokenIndex);
125
1677
  cursor = skipped;
126
1678
  continue;
127
1679
  }
128
1680
  if (source[cursor] === ";")
129
1681
  return null;
1682
+ if (isExportDeclaration &&
1683
+ source[cursor] === "/" &&
1684
+ isCompletedLocalExportListBeforeRegex(source, cursor, previousTokenIndex, statementStart)) {
1685
+ return null;
1686
+ }
1687
+ if (source[cursor] === "/" &&
1688
+ canStartRegexLiteral(source, cursor, statementStart, matchingOpenBraces, matchingOpenParens, undefined, previousTokenIndex, moduleDeclarationBefore)) {
1689
+ cursor = skipRegexLiteral(source, cursor);
1690
+ previousTokenIndex = cursor - 1;
1691
+ continue;
1692
+ }
130
1693
  if (source.startsWith("from", cursor) &&
131
- !isIdentifierChar(source[cursor - 1]) &&
132
- !isIdentifierChar(source[cursor + 4])) {
133
- const quoteIndex = skipWhitespace(source, cursor + 4);
1694
+ !isIdentifierPartAt(source, cursor - 1) &&
1695
+ !isIdentifierPartAt(source, cursor + 4)) {
1696
+ const quoteIndex = skipWhitespaceAndComments(source, cursor + 4);
134
1697
  const quoted = readQuotedSpecifier(source, quoteIndex);
135
1698
  if (!quoted) {
136
1699
  cursor++;
@@ -146,10 +1709,21 @@ function findFromSpan(source, statementStart, matcher) {
146
1709
  end: quoted.end,
147
1710
  };
148
1711
  }
1712
+ if (!/\s/.test(source[cursor] ?? ""))
1713
+ previousTokenIndex = cursor;
149
1714
  cursor++;
150
1715
  }
151
1716
  return null;
152
1717
  }
1718
+ function canExportHaveFromClause(source, statementStart) {
1719
+ let cursor = skipWhitespaceAndComments(source, statementStart);
1720
+ if (source.startsWith("type", cursor) &&
1721
+ !isIdentifierPartAt(source, cursor - 1) &&
1722
+ !isIdentifierPartAt(source, cursor + "type".length)) {
1723
+ cursor = skipWhitespaceAndComments(source, cursor + "type".length);
1724
+ }
1725
+ return source[cursor] === "*" || source[cursor] === "{";
1726
+ }
153
1727
  /**
154
1728
  * Validate the match bound every scanner requires.
155
1729
  *
@@ -170,97 +1744,368 @@ export function findStaticImportFromSpans(source, matcher, maxMatches) {
170
1744
  assertMaxMatches(maxMatches);
171
1745
  const spans = [];
172
1746
  let cursor = 0;
1747
+ let atStatementStart = true;
1748
+ const openBraces = [];
1749
+ const matchingOpenBraces = new Map();
1750
+ const openParens = [];
1751
+ const matchingOpenParens = new Map();
1752
+ let previousTokenIndex = -1;
1753
+ const moduleDeclarationBefore = createModuleDeclarationTracker(source, 0);
1754
+ const completedRegexLiteralEnds = new Set();
1755
+ let rawJsxTextDepth = 0;
1756
+ let rawJsxExpressionBraceDepth = 0;
1757
+ const rawJsxExpressionBraceStack = [];
1758
+ const rawJsxLookaheadCache = createRawJsxLookaheadCache();
173
1759
  while (cursor < source.length) {
174
- const skipped = skipIgnored(source, cursor);
1760
+ const char = source[cursor];
1761
+ const jsxTag = readRawJsxTag(source, cursor, {
1762
+ allowClosingTagAfterText: isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth),
1763
+ lookaheadCache: rawJsxLookaheadCache,
1764
+ });
1765
+ if (jsxTag !== null) {
1766
+ if (jsxTag.isClosingTag) {
1767
+ rawJsxTextDepth = Math.max(0, rawJsxTextDepth - 1);
1768
+ }
1769
+ else if (!jsxTag.isSelfClosingTag) {
1770
+ rawJsxTextDepth++;
1771
+ }
1772
+ atStatementStart = false;
1773
+ previousTokenIndex = jsxTag.end - 1;
1774
+ cursor = jsxTag.end;
1775
+ continue;
1776
+ }
1777
+ if (isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth)) {
1778
+ const textEnd = skipRawJsxText(source, cursor);
1779
+ if (textEnd !== cursor) {
1780
+ atStatementStart = false;
1781
+ cursor = textEnd;
1782
+ continue;
1783
+ }
1784
+ }
1785
+ const skipped = skipExpressionIgnored(source, cursor, 0, 0, matchingOpenBraces, matchingOpenParens, openParens.at(-1), previousTokenIndex, moduleDeclarationBefore, rawJsxLookaheadCache, completedRegexLiteralEnds);
175
1786
  if (skipped !== cursor) {
1787
+ if (char === "/" && source[cursor + 1] === "/")
1788
+ atStatementStart = true;
1789
+ else if (char === "/" && source[cursor + 1] === "*") {
1790
+ if (hasLineTerminatorBetween(source, cursor + 2, skipped - 2))
1791
+ atStatementStart = true;
1792
+ }
1793
+ else
1794
+ atStatementStart = false;
1795
+ previousTokenIndex = tokenIndexAfterIgnored(source, cursor, skipped, previousTokenIndex);
176
1796
  cursor = skipped;
177
1797
  continue;
178
1798
  }
179
- const isImport = isStatementKeywordAt(source, cursor, "import");
180
- const isExport = isStatementKeywordAt(source, cursor, "export");
1799
+ if (char === "{") {
1800
+ const isRawJsxExpressionBrace = isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth);
1801
+ rawJsxExpressionBraceStack.push(isRawJsxExpressionBrace);
1802
+ if (isRawJsxExpressionBrace)
1803
+ rawJsxExpressionBraceDepth++;
1804
+ openBraces.push(openBraceContext(source, 0, cursor, previousTokenIndex, matchingOpenParens, openParens.at(-1), openBraces.at(-1), completedRegexLiteralEnds));
1805
+ atStatementStart = false;
1806
+ previousTokenIndex = cursor;
1807
+ cursor++;
1808
+ continue;
1809
+ }
1810
+ if (char === "}") {
1811
+ const isRawJsxExpressionBrace = rawJsxExpressionBraceStack.pop();
1812
+ if (isRawJsxExpressionBrace) {
1813
+ rawJsxExpressionBraceDepth = Math.max(0, rawJsxExpressionBraceDepth - 1);
1814
+ }
1815
+ const openBrace = openBraces.pop();
1816
+ if (openBrace !== undefined)
1817
+ matchingOpenBraces.set(cursor, openBrace);
1818
+ atStatementStart = true;
1819
+ previousTokenIndex = cursor;
1820
+ cursor++;
1821
+ continue;
1822
+ }
1823
+ if (char === "(") {
1824
+ openParens.push(openParenContext(source, cursor, previousTokenIndex));
1825
+ atStatementStart = false;
1826
+ previousTokenIndex = cursor;
1827
+ cursor++;
1828
+ continue;
1829
+ }
1830
+ if (char === ")") {
1831
+ const openParen = openParens.pop();
1832
+ if (openParen !== undefined)
1833
+ matchingOpenParens.set(cursor, openParen);
1834
+ atStatementStart = false;
1835
+ previousTokenIndex = cursor;
1836
+ cursor++;
1837
+ continue;
1838
+ }
1839
+ if (char === ";" && openParens.at(-1)?.isForHeader) {
1840
+ openParens.at(-1).hasSemicolon = true;
1841
+ }
1842
+ if (char === ";" || (char !== undefined && isLineTerminator(char))) {
1843
+ atStatementStart = true;
1844
+ if (char === ";")
1845
+ previousTokenIndex = cursor;
1846
+ cursor++;
1847
+ continue;
1848
+ }
1849
+ if (/\s/.test(char ?? "")) {
1850
+ cursor++;
1851
+ continue;
1852
+ }
1853
+ const isImport = isStatementKeywordAt(source, cursor, "import", atStatementStart);
1854
+ const isExport = isStatementKeywordAt(source, cursor, "export", atStatementStart);
181
1855
  if (!isImport && !isExport) {
1856
+ atStatementStart = false;
1857
+ previousTokenIndex = cursor;
182
1858
  cursor++;
183
1859
  continue;
184
1860
  }
185
1861
  const keywordLength = isImport ? "import".length : "export".length;
186
- const afterKeyword = skipWhitespace(source, cursor + keywordLength);
1862
+ const afterKeyword = skipWhitespaceAndComments(source, cursor + keywordLength);
187
1863
  if (isImport && source[afterKeyword] === "(") {
1864
+ atStatementStart = false;
1865
+ openParens.push({
1866
+ index: afterKeyword,
1867
+ isControlCondition: false,
1868
+ isForHeader: false,
1869
+ hasSemicolon: false,
1870
+ });
1871
+ previousTokenIndex = afterKeyword;
188
1872
  cursor = afterKeyword + 1;
189
1873
  continue;
190
1874
  }
191
- const span = findFromSpan(source, afterKeyword, matcher);
1875
+ if (isExport && !canExportHaveFromClause(source, afterKeyword)) {
1876
+ atStatementStart = false;
1877
+ previousTokenIndex = cursor + keywordLength - 1;
1878
+ cursor = afterKeyword;
1879
+ continue;
1880
+ }
1881
+ const span = findFromSpan(source, afterKeyword, matcher, isExport);
192
1882
  if (span) {
193
1883
  spans.push(span);
194
1884
  if (spans.length >= maxMatches)
195
1885
  return spans;
1886
+ atStatementStart = false;
1887
+ previousTokenIndex = span.end - 1;
196
1888
  cursor = span.end;
197
1889
  continue;
198
1890
  }
1891
+ atStatementStart = true;
199
1892
  cursor = nextStatementCursor(source, afterKeyword);
1893
+ previousTokenIndex = Math.max(previousTokenIndex, cursor - 1);
200
1894
  }
201
1895
  return spans;
202
1896
  }
203
- /**
204
- * Find `import("…")` expressions with a literal specifier.
205
- *
206
- * The returned span covers the quoted specifier itself (quotes included), not
207
- * the surrounding `import(...)`, so a replacement is a bare quoted string.
208
- * Dynamic imports whose argument is not a string literal are skipped, since
209
- * their target is only known at runtime. That includes an argument the literal
210
- * merely starts: rewriting the `"./foo"` in `import("./foo" + suffix)` would
211
- * build a path out of a resolved prefix and an unresolved tail.
212
- *
213
- * `maxMatches` bounds the scan on the same terms as
214
- * {@link findStaticImportFromSpans}.
215
- */
216
- export function findDynamicImportSpans(source, matcher, maxMatches) {
217
- assertMaxMatches(maxMatches);
218
- const spans = [];
219
- let cursor = 0;
220
- while (cursor < source.length) {
221
- const skipped = skipIgnored(source, cursor);
222
- if (skipped !== cursor) {
1897
+ function scanTemplateExpressionDynamicImports(source, templateIndex, rangeEnd, matcher, maxMatches, spans) {
1898
+ let cursor = templateIndex + 1;
1899
+ while (cursor < rangeEnd && cursor < source.length) {
1900
+ if (source[cursor] === "\\") {
1901
+ cursor += 2;
1902
+ continue;
1903
+ }
1904
+ if (source[cursor] === "`")
1905
+ return cursor + 1;
1906
+ if (source[cursor] === "$" && source[cursor + 1] === "{") {
1907
+ const expressionStart = cursor + 2;
1908
+ const expressionEnd = findTemplateExpressionEnd(source, expressionStart);
1909
+ if (expressionEnd === null)
1910
+ return source.length;
1911
+ scanDynamicImportRange(source, expressionStart, expressionEnd, matcher, maxMatches, spans);
1912
+ if (spans.length >= maxMatches)
1913
+ return expressionEnd + 1;
1914
+ cursor = expressionEnd + 1;
1915
+ continue;
1916
+ }
1917
+ cursor++;
1918
+ }
1919
+ return source.length;
1920
+ }
1921
+ function scanDynamicImportRange(source, rangeStart, rangeEnd, matcher, maxMatches, spans) {
1922
+ let cursor = rangeStart;
1923
+ const openBraces = [];
1924
+ const matchingOpenBraces = new Map();
1925
+ const openParens = [];
1926
+ const matchingOpenParens = new Map();
1927
+ let previousTokenIndex = rangeStart - 1;
1928
+ let rawJsxTextDepth = 0;
1929
+ let rawJsxExpressionBraceDepth = 0;
1930
+ const rawJsxExpressionBraceStack = [];
1931
+ const moduleDeclarationBefore = createModuleDeclarationTracker(source, rangeStart);
1932
+ const rawJsxLookaheadCache = createRawJsxLookaheadCache();
1933
+ const completedRegexLiteralEnds = new Set();
1934
+ while (cursor < rangeEnd) {
1935
+ const char = source[cursor];
1936
+ const next = source[cursor + 1];
1937
+ const jsxTag = readRawJsxTag(source, cursor, {
1938
+ allowClosingTagAfterText: isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth),
1939
+ lookaheadCache: rawJsxLookaheadCache,
1940
+ });
1941
+ if (jsxTag !== null) {
1942
+ for (const range of jsxTag.expressionRanges) {
1943
+ scanDynamicImportRange(source, range.start, range.end, matcher, maxMatches, spans);
1944
+ if (spans.length >= maxMatches)
1945
+ return;
1946
+ }
1947
+ if (jsxTag.isClosingTag) {
1948
+ rawJsxTextDepth = Math.max(0, rawJsxTextDepth - 1);
1949
+ }
1950
+ else if (!jsxTag.isSelfClosingTag) {
1951
+ rawJsxTextDepth++;
1952
+ }
1953
+ previousTokenIndex = jsxTag.end - 1;
1954
+ cursor = jsxTag.end;
1955
+ continue;
1956
+ }
1957
+ if (isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth)) {
1958
+ const textEnd = skipRawJsxText(source, cursor);
1959
+ if (textEnd !== cursor) {
1960
+ cursor = textEnd;
1961
+ continue;
1962
+ }
1963
+ }
1964
+ if ((char === "/" && (next === "/" || next === "*")) ||
1965
+ char === '"' ||
1966
+ char === "'") {
1967
+ const skipped = skipIgnored(source, cursor);
1968
+ previousTokenIndex = tokenIndexAfterIgnored(source, cursor, skipped, previousTokenIndex);
223
1969
  cursor = skipped;
224
1970
  continue;
225
1971
  }
1972
+ if (char === "/" &&
1973
+ canStartRegexLiteral(source, cursor, rangeStart, matchingOpenBraces, matchingOpenParens, openParens.at(-1), previousTokenIndex, moduleDeclarationBefore)) {
1974
+ cursor = skipRegexLiteral(source, cursor);
1975
+ previousTokenIndex = cursor - 1;
1976
+ completedRegexLiteralEnds.add(previousTokenIndex);
1977
+ continue;
1978
+ }
1979
+ if (char === "`") {
1980
+ cursor = scanTemplateExpressionDynamicImports(source, cursor, rangeEnd, matcher, maxMatches, spans);
1981
+ if (spans.length >= maxMatches)
1982
+ return;
1983
+ previousTokenIndex = cursor - 1;
1984
+ continue;
1985
+ }
1986
+ if (char === "{") {
1987
+ const isRawJsxExpressionBrace = isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth);
1988
+ rawJsxExpressionBraceStack.push(isRawJsxExpressionBrace);
1989
+ if (isRawJsxExpressionBrace)
1990
+ rawJsxExpressionBraceDepth++;
1991
+ openBraces.push(openBraceContext(source, rangeStart, cursor, previousTokenIndex, matchingOpenParens, openParens.at(-1), openBraces.at(-1), completedRegexLiteralEnds));
1992
+ previousTokenIndex = cursor;
1993
+ cursor++;
1994
+ continue;
1995
+ }
1996
+ if (char === "}") {
1997
+ const isRawJsxExpressionBrace = rawJsxExpressionBraceStack.pop();
1998
+ if (isRawJsxExpressionBrace) {
1999
+ rawJsxExpressionBraceDepth = Math.max(0, rawJsxExpressionBraceDepth - 1);
2000
+ }
2001
+ const openBrace = openBraces.pop();
2002
+ if (openBrace !== undefined)
2003
+ matchingOpenBraces.set(cursor, openBrace);
2004
+ previousTokenIndex = cursor;
2005
+ cursor++;
2006
+ continue;
2007
+ }
2008
+ if (char === "(") {
2009
+ openParens.push(openParenContext(source, cursor, previousTokenIndex));
2010
+ previousTokenIndex = cursor;
2011
+ cursor++;
2012
+ continue;
2013
+ }
2014
+ if (char === ")") {
2015
+ const openParen = openParens.pop();
2016
+ if (openParen !== undefined)
2017
+ matchingOpenParens.set(cursor, openParen);
2018
+ previousTokenIndex = cursor;
2019
+ cursor++;
2020
+ continue;
2021
+ }
2022
+ if (char === ";" && openParens.at(-1)?.isForHeader) {
2023
+ openParens.at(-1).hasSemicolon = true;
2024
+ }
2025
+ if (/\s/.test(char ?? "")) {
2026
+ cursor++;
2027
+ continue;
2028
+ }
226
2029
  // `import` used as an expression: not preceded by an identifier char or a
227
2030
  // dot (which would make it `foo.import` or part of a longer word).
228
2031
  if (!source.startsWith("import", cursor) ||
229
- isIdentifierChar(source[cursor - 1]) ||
230
- source[cursor - 1] === "." ||
231
- isIdentifierChar(source[cursor + "import".length])) {
2032
+ isIdentifierBoundaryBefore(source, cursor) ||
2033
+ isPropertyAccessBeforeImport(source, previousTokenIndex, rangeStart) ||
2034
+ isIdentifierBoundaryAfter(source, cursor + "import".length)) {
2035
+ previousTokenIndex = cursor;
232
2036
  cursor++;
233
2037
  continue;
234
2038
  }
235
2039
  const parenIndex = skipWhitespaceAndComments(source, cursor + "import".length);
236
- if (source[parenIndex] !== "(") {
2040
+ if (parenIndex >= rangeEnd || source[parenIndex] !== "(") {
2041
+ previousTokenIndex = cursor;
237
2042
  cursor++;
238
2043
  continue;
239
2044
  }
240
- const quoteIndex = skipWhitespaceAndComments(source, parenIndex + 1);
241
- const quoted = readQuotedSpecifier(source, quoteIndex);
242
- if (!quoted) {
2045
+ // The scanner jumps directly from `import` to its argument, so record the
2046
+ // opening parenthesis that the ordinary character walk does not visit.
2047
+ openParens.push({
2048
+ index: parenIndex,
2049
+ isControlCondition: false,
2050
+ isForHeader: false,
2051
+ hasSemicolon: false,
2052
+ });
2053
+ const literalIndex = skipWhitespaceAndComments(source, parenIndex + 1);
2054
+ if (literalIndex >= rangeEnd) {
2055
+ previousTokenIndex = parenIndex;
2056
+ cursor = parenIndex + 1;
2057
+ continue;
2058
+ }
2059
+ const literal = readLiteralSpecifier(source, literalIndex);
2060
+ if (!literal || literal.end > rangeEnd) {
2061
+ previousTokenIndex = parenIndex;
243
2062
  cursor = parenIndex + 1;
244
2063
  continue;
245
2064
  }
246
2065
  // The literal must be the whole first argument. `)` closes the call and `,`
247
2066
  // starts the import-attributes argument; anything else (`+`, a template
248
2067
  // continuation, a ternary) means the runtime specifier is not this string.
249
- const afterSpecifier = skipWhitespaceAndComments(source, quoted.end);
250
- const isWholeArgument = source[afterSpecifier] === ")" || source[afterSpecifier] === ",";
251
- const matchedPath = isWholeArgument ? matcher(quoted.specifier) : null;
2068
+ const afterSpecifier = skipWhitespaceAndComments(source, literal.end);
2069
+ const isWholeArgument = afterSpecifier < rangeEnd &&
2070
+ (source[afterSpecifier] === ")" || source[afterSpecifier] === ",");
2071
+ const matchedPath = isWholeArgument ? matcher(literal.specifier) : null;
252
2072
  if (matchedPath) {
253
2073
  spans.push({
254
- original: source.slice(quoteIndex, quoted.end),
2074
+ original: source.slice(literalIndex, literal.end),
255
2075
  path: matchedPath,
256
- start: quoteIndex,
257
- end: quoted.end,
2076
+ start: literalIndex,
2077
+ end: literal.end,
258
2078
  });
259
2079
  if (spans.length >= maxMatches)
260
- return spans;
2080
+ return;
261
2081
  }
262
- cursor = quoted.end;
2082
+ previousTokenIndex = literal.end - 1;
2083
+ cursor = literal.end;
263
2084
  }
2085
+ }
2086
+ /**
2087
+ * Find `import("…")` expressions with a literal specifier.
2088
+ *
2089
+ * The returned span covers the quoted specifier itself (quotes included), not
2090
+ * the surrounding `import(...)`, so a replacement is a bare quoted string.
2091
+ *
2092
+ * A literal here is a single- or double-quoted string, or a backtick template
2093
+ * with no `${}` substitution — the three forms whose target is fully known at
2094
+ * scan time. An interpolated template and any other expression are skipped,
2095
+ * since their target is only known at runtime. So is an argument the literal
2096
+ * merely starts: rewriting the `"./foo"` in `import("./foo" + suffix)` would
2097
+ * build a path out of a resolved prefix and an unresolved tail.
2098
+ *
2099
+ * The scan also runs inside template substitutions, so a dynamic import nested
2100
+ * in a `${…}` expression is found.
2101
+ *
2102
+ * `maxMatches` bounds the scan on the same terms as
2103
+ * {@link findStaticImportFromSpans}.
2104
+ */
2105
+ export function findDynamicImportSpans(source, matcher, maxMatches) {
2106
+ assertMaxMatches(maxMatches);
2107
+ const spans = [];
2108
+ scanDynamicImportRange(source, 0, source.length, matcher, maxMatches, spans);
264
2109
  return spans;
265
2110
  }
266
2111
  /**
@@ -273,34 +2118,140 @@ export function findStaticSideEffectImportSpans(source, matcher, maxMatches) {
273
2118
  assertMaxMatches(maxMatches);
274
2119
  const spans = [];
275
2120
  let cursor = 0;
2121
+ let atStatementStart = true;
2122
+ const openBraces = [];
2123
+ const matchingOpenBraces = new Map();
2124
+ const openParens = [];
2125
+ const matchingOpenParens = new Map();
2126
+ let previousTokenIndex = -1;
2127
+ const moduleDeclarationBefore = createModuleDeclarationTracker(source, 0);
2128
+ const completedRegexLiteralEnds = new Set();
2129
+ let rawJsxTextDepth = 0;
2130
+ let rawJsxExpressionBraceDepth = 0;
2131
+ const rawJsxExpressionBraceStack = [];
2132
+ const rawJsxLookaheadCache = createRawJsxLookaheadCache();
276
2133
  while (cursor < source.length) {
277
- const skipped = skipIgnored(source, cursor);
2134
+ const char = source[cursor];
2135
+ const jsxTag = readRawJsxTag(source, cursor, {
2136
+ allowClosingTagAfterText: isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth),
2137
+ lookaheadCache: rawJsxLookaheadCache,
2138
+ });
2139
+ if (jsxTag !== null) {
2140
+ if (jsxTag.isClosingTag) {
2141
+ rawJsxTextDepth = Math.max(0, rawJsxTextDepth - 1);
2142
+ }
2143
+ else if (!jsxTag.isSelfClosingTag) {
2144
+ rawJsxTextDepth++;
2145
+ }
2146
+ atStatementStart = false;
2147
+ previousTokenIndex = jsxTag.end - 1;
2148
+ cursor = jsxTag.end;
2149
+ continue;
2150
+ }
2151
+ if (isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth)) {
2152
+ const textEnd = skipRawJsxText(source, cursor);
2153
+ if (textEnd !== cursor) {
2154
+ atStatementStart = false;
2155
+ cursor = textEnd;
2156
+ continue;
2157
+ }
2158
+ }
2159
+ const skipped = skipExpressionIgnored(source, cursor, 0, 0, matchingOpenBraces, matchingOpenParens, openParens.at(-1), previousTokenIndex, moduleDeclarationBefore, rawJsxLookaheadCache, completedRegexLiteralEnds);
278
2160
  if (skipped !== cursor) {
2161
+ if (char === "/" && source[cursor + 1] === "/")
2162
+ atStatementStart = true;
2163
+ else if (char === "/" && source[cursor + 1] === "*") {
2164
+ if (hasLineTerminatorBetween(source, cursor + 2, skipped - 2))
2165
+ atStatementStart = true;
2166
+ }
2167
+ else
2168
+ atStatementStart = false;
2169
+ previousTokenIndex = tokenIndexAfterIgnored(source, cursor, skipped, previousTokenIndex);
279
2170
  cursor = skipped;
280
2171
  continue;
281
2172
  }
282
- if (!isStatementKeywordAt(source, cursor, "import")) {
2173
+ if (char === "{") {
2174
+ const isRawJsxExpressionBrace = isInRawJsxText(rawJsxTextDepth, rawJsxExpressionBraceDepth);
2175
+ rawJsxExpressionBraceStack.push(isRawJsxExpressionBrace);
2176
+ if (isRawJsxExpressionBrace)
2177
+ rawJsxExpressionBraceDepth++;
2178
+ openBraces.push(openBraceContext(source, 0, cursor, previousTokenIndex, matchingOpenParens, openParens.at(-1), openBraces.at(-1), completedRegexLiteralEnds));
2179
+ atStatementStart = false;
2180
+ previousTokenIndex = cursor;
2181
+ cursor++;
2182
+ continue;
2183
+ }
2184
+ if (char === "}") {
2185
+ const isRawJsxExpressionBrace = rawJsxExpressionBraceStack.pop();
2186
+ if (isRawJsxExpressionBrace) {
2187
+ rawJsxExpressionBraceDepth = Math.max(0, rawJsxExpressionBraceDepth - 1);
2188
+ }
2189
+ const openBrace = openBraces.pop();
2190
+ if (openBrace !== undefined)
2191
+ matchingOpenBraces.set(cursor, openBrace);
2192
+ atStatementStart = true;
2193
+ previousTokenIndex = cursor;
2194
+ cursor++;
2195
+ continue;
2196
+ }
2197
+ if (char === "(") {
2198
+ openParens.push(openParenContext(source, cursor, previousTokenIndex));
2199
+ atStatementStart = false;
2200
+ previousTokenIndex = cursor;
2201
+ cursor++;
2202
+ continue;
2203
+ }
2204
+ if (char === ")") {
2205
+ const openParen = openParens.pop();
2206
+ if (openParen !== undefined)
2207
+ matchingOpenParens.set(cursor, openParen);
2208
+ atStatementStart = false;
2209
+ previousTokenIndex = cursor;
2210
+ cursor++;
2211
+ continue;
2212
+ }
2213
+ if (char === ";" && openParens.at(-1)?.isForHeader) {
2214
+ openParens.at(-1).hasSemicolon = true;
2215
+ }
2216
+ if (char === ";" || (char !== undefined && isLineTerminator(char))) {
2217
+ atStatementStart = true;
2218
+ if (char === ";")
2219
+ previousTokenIndex = cursor;
2220
+ cursor++;
2221
+ continue;
2222
+ }
2223
+ if (/\s/.test(char ?? "")) {
2224
+ cursor++;
2225
+ continue;
2226
+ }
2227
+ if (!isStatementKeywordAt(source, cursor, "import", atStatementStart)) {
2228
+ atStatementStart = false;
2229
+ previousTokenIndex = cursor;
283
2230
  cursor++;
284
2231
  continue;
285
2232
  }
286
- const quoteIndex = skipWhitespace(source, cursor + "import".length);
287
- const quoted = readQuotedSpecifier(source, quoteIndex);
288
- if (!quoted) {
289
- cursor = nextStatementCursor(source, quoteIndex);
2233
+ const literalIndex = skipWhitespaceAndComments(source, cursor + "import".length);
2234
+ const literal = readLiteralSpecifier(source, literalIndex);
2235
+ if (!literal) {
2236
+ atStatementStart = true;
2237
+ cursor = nextStatementCursor(source, literalIndex);
2238
+ previousTokenIndex = Math.max(previousTokenIndex, cursor - 1);
290
2239
  continue;
291
2240
  }
292
- const matchedPath = matcher(quoted.specifier);
2241
+ const matchedPath = matcher(literal.specifier);
293
2242
  if (matchedPath) {
294
2243
  spans.push({
295
- original: source.slice(cursor, quoted.end),
2244
+ original: source.slice(cursor, literal.end),
296
2245
  path: matchedPath,
297
2246
  start: cursor,
298
- end: quoted.end,
2247
+ end: literal.end,
299
2248
  });
300
2249
  if (spans.length >= maxMatches)
301
2250
  return spans;
302
2251
  }
303
- cursor = quoted.end;
2252
+ atStatementStart = false;
2253
+ previousTokenIndex = literal.end - 1;
2254
+ cursor = literal.end;
304
2255
  }
305
2256
  return spans;
306
2257
  }