@octanejs/tanstack-start 0.1.0

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 (266) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +52 -0
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/package.json +149 -0
  5. package/src/client-only.d.ts +1 -0
  6. package/src/client-only.js +0 -0
  7. package/src/client-rpc.d.ts +1 -0
  8. package/src/client-rpc.js +1 -0
  9. package/src/client.d.ts +3 -0
  10. package/src/client.js +2 -0
  11. package/src/default-entry/client.js +12 -0
  12. package/src/default-entry/server.js +13 -0
  13. package/src/default-entry/start.js +1 -0
  14. package/src/default-entry-paths.d.ts +5 -0
  15. package/src/default-entry-paths.js +11 -0
  16. package/src/index.d.ts +11 -0
  17. package/src/index.js +22 -0
  18. package/src/internal/README.md +15 -0
  19. package/src/internal/router-generator/config.d.ts +255 -0
  20. package/src/internal/router-generator/config.js +134 -0
  21. package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
  22. package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
  23. package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
  24. package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
  25. package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
  26. package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
  27. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
  28. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
  29. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
  30. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
  31. package/src/internal/router-generator/generator.d.ts +119 -0
  32. package/src/internal/router-generator/generator.js +1080 -0
  33. package/src/internal/router-generator/index.d.ts +40 -0
  34. package/src/internal/router-generator/index.js +49 -0
  35. package/src/internal/router-generator/logger.d.ts +8 -0
  36. package/src/internal/router-generator/logger.js +30 -0
  37. package/src/internal/router-generator/plugin/types.d.ts +37 -0
  38. package/src/internal/router-generator/template.d.ts +38 -0
  39. package/src/internal/router-generator/template.js +220 -0
  40. package/src/internal/router-generator/transform/transform.d.ts +8 -0
  41. package/src/internal/router-generator/transform/transform.js +385 -0
  42. package/src/internal/router-generator/transform/types.d.ts +34 -0
  43. package/src/internal/router-generator/types.d.ts +73 -0
  44. package/src/internal/router-generator/utils.d.ts +270 -0
  45. package/src/internal/router-generator/utils.js +864 -0
  46. package/src/internal/router-generator/validate-route-params.d.ts +13 -0
  47. package/src/internal/router-generator/validate-route-params.js +75 -0
  48. package/src/internal/router-plugin/context.d.ts +2 -0
  49. package/src/internal/router-plugin/context.js +2 -0
  50. package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
  51. package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
  52. package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
  53. package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
  54. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
  55. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
  56. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
  57. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
  58. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
  59. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
  60. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
  61. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
  62. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
  63. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
  64. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
  65. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
  66. package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
  67. package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
  68. package/src/internal/router-plugin/core/config.d.ts +294 -0
  69. package/src/internal/router-plugin/core/config.js +56 -0
  70. package/src/internal/router-plugin/core/constants.d.ts +12 -0
  71. package/src/internal/router-plugin/core/constants.js +13 -0
  72. package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
  73. package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
  74. package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
  75. package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
  76. package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
  77. package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
  78. package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
  79. package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
  80. package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
  81. package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
  82. package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
  83. package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
  84. package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
  85. package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
  86. package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
  87. package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
  88. package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
  89. package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
  90. package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
  91. package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
  92. package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
  93. package/src/internal/router-plugin/core/utils.d.ts +17 -0
  94. package/src/internal/router-plugin/core/utils.js +47 -0
  95. package/src/internal/router-plugin/esbuild.d.ts +197 -0
  96. package/src/internal/router-plugin/esbuild.js +58 -0
  97. package/src/internal/router-plugin/index.d.ts +19 -0
  98. package/src/internal/router-plugin/index.js +17 -0
  99. package/src/internal/router-plugin/rspack.d.ts +61 -0
  100. package/src/internal/router-plugin/rspack.js +92 -0
  101. package/src/internal/router-plugin/vite.d.ts +201 -0
  102. package/src/internal/router-plugin/vite.js +62 -0
  103. package/src/internal/router-plugin/webpack.d.ts +50 -0
  104. package/src/internal/router-plugin/webpack.js +77 -0
  105. package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
  106. package/src/internal/start-plugin-core/build-sitemap.js +125 -0
  107. package/src/internal/start-plugin-core/config-context.d.ts +30 -0
  108. package/src/internal/start-plugin-core/config-context.js +89 -0
  109. package/src/internal/start-plugin-core/constants.d.ts +20 -0
  110. package/src/internal/start-plugin-core/constants.js +24 -0
  111. package/src/internal/start-plugin-core/debug.d.ts +1 -0
  112. package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
  113. package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
  114. package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
  115. package/src/internal/start-plugin-core/hydration-constants.js +4 -0
  116. package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
  117. package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
  118. package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
  119. package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
  120. package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
  121. package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
  122. package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
  123. package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
  124. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
  125. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
  126. package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
  127. package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
  128. package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
  129. package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
  130. package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
  131. package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
  132. package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
  133. package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
  134. package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
  135. package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
  136. package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
  137. package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
  138. package/src/internal/start-plugin-core/index.d.ts +8 -0
  139. package/src/internal/start-plugin-core/index.js +2 -0
  140. package/src/internal/start-plugin-core/planning.d.ts +44 -0
  141. package/src/internal/start-plugin-core/planning.js +98 -0
  142. package/src/internal/start-plugin-core/post-build.d.ts +12 -0
  143. package/src/internal/start-plugin-core/post-build.js +40 -0
  144. package/src/internal/start-plugin-core/prerender.d.ts +17 -0
  145. package/src/internal/start-plugin-core/prerender.js +172 -0
  146. package/src/internal/start-plugin-core/queue.d.ts +37 -0
  147. package/src/internal/start-plugin-core/queue.js +118 -0
  148. package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
  149. package/src/internal/start-plugin-core/resolve-entries.js +32 -0
  150. package/src/internal/start-plugin-core/schema.d.ts +1799 -0
  151. package/src/internal/start-plugin-core/schema.js +252 -0
  152. package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
  153. package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
  154. package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
  155. package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
  156. package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
  157. package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
  158. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
  159. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
  160. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
  161. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
  162. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
  163. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
  164. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
  165. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
  166. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
  167. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
  168. package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
  169. package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
  170. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
  171. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
  172. package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
  173. package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
  174. package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
  175. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
  176. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
  177. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
  178. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
  179. package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
  180. package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
  181. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
  182. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
  183. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
  184. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
  185. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
  186. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
  187. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
  188. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
  189. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
  190. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
  191. package/src/internal/start-plugin-core/types.d.ts +135 -0
  192. package/src/internal/start-plugin-core/types.js +4 -0
  193. package/src/internal/start-plugin-core/utils.d.ts +13 -0
  194. package/src/internal/start-plugin-core/utils.js +42 -0
  195. package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
  196. package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
  197. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
  198. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
  199. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
  200. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
  201. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
  202. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
  203. package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
  204. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
  205. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
  206. package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
  207. package/src/internal/start-plugin-core/vite/index.js +4 -0
  208. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
  209. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
  210. package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
  211. package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
  212. package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
  213. package/src/internal/start-plugin-core/vite/planning.js +152 -0
  214. package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
  215. package/src/internal/start-plugin-core/vite/plugin.js +208 -0
  216. package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
  217. package/src/internal/start-plugin-core/vite/plugins.js +72 -0
  218. package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
  219. package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
  220. package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
  221. package/src/internal/start-plugin-core/vite/prerender.js +52 -0
  222. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
  223. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
  224. package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
  225. package/src/internal/start-plugin-core/vite/schema.js +17 -0
  226. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
  227. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
  228. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
  229. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
  230. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
  231. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
  232. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
  233. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
  234. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
  235. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
  236. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
  237. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
  238. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
  239. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
  240. package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
  241. package/src/package-names.js +10 -0
  242. package/src/plugin-vite.d.ts +23 -0
  243. package/src/plugin-vite.js +62 -0
  244. package/src/runtime/client/StartClient.d.ts +11 -0
  245. package/src/runtime/client/StartClient.js +16 -0
  246. package/src/runtime/client/hydrateStart.d.ts +4 -0
  247. package/src/runtime/client/hydrateStart.js +30 -0
  248. package/src/runtime/server/StartServer.d.ts +10 -0
  249. package/src/runtime/server/StartServer.js +6 -0
  250. package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
  251. package/src/runtime/server/defaultRenderHandler.js +11 -0
  252. package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
  253. package/src/runtime/server/defaultStreamHandler.js +13 -0
  254. package/src/server-entry.d.ts +11 -0
  255. package/src/server-entry.js +13 -0
  256. package/src/server-only.d.ts +1 -0
  257. package/src/server-only.js +0 -0
  258. package/src/server-rpc.d.ts +1 -0
  259. package/src/server-rpc.js +1 -0
  260. package/src/server.d.ts +6 -0
  261. package/src/server.js +4 -0
  262. package/src/ssr-rpc.d.ts +1 -0
  263. package/src/ssr-rpc.js +1 -0
  264. package/src/use-server-fn.d.ts +3 -0
  265. package/src/use-server-fn.js +18 -0
  266. package/src/validate-options.js +7 -0
@@ -0,0 +1,40 @@
1
+ import { CompiledMatcher } from './matchers.js';
2
+ export type ImportProtectionEnvType = 'client' | 'server';
3
+ export interface ImportProtectionEnvRules {
4
+ specifiers: Array<CompiledMatcher>;
5
+ files: Array<CompiledMatcher>;
6
+ excludeFiles: Array<CompiledMatcher>;
7
+ }
8
+ /**
9
+ * Shared subset of adapter config used to decide which environment rules apply
10
+ * and whether an importer should be checked at all.
11
+ */
12
+ export interface ImportProtectionAdapterConfig {
13
+ root: string;
14
+ srcDirectory: string;
15
+ compiledRules: {
16
+ client: ImportProtectionEnvRules;
17
+ server: ImportProtectionEnvRules;
18
+ };
19
+ includeMatchers: Array<CompiledMatcher>;
20
+ excludeMatchers: Array<CompiledMatcher>;
21
+ ignoreImporterMatchers: Array<CompiledMatcher>;
22
+ envTypeMap: Map<string, ImportProtectionEnvType>;
23
+ }
24
+ export declare function getImportProtectionRelativePath(root: string, absolutePath: string): string;
25
+ export declare function getImportProtectionEnvType(
26
+ config: Pick<ImportProtectionAdapterConfig, 'envTypeMap'>,
27
+ envName: string,
28
+ ): ImportProtectionEnvType;
29
+ export declare function getImportProtectionRulesForEnvironment(
30
+ config: Pick<ImportProtectionAdapterConfig, 'compiledRules' | 'envTypeMap'>,
31
+ envName: string,
32
+ ): ImportProtectionEnvRules;
33
+ export declare function shouldCheckImportProtectionImporter(
34
+ config: Pick<
35
+ ImportProtectionAdapterConfig,
36
+ 'root' | 'srcDirectory' | 'includeMatchers' | 'excludeMatchers' | 'ignoreImporterMatchers'
37
+ >,
38
+ importer: string,
39
+ cache?: Map<string, boolean>,
40
+ ): boolean;
@@ -0,0 +1,42 @@
1
+ import { isInsideDirectory, normalizeFilePath, relativizePath } from './utils.js';
2
+ import { matchesAny } from './matchers.js';
3
+ //#region src/import-protection/adapterUtils.ts
4
+ function getImportProtectionRelativePath(root, absolutePath) {
5
+ return relativizePath(normalizeFilePath(absolutePath), root);
6
+ }
7
+ function getImportProtectionEnvType(config, envName) {
8
+ return config.envTypeMap.get(envName) ?? 'server';
9
+ }
10
+ function getImportProtectionRulesForEnvironment(config, envName) {
11
+ return getImportProtectionEnvType(config, envName) === 'client'
12
+ ? config.compiledRules.client
13
+ : config.compiledRules.server;
14
+ }
15
+ function shouldCheckImportProtectionImporter(config, importer, cache) {
16
+ const normalizedImporter = normalizeFilePath(importer);
17
+ if (cache) {
18
+ const cached = cache.get(normalizedImporter);
19
+ if (cached !== void 0) return cached;
20
+ }
21
+ const relativePath = relativizePath(normalizedImporter, config.root);
22
+ let result;
23
+ if (
24
+ (config.excludeMatchers.length > 0 && matchesAny(relativePath, config.excludeMatchers)) ||
25
+ (config.ignoreImporterMatchers.length > 0 &&
26
+ matchesAny(relativePath, config.ignoreImporterMatchers))
27
+ )
28
+ result = false;
29
+ else if (config.includeMatchers.length > 0)
30
+ result = !!matchesAny(relativePath, config.includeMatchers);
31
+ else if (config.srcDirectory) result = isInsideDirectory(normalizedImporter, config.srcDirectory);
32
+ else result = true;
33
+ cache?.set(normalizedImporter, result);
34
+ return result;
35
+ }
36
+ //#endregion
37
+ export {
38
+ getImportProtectionEnvType,
39
+ getImportProtectionRelativePath,
40
+ getImportProtectionRulesForEnvironment,
41
+ shouldCheckImportProtectionImporter,
42
+ };
@@ -0,0 +1,63 @@
1
+ import { LineIndex, TransformResult } from './sourceLocation.js';
2
+ import { ParseAstResult } from '@tanstack/router-utils';
3
+ export type UsagePos = {
4
+ line: number;
5
+ column0: number;
6
+ };
7
+ type BoundaryEnv = 'client' | 'server';
8
+ type ImportBindingInfo = {
9
+ importedLocalNames: Set<string>;
10
+ };
11
+ type UsageCacheKey = `${BoundaryEnv | 'post'}::${string}`;
12
+ export type ImportAnalysis = {
13
+ ast: ParseAstResult;
14
+ lineIndex: LineIndex;
15
+ importSourcesInOrder: Array<string>;
16
+ importSpecifierLocationIndex: Map<string, number>;
17
+ importBindingsBySource: Map<string, ImportBindingInfo>;
18
+ mockExportNamesBySource: Map<string, Array<string>>;
19
+ namedExports: Array<string>;
20
+ usageByKey: Map<UsageCacheKey, UsagePos | null>;
21
+ };
22
+ export declare function isValidExportName(name: string): boolean;
23
+ export declare function getOrCreateImportAnalysis(result: TransformResult): ImportAnalysis;
24
+ export declare function getImportSourcesFromResult(result: TransformResult): Array<string>;
25
+ export declare function getImportSources(
26
+ code: string,
27
+ filename?: string,
28
+ perf?: TransformResult['perf'],
29
+ ): Array<string>;
30
+ export declare function getImportSpecifierLocationFromResult(
31
+ result: TransformResult,
32
+ source: string,
33
+ ): number;
34
+ export declare function getMockExportNamesBySourceFromResult(
35
+ result: TransformResult,
36
+ ): Map<string, Array<string>>;
37
+ export declare function getMockExportNamesBySource(
38
+ code: string,
39
+ filename?: string,
40
+ perf?: TransformResult['perf'],
41
+ ): Map<string, Array<string>>;
42
+ export declare function getNamedExportsFromResult(result: TransformResult): Array<string>;
43
+ export declare function getNamedExports(
44
+ code: string,
45
+ filename?: string,
46
+ perf?: TransformResult['perf'],
47
+ ): Array<string>;
48
+ export declare function findPostCompileUsagePosFromResult(
49
+ result: TransformResult,
50
+ source: string,
51
+ ): UsagePos | undefined;
52
+ export declare function findPostCompileUsagePos(code: string, source: string): UsagePos | undefined;
53
+ export declare function findOriginalUnsafeUsagePosFromResult(
54
+ result: TransformResult,
55
+ source: string,
56
+ envType: BoundaryEnv,
57
+ ): UsagePos | undefined;
58
+ export declare function findOriginalUnsafeUsagePos(
59
+ code: string,
60
+ source: string,
61
+ envType: BoundaryEnv,
62
+ ): UsagePos | undefined;
63
+ export {};
@@ -0,0 +1,533 @@
1
+ import { getOrCreate } from './utils.js';
2
+ import { buildLineIndex } from './sourceLocation.js';
3
+ import * as t from '@babel/types';
4
+ import { parseAst } from '@tanstack/router-utils';
5
+ //#region src/import-protection/analysis.ts
6
+ function mayContainImportOrExport(code) {
7
+ return code.includes('import') || code.includes('export');
8
+ }
9
+ function makeTransientResult(code, filename, perf) {
10
+ const result = {
11
+ code,
12
+ filename,
13
+ map: void 0,
14
+ originalCode: void 0,
15
+ };
16
+ if (perf) result.perf = perf;
17
+ return result;
18
+ }
19
+ function getOrParseAst(result) {
20
+ if (result.parsedAst) {
21
+ result.perf?.count('analysis.parseAst.cached');
22
+ return result.parsedAst;
23
+ }
24
+ const startedAt = result.perf ? performance.now() : 0;
25
+ result.perf?.count('analysis.parseAst.calls');
26
+ try {
27
+ const ast = parseAst({
28
+ code: result.code,
29
+ filename: result.filename,
30
+ });
31
+ result.parsedAst = ast;
32
+ return ast;
33
+ } finally {
34
+ if (result.perf) result.perf.time('analysis.parseAst', startedAt);
35
+ }
36
+ }
37
+ function getModuleExportName(node) {
38
+ return t.isIdentifier(node) ? node.name : node.value;
39
+ }
40
+ function getStringLiteralValueStart(node) {
41
+ if (node.start == null) return -1;
42
+ const raw = node.extra?.raw;
43
+ if (typeof raw === 'string' && (raw.startsWith("'") || raw.startsWith('"')))
44
+ return node.start + 1;
45
+ return node.start;
46
+ }
47
+ function isTypeOnlyImportDeclaration(node) {
48
+ if (node.importKind === 'type') return true;
49
+ if (node.specifiers.length === 0) return false;
50
+ return node.specifiers.every(
51
+ (specifier) => t.isImportSpecifier(specifier) && specifier.importKind === 'type',
52
+ );
53
+ }
54
+ function isTypeOnlyExportNamedDeclaration(node) {
55
+ if (node.exportKind === 'type') return true;
56
+ if (!node.source || node.declaration || node.specifiers.length === 0) return false;
57
+ return node.specifiers.every(
58
+ (specifier) => t.isExportSpecifier(specifier) && specifier.exportKind === 'type',
59
+ );
60
+ }
61
+ function collectIdentifiersFromPattern$1(pattern, add) {
62
+ if (t.isIdentifier(pattern)) add(pattern.name);
63
+ else if (t.isObjectPattern(pattern))
64
+ for (const prop of pattern.properties)
65
+ if (t.isRestElement(prop)) collectIdentifiersFromPattern$1(prop.argument, add);
66
+ else collectIdentifiersFromPattern$1(prop.value, add);
67
+ else if (t.isArrayPattern(pattern)) {
68
+ for (const elem of pattern.elements) if (elem) collectIdentifiersFromPattern$1(elem, add);
69
+ } else if (t.isAssignmentPattern(pattern)) collectIdentifiersFromPattern$1(pattern.left, add);
70
+ else if (t.isRestElement(pattern)) collectIdentifiersFromPattern$1(pattern.argument, add);
71
+ }
72
+ function isValidExportName(name) {
73
+ if (name === 'default' || name.length === 0) return false;
74
+ const first = name.charCodeAt(0);
75
+ if (
76
+ !((first >= 65 && first <= 90) || (first >= 97 && first <= 122) || first === 95 || first === 36)
77
+ )
78
+ return false;
79
+ for (let i = 1; i < name.length; i++) {
80
+ const ch = name.charCodeAt(i);
81
+ if (
82
+ !(
83
+ (ch >= 65 && ch <= 90) ||
84
+ (ch >= 97 && ch <= 122) ||
85
+ (ch >= 48 && ch <= 57) ||
86
+ ch === 95 ||
87
+ ch === 36
88
+ )
89
+ )
90
+ return false;
91
+ }
92
+ return true;
93
+ }
94
+ function buildImportAnalysis(result) {
95
+ const ast = getOrParseAst(result);
96
+ const importSourcesInOrder = [];
97
+ const importSpecifierLocationIndex = /* @__PURE__ */ new Map();
98
+ const importBindingsBySource = /* @__PURE__ */ new Map();
99
+ const memberBindingSources = /* @__PURE__ */ new Map();
100
+ const mockNamesBySource = /* @__PURE__ */ new Map();
101
+ const namedExports = /* @__PURE__ */ new Set();
102
+ const getBindingInfo = (source) =>
103
+ getOrCreate(importBindingsBySource, source, () => ({
104
+ importedLocalNames: /* @__PURE__ */ new Set(),
105
+ }));
106
+ const addSpecifierLocation = (node) => {
107
+ importSourcesInOrder.push(node.value);
108
+ const index = getStringLiteralValueStart(node);
109
+ if (index === -1) return;
110
+ const prev = importSpecifierLocationIndex.get(node.value);
111
+ if (prev == null || index < prev) importSpecifierLocationIndex.set(node.value, index);
112
+ };
113
+ const addMockName = (source, name) => {
114
+ if (name === 'default' || name.length === 0) return;
115
+ getOrCreate(mockNamesBySource, source, () => /* @__PURE__ */ new Set()).add(name);
116
+ };
117
+ const addMemberBinding = (localName, source) => {
118
+ getOrCreate(memberBindingSources, localName, () => /* @__PURE__ */ new Set()).add(source);
119
+ };
120
+ const addNamedExport = (name) => {
121
+ if (name !== 'default' && name.length > 0) namedExports.add(name);
122
+ };
123
+ const visit = (node) => {
124
+ if (t.isImportDeclaration(node)) {
125
+ if (!isTypeOnlyImportDeclaration(node)) {
126
+ addSpecifierLocation(node.source);
127
+ const source = node.source.value;
128
+ const bindingInfo = getBindingInfo(source);
129
+ for (const specifier of node.specifiers) {
130
+ if (t.isImportNamespaceSpecifier(specifier)) {
131
+ bindingInfo.importedLocalNames.add(specifier.local.name);
132
+ addMemberBinding(specifier.local.name, source);
133
+ continue;
134
+ }
135
+ if (t.isImportDefaultSpecifier(specifier)) {
136
+ bindingInfo.importedLocalNames.add(specifier.local.name);
137
+ addMemberBinding(specifier.local.name, source);
138
+ continue;
139
+ }
140
+ if (!t.isImportSpecifier(specifier)) continue;
141
+ if (specifier.importKind === 'type') continue;
142
+ bindingInfo.importedLocalNames.add(specifier.local.name);
143
+ const importedName = getModuleExportName(specifier.imported);
144
+ if (importedName !== 'default') addMockName(source, importedName);
145
+ }
146
+ }
147
+ } else if (t.isExportNamedDeclaration(node)) {
148
+ const isTypeOnly = isTypeOnlyExportNamedDeclaration(node);
149
+ if (!isTypeOnly && node.source && t.isStringLiteral(node.source))
150
+ addSpecifierLocation(node.source);
151
+ if (!isTypeOnly && node.source?.value) {
152
+ const source = node.source.value;
153
+ for (const specifier of node.specifiers) {
154
+ if (!t.isExportSpecifier(specifier)) continue;
155
+ if (specifier.exportKind === 'type') continue;
156
+ addMockName(source, getModuleExportName(specifier.local));
157
+ }
158
+ }
159
+ if (!isTypeOnly) {
160
+ if (node.declaration) {
161
+ const decl = node.declaration;
162
+ if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
163
+ if (decl.id?.name) addNamedExport(decl.id.name);
164
+ } else if (t.isVariableDeclaration(decl))
165
+ for (const d of decl.declarations)
166
+ collectIdentifiersFromPattern$1(d.id, addNamedExport);
167
+ }
168
+ for (const specifier of node.specifiers) {
169
+ if (!t.isExportSpecifier(specifier)) continue;
170
+ if (specifier.exportKind === 'type') continue;
171
+ addNamedExport(getModuleExportName(specifier.exported));
172
+ }
173
+ }
174
+ } else if (t.isExportAllDeclaration(node)) {
175
+ if (node.exportKind !== 'type') addSpecifierLocation(node.source);
176
+ } else if (t.isImportExpression(node)) {
177
+ if (t.isStringLiteral(node.source)) addSpecifierLocation(node.source);
178
+ } else if (t.isCallExpression(node) && t.isImport(node.callee)) {
179
+ const sourceNode = node.arguments[0];
180
+ if (t.isStringLiteral(sourceNode)) addSpecifierLocation(sourceNode);
181
+ } else if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
182
+ const object = node.object;
183
+ if (t.isIdentifier(object)) {
184
+ const sources = memberBindingSources.get(object.name);
185
+ if (sources) {
186
+ const property = node.property;
187
+ for (const source of sources)
188
+ if (!node.computed && t.isIdentifier(property)) addMockName(source, property.name);
189
+ else if (node.computed && t.isStringLiteral(property))
190
+ addMockName(source, property.value);
191
+ }
192
+ }
193
+ }
194
+ const keys = t.VISITOR_KEYS[node.type];
195
+ if (!keys) return;
196
+ for (const key of keys) {
197
+ const child = node[key];
198
+ if (Array.isArray(child)) {
199
+ for (const item of child)
200
+ if (item && typeof item === 'object' && 'type' in item) visit(item);
201
+ } else if (child && typeof child === 'object' && 'type' in child) visit(child);
202
+ }
203
+ };
204
+ visit(ast.program);
205
+ const mockExportNamesBySource = /* @__PURE__ */ new Map();
206
+ for (const [source, names] of mockNamesBySource)
207
+ mockExportNamesBySource.set(source, Array.from(names).sort());
208
+ const lineIndex = result.lineIndex ?? buildLineIndex(result.code);
209
+ result.lineIndex = lineIndex;
210
+ return {
211
+ ast,
212
+ lineIndex,
213
+ importSourcesInOrder,
214
+ importSpecifierLocationIndex,
215
+ importBindingsBySource,
216
+ mockExportNamesBySource,
217
+ namedExports: Array.from(namedExports).sort(),
218
+ usageByKey: /* @__PURE__ */ new Map(),
219
+ };
220
+ }
221
+ function getOrCreateImportAnalysis(result) {
222
+ if (!result.analysis) result.analysis = buildImportAnalysis(result);
223
+ return result.analysis;
224
+ }
225
+ function getImportSourcesFromResult(result) {
226
+ if (!mayContainImportOrExport(result.code)) return [];
227
+ return getOrCreateImportAnalysis(result).importSourcesInOrder;
228
+ }
229
+ function getImportSources(code, filename, perf) {
230
+ return getImportSourcesFromResult(makeTransientResult(code, filename, perf));
231
+ }
232
+ function getImportSpecifierLocationFromResult(result, source) {
233
+ return getOrCreateImportAnalysis(result).importSpecifierLocationIndex.get(source) ?? -1;
234
+ }
235
+ function getMockExportNamesBySourceFromResult(result) {
236
+ return getOrCreateImportAnalysis(result).mockExportNamesBySource;
237
+ }
238
+ function getMockExportNamesBySource(code, filename, perf) {
239
+ return getMockExportNamesBySourceFromResult(makeTransientResult(code, filename, perf));
240
+ }
241
+ function getNamedExportsFromResult(result) {
242
+ return getOrCreateImportAnalysis(result).namedExports;
243
+ }
244
+ function getNamedExports(code, filename, perf) {
245
+ return getNamedExportsFromResult(makeTransientResult(code, filename, perf));
246
+ }
247
+ function isCompilerSafeBoundaryCall(call, fnNode, envType) {
248
+ if (!call.arguments.some((arg) => arg === fnNode)) return false;
249
+ const callee = call.callee;
250
+ if (t.isIdentifier(callee))
251
+ return envType === 'client'
252
+ ? callee.name === 'createServerOnlyFn'
253
+ : callee.name === 'createClientOnlyFn';
254
+ if (!t.isMemberExpression(callee) || callee.computed) return false;
255
+ if (!t.isIdentifier(callee.property)) return false;
256
+ const prop = callee.property.name;
257
+ const rootName = getCalleeRootName(callee.object);
258
+ if (envType === 'client') {
259
+ if (prop === 'handler')
260
+ return rootName === 'createServerFn' || /ServerFn$/.test(rootName ?? '');
261
+ if (prop === 'server')
262
+ return (
263
+ rootName === 'createMiddleware' ||
264
+ rootName === 'createIsomorphicFn' ||
265
+ /Middleware$/.test(rootName ?? '')
266
+ );
267
+ return false;
268
+ }
269
+ if (prop === 'client') return rootName === 'createIsomorphicFn';
270
+ return false;
271
+ }
272
+ function getCalleeRootName(node) {
273
+ if (t.isIdentifier(node)) return node.name;
274
+ if (t.isCallExpression(node)) return getCalleeRootName(node.callee);
275
+ if (t.isMemberExpression(node)) return getCalleeRootName(node.object);
276
+ }
277
+ function getBoundNamesFromPattern(pattern, out) {
278
+ if (t.isIdentifier(pattern)) out.add(pattern.name);
279
+ else if (t.isObjectPattern(pattern))
280
+ for (const prop of pattern.properties)
281
+ if (t.isRestElement(prop)) getBoundNamesFromPattern(prop.argument, out);
282
+ else getBoundNamesFromPattern(prop.value, out);
283
+ else if (t.isArrayPattern(pattern)) {
284
+ for (const elem of pattern.elements) if (elem) getBoundNamesFromPattern(elem, out);
285
+ } else if (t.isAssignmentPattern(pattern)) getBoundNamesFromPattern(pattern.left, out);
286
+ else if (t.isRestElement(pattern)) getBoundNamesFromPattern(pattern.argument, out);
287
+ }
288
+ function addPatternBindingsIfTracked(pattern, tracked, out) {
289
+ const names = /* @__PURE__ */ new Set();
290
+ getBoundNamesFromPattern(pattern, names);
291
+ for (const name of names) if (tracked.has(name)) out.add(name);
292
+ }
293
+ function collectHoistedVarBindings(node, tracked, out, isRoot = true) {
294
+ if (!isRoot && t.isFunction(node)) return;
295
+ if (t.isVariableDeclaration(node) && node.kind === 'var')
296
+ for (const decl of node.declarations) addPatternBindingsIfTracked(decl.id, tracked, out);
297
+ const keys = t.VISITOR_KEYS[node.type];
298
+ if (!keys) return;
299
+ for (const key of keys) {
300
+ const child = node[key];
301
+ if (Array.isArray(child)) {
302
+ for (const item of child)
303
+ if (item && typeof item === 'object' && 'type' in item)
304
+ collectHoistedVarBindings(item, tracked, out, false);
305
+ } else if (child && typeof child === 'object' && 'type' in child)
306
+ collectHoistedVarBindings(child, tracked, out, false);
307
+ }
308
+ }
309
+ function collectProgramBindings(program, tracked) {
310
+ const bindings = /* @__PURE__ */ new Set();
311
+ for (const node of program.body) {
312
+ if (t.isVariableDeclaration(node)) {
313
+ for (const decl of node.declarations) addPatternBindingsIfTracked(decl.id, tracked, bindings);
314
+ continue;
315
+ }
316
+ if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {
317
+ if (node.id && tracked.has(node.id.name)) bindings.add(node.id.name);
318
+ }
319
+ }
320
+ return bindings;
321
+ }
322
+ function collectBlockBindings(block, tracked) {
323
+ const bindings = /* @__PURE__ */ new Set();
324
+ for (const node of block.body) {
325
+ if (t.isVariableDeclaration(node) && node.kind !== 'var') {
326
+ for (const decl of node.declarations) addPatternBindingsIfTracked(decl.id, tracked, bindings);
327
+ continue;
328
+ }
329
+ if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {
330
+ if (node.id && tracked.has(node.id.name)) bindings.add(node.id.name);
331
+ }
332
+ }
333
+ return bindings;
334
+ }
335
+ function collectFunctionBindings(fn, tracked) {
336
+ const bindings = /* @__PURE__ */ new Set();
337
+ if (
338
+ (t.isFunctionDeclaration(fn) || t.isFunctionExpression(fn)) &&
339
+ fn.id &&
340
+ tracked.has(fn.id.name)
341
+ )
342
+ bindings.add(fn.id.name);
343
+ for (const param of fn.params) addPatternBindingsIfTracked(param, tracked, bindings);
344
+ if (t.isBlockStatement(fn.body)) collectHoistedVarBindings(fn.body, tracked, bindings);
345
+ return bindings;
346
+ }
347
+ function isShadowedByScope(name, scopeStack) {
348
+ for (let i = scopeStack.length - 1; i >= 0; i--) if (scopeStack[i]?.has(name)) return true;
349
+ return false;
350
+ }
351
+ function isBindingIdentifierInParent(node, parent) {
352
+ if (!parent) return false;
353
+ if (t.isImportSpecifier(parent) || t.isImportDefaultSpecifier(parent))
354
+ return parent.local === node;
355
+ if (t.isImportNamespaceSpecifier(parent)) return parent.local === node;
356
+ if (t.isFunctionDeclaration(parent) || t.isFunctionExpression(parent))
357
+ return parent.id === node || parent.params.includes(node);
358
+ if (t.isArrowFunctionExpression(parent)) return parent.params.includes(node);
359
+ if (t.isClassDeclaration(parent) || t.isClassExpression(parent)) return parent.id === node;
360
+ if (t.isVariableDeclarator(parent)) return parent.id === node;
361
+ if (t.isCatchClause(parent)) return parent.param === node;
362
+ return false;
363
+ }
364
+ function isInsideCompilerSafeBoundaryNodes(parents, envType) {
365
+ for (let i = parents.length - 1; i >= 0; i--) {
366
+ const node = parents[i];
367
+ if (!t.isFunction(node)) continue;
368
+ const call = parents[i - 1];
369
+ if (call && t.isCallExpression(call) && isCompilerSafeBoundaryCall(call, node, envType))
370
+ return true;
371
+ }
372
+ return false;
373
+ }
374
+ function findUsagePosInAnalysis(result, source, envType) {
375
+ const analysis = getOrCreateImportAnalysis(result);
376
+ const cacheKey = `${envType ?? 'post'}::${source}`;
377
+ if (analysis.usageByKey.has(cacheKey)) return analysis.usageByKey.get(cacheKey) ?? void 0;
378
+ const imported = analysis.importBindingsBySource.get(source)?.importedLocalNames;
379
+ if (!imported || imported.size === 0) {
380
+ analysis.usageByKey.set(cacheKey, null);
381
+ return;
382
+ }
383
+ let preferred;
384
+ let anyUsage;
385
+ const visit = (node, ctx) => {
386
+ if (preferred && anyUsage) return;
387
+ if (t.isProgram(node)) {
388
+ const nextCtx = {
389
+ parents: [...ctx.parents, node],
390
+ scopeStack: [...ctx.scopeStack, collectProgramBindings(node, imported)],
391
+ };
392
+ for (const child of node.body) visit(child, nextCtx);
393
+ return;
394
+ }
395
+ if (t.isFunction(node)) {
396
+ const functionCtx = {
397
+ parents: [...ctx.parents, node],
398
+ scopeStack: [...ctx.scopeStack, collectFunctionBindings(node, imported)],
399
+ };
400
+ visit(node.body, functionCtx);
401
+ return;
402
+ }
403
+ if (t.isBlockStatement(node)) {
404
+ const nextCtx = {
405
+ parents: [...ctx.parents, node],
406
+ scopeStack: [...ctx.scopeStack, collectBlockBindings(node, imported)],
407
+ };
408
+ for (const child of node.body) visit(child, nextCtx);
409
+ return;
410
+ }
411
+ if (t.isCatchClause(node)) {
412
+ const bindings = /* @__PURE__ */ new Set();
413
+ if (node.param) addPatternBindingsIfTracked(node.param, imported, bindings);
414
+ const nextCtx = {
415
+ parents: [...ctx.parents, node],
416
+ scopeStack: bindings.size ? [...ctx.scopeStack, bindings] : ctx.scopeStack,
417
+ };
418
+ visit(node.body, nextCtx);
419
+ return;
420
+ }
421
+ if (t.isForStatement(node) && t.isVariableDeclaration(node.init) && node.init.kind !== 'var') {
422
+ const bindings = /* @__PURE__ */ new Set();
423
+ for (const decl of node.init.declarations)
424
+ addPatternBindingsIfTracked(decl.id, imported, bindings);
425
+ const nextCtx = {
426
+ parents: [...ctx.parents, node],
427
+ scopeStack: bindings.size ? [...ctx.scopeStack, bindings] : ctx.scopeStack,
428
+ };
429
+ visit(node.init, nextCtx);
430
+ if (node.test) visit(node.test, nextCtx);
431
+ if (node.update) visit(node.update, nextCtx);
432
+ visit(node.body, nextCtx);
433
+ return;
434
+ }
435
+ if (
436
+ (t.isForInStatement(node) || t.isForOfStatement(node)) &&
437
+ t.isVariableDeclaration(node.left) &&
438
+ node.left.kind !== 'var'
439
+ ) {
440
+ const bindings = /* @__PURE__ */ new Set();
441
+ for (const decl of node.left.declarations)
442
+ addPatternBindingsIfTracked(decl.id, imported, bindings);
443
+ const nextCtx = {
444
+ parents: [...ctx.parents, node],
445
+ scopeStack: bindings.size ? [...ctx.scopeStack, bindings] : ctx.scopeStack,
446
+ };
447
+ visit(node.left, nextCtx);
448
+ visit(node.right, nextCtx);
449
+ visit(node.body, nextCtx);
450
+ return;
451
+ }
452
+ const nextParents = [...ctx.parents, node];
453
+ if (t.isIdentifier(node)) {
454
+ const parent = ctx.parents[ctx.parents.length - 1];
455
+ if (imported.has(node.name)) {
456
+ if (!isBindingIdentifierInParent(node, parent)) {
457
+ if (
458
+ !(
459
+ t.isObjectProperty(parent) &&
460
+ parent.key === node &&
461
+ !parent.computed &&
462
+ !parent.shorthand
463
+ ) &&
464
+ !(t.isObjectMethod(parent) && parent.key === node && !parent.computed) &&
465
+ !(t.isExportSpecifier(parent) && parent.exported === node) &&
466
+ !isShadowedByScope(node.name, ctx.scopeStack) &&
467
+ !(envType && isInsideCompilerSafeBoundaryNodes(ctx.parents, envType))
468
+ ) {
469
+ const loc = node.loc?.start;
470
+ if (loc) {
471
+ const pos = {
472
+ line: loc.line,
473
+ column0: loc.column,
474
+ };
475
+ if (
476
+ (t.isCallExpression(parent) && parent.callee === node) ||
477
+ (t.isNewExpression(parent) && parent.callee === node) ||
478
+ ((t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) &&
479
+ parent.object === node)
480
+ )
481
+ preferred ||= pos;
482
+ else anyUsage ||= pos;
483
+ }
484
+ }
485
+ }
486
+ }
487
+ }
488
+ if (t.isImportDeclaration(node)) return;
489
+ const keys = t.VISITOR_KEYS[node.type];
490
+ if (!keys) return;
491
+ for (const key of keys) {
492
+ const child = node[key];
493
+ if (Array.isArray(child)) {
494
+ for (const item of child)
495
+ if (item && typeof item === 'object' && 'type' in item)
496
+ visit(item, {
497
+ parents: nextParents,
498
+ scopeStack: ctx.scopeStack,
499
+ });
500
+ } else if (child && typeof child === 'object' && 'type' in child)
501
+ visit(child, {
502
+ parents: nextParents,
503
+ scopeStack: ctx.scopeStack,
504
+ });
505
+ }
506
+ };
507
+ visit(analysis.ast.program, {
508
+ parents: [],
509
+ scopeStack: [],
510
+ });
511
+ const pos = preferred ?? anyUsage ?? null;
512
+ analysis.usageByKey.set(cacheKey, pos);
513
+ return pos ?? void 0;
514
+ }
515
+ function findPostCompileUsagePosFromResult(result, source) {
516
+ return findUsagePosInAnalysis(result, source);
517
+ }
518
+ function findOriginalUnsafeUsagePosFromResult(result, source, envType) {
519
+ return findUsagePosInAnalysis(result, source, envType);
520
+ }
521
+ //#endregion
522
+ export {
523
+ findOriginalUnsafeUsagePosFromResult,
524
+ findPostCompileUsagePosFromResult,
525
+ getImportSources,
526
+ getImportSourcesFromResult,
527
+ getImportSpecifierLocationFromResult,
528
+ getMockExportNamesBySource,
529
+ getMockExportNamesBySourceFromResult,
530
+ getNamedExports,
531
+ getNamedExportsFromResult,
532
+ isValidExportName,
533
+ };
@@ -0,0 +1,11 @@
1
+ export declare const SERVER_FN_LOOKUP_QUERY = '?server-fn-module-lookup';
2
+ export declare const MOCK_MODULE_ID = 'tanstack-start-import-protection:mock';
3
+ export declare const MOCK_BUILD_PREFIX = 'tanstack-start-import-protection:mock:build:';
4
+ export declare const MOCK_EDGE_PREFIX = 'tanstack-start-import-protection:mock-edge:';
5
+ export declare const MOCK_RUNTIME_PREFIX = 'tanstack-start-import-protection:mock-runtime:';
6
+ export declare const MARKER_PREFIX = 'tanstack-start-import-protection:marker:';
7
+ export declare const IMPORT_PROTECTION_DEBUG: boolean;
8
+ export declare const IMPORT_PROTECTION_DEBUG_FILTER: string | undefined;
9
+ export declare const KNOWN_SOURCE_EXTENSIONS: Set<string>;
10
+ /** Vite's browser-visible prefix for virtual modules (replaces `\0`). */
11
+ export declare const VITE_BROWSER_VIRTUAL_PREFIX = '/@id/__x00__';