@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.61

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 (278) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +8 -2
  3. package/README.md +8 -3
  4. package/akanApp/akanApp.host.test.ts +4 -2
  5. package/akanApp/akanApp.host.ts +11 -0
  6. package/akanConfig/akanBin.ts +4 -0
  7. package/akanConfig/akanConfig.test.ts +280 -19
  8. package/akanConfig/akanConfig.ts +96 -270
  9. package/akanConfig/akanWorkers.test.ts +73 -0
  10. package/akanConfig/akanWorkers.ts +61 -0
  11. package/akanConfig/desktopServerConfig.ts +96 -0
  12. package/akanConfig/dockerImage.ts +216 -0
  13. package/akanConfig/index.ts +2 -0
  14. package/akanConfig/nativeFileSettings.ts +33 -0
  15. package/akanConfig/nativeKeys.ts +52 -0
  16. package/akanConfig/types.ts +2 -0
  17. package/app/appBin.test.ts +63 -0
  18. package/app/appBin.ts +50 -0
  19. package/app/applicationBuildReporter.test.ts +51 -1
  20. package/app/applicationBuildReporter.ts +6 -1
  21. package/app/applicationBuildRunner.test.ts +358 -5
  22. package/app/applicationBuildRunner.ts +204 -30
  23. package/app/dictionarySizes.test.ts +40 -0
  24. package/app/dictionarySizes.ts +95 -0
  25. package/app/routeFilesReport.test.ts +59 -0
  26. package/app/routeFilesReport.ts +46 -0
  27. package/app/routeJsBudget.ts +18 -4
  28. package/artifact/implicitRootLayout.test.ts +19 -0
  29. package/artifact/implicitRootLayout.ts +16 -2
  30. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  31. package/artifact/storeBootstrap.test.ts +28 -0
  32. package/artifact/storeBootstrap.ts +64 -8
  33. package/biome.base.json +7 -5
  34. package/codeAgent/agent/CodeAgent.ts +36 -16
  35. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  36. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  37. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  38. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  39. package/codeAgent/agent/codeAgent.test.ts +62 -0
  40. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  41. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  42. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  43. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  44. package/codeAgent/skills/akan-debug/SKILL.md +1 -1
  45. package/codeAgent/skills/akan-deps/SKILL.md +3 -2
  46. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  47. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  48. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  49. package/codeAgent/skills/akan-page/SKILL.md +52 -28
  50. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  51. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  52. package/codeAgent/skills/akan-service/SKILL.md +10 -11
  53. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  54. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  55. package/commandDecorators/command.ts +28 -12
  56. package/commandDecorators/commandBuilder.ts +8 -1
  57. package/commandDecorators/commandDecorators.test.ts +70 -3
  58. package/commandDecorators/helpFormatter.ts +14 -12
  59. package/context/akanContext.ts +2 -0
  60. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  61. package/docs/apiReference.test.ts +19 -0
  62. package/docs/apiReference.ts +28 -5
  63. package/executors/appExecutor.ts +26 -12
  64. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  65. package/executors/clientRuntimeKeys.fixture.json +393 -0
  66. package/executors/clientRuntimeKeys.test.ts +1690 -0
  67. package/executors/executor.ts +14 -6
  68. package/executors/executors.test.ts +140 -1
  69. package/executors/sysExecutor.ts +112 -8
  70. package/executors/workspaceExecutor.ts +7 -4
  71. package/frontendBuild/allRoutesBuilder.ts +99 -7
  72. package/frontendBuild/autoImportSync.ts +3 -2
  73. package/frontendBuild/buildRouteClient.test.ts +686 -13
  74. package/frontendBuild/clientBuildTypes.ts +26 -0
  75. package/frontendBuild/clientEntriesBundler.ts +49 -1
  76. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  77. package/frontendBuild/clientEntryDiscovery.ts +136 -14
  78. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  79. package/frontendBuild/clientEntryGroups.ts +61 -0
  80. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  81. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  82. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  83. package/frontendBuild/csrDevPatcher.test.ts +1 -1
  84. package/frontendBuild/csrDevPatcher.ts +33 -7
  85. package/frontendBuild/csrDevTypes.ts +9 -0
  86. package/frontendBuild/devBarrelImports.test.ts +154 -0
  87. package/frontendBuild/devBarrelImports.ts +83 -23
  88. package/frontendBuild/devRegistryBundler.ts +4 -2
  89. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  90. package/frontendBuild/devRouteRuntime.ts +167 -0
  91. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  92. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  93. package/frontendBuild/dictionaryConstants.ts +136 -0
  94. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  95. package/frontendBuild/dictionaryPackState.ts +131 -0
  96. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  97. package/frontendBuild/dictionaryPacking.ts +160 -0
  98. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  99. package/frontendBuild/dictionaryRoutes.ts +227 -0
  100. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  101. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  102. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  103. package/frontendBuild/precompressArtifacts.ts +34 -8
  104. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  105. package/frontendBuild/renderedEntries.ts +144 -0
  106. package/frontendBuild/routeClientBuilder.ts +407 -43
  107. package/frontendBuild/routeHandoffs.test.ts +155 -0
  108. package/frontendBuild/routeHandoffs.ts +117 -0
  109. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  110. package/frontendBuild/routeModulePreloads.ts +20 -11
  111. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  112. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  113. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  114. package/frontendBuild/routeRuntimePays.ts +117 -0
  115. package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
  116. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  117. package/frontendBuild/ssrDevBundler.ts +66 -11
  118. package/frontendBuild/vendorFileImports.test.ts +254 -0
  119. package/frontendBuild/vendorFileImports.ts +163 -0
  120. package/frontendBuild/vendorNarrowing.ts +28 -0
  121. package/frontendBuild/vendorSpecifiers.ts +2 -0
  122. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  123. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  124. package/incrementalBuilder/builderBoot.ts +5 -5
  125. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  126. package/incrementalBuilder/builderLanes.ts +2 -2
  127. package/incrementalBuilder/builderWatch.ts +8 -8
  128. package/incrementalBuilder/csrRegistry.ts +4 -4
  129. package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
  130. package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
  131. package/incrementalBuilder/ssrRegistry.ts +6 -6
  132. package/index.ts +1 -1
  133. package/integration/renderAdmissionSoak.test.ts +99 -0
  134. package/integration/renderAdmissionSoak.ts +609 -0
  135. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  136. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  137. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  138. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  139. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  140. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  141. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  142. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  143. package/lint/biomeBase.test.ts +50 -3
  144. package/lint/biomeBase.ts +1 -1
  145. package/lint/biomeCheck.test.ts +162 -0
  146. package/lint/biomeCheck.ts +131 -0
  147. package/lint/linter.test.ts +16 -11
  148. package/lint/no-arbitrary-color.grit +5 -0
  149. package/lint/no-conditional-st-hook.grit +5 -1
  150. package/lint/no-daisyui-legacy-class.grit +8 -0
  151. package/lint/no-document-cookie.grit +3 -0
  152. package/lint/no-inline-color.grit +10 -2
  153. package/lint/no-oversized-list-limit.grit +2 -0
  154. package/lint/no-raw-palette-class.grit +7 -0
  155. package/lint/no-unpublished-form-setter.grit +2 -0
  156. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  157. package/lint/no-web-storage.grit +3 -0
  158. package/lint/withheldEnvFile.ts +17 -0
  159. package/mobile/desktopBin.ts +2 -2
  160. package/mobile/desktopServerStage.test.ts +18 -3
  161. package/mobile/desktopServerStage.ts +7 -2
  162. package/mobile/nativeApp.test.ts +7 -5
  163. package/mobile/nativeApp.ts +2 -2
  164. package/mobile/nativeConfig.test.ts +96 -1
  165. package/mobile/nativeConfig.ts +46 -12
  166. package/mobile/nativePublicEnv.ts +1 -1
  167. package/mobile/serverBundleSecrets.ts +43 -0
  168. package/package.json +20 -171
  169. package/packageExports.test.ts +38 -24
  170. package/quality/dictionaryKeys.test.ts +356 -0
  171. package/quality/dictionaryKeys.ts +488 -0
  172. package/quality/objectImportReport.test.ts +36 -0
  173. package/quality/objectImportReport.ts +105 -0
  174. package/quality/qualityScanner.ts +1 -1
  175. package/quality/routeRuntimeReport.test.ts +91 -0
  176. package/quality/routeRuntimeReport.ts +121 -0
  177. package/quality/runtimeConstantFacts.ts +71 -0
  178. package/quality/runtimeConstantGraph.ts +123 -0
  179. package/quality/runtimeConstantReads.ts +116 -0
  180. package/quality/runtimeImports.test.ts +190 -0
  181. package/quality/runtimeImports.ts +233 -0
  182. package/quality/runtimeKeyNames.ts +46 -0
  183. package/quality/runtimeLexicalScope.ts +132 -0
  184. package/quality/runtimeMarkerReach.test.ts +84 -0
  185. package/quality/runtimeMarkerReach.ts +255 -0
  186. package/quality/runtimeModuleFacts.ts +290 -0
  187. package/quality/runtimeNameTable.test.ts +172 -0
  188. package/quality/runtimeNameTable.ts +477 -0
  189. package/quality/runtimeScopeReport.test.ts +123 -0
  190. package/quality/runtimeScopeReport.ts +167 -0
  191. package/quality/runtimeSliceKey.ts +269 -0
  192. package/quality/runtimeSyntax.ts +133 -0
  193. package/quality/runtimeTable.fixture.ts +189 -0
  194. package/quality/runtimeUse.test.ts +737 -0
  195. package/quality/runtimeUse.ts +696 -0
  196. package/quality/runtimeUseReadable.test.ts +393 -0
  197. package/quality/ssrScanner.test.ts +13 -0
  198. package/quality/ssrScanner.ts +1 -1
  199. package/quality/translatorBindings.ts +187 -0
  200. package/test/secretEnvFixture.ts +134 -0
  201. package/test/testHelpers.ts +11 -0
  202. package/transforms/barrelAnalyzer.ts +26 -4
  203. package/transforms/barrelImportsPlugin.ts +121 -32
  204. package/transforms/exportReach.test.ts +162 -0
  205. package/transforms/exportReach.ts +308 -0
  206. package/transforms/frameworkObjects.fixture.tsx +58 -0
  207. package/transforms/frameworkObjects.test.ts +54 -0
  208. package/transforms/modelReference.test.ts +196 -0
  209. package/transforms/modelReference.ts +39 -0
  210. package/transforms/moduleParts.test.ts +225 -0
  211. package/transforms/moduleParts.ts +418 -0
  212. package/transforms/objectImportEdits.ts +150 -0
  213. package/transforms/objectMemberImports.test.ts +633 -0
  214. package/transforms/objectMemberImports.ts +571 -0
  215. package/transforms/objectMemberLookup.ts +150 -0
  216. package/transforms/objectModule.test.ts +307 -0
  217. package/transforms/objectModule.ts +482 -0
  218. package/transforms/objectModuleAnalyzer.ts +104 -0
  219. package/transforms/partImports.test.ts +76 -0
  220. package/transforms/partImports.ts +110 -0
  221. package/transforms/partModules.test.ts +187 -0
  222. package/transforms/partModules.ts +90 -0
  223. package/transforms/partPurity.ts +124 -0
  224. package/transforms/reactIconImports.test.ts +231 -0
  225. package/transforms/reactIconImports.ts +325 -0
  226. package/transforms/routeConstants.ts +122 -0
  227. package/transforms/routeRuntime.test.ts +835 -0
  228. package/transforms/routeRuntime.ts +703 -0
  229. package/transforms/routeRuntimeEdits.ts +92 -0
  230. package/transforms/routeRuntimeGraph.ts +66 -0
  231. package/transforms/routeRuntimePlan.ts +244 -0
  232. package/transforms/secretEnvDeclaration.test.ts +208 -0
  233. package/transforms/secretEnvDeclaration.ts +213 -0
  234. package/transforms/secretEnvFile.test.ts +117 -0
  235. package/transforms/secretEnvFile.ts +113 -0
  236. package/transforms/secretEnvName.test.ts +54 -0
  237. package/transforms/secretEnvName.ts +29 -0
  238. package/transforms/secretEnvSource.test.ts +148 -0
  239. package/transforms/secretEnvSource.ts +166 -0
  240. package/transforms/serverEnvEvaluationError.ts +11 -0
  241. package/transforms/serverEnvPlugin.test.ts +2 -1
  242. package/transforms/serverEnvPlugin.ts +13 -0
  243. package/transforms/serverEnvProfile.test.ts +129 -2
  244. package/transforms/serverEnvProfile.ts +126 -40
  245. package/transforms/serverEnvSecrets.test.ts +292 -0
  246. package/transforms/signalDescriptors.test.ts +280 -0
  247. package/transforms/signalDescriptors.ts +227 -0
  248. package/transforms/thisFreeExports.ts +87 -0
  249. package/transforms/transforms.test.ts +180 -3
  250. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  251. package/tunnel/createTunnel.test.ts +29 -8
  252. package/tunnel/createTunnel.ts +22 -11
  253. package/tunnel/ssh2Module.test.ts +37 -0
  254. package/tunnel/ssh2Module.ts +32 -0
  255. package/tunnel/sshTunnel.ts +4 -2
  256. package/typecheck/projectTypecheck.test.ts +32 -1
  257. package/typecheck/projectTypecheck.ts +3 -3
  258. package/typecheck/typeChecker.test.ts +49 -0
  259. package/typecheck/typeChecker.ts +9 -7
  260. package/typecheck/withheldDiagnostics.ts +41 -0
  261. package/util/fileEditor.ts +1 -0
  262. package/util/selectModel.ts +1 -0
  263. package/workflow/executor.ts +6 -2
  264. package/workflow/index.ts +1 -0
  265. package/workflow/plan.ts +36 -7
  266. package/workflow/types.ts +1 -1
  267. package/workflow/uiTarget.ts +50 -0
  268. package/workspace/envSeed.test.ts +30 -1
  269. package/workspace/envSeed.ts +30 -1
  270. package/workspace/getRelatedCnsts.ts +7 -0
  271. package/workspace/mainCheckout.test.ts +55 -0
  272. package/workspace/mainCheckout.ts +38 -0
  273. package/workspace/scanInfo.test.ts +39 -0
  274. package/workspace/scanInfo.ts +55 -6
  275. package/workspace/slicePlanner.ts +1 -1
  276. package/workspace/workspaceLayout.test.ts +5 -1
  277. package/workspace/workspaceLayout.ts +3 -0
  278. package/CHANGELOG.md +0 -2717
@@ -0,0 +1,190 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import path from "node:path";
3
+ import ts from "typescript";
4
+ import { RuntimeImports } from "./runtimeImports";
5
+
6
+ const files = [
7
+ "apps/demo/ui/Card.tsx",
8
+ "apps/demo/lib/memo/Memo.Zone.tsx",
9
+ "apps/demo/lib/st/inner.ts",
10
+ "libs/kit/ui/deep/inner/Panel.tsx",
11
+ ];
12
+ const targets = [
13
+ "apps/demo/client",
14
+ "apps/demo/lib/useClient",
15
+ "apps/demo/lib/usePage",
16
+ "apps/demo/lib/st",
17
+ "apps/demo/lib/sig",
18
+ "apps/demo/lib/__client/memo.st",
19
+ "libs/kit/client",
20
+ "libs/kit/lib/useClient",
21
+ ];
22
+ const tails = ["", ".ts", ".tsx", ".js", ".jsx", "/index", "/index.ts", "/index.js"];
23
+ const frameworks = ["akanjs/store", "akanjs/client", "akanjs/./store", "akanjs/client/index", "akanjs/store/baseSt"];
24
+
25
+ const spellingsOf = (file: string, target: string) => {
26
+ const [root = "", scope = "", ...rest] = target.split("/");
27
+ const relative = path.posix.relative(path.posix.dirname(file), target);
28
+ const dotted = relative.startsWith(".") ? relative : `./${relative}`;
29
+ return [
30
+ ...tails.flatMap((tail) => [
31
+ `@${target}${tail}`,
32
+ `@${root}/${scope}//${rest.join("/")}${tail}`,
33
+ `@${root}/${scope}/./${rest.join("/")}${tail}`,
34
+ `${dotted}${tail}`,
35
+ `${dotted.replace(/\//g, "//")}${tail}`,
36
+ `${dotted}/../${path.posix.basename(target)}${tail}`,
37
+ `./ /..${dotted.slice(1)}${tail}`,
38
+ ]),
39
+ ".",
40
+ "..",
41
+ "./",
42
+ "../.",
43
+ ];
44
+ };
45
+
46
+ const escapedOf = (spelling: string) => {
47
+ const at = spelling.search(/[a-z](?=[^/]*$)/);
48
+ if (at < 0) return [spelling];
49
+ const code = spelling.charCodeAt(at);
50
+ const swap = (escape: string) => `${spelling.slice(0, at)}${escape}${spelling.slice(at + 1)}`;
51
+ return [
52
+ spelling,
53
+ swap(`\\u${code.toString(16).padStart(4, "0")}`),
54
+ swap(`\\u{${code.toString(16)}}`),
55
+ swap(`\\x${code.toString(16)}`),
56
+ swap(`\\\n${spelling[at]}`),
57
+ swap(`\\\r\n${spelling[at]}`),
58
+ ];
59
+ };
60
+
61
+ const statementsOf = (literal: string) => [
62
+ `import { st } from ${literal};\n`,
63
+ `export * from ${literal};\n`,
64
+ `import client = require(${literal});\n`,
65
+ `const client = require(${literal});\n`,
66
+ `export const load = () => import(${literal});\n`,
67
+ `import ${literal};\n`,
68
+ ];
69
+
70
+ const specifierOf = (file: string, text: string) => {
71
+ let found: string | null = null;
72
+ const visit = (node: ts.Node) => {
73
+ if (found === null && ts.isStringLiteralLike(node)) found = node.text;
74
+ ts.forEachChild(node, visit);
75
+ };
76
+ visit(ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX));
77
+ return found as string | null;
78
+ };
79
+
80
+ describe("RuntimeImports", () => {
81
+ test("never skips a file whose specifier, in any spelling, the specifier reader resolves", () => {
82
+ let resolved = 0;
83
+ const skipped: string[] = [];
84
+ for (const file of files)
85
+ for (const spelling of [...targets.flatMap((target) => spellingsOf(file, target)), ...frameworks])
86
+ for (const escaped of escapedOf(spelling))
87
+ for (const quote of ['"', "'", "`"])
88
+ for (const text of statementsOf(`${quote}${escaped}${quote}`)) {
89
+ const specifier = specifierOf(file, `// a \`note\`, it's\n${text}`);
90
+ if (specifier === null || !RuntimeImports.targetOf(specifier, file)) continue;
91
+ resolved++;
92
+ if (!RuntimeImports.mayUseRuntime(`// a \`note\`, it's\n${text}`, file)) skipped.push(`${file}: ${text}`);
93
+ }
94
+ expect(skipped).toEqual([]);
95
+ expect(resolved).toBeGreaterThan(20000);
96
+ });
97
+
98
+ test("reads a specifier through its extension, index, doubled slashes and dot segments", () => {
99
+ const file = "apps/demo/lib/memo/Memo.Zone.tsx";
100
+ expect(
101
+ [
102
+ "@apps/demo/client.js",
103
+ "@apps/demo//client",
104
+ "@apps/demo/./lib/../client/index.tsx",
105
+ "../useClient.js",
106
+ "../__client/memo.st",
107
+ "../__client/_base.fetch",
108
+ "../__client/_st",
109
+ "../__client/_useClient.ts",
110
+ "akanjs/./store",
111
+ "akanjs/store/baseSt",
112
+ "akanjs/client/native/haptics",
113
+ "akanjs/fetch",
114
+ "@apps/demo/lib/cnst",
115
+ ].map((specifier) => RuntimeImports.targetOf(specifier, file)?.kind ?? null),
116
+ ).toEqual([
117
+ "client",
118
+ "client",
119
+ "client",
120
+ "useClient",
121
+ "piece",
122
+ "piece",
123
+ "_st",
124
+ "_useClient",
125
+ "framework-store",
126
+ "framework-deep",
127
+ null,
128
+ "framework-fetch",
129
+ null,
130
+ ]);
131
+ });
132
+
133
+ test("names the agent entry apart, and lists as its screen exports the files that import no store or fetch", async () => {
134
+ const kindOf = (specifier: string) => RuntimeImports.targetOf(specifier, "apps/demo/ui/Card.tsx")?.kind ?? null;
135
+ expect(
136
+ [
137
+ "akanjs/store/agent",
138
+ "akanjs/store/agent/index.ts",
139
+ "akanjs/store/agent/ScreenSettle",
140
+ "akanjs/client/agent",
141
+ ].map(kindOf),
142
+ ).toEqual(["framework-agent", "framework-agent", "framework-deep", "framework-deep"]);
143
+ const use = (name: string) => RuntimeImports.useOf({ scope: "apps/demo", kind: "framework-agent" }, name, false);
144
+ expect([use("ScreenSettle"), use("AgentBridge"), use("somethingNew")]).toEqual([
145
+ null,
146
+ { reason: "whole-runtime-import", why: "a framework internal may hand out the whole runtime" },
147
+ { reason: "whole-runtime-import", why: "a framework internal may hand out the whole runtime" },
148
+ ]);
149
+
150
+ const dir = path.join(import.meta.dir, "../../../akanjs/store/agent");
151
+ const index = await Bun.file(path.join(dir, "index.ts")).text();
152
+ const files = new Map<string, { imports: string[]; exports: string[]; text: string }>();
153
+ for (const [, name = ""] of index.matchAll(/export \* from "\.\/(\w+)";/g)) {
154
+ const text = await Bun.file(path.join(dir, `${name}.ts`)).text();
155
+ const source = ts.createSourceFile(name, text, ts.ScriptTarget.Latest);
156
+ const imports = source.statements.flatMap((statement) => {
157
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return [];
158
+ const clause = statement.importClause;
159
+ const named =
160
+ clause?.namedBindings && ts.isNamedImports(clause.namedBindings) ? clause.namedBindings.elements : [];
161
+ const values = named.filter((element) => !element.isTypeOnly).map((element) => element.name.text);
162
+ if (clause?.isTypeOnly || (clause && !clause.name && named.length && !values.length)) return [];
163
+ const specifier = statement.moduleSpecifier.text;
164
+ return specifier === "akanjs/client" && values.join() === "router" ? [] : [specifier];
165
+ });
166
+ const exports = source.statements.flatMap((statement) => {
167
+ const exported =
168
+ ts.canHaveModifiers(statement) &&
169
+ ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
170
+ if (!exported) return [];
171
+ if (ts.isVariableStatement(statement))
172
+ return statement.declarationList.declarations.map((declaration) => declaration.name.getText(source));
173
+ return [(statement as ts.DeclarationStatement).name?.text ?? "default"];
174
+ });
175
+ files.set(name, { imports, exports, text });
176
+ }
177
+ expect(files.size).toBe(12);
178
+ const outside = new Set(["akanjs/base", "use-agentic"]);
179
+ for (let size = -1; size !== files.size; ) {
180
+ size = files.size;
181
+ for (const [name, { imports }] of files)
182
+ if (!imports.every((specifier) => outside.has(specifier) || files.has(specifier.replace(/^\.\//, ""))))
183
+ files.delete(name);
184
+ }
185
+ expect([...files.values()].filter(({ text }) => /globalThis|Symbol\.for\(|import\(/.test(text))).toEqual([]);
186
+ expect([...files.values()].flatMap(({ exports }) => exports).sort()).toEqual(
187
+ [...RuntimeImports.agentScreenNames].sort(),
188
+ );
189
+ });
190
+ });
@@ -0,0 +1,233 @@
1
+ import path from "node:path";
2
+ import { RuntimeConstantFacts } from "./runtimeConstantFacts";
3
+ import type { RuntimeFamily } from "./runtimeNameTable";
4
+
5
+ export type RuntimeImportKind =
6
+ | "client"
7
+ | "useClient"
8
+ | "usePage"
9
+ | "st"
10
+ | "sig"
11
+ | "piece"
12
+ | "_st"
13
+ | "_useClient"
14
+ | "framework-store"
15
+ | "framework-client"
16
+ | "framework-fetch"
17
+ | "framework-agent"
18
+ | "framework-deep";
19
+
20
+ export interface RuntimeImportTarget {
21
+ scope: string | null;
22
+ kind: RuntimeImportKind;
23
+ }
24
+
25
+ export type RuntimeHandleKind =
26
+ | "st"
27
+ | "root"
28
+ | "self"
29
+ | "state"
30
+ | "getter"
31
+ | "fetch"
32
+ | "signal"
33
+ | "akanjs/store"
34
+ | "akanjs/client"
35
+ | Exclude<RuntimeFamily, "fetch">;
36
+
37
+ export interface RuntimeHandle {
38
+ kind: RuntimeHandleKind;
39
+ members?: ReadonlySet<string>;
40
+ cast?: boolean;
41
+ }
42
+
43
+ export type RuntimeBinding =
44
+ | { type: "handle"; handle: RuntimeHandle }
45
+ | { type: "rootStore" }
46
+ | { type: "storeFactory" }
47
+ | { type: "whole"; name: string }
48
+ | { type: "cnst"; scope: string };
49
+
50
+ export interface RuntimeConstantTarget {
51
+ scope: string;
52
+ kind: "cnst" | "barrel";
53
+ }
54
+
55
+ export type RuntimeImportUse =
56
+ | { binding: RuntimeBinding }
57
+ | { reason: "unknown-name" | "whole-runtime-import"; why: string }
58
+ | null;
59
+
60
+ const runtimePathPattern =
61
+ /^((?:apps|libs)\/[^/]+)\/(client|lib\/useClient|lib\/usePage|lib\/st|lib\/sig|lib\/__client\/.+)$/;
62
+ const frameworkPathPattern = /^akanjs\/(store|client|fetch)(\/.+)?$/;
63
+ const constantPathPattern = /^((?:apps|libs)\/[^/]+)\/lib\/cnst$/;
64
+ const quotedPattern = /(?=(["'])((?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\n\r])*)\1)|(?=`((?:\\[\s\S]|[^\\`])*)`)/g;
65
+ const loaderPattern = /\brequire\b|\bimport\s*(?:\(|\/[/*])/;
66
+ const escapePattern = /\\(u\{[0-9a-fA-F]+\}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|\r\n|[\s\S])/g;
67
+ const simpleEscapes: Record<string, string> = {
68
+ n: "\n",
69
+ r: "\r",
70
+ t: "\t",
71
+ b: "\b",
72
+ f: "\f",
73
+ v: "\v",
74
+ "0": "\0",
75
+ "\r\n": "",
76
+ "\n": "",
77
+ "\r": "",
78
+ "
": "",
79
+ "
": "",
80
+ };
81
+ const quietNames = new Set(["usePage", "msg", "Err"]);
82
+ const wholePieces = new Set(["_st", "_useClient"]);
83
+ //? Each of these hands out the tab's one root store or fetch client, so a name read through it is not visible here.
84
+ const frameworkWholeNames = new Set([
85
+ "RootStore",
86
+ "StoreRegistry",
87
+ "StoreInstance",
88
+ "base",
89
+ "BaseStore",
90
+ "StoreCatalogue",
91
+ "StoreSurfaceSource",
92
+ "ensureStoreSurface",
93
+ "AgentBridge",
94
+ "AgentContext",
95
+ "FetchClient",
96
+ ]);
97
+ //? What `akanjs/store/agent` exports that reads the screen or the router and never the root store or the fetch client.
98
+ const agentScreenNames = new Set([
99
+ "AgentCursor",
100
+ "AgentPrompts",
101
+ "AgentVisual",
102
+ "AgentVisualOption",
103
+ "ScreenFlash",
104
+ "ScreenImage",
105
+ "ScreenImageView",
106
+ "ScreenReadOptions",
107
+ "ScreenReader",
108
+ "ScreenSettle",
109
+ "ScreenSettleOptions",
110
+ "ScreenTarget",
111
+ ]);
112
+
113
+ export class RuntimeImports {
114
+ static readonly frameworkWholeNames: ReadonlySet<string> = frameworkWholeNames;
115
+ static readonly agentScreenNames: ReadonlySet<string> = agentScreenNames;
116
+
117
+ static mayUseRuntime(text: string, fileName: string) {
118
+ return (
119
+ loaderPattern.test(text) ||
120
+ (text.includes("sliceName") && text.includes("refName")) ||
121
+ RuntimeImports.#quotes(text, (specifier) => !!RuntimeImports.targetOf(specifier, fileName))
122
+ );
123
+ }
124
+
125
+ static mayUseConstants(text: string, fileName: string) {
126
+ return RuntimeImports.#quotes(
127
+ text,
128
+ (specifier) =>
129
+ !!RuntimeImports.constantTargetOf(specifier, fileName) || !!RuntimeConstantFacts.ownerOf(specifier, fileName),
130
+ );
131
+ }
132
+
133
+ static #quotes(text: string, found: (specifier: string) => boolean) {
134
+ for (const [, , quoted, template] of text.matchAll(quotedPattern)) {
135
+ const raw = quoted ?? template?.replace(/\r\n?/g, "\n") ?? "";
136
+ if (found(RuntimeImports.#decode(raw))) return true;
137
+ }
138
+ return false;
139
+ }
140
+
141
+ static targetOf(specifier: string, fileName: string): RuntimeImportTarget | null {
142
+ const fileScope = fileName.match(/^((?:apps|libs)\/[^/]+)\//)?.[1] ?? null;
143
+ if (specifier.startsWith("akanjs/")) {
144
+ const framework = RuntimeImports.#stripped(path.posix.normalize(specifier)).match(frameworkPathPattern);
145
+ const [, facet, deep] = framework ?? [];
146
+ if (!facet || (facet === "client" && deep && /^\/native(?:\/|$)/.test(deep))) return null;
147
+ const kind = !deep ? `framework-${facet}` : facet === "store" && deep === "/agent" ? "framework-agent" : null;
148
+ return { scope: fileScope, kind: (kind ?? "framework-deep") as RuntimeImportKind };
149
+ }
150
+ const aliased = specifier.match(/^@(apps|libs)\/([\s\S]+)$/);
151
+ const joined = aliased
152
+ ? `${aliased[1]}/${aliased[2]}`
153
+ : specifier.startsWith(".")
154
+ ? path.posix.join(path.posix.dirname(fileName), specifier)
155
+ : null;
156
+ const match =
157
+ joined === null ? null : RuntimeImports.#stripped(path.posix.normalize(joined)).match(runtimePathPattern);
158
+ if (!match?.[1] || !match[2]) return null;
159
+ const piece = match[2].match(/^lib\/__client\/(.+)$/)?.[1];
160
+ const kind = piece === undefined ? match[2].replace(/^lib\//, "") : wholePieces.has(piece) ? piece : "piece";
161
+ return { scope: match[1], kind: kind as RuntimeImportKind };
162
+ }
163
+
164
+ static constantTargetOf(specifier: string, fileName: string): RuntimeConstantTarget | null {
165
+ const barrel = specifier.match(/^@(libs\/[^/]+)$/)?.[1];
166
+ if (barrel) return { scope: barrel, kind: "barrel" };
167
+ const aliased = specifier.match(/^@((?:apps|libs)\/[\s\S]+)$/)?.[1];
168
+ const joined =
169
+ aliased ?? (specifier.startsWith(".") ? path.posix.join(path.posix.dirname(fileName), specifier) : null);
170
+ const scope = joined && RuntimeImports.#stripped(path.posix.normalize(joined)).match(constantPathPattern)?.[1];
171
+ return scope ? { scope, kind: "cnst" } : null;
172
+ }
173
+
174
+ static useOf(target: RuntimeImportTarget, imported: string, typeOnly: boolean): RuntimeImportUse {
175
+ const { kind } = target;
176
+ if (kind.startsWith("framework-")) return typeOnly ? null : RuntimeImports.#frameworkUse(kind, imported);
177
+ const whole = (why: string): RuntimeImportUse => ({ reason: "whole-runtime-import", why });
178
+ if (imported === "RootStore" && (kind === "client" || kind === "st" || kind === "_st"))
179
+ return typeOnly
180
+ ? { binding: { type: "rootStore" } }
181
+ : whole("a value import of RootStore loads the store runtime whole");
182
+ if (typeOnly) return null;
183
+ if (kind === "sig" || kind === "_st" || kind === "_useClient")
184
+ return whole(`the ${kind} file holds the runtime of every module`);
185
+ if (kind === "piece") return whole("a runtime piece imported by hand is not read name by name");
186
+ const handle = (handleKind: RuntimeHandleKind): RuntimeImportUse => ({
187
+ binding: { type: "handle", handle: { kind: handleKind } },
188
+ });
189
+ if ((imported === "fetch" || imported === "sig") && kind !== "st") return handle(imported);
190
+ if (imported === "st" && kind !== "useClient") return handle("st");
191
+ if (kind === "st" || (kind === "client" && imported === "store"))
192
+ return whole(`${imported} holds every module's store`);
193
+ if (kind !== "client" ? quietNames.has(imported) : quietNames.has(imported) || imported === "cnst") return null;
194
+ if (kind === "client" && /^[A-Z]/.test(imported)) return null;
195
+ return { reason: "unknown-name", why: `${imported} reaches past the names a module answers` };
196
+ }
197
+
198
+ static #frameworkUse(kind: RuntimeImportKind, imported: string): RuntimeImportUse {
199
+ if (kind === "framework-agent" && agentScreenNames.has(imported)) return null;
200
+ if (kind === "framework-deep" || kind === "framework-agent")
201
+ return { reason: "whole-runtime-import", why: "a framework internal may hand out the whole runtime" };
202
+ if (frameworkWholeNames.has(imported)) return { binding: { type: "whole", name: imported } };
203
+ if (kind === "framework-store" && imported === "st") return { binding: { type: "handle", handle: { kind: "st" } } };
204
+ if (kind === "framework-store" && imported === "store") return { binding: { type: "storeFactory" } };
205
+ if (kind === "framework-client" && (imported === "fetch" || imported === "sig"))
206
+ return { binding: { type: "handle", handle: { kind: imported } } };
207
+ return null;
208
+ }
209
+
210
+ static namespaceUse(kind: RuntimeImportKind, name: string): RuntimeImportUse {
211
+ if (kind === "framework-store" || kind === "framework-client")
212
+ return {
213
+ binding: { type: "handle", handle: { kind: kind === "framework-store" ? "akanjs/store" : "akanjs/client" } },
214
+ };
215
+ if (kind === "framework-fetch") return { binding: { type: "whole", name } };
216
+ return { reason: "whole-runtime-import", why: "a namespace or default import holds the whole runtime" };
217
+ }
218
+
219
+ static #stripped(resolved: string) {
220
+ return resolved.replace(/\.(?:tsx?|jsx?)$/, "").replace(/\/index$/, "");
221
+ }
222
+
223
+ static #decode(raw: string) {
224
+ return raw.replace(escapePattern, (_, escape: string) => {
225
+ if (escape.startsWith("u{")) {
226
+ const code = Number.parseInt(escape.slice(2, -1), 16);
227
+ return code <= 0x10ffff ? String.fromCodePoint(code) : "";
228
+ }
229
+ if (escape.length > 1 && /^[ux]/.test(escape)) return String.fromCharCode(Number.parseInt(escape.slice(1), 16));
230
+ return simpleEscapes[escape] ?? escape;
231
+ });
232
+ }
233
+ }
@@ -0,0 +1,46 @@
1
+ import ts from "typescript";
2
+ import type { RuntimeLexicalScope } from "./runtimeLexicalScope";
3
+ import { staticName } from "./runtimeSyntax";
4
+
5
+ const maxDepth = 8;
6
+
7
+ export class RuntimeKeyNames {
8
+ readonly #lexical: RuntimeLexicalScope;
9
+
10
+ constructor(lexical: RuntimeLexicalScope) {
11
+ this.#lexical = lexical;
12
+ }
13
+
14
+ //? An assertion to literal names wins over the value under it: the author states the key behaves as that name.
15
+ namesOf(expression: ts.Expression, depth = 0): string[] | null {
16
+ let value = expression;
17
+ while (ts.isParenthesizedExpression(value) || ts.isNonNullExpression(value)) value = value.expression;
18
+ if (ts.isStringLiteralLike(value) || ts.isNumericLiteral(value)) return [value.text];
19
+ if (ts.isAsExpression(value) || ts.isTypeAssertionExpression(value) || ts.isSatisfiesExpression(value))
20
+ return RuntimeKeyNames.#literalsOf(value.type) ?? this.namesOf(value.expression, depth);
21
+ const initializer = ts.isIdentifier(value) && depth < maxDepth ? this.constantOf(value) : null;
22
+ return initializer ? this.namesOf(initializer, depth + 1) : null;
23
+ }
24
+
25
+ ofProperty(name: ts.PropertyName | ts.BindingName): string[] | null {
26
+ if (ts.isComputedPropertyName(name)) return this.namesOf(name.expression);
27
+ const text = staticName(name);
28
+ return text === null ? null : [text];
29
+ }
30
+
31
+ constantOf(identifier: ts.Identifier): ts.Expression | null {
32
+ const declaration = this.#lexical.resolve(identifier)?.parent;
33
+ if (!declaration || !ts.isVariableDeclaration(declaration) || !ts.isIdentifier(declaration.name)) return null;
34
+ const list = declaration.parent;
35
+ const constant = ts.isVariableDeclarationList(list) && !!(list.flags & ts.NodeFlags.Const);
36
+ return constant ? (declaration.initializer ?? null) : null;
37
+ }
38
+
39
+ static #literalsOf(type: ts.TypeNode): string[] | null {
40
+ if (ts.isParenthesizedTypeNode(type)) return RuntimeKeyNames.#literalsOf(type.type);
41
+ if (ts.isLiteralTypeNode(type)) return ts.isStringLiteralLike(type.literal) ? [type.literal.text] : null;
42
+ if (!ts.isUnionTypeNode(type)) return null;
43
+ const names = type.types.map((member) => RuntimeKeyNames.#literalsOf(member));
44
+ return names.every((member): member is string[] => member !== null) ? [...new Set(names.flat())] : null;
45
+ }
46
+ }
@@ -0,0 +1,132 @@
1
+ import ts from "typescript";
2
+
3
+ export type RuntimeThisOwner =
4
+ | { kind: "class"; node: ts.ClassLikeDeclaration; isStatic: boolean }
5
+ | { kind: "function"; node: ts.SignatureDeclaration };
6
+
7
+ export class RuntimeLexicalScope {
8
+ readonly #declared = new WeakMap<ts.Node, Map<string, ts.Identifier>>();
9
+
10
+ resolve(identifier: ts.Identifier): ts.Identifier | null {
11
+ for (let node: ts.Node | undefined = identifier.parent; node; node = node.parent) {
12
+ if (ts.isFunctionLike(node) && RuntimeLexicalScope.evaluatedOutside(node, identifier)) continue;
13
+ const names = this.#namesOf(node);
14
+ const found = names?.get(identifier.text);
15
+ if (found) return found;
16
+ }
17
+ return null;
18
+ }
19
+
20
+ static thisOwnerOf(node: ts.Node): RuntimeThisOwner | null {
21
+ for (let at: ts.Node | undefined = node.parent; at; at = at.parent) {
22
+ if (ts.isArrowFunction(at) || ts.isClassLike(at)) continue;
23
+ if (ts.isClassElement(at) && ts.isClassLike(at.parent)) {
24
+ if (RuntimeLexicalScope.evaluatedOutside(at, node)) continue;
25
+ const isStatic =
26
+ ts.isClassStaticBlockDeclaration(at) || !!(ts.getCombinedModifierFlags(at) & ts.ModifierFlags.Static);
27
+ return { kind: "class", node: at.parent, isStatic };
28
+ }
29
+ if (ts.isFunctionLike(at)) return { kind: "function", node: at };
30
+ if (ts.isSourceFile(at) || ts.isModuleBlock(at)) return null;
31
+ }
32
+ return null;
33
+ }
34
+
35
+ //? A computed member name and a decorator run where the member is defined, outside its own scope and `this`.
36
+ static evaluatedOutside(member: ts.Node, node: ts.Node) {
37
+ const within = (outer: ts.Node) => node.pos >= outer.pos && node.end <= outer.end;
38
+ const name = (member as ts.NamedDeclaration).name;
39
+ if (name && ts.isComputedPropertyName(name) && within(name)) return true;
40
+ const parameters = ts.isFunctionLike(member) ? member.parameters : [];
41
+ return [member, ...parameters].some(
42
+ (decorated) => ts.canHaveDecorators(decorated) && (ts.getDecorators(decorated) ?? []).some(within),
43
+ );
44
+ }
45
+
46
+ static isReference(identifier: ts.Identifier) {
47
+ const parent = identifier.parent;
48
+ if (ts.isPropertyAccessExpression(parent)) return parent.expression === identifier;
49
+ if (ts.isQualifiedName(parent)) return parent.left === identifier;
50
+ if (ts.isBindingElement(parent)) return parent.initializer === identifier;
51
+ if (ts.isPropertyAssignment(parent) || ts.isPropertyDeclaration(parent) || ts.isParameter(parent))
52
+ return parent.initializer === identifier;
53
+ if (ts.isVariableDeclaration(parent) || ts.isEnumMember(parent)) return parent.initializer === identifier;
54
+ if (
55
+ ts.isImportSpecifier(parent) ||
56
+ ts.isImportClause(parent) ||
57
+ ts.isNamespaceImport(parent) ||
58
+ ts.isExportSpecifier(parent) ||
59
+ ts.isJsxAttribute(parent) ||
60
+ ts.isLabeledStatement(parent) ||
61
+ ts.isBreakOrContinueStatement(parent) ||
62
+ ts.isTypeParameterDeclaration(parent)
63
+ )
64
+ return false;
65
+ if (
66
+ (ts.isFunctionLike(parent) ||
67
+ ts.isClassLike(parent) ||
68
+ ts.isInterfaceDeclaration(parent) ||
69
+ ts.isTypeAliasDeclaration(parent) ||
70
+ ts.isEnumDeclaration(parent) ||
71
+ ts.isModuleDeclaration(parent) ||
72
+ ts.isPropertySignature(parent) ||
73
+ ts.isGetAccessor(parent) ||
74
+ ts.isSetAccessor(parent)) &&
75
+ (parent as ts.NamedDeclaration).name === identifier
76
+ )
77
+ return false;
78
+ return true;
79
+ }
80
+
81
+ #namesOf(node: ts.Node) {
82
+ const cached = this.#declared.get(node);
83
+ if (cached) return cached;
84
+ const names = RuntimeLexicalScope.#collect(node);
85
+ if (names) this.#declared.set(node, names);
86
+ return names;
87
+ }
88
+
89
+ static #collect(node: ts.Node): Map<string, ts.Identifier> | null {
90
+ const names = new Map<string, ts.Identifier>();
91
+ const addBinding = (name: ts.BindingName) => {
92
+ if (ts.isIdentifier(name)) names.set(name.text, name);
93
+ else for (const element of name.elements) if (!ts.isOmittedExpression(element)) addBinding(element.name);
94
+ };
95
+ const addStatements = (statements: readonly ts.Statement[]) => {
96
+ for (const statement of statements) {
97
+ if (ts.isVariableStatement(statement))
98
+ for (const declaration of statement.declarationList.declarations) addBinding(declaration.name);
99
+ else if (
100
+ (ts.isFunctionDeclaration(statement) ||
101
+ ts.isClassDeclaration(statement) ||
102
+ ts.isEnumDeclaration(statement)) &&
103
+ statement.name
104
+ )
105
+ names.set(statement.name.text, statement.name);
106
+ else if (ts.isImportDeclaration(statement)) RuntimeLexicalScope.#addImport(statement, names);
107
+ }
108
+ };
109
+ if (ts.isSourceFile(node) || ts.isBlock(node) || ts.isModuleBlock(node)) addStatements(node.statements);
110
+ else if (ts.isCaseBlock(node)) for (const clause of node.clauses) addStatements(clause.statements);
111
+ else if (ts.isFunctionLike(node)) {
112
+ for (const parameter of node.parameters) addBinding(parameter.name);
113
+ if (ts.isFunctionExpression(node) && node.name) names.set(node.name.text, node.name);
114
+ } else if (ts.isClassExpression(node) && node.name) names.set(node.name.text, node.name);
115
+ else if (ts.isForStatement(node) || ts.isForInStatement(node) || ts.isForOfStatement(node)) {
116
+ const initializer = node.initializer;
117
+ if (initializer && ts.isVariableDeclarationList(initializer))
118
+ for (const declaration of initializer.declarations) addBinding(declaration.name);
119
+ } else if (ts.isCatchClause(node) && node.variableDeclaration) addBinding(node.variableDeclaration.name);
120
+ else return null;
121
+ return names;
122
+ }
123
+
124
+ static #addImport(statement: ts.ImportDeclaration, names: Map<string, ts.Identifier>) {
125
+ const clause = statement.importClause;
126
+ if (!clause) return;
127
+ if (clause.name) names.set(clause.name.text, clause.name);
128
+ const bindings = clause.namedBindings;
129
+ if (bindings && ts.isNamespaceImport(bindings)) names.set(bindings.name.text, bindings.name);
130
+ else if (bindings) for (const element of bindings.elements) names.set(element.name.text, element.name);
131
+ }
132
+ }