prunelle 0.0.0-stage → 0.5.2

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 (200) hide show
  1. package/llms.txt +152 -0
  2. package/package.json +59 -4
  3. package/src/a11y/declaration.ts +335 -0
  4. package/src/a11y/index.ts +446 -0
  5. package/src/a11y/rgaa-map.ts +184 -0
  6. package/src/ambient.d.ts +6 -0
  7. package/src/attrs.ts +43 -0
  8. package/src/build/bundle.ts +657 -0
  9. package/src/build/carry.ts +57 -0
  10. package/src/build/client-entries.ts +107 -0
  11. package/src/build/client-plugin.ts +173 -0
  12. package/src/build/client-prune.ts +168 -0
  13. package/src/build/compile.ts +129 -0
  14. package/src/build/ecoindex.ts +229 -0
  15. package/src/build/files.ts +156 -0
  16. package/src/build/first-load.ts +164 -0
  17. package/src/build/graph.ts +247 -0
  18. package/src/build/index.ts +641 -0
  19. package/src/build/is-inside.ts +12 -0
  20. package/src/build/islands.ts +641 -0
  21. package/src/build/manifest.ts +325 -0
  22. package/src/build/output.ts +84 -0
  23. package/src/build/plugin-host.ts +278 -0
  24. package/src/build/precompress.ts +139 -0
  25. package/src/build/prerender.ts +232 -0
  26. package/src/build/render-rules.ts +205 -0
  27. package/src/build/report.ts +268 -0
  28. package/src/build/resolve.ts +52 -0
  29. package/src/build/routes.ts +342 -0
  30. package/src/build/server-entry.ts +38 -0
  31. package/src/build/static.ts +207 -0
  32. package/src/build/status-pages.ts +127 -0
  33. package/src/build/style-bundles.ts +526 -0
  34. package/src/cli/check-forms.ts +654 -0
  35. package/src/cli/check-links.ts +619 -0
  36. package/src/cli/check.ts +381 -0
  37. package/src/cli/commands.ts +345 -0
  38. package/src/cli/docs.ts +402 -0
  39. package/src/cli/index.ts +70 -0
  40. package/src/cli/inspect.ts +345 -0
  41. package/src/cli/mcp-tools.ts +480 -0
  42. package/src/cli/mcp.ts +205 -0
  43. package/src/cli/new.ts +41 -0
  44. package/src/cli/render.ts +261 -0
  45. package/src/cli/upgrade-names.ts +209 -0
  46. package/src/cli/upgrade.ts +354 -0
  47. package/src/compiler/analyze.ts +632 -0
  48. package/src/compiler/ast.ts +82 -0
  49. package/src/compiler/browser-globals.ts +127 -0
  50. package/src/compiler/cacheability.ts +592 -0
  51. package/src/compiler/compliance-rgaa.ts +502 -0
  52. package/src/compiler/compliance.ts +497 -0
  53. package/src/compiler/data-keys.ts +295 -0
  54. package/src/compiler/dev-source.ts +87 -0
  55. package/src/compiler/dom-attrs.ts +452 -0
  56. package/src/compiler/dom.ts +567 -0
  57. package/src/compiler/emit.ts +131 -0
  58. package/src/compiler/expr-context.ts +518 -0
  59. package/src/compiler/index.ts +8 -0
  60. package/src/compiler/interactivity.ts +366 -0
  61. package/src/compiler/mistakes.ts +499 -0
  62. package/src/compiler/node-env.ts +50 -0
  63. package/src/compiler/patch.ts +97 -0
  64. package/src/compiler/props.ts +511 -0
  65. package/src/compiler/scope.ts +607 -0
  66. package/src/compiler/server-only.ts +326 -0
  67. package/src/compiler/shared.ts +369 -0
  68. package/src/compiler/signal-reads.ts +242 -0
  69. package/src/compiler/slots.ts +227 -0
  70. package/src/compiler/ssr-helpers.ts +555 -0
  71. package/src/compiler/ssr-island.ts +90 -0
  72. package/src/compiler/ssr-prunelle-tags.ts +69 -0
  73. package/src/compiler/ssr.ts +526 -0
  74. package/src/context.ts +165 -0
  75. package/src/dev/child.ts +30 -0
  76. package/src/dev/error-log.ts +151 -0
  77. package/src/dev/index.ts +258 -0
  78. package/src/dev/modules.ts +68 -0
  79. package/src/dev/open-editor.ts +204 -0
  80. package/src/dev/protocol.ts +22 -0
  81. package/src/dev/queue.ts +79 -0
  82. package/src/dev/reload.ts +159 -0
  83. package/src/dev/supervisor.ts +204 -0
  84. package/src/dev/watchers.ts +251 -0
  85. package/src/dom/action.ts +164 -0
  86. package/src/dom/attrs.ts +84 -0
  87. package/src/dom/claim.ts +120 -0
  88. package/src/dom/extras.ts +562 -0
  89. package/src/dom/index.ts +289 -0
  90. package/src/dom/island.ts +285 -0
  91. package/src/dom/loop.ts +450 -0
  92. package/src/dom/revive.ts +36 -0
  93. package/src/index.ts +22 -0
  94. package/src/jsx-runtime.ts +566 -0
  95. package/src/plugins/config.ts +86 -0
  96. package/src/plugins/context.ts +66 -0
  97. package/src/plugins/index.ts +14 -0
  98. package/src/plugins/load.ts +70 -0
  99. package/src/plugins/order.ts +111 -0
  100. package/src/plugins/public.ts +15 -0
  101. package/src/plugins/requires.ts +47 -0
  102. package/src/plugins/services.ts +97 -0
  103. package/src/plugins/types.ts +261 -0
  104. package/src/reactivity/graph.ts +249 -0
  105. package/src/reactivity/index.ts +533 -0
  106. package/src/reactivity/selector.ts +51 -0
  107. package/src/reactivity/store.ts +208 -0
  108. package/src/server/action-protect.ts +198 -0
  109. package/src/server/action-registry.ts +78 -0
  110. package/src/server/action.ts +530 -0
  111. package/src/server/app-entry.ts +23 -0
  112. package/src/server/assets.ts +168 -0
  113. package/src/server/compress.ts +642 -0
  114. package/src/server/consent.ts +253 -0
  115. package/src/server/cookies.ts +139 -0
  116. package/src/server/document.ts +271 -0
  117. package/src/server/env.ts +33 -0
  118. package/src/server/errors.ts +391 -0
  119. package/src/server/form-schema.ts +343 -0
  120. package/src/server/health.ts +244 -0
  121. package/src/server/http.ts +538 -0
  122. package/src/server/index.ts +586 -0
  123. package/src/server/lifecycle.ts +75 -0
  124. package/src/server/loader.ts +123 -0
  125. package/src/server/page.ts +107 -0
  126. package/src/server/param-matchers.ts +112 -0
  127. package/src/server/plugin-host.ts +265 -0
  128. package/src/server/prerendered.ts +71 -0
  129. package/src/server/public.ts +19 -0
  130. package/src/server/rate-limit.ts +156 -0
  131. package/src/server/region.ts +96 -0
  132. package/src/server/request-body.ts +27 -0
  133. package/src/server/request-path.ts +73 -0
  134. package/src/server/request-scope.ts +22 -0
  135. package/src/server/route-cache.ts +423 -0
  136. package/src/server/route-table.ts +410 -0
  137. package/src/server/router.ts +261 -0
  138. package/src/server/routing.ts +472 -0
  139. package/src/server/security.ts +499 -0
  140. package/src/server/serve-handlers.ts +83 -0
  141. package/src/server/served-file.ts +128 -0
  142. package/src/server/standard-schema.ts +87 -0
  143. package/src/server/start.ts +143 -0
  144. package/src/server/static-dir.ts +220 -0
  145. package/src/server/stream.ts +211 -0
  146. package/src/ssr/context.ts +383 -0
  147. package/src/ssr/index.ts +596 -0
  148. package/src/ssr/navigation.ts +96 -0
  149. package/src/ssr/region.ts +183 -0
  150. package/src/style.ts +33 -0
  151. package/src/test/browser.ts +192 -0
  152. package/src/test/index.ts +191 -0
  153. package/src/ts-plugin/diagnostics.ts +378 -0
  154. package/src/ts-plugin/fixes.ts +364 -0
  155. package/src/ts-plugin/index.ts +194 -0
  156. package/src/unrenderable.ts +35 -0
  157. package/templates/_shared/AGENTS.md +10 -0
  158. package/templates/_shared/CLAUDE.md +1 -0
  159. package/templates/_shared/gitignore +3 -0
  160. package/templates/_shared/mcp.json +11 -0
  161. package/templates/_shared/public/robots.txt +2 -0
  162. package/templates/_shared/src/routes/legal.tsx +13 -0
  163. package/templates/_shared/tsconfig.json +25 -0
  164. package/templates/app/.env.example +4 -0
  165. package/templates/app/package.json +21 -0
  166. package/templates/app/prunelle.config.ts +11 -0
  167. package/templates/app/src/auth.ts +14 -0
  168. package/templates/app/src/routes/_layout.tsx +32 -0
  169. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  170. package/templates/app/src/routes/dashboard/index.tsx +13 -0
  171. package/templates/app/src/routes/index.tsx +15 -0
  172. package/templates/app/src/routes/login.tsx +34 -0
  173. package/templates/app/src/styles/app.css +7 -0
  174. package/templates/app/tests/app.test.ts +32 -0
  175. package/templates/blog/content/posts/welcome.md +9 -0
  176. package/templates/blog/package.json +22 -0
  177. package/templates/blog/prunelle.config.ts +23 -0
  178. package/templates/blog/src/posts.ts +26 -0
  179. package/templates/blog/src/routes/_layout.tsx +20 -0
  180. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  181. package/templates/blog/src/routes/index.tsx +33 -0
  182. package/templates/blog/src/styles/app.css +10 -0
  183. package/templates/fullstack/package.json +19 -0
  184. package/templates/fullstack/prunelle.config.ts +6 -0
  185. package/templates/fullstack/src/actions/greet.ts +19 -0
  186. package/templates/fullstack/src/components/Counter.tsx +10 -0
  187. package/templates/fullstack/src/components/GreetForm.tsx +27 -0
  188. package/templates/fullstack/src/routes/_layout.tsx +14 -0
  189. package/templates/fullstack/src/routes/api/health.ts +5 -0
  190. package/templates/fullstack/src/routes/index.tsx +13 -0
  191. package/templates/fullstack/src/styles/app.css +29 -0
  192. package/templates/fullstack/tests/app.test.ts +37 -0
  193. package/templates/minimal/package.json +19 -0
  194. package/templates/minimal/prunelle.config.ts +6 -0
  195. package/templates/minimal/src/components/Counter.tsx +10 -0
  196. package/templates/minimal/src/routes/_layout.tsx +14 -0
  197. package/templates/minimal/src/routes/index.tsx +11 -0
  198. package/templates/minimal/src/styles/app.css +22 -0
  199. package/ts-plugin.cjs +4277 -0
  200. package/README.md +0 -3
@@ -0,0 +1,366 @@
1
+ // Which exports of a module run in the browser: facts gathered per top-level binding, spread through the local calls between them. A local component rendered as a tag is an island of its own instead.
2
+
3
+ import type { ImportInfo } from './analyze'
4
+
5
+ export interface Fact {
6
+ reason: string
7
+ offset: number
8
+ }
9
+
10
+ export interface BindingFacts {
11
+ /** The top-level name, `default` for an anonymous default export, or '' for module-level code. */
12
+ name: string
13
+ start: number
14
+ end: number
15
+ /** The first thing its own code does that needs the browser. */
16
+ fact: Fact | undefined
17
+ /** Top-level bindings and imports its code names (including JSX tags), each at its first use. */
18
+ refs: Map<string, number>
19
+ /** Top-level bindings and imports referenced in value expressions (excluding JSX tag names), each at its first use. */
20
+ valueRefs: Map<string, number>
21
+ /** Non-computed member names read from a value reference (`S.count` -> `'count'`), or `'*'` when read bare. */
22
+ memberRefs: Map<string, Set<string>>
23
+ /** Component tags it renders, `NS.Tag` included. */
24
+ tags: Set<string>
25
+ /** The first `<Head>`, `<Region>`, or `<Suspense>` it renders. */
26
+ serverOnlyTag: string | undefined
27
+ }
28
+
29
+ export interface ExportFacts {
30
+ interactive: boolean
31
+ /** Why it runs in the browser, e.g. `uses onClick`. */
32
+ reason?: string | undefined
33
+ offset?: number | undefined
34
+ }
35
+
36
+ export interface Interactivity {
37
+ /** Some binding or module-level code runs in the browser. */
38
+ isInteractive: boolean
39
+ /** The first reason in source order. */
40
+ interactiveReason: string | undefined
41
+ interactiveOffset: number | undefined
42
+ exports: Map<string, ExportFacts>
43
+ /** Top-level components that run in the browser and are rendered as a tag by server code of the same module: each is an island of its own. */
44
+ localIslands: Map<string, Fact>
45
+ /** Component tags rendered by code that runs on the server: the ones an imported island can stand for. */
46
+ staticJsxTags: Set<string>
47
+ /** Spans of code that only runs inside an island, where an imported island is part of the outer one. */
48
+ islandSpans: [number, number][]
49
+ /** Spans of code that may run in the browser: each binding that runs there and every local binding it reaches, whose HTML hydration claims. */
50
+ browserSpans: [number, number][]
51
+ /** An island rendering `<Head>` or `<Suspense>`, itself or through a local component. */
52
+ serverOnly: ServerOnlyInIsland | undefined
53
+ }
54
+
55
+ export interface ServerOnlyInIsland {
56
+ tag: string
57
+ /** The island's name, `the default export` or `the module` when it has none. */
58
+ island: string
59
+ reason: string
60
+ offset: number
61
+ }
62
+
63
+ /** `reads` maps imported locals to a reason, `reads count from './store'` for reactive state another module exports. */
64
+ export function resolveInteractivity(bindings: readonly BindingFacts[], exportLocals: ReadonlyMap<string, string>, reads: ReadonlyMap<string, string> = new Map()): Interactivity {
65
+ const named = new Map<string, BindingFacts>()
66
+ for (const b of bindings) {
67
+ if (b.name !== '')
68
+ named.set(b.name, b)
69
+ }
70
+ const facts = spreadFacts(bindings, named, reads)
71
+
72
+ const exported = new Set(exportLocals.values())
73
+ const serverSide = new Set<BindingFacts>()
74
+ const stack = bindings.filter(b => !facts.has(b) && (b.name === '' || exported.has(b.name)))
75
+ for (let b = stack.pop(); b !== undefined; b = stack.pop()) {
76
+ if (serverSide.has(b))
77
+ continue
78
+ serverSide.add(b)
79
+ for (const ref of b.refs.keys()) {
80
+ const dep = named.get(ref)
81
+ if (dep !== undefined && !facts.has(dep))
82
+ stack.push(dep)
83
+ }
84
+ }
85
+
86
+ const exports = new Map<string, ExportFacts>()
87
+ for (const [name, local] of exportLocals) {
88
+ const binding = named.get(local)
89
+ const fact = binding === undefined ? undefined : facts.get(binding)
90
+ exports.set(name, fact === undefined ? { interactive: false } : { interactive: true, reason: fact.reason, offset: fact.offset })
91
+ }
92
+ const staticJsxTags = new Set([...serverSide].flatMap(b => [...b.tags]))
93
+ const localIslands = new Map<string, Fact>()
94
+ for (const [binding, fact] of facts) {
95
+ if (binding.name !== '' && staticJsxTags.has(binding.name))
96
+ localIslands.set(binding.name, fact)
97
+ }
98
+ const first = bindings.find(b => facts.has(b))
99
+ const firstFact = first === undefined ? undefined : facts.get(first)
100
+ return {
101
+ isInteractive: facts.size > 0,
102
+ interactiveReason: firstFact?.reason,
103
+ interactiveOffset: firstFact?.offset,
104
+ exports,
105
+ localIslands,
106
+ staticJsxTags,
107
+ islandSpans: bindings.filter(b => !serverSide.has(b)).map(b => [b.start, b.end]),
108
+ browserSpans: [...reachedFrom([...facts.keys()], named)].map(b => [b.start, b.end]),
109
+ serverOnly: serverOnlyInIsland(bindings, named, facts),
110
+ }
111
+ }
112
+
113
+ function spreadFacts(bindings: readonly BindingFacts[], named: ReadonlyMap<string, BindingFacts>, reads: ReadonlyMap<string, string>): Map<BindingFacts, Fact> {
114
+ const facts = new Map<BindingFacts, Fact>()
115
+ let moduleFact: Fact | undefined
116
+ for (const b of bindings) {
117
+ let own = b.fact
118
+ for (const [ref, offset] of b.valueRefs) {
119
+ if (own !== undefined)
120
+ break
121
+ const reason = reads.get(ref)
122
+ if (reason !== undefined) {
123
+ own = { reason, offset }
124
+ continue
125
+ }
126
+ const members = b.memberRefs.get(ref)
127
+ if (members !== undefined) {
128
+ for (const m of members) {
129
+ const mReason = reads.get(`${ref}.${m}`)
130
+ if (mReason !== undefined) {
131
+ own = { reason: mReason, offset }
132
+ break
133
+ }
134
+ }
135
+ }
136
+ }
137
+ if (own !== undefined)
138
+ facts.set(b, own)
139
+ if (b.name === '')
140
+ moduleFact ??= own
141
+ }
142
+ // Module-level code that needs the browser runs with every island of the module, so every binding gets its reason.
143
+ if (moduleFact !== undefined) {
144
+ for (const b of named.values()) {
145
+ if (!facts.has(b))
146
+ facts.set(b, moduleFact)
147
+ }
148
+ }
149
+ // A binding calling or reading an interactive one runs in the browser too; repeat until nothing changes. Rendering one as `<Tag />` does not: the tag becomes an island of its own.
150
+ for (let changed = true; changed;) {
151
+ changed = false
152
+ for (const b of named.values()) {
153
+ if (facts.has(b))
154
+ continue
155
+ for (const [ref, offset] of b.refs) {
156
+ if (b.tags.has(ref) && !b.valueRefs.has(ref))
157
+ continue
158
+ const dep = named.get(ref)
159
+ const depFact = dep === undefined ? undefined : facts.get(dep)
160
+ if (depFact !== undefined) {
161
+ facts.set(b, { reason: `uses ${ref}, which ${depFact.reason}`, offset })
162
+ changed = true
163
+ break
164
+ }
165
+ }
166
+ }
167
+ }
168
+ return facts
169
+ }
170
+
171
+ function serverOnlyInIsland(bindings: readonly BindingFacts[], named: ReadonlyMap<string, BindingFacts>, facts: ReadonlyMap<BindingFacts, Fact>): Interactivity['serverOnly'] {
172
+ for (const island of bindings) {
173
+ const fact = facts.get(island)
174
+ if (fact === undefined)
175
+ continue
176
+ const seen = new Set<BindingFacts>()
177
+ const stack = [island]
178
+ for (let b = stack.pop(); b !== undefined; b = stack.pop()) {
179
+ if (seen.has(b))
180
+ continue
181
+ seen.add(b)
182
+ if (b.serverOnlyTag !== undefined) {
183
+ const name = island.name === '' ? 'the module' : island.name === 'default' ? 'the default export' : island.name
184
+ return { tag: b.serverOnlyTag, island: name, reason: fact.reason, offset: fact.offset }
185
+ }
186
+ for (const ref of b.refs.keys()) {
187
+ const dep = named.get(ref)
188
+ if (dep !== undefined)
189
+ stack.push(dep)
190
+ }
191
+ }
192
+ }
193
+ return undefined
194
+ }
195
+
196
+ /** The module re-resolved once its imports of other modules' reactive state or hooks are known, or `undefined` when it imports none. */
197
+ export function withStateReads(analysis: { imports: ImportInfo[], jsxTags: Set<string>, bindings: BindingFacts[], exportLocals: Map<string, string> }, isState: (imp: ImportInfo, imported: string) => boolean): Interactivity | undefined {
198
+ const reads = new Map<string, string>()
199
+ const allValueRefs = new Set<string>()
200
+ const allMemberRefs = new Map<string, Set<string>>()
201
+ for (const b of analysis.bindings) {
202
+ for (const ref of b.valueRefs.keys())
203
+ allValueRefs.add(ref)
204
+ for (const [ref, members] of b.memberRefs) {
205
+ let set = allMemberRefs.get(ref)
206
+ if (set === undefined) {
207
+ set = new Set()
208
+ allMemberRefs.set(ref, set)
209
+ }
210
+ for (const m of members)
211
+ set.add(m)
212
+ }
213
+ }
214
+ for (const imp of analysis.imports) {
215
+ for (const spec of imp.specifiers) {
216
+ if (!allValueRefs.has(spec.local))
217
+ continue
218
+ if (spec.imported === '*') {
219
+ const members = allMemberRefs.get(spec.local)
220
+ if (members === undefined)
221
+ continue
222
+ for (const m of members) {
223
+ if (isState(imp, m))
224
+ reads.set(`${spec.local}.${m}`, `reads ${spec.local} from '${imp.source}'`)
225
+ }
226
+ }
227
+ else if (isState(imp, spec.imported)) {
228
+ reads.set(spec.local, `reads ${spec.local} from '${imp.source}'`)
229
+ }
230
+ }
231
+ }
232
+ return reads.size === 0 ? undefined : resolveInteractivity(analysis.bindings, analysis.exportLocals, reads)
233
+ }
234
+
235
+ export interface CrossFileModuleLike {
236
+ isInteractive: boolean
237
+ imports: ImportInfo[]
238
+ bindings: BindingFacts[]
239
+ exportLocals: Map<string, string>
240
+ exports: Map<string, ExportFacts>
241
+ }
242
+
243
+ /** The `roots` and every top-level binding their code names, transitively. */
244
+ function reachedFrom(roots: readonly BindingFacts[], named: ReadonlyMap<string, BindingFacts>): Set<BindingFacts> {
245
+ const seen = new Set<BindingFacts>()
246
+ const stack = [...roots]
247
+ for (let b = stack.pop(); b !== undefined; b = stack.pop()) {
248
+ if (seen.has(b))
249
+ continue
250
+ seen.add(b)
251
+ for (const ref of b.refs.keys()) {
252
+ const dep = named.get(ref)
253
+ if (dep !== undefined)
254
+ stack.push(dep)
255
+ }
256
+ }
257
+ return seen
258
+ }
259
+
260
+ /** What the browser runs of a module for the islands `localNames`: those bindings, the module-level code, and every binding they reach. */
261
+ export function clientReach(bindings: readonly BindingFacts[], localNames: readonly string[]): BindingFacts[] {
262
+ return localReach(bindings, localNames, bindings.filter(b => b.name === ''))
263
+ }
264
+
265
+ /** The top-level bindings named `localNames`, and every binding they reach. */
266
+ function localReach(bindings: readonly BindingFacts[], localNames: readonly string[], extraRoots: readonly BindingFacts[] = []): BindingFacts[] {
267
+ const named = new Map<string, BindingFacts>()
268
+ for (const b of bindings) {
269
+ if (b.name !== '')
270
+ named.set(b.name, b)
271
+ }
272
+ return [...reachedFrom([...extraRoots, ...localNames.flatMap(name => named.get(name) ?? [])], named)]
273
+ }
274
+
275
+ function importedTargetsOf(
276
+ file: string,
277
+ analysis: CrossFileModuleLike,
278
+ bindings: readonly BindingFacts[],
279
+ resolveTarget: (fromFile: string, source: string, exportName: string) => { file: string, exportName: string } | undefined,
280
+ ): { file: string, exportName: string, offset: number }[] {
281
+ const out: { file: string, exportName: string, offset: number }[] = []
282
+ for (const imp of analysis.imports) {
283
+ for (const spec of imp.specifiers) {
284
+ for (const b of bindings) {
285
+ if (spec.imported === '*') {
286
+ const members = new Set<string>()
287
+ for (const tag of b.tags) {
288
+ if (tag.startsWith(`${spec.local}.`))
289
+ members.add(tag.slice(spec.local.length + 1).split('.')[0]!)
290
+ }
291
+ for (const m of b.memberRefs.get(spec.local) ?? []) {
292
+ if (m !== '*')
293
+ members.add(m)
294
+ }
295
+ const offset = b.refs.get(spec.local) ?? b.start
296
+ for (const member of members) {
297
+ const target = resolveTarget(file, imp.source, member)
298
+ if (target !== undefined)
299
+ out.push({ file: target.file, exportName: target.exportName, offset })
300
+ }
301
+ }
302
+ else {
303
+ const offset = b.refs.get(spec.local)
304
+ if (offset !== undefined) {
305
+ const target = resolveTarget(file, imp.source, spec.imported)
306
+ if (target !== undefined)
307
+ out.push({ file: target.file, exportName: target.exportName, offset })
308
+ }
309
+ }
310
+ }
311
+ }
312
+ }
313
+ return out
314
+ }
315
+
316
+ /** Finds `<Head>`, `<Region>`, or `<Suspense>` rendered across file boundaries by an interactive export of `file`. */
317
+ export function findCrossFileServerOnly(
318
+ file: string,
319
+ analysis: CrossFileModuleLike,
320
+ loadModule: (file: string) => CrossFileModuleLike | undefined,
321
+ resolveTarget: (fromFile: string, source: string, exportName: string) => { file: string, exportName: string } | undefined,
322
+ ): ServerOnlyInIsland | undefined {
323
+ if (!analysis.isInteractive)
324
+ return undefined
325
+ for (const [exportName, expFact] of analysis.exports) {
326
+ if (!expFact.interactive)
327
+ continue
328
+ const local = analysis.exportLocals.get(exportName)
329
+ if (local === undefined)
330
+ continue
331
+ const startBindings = localReach(analysis.bindings, [local])
332
+ const visited = new Set<string>()
333
+ const findInTarget = (tFile: string, tExport: string): string | undefined => {
334
+ const key = `${tFile}\0${tExport}`
335
+ if (visited.has(key))
336
+ return undefined
337
+ visited.add(key)
338
+ const a = loadModule(tFile)
339
+ if (a === undefined)
340
+ return undefined
341
+ const tLocal = a.exportLocals.get(tExport)
342
+ if (tLocal === undefined)
343
+ return undefined
344
+ const reached = localReach(a.bindings, [tLocal])
345
+ const hit = reached.find(b => b.serverOnlyTag !== undefined)
346
+ if (hit !== undefined)
347
+ return hit.serverOnlyTag
348
+ for (const next of importedTargetsOf(tFile, a, reached, resolveTarget)) {
349
+ const nested = findInTarget(next.file, next.exportName)
350
+ if (nested !== undefined)
351
+ return nested
352
+ }
353
+ return undefined
354
+ }
355
+ for (const next of importedTargetsOf(file, analysis, startBindings, resolveTarget)) {
356
+ if (next.file === file)
357
+ continue
358
+ const tag = findInTarget(next.file, next.exportName)
359
+ if (tag !== undefined) {
360
+ const island = local === 'default' ? 'the default export' : local
361
+ return { tag, island, reason: expFact.reason ?? 'is interactive', offset: next.offset }
362
+ }
363
+ }
364
+ }
365
+ return undefined
366
+ }