@ogygia/compiler 0.0.0-stage → 0.14.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  4. package/dist/app-spec.d.ts +18 -0
  5. package/dist/app-spec.js +22 -0
  6. package/dist/blank-styles.d.ts +1 -0
  7. package/dist/blank-styles.js +24 -0
  8. package/dist/bom.d.ts +2 -0
  9. package/dist/bom.js +7 -0
  10. package/dist/build-cache.d.ts +13 -0
  11. package/dist/build-cache.js +65 -0
  12. package/dist/ctx.d.ts +238 -0
  13. package/dist/ctx.js +221 -0
  14. package/dist/dev/css-scope.d.ts +16 -0
  15. package/dist/dev/css-scope.js +32 -0
  16. package/dist/dev/dev-hmr.d.ts +24 -0
  17. package/dist/dev/dev-hmr.js +51 -0
  18. package/dist/dev/hmr.d.ts +34 -0
  19. package/dist/dev/hmr.js +52 -0
  20. package/dist/driver.d.ts +349 -0
  21. package/dist/driver.js +1401 -0
  22. package/dist/exports/index.d.ts +77 -0
  23. package/dist/exports/index.js +349 -0
  24. package/dist/exports/parse.d.ts +65 -0
  25. package/dist/exports/parse.js +251 -0
  26. package/dist/fouc-css.d.ts +102 -0
  27. package/dist/fouc-css.js +304 -0
  28. package/dist/free-vars.d.ts +32 -0
  29. package/dist/free-vars.js +454 -0
  30. package/dist/fs.d.ts +31 -0
  31. package/dist/fs.js +82 -0
  32. package/dist/ids.d.ts +49 -0
  33. package/dist/ids.js +52 -0
  34. package/dist/index.d.ts +23 -0
  35. package/dist/index.js +23 -0
  36. package/dist/kit.d.ts +204 -0
  37. package/dist/kit.js +554 -0
  38. package/dist/leg.d.ts +34 -0
  39. package/dist/leg.js +26 -0
  40. package/dist/link/analyses.d.ts +26 -0
  41. package/dist/link/analyses.js +237 -0
  42. package/dist/link/build-output.d.ts +47 -0
  43. package/dist/link/build-output.js +168 -0
  44. package/dist/link/caps.d.ts +32 -0
  45. package/dist/link/caps.js +39 -0
  46. package/dist/link/context-detect.d.ts +28 -0
  47. package/dist/link/context-detect.js +143 -0
  48. package/dist/link/emit-gate.d.ts +43 -0
  49. package/dist/link/emit-gate.js +55 -0
  50. package/dist/link/file-token.d.ts +11 -0
  51. package/dist/link/file-token.js +15 -0
  52. package/dist/link/island-deps.d.ts +183 -0
  53. package/dist/link/island-deps.js +802 -0
  54. package/dist/link/location-map.d.ts +24 -0
  55. package/dist/link/location-map.js +51 -0
  56. package/dist/link/own-reach.d.ts +15 -0
  57. package/dist/link/own-reach.js +188 -0
  58. package/dist/link/registry-stub.d.ts +50 -0
  59. package/dist/link/registry-stub.js +163 -0
  60. package/dist/link/relocations.d.ts +79 -0
  61. package/dist/link/relocations.js +198 -0
  62. package/dist/link/router-css.d.ts +38 -0
  63. package/dist/link/router-css.js +124 -0
  64. package/dist/link/runtime-entry.d.ts +103 -0
  65. package/dist/link/runtime-entry.js +183 -0
  66. package/dist/link/server-manifest.d.ts +25 -0
  67. package/dist/link/server-manifest.js +102 -0
  68. package/dist/link/transport.d.ts +42 -0
  69. package/dist/link/transport.js +91 -0
  70. package/dist/macros/dollar.d.ts +24 -0
  71. package/dist/macros/dollar.js +397 -0
  72. package/dist/macros/pipeline.d.ts +50 -0
  73. package/dist/macros/pipeline.js +133 -0
  74. package/dist/macros/source.d.ts +9 -0
  75. package/dist/macros/source.js +115 -0
  76. package/dist/macros/store.d.ts +22 -0
  77. package/dist/macros/store.js +217 -0
  78. package/dist/macros/wire.d.ts +17 -0
  79. package/dist/macros/wire.js +116 -0
  80. package/dist/map-chain.d.ts +18 -0
  81. package/dist/map-chain.js +42 -0
  82. package/dist/messages.d.ts +672 -0
  83. package/dist/messages.js +938 -0
  84. package/dist/ownership-stamps.d.ts +9 -0
  85. package/dist/ownership-stamps.js +101 -0
  86. package/dist/parse/oxc.d.ts +36 -0
  87. package/dist/parse/oxc.js +35 -0
  88. package/dist/parse/roots.d.ts +4 -0
  89. package/dist/parse/roots.js +27 -0
  90. package/dist/parse/scan.d.ts +65 -0
  91. package/dist/parse/scan.js +297 -0
  92. package/dist/parse/svelte-ast.d.ts +7 -0
  93. package/dist/parse/svelte-ast.js +99 -0
  94. package/dist/program.d.ts +140 -0
  95. package/dist/program.js +304 -0
  96. package/dist/queries.d.ts +105 -0
  97. package/dist/queries.js +326 -0
  98. package/dist/region/emit.d.ts +168 -0
  99. package/dist/region/emit.js +292 -0
  100. package/dist/region/identity.d.ts +32 -0
  101. package/dist/region/identity.js +46 -0
  102. package/dist/region/ir.d.ts +56 -0
  103. package/dist/region/ir.js +0 -0
  104. package/dist/region/marked-imports.d.ts +27 -0
  105. package/dist/region/marked-imports.js +265 -0
  106. package/dist/region/transform.d.ts +189 -0
  107. package/dist/region/transform.js +1565 -0
  108. package/dist/scan-facts.d.ts +36 -0
  109. package/dist/scan-facts.js +54 -0
  110. package/dist/script-request.d.ts +1 -0
  111. package/dist/script-request.js +33 -0
  112. package/dist/splice.d.ts +11 -0
  113. package/dist/splice.js +33 -0
  114. package/dist/transportables.d.ts +23 -0
  115. package/dist/transportables.js +144 -0
  116. package/dist/virtual/core.d.ts +158 -0
  117. package/dist/virtual/core.js +588 -0
  118. package/dist/virtual/resolver.d.ts +56 -0
  119. package/dist/virtual/resolver.js +249 -0
  120. package/dist/virtual/specifier.d.ts +10 -0
  121. package/dist/virtual/specifier.js +6 -0
  122. package/dist/virtual/table.d.ts +118 -0
  123. package/dist/virtual/table.js +54 -0
  124. package/dist/virtual/types.d.ts +17 -0
  125. package/dist/virtual/types.js +100 -0
  126. package/dist/virtual/value-names.d.ts +2 -0
  127. package/dist/virtual/value-names.js +18 -0
  128. package/dist/vite/definers.d.ts +16 -0
  129. package/dist/vite/definers.js +69 -0
  130. package/dist/vite/dev-maps.d.ts +34 -0
  131. package/dist/vite/dev-maps.js +91 -0
  132. package/dist/vite/index.d.ts +21 -0
  133. package/dist/vite/index.js +874 -0
  134. package/dist/vite/kit-dirs.d.ts +6 -0
  135. package/dist/vite/kit-dirs.js +53 -0
  136. package/dist/vite/late-island.d.ts +11 -0
  137. package/dist/vite/late-island.js +19 -0
  138. package/dist/vite/lazy-files.d.ts +2 -0
  139. package/dist/vite/lazy-files.js +72 -0
  140. package/dist/vite/options.d.ts +195 -0
  141. package/dist/vite/options.js +72 -0
  142. package/dist/vite/package-files.d.ts +3 -0
  143. package/dist/vite/package-files.js +88 -0
  144. package/dist/vite/paths.d.ts +14 -0
  145. package/dist/vite/paths.js +37 -0
  146. package/dist/vite/plugin-api.d.ts +316 -0
  147. package/dist/vite/plugin-api.js +328 -0
  148. package/dist/vite/session.d.ts +28 -0
  149. package/dist/vite/session.js +43 -0
  150. package/dist/vite/sourcemaps.d.ts +19 -0
  151. package/dist/vite/sourcemaps.js +75 -0
  152. package/dist/vite/style-preprocess.d.ts +2 -0
  153. package/dist/vite/style-preprocess.js +84 -0
  154. package/dist/vite/svelte-entries.d.ts +4 -0
  155. package/dist/vite/svelte-entries.js +10 -0
  156. package/package.json +85 -3
@@ -0,0 +1,454 @@
1
+ import { walk } from "estree-walker";
2
+ // src/free-vars.ts
3
+ const FUNCTION_TYPES = /* @__PURE__ */ new Set([
4
+ "FunctionDeclaration",
5
+ "FunctionExpression",
6
+ "ArrowFunctionExpression"
7
+ ]);
8
+ const LOOP_TYPES = /* @__PURE__ */ new Set([
9
+ "ForStatement",
10
+ "ForInStatement",
11
+ "ForOfStatement"
12
+ ]);
13
+ /** Collect bound names from an estree binding pattern (never the names its defaults read). */
14
+ function collect_pattern_names(node, out) {
15
+ if (!node) return;
16
+ switch (node.type) {
17
+ case "Identifier":
18
+ out.add(node.name);
19
+ break;
20
+ case "ObjectPattern":
21
+ for (const prop of node.properties) if (prop.type === "RestElement") collect_pattern_names(prop.argument, out);
22
+ else collect_pattern_names(prop.value, out);
23
+ break;
24
+ case "ArrayPattern":
25
+ for (const el of node.elements) collect_pattern_names(el, out);
26
+ break;
27
+ case "AssignmentPattern":
28
+ collect_pattern_names(node.left, out);
29
+ break;
30
+ case "RestElement":
31
+ collect_pattern_names(node.argument, out);
32
+ break;
33
+ case "ObjectExpression":
34
+ for (const prop of node.properties) if (prop.type === "SpreadElement") collect_pattern_names(prop.argument, out);
35
+ else collect_pattern_names(prop.value, out);
36
+ break;
37
+ case "ArrayExpression":
38
+ for (const el of node.elements) collect_pattern_names(el, out);
39
+ break;
40
+ case "SpreadElement":
41
+ collect_pattern_names(node.argument, out);
42
+ break;
43
+ case "AssignmentExpression": collect_pattern_names(node.left, out);
44
+ }
45
+ }
46
+ function member_root(node) {
47
+ let cur = node;
48
+ while (cur && cur.type === "MemberExpression") cur = cur.object;
49
+ return cur && cur.type === "Identifier" ? cur.name : null;
50
+ }
51
+ function collect_write_roots(target, roots) {
52
+ if (!target) return;
53
+ switch (target.type) {
54
+ case "Identifier":
55
+ roots.add(target.name);
56
+ break;
57
+ case "MemberExpression": {
58
+ const r = member_root(target);
59
+ if (r) roots.add(r);
60
+ break;
61
+ }
62
+ case "ObjectPattern":
63
+ for (const prop of target.properties) if (prop.type === "RestElement") collect_write_roots(prop.argument, roots);
64
+ else collect_write_roots(prop.value, roots);
65
+ break;
66
+ case "ArrayPattern":
67
+ for (const el of target.elements) if (el) collect_write_roots(el, roots);
68
+ break;
69
+ case "AssignmentPattern":
70
+ collect_write_roots(target.left, roots);
71
+ break;
72
+ case "RestElement": collect_write_roots(target.argument, roots);
73
+ }
74
+ }
75
+ function is_reference(node, parent, key) {
76
+ if (!parent) return true;
77
+ switch (parent.type) {
78
+ case "MemberExpression": return key !== "property" || parent.computed;
79
+ case "Property":
80
+ case "MethodDefinition":
81
+ case "PropertyDefinition": return key !== "key" || parent.computed;
82
+ case "ImportSpecifier":
83
+ case "ImportDefaultSpecifier":
84
+ case "ImportNamespaceSpecifier": return false;
85
+ case "LabeledStatement":
86
+ case "BreakStatement":
87
+ case "ContinueStatement": return key !== "label";
88
+ case "MetaProperty": return false;
89
+ default: return !parent.type.startsWith("TS") || key === "expression";
90
+ }
91
+ }
92
+ function add_expression_refs(expr, svelte_bound, sink) {
93
+ if (!expr) return;
94
+ const scopes = [/* @__PURE__ */ new Set()];
95
+ const has = (name) => {
96
+ if (svelte_bound.has(name)) return true;
97
+ for (let i = scopes.length - 1; i >= 0; i--) if (scopes[i].has(name)) return true;
98
+ return false;
99
+ };
100
+ const record_writes = (target) => {
101
+ const roots = /* @__PURE__ */ new Set();
102
+ collect_write_roots(target, roots);
103
+ for (const r of roots) if (!has(r)) sink.mutated.add(r);
104
+ };
105
+ walk(expr, {
106
+ enter(node, parent, key) {
107
+ if (SCOPE_TYPES.has(node.type)) scopes.push(scope_bindings(node));
108
+ else if (node.type === "AssignmentExpression") record_writes(node.left);
109
+ else if (node.type === "UpdateExpression") record_writes(node.argument);
110
+ else if (node.type === "Identifier" && is_reference(node, parent, key)) {
111
+ if (!has(node.name)) {
112
+ sink.refs.add(node.name);
113
+ const at = node;
114
+ if (node.name.startsWith("$") && at.start != null && at.end != null) {
115
+ let sites = sink.stores.get(node.name);
116
+ if (!sites) sink.stores.set(node.name, sites = []);
117
+ sites.push({
118
+ start: at.start,
119
+ end: at.end
120
+ });
121
+ }
122
+ }
123
+ }
124
+ },
125
+ leave(node) {
126
+ if (SCOPE_TYPES.has(node.type)) scopes.pop();
127
+ }
128
+ });
129
+ }
130
+ function lexical_names(stmts, out) {
131
+ for (const stmt of stmts ?? []) {
132
+ const s = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration ?? stmt : stmt;
133
+ if (s.type === "VariableDeclaration" && s.kind !== "var") for (const d of s.declarations) collect_pattern_names(d.id, out);
134
+ else if ((s.type === "FunctionDeclaration" || s.type === "ClassDeclaration") && s.id) out.add(s.id.name);
135
+ else if (s.type === "ImportDeclaration") {
136
+ for (const sp of s.specifiers ?? []) if (sp.local?.name) out.add(sp.local.name);
137
+ }
138
+ }
139
+ }
140
+ function var_names(node, out) {
141
+ if (!node) return;
142
+ switch (node.type) {
143
+ case "VariableDeclaration":
144
+ if (node.kind === "var") for (const d of node.declarations) collect_pattern_names(d.id, out);
145
+ break;
146
+ case "Program":
147
+ case "BlockStatement":
148
+ case "StaticBlock":
149
+ for (const s of node.body) var_names(s, out);
150
+ break;
151
+ case "ExportNamedDeclaration":
152
+ var_names(node.declaration, out);
153
+ break;
154
+ case "IfStatement":
155
+ var_names(node.consequent, out);
156
+ var_names(node.alternate, out);
157
+ break;
158
+ case "ForStatement":
159
+ var_names(node.init, out);
160
+ var_names(node.body, out);
161
+ break;
162
+ case "ForInStatement":
163
+ case "ForOfStatement":
164
+ var_names(node.left, out);
165
+ var_names(node.body, out);
166
+ break;
167
+ case "WhileStatement":
168
+ case "DoWhileStatement":
169
+ case "LabeledStatement":
170
+ case "WithStatement":
171
+ var_names(node.body, out);
172
+ break;
173
+ case "TryStatement":
174
+ var_names(node.block, out);
175
+ var_names(node.handler?.body, out);
176
+ var_names(node.finalizer, out);
177
+ break;
178
+ case "SwitchStatement": for (const c of node.cases) for (const s of c.consequent) var_names(s, out);
179
+ }
180
+ }
181
+ const SCOPE_TYPES = /* @__PURE__ */ new Set([
182
+ ...FUNCTION_TYPES,
183
+ ...LOOP_TYPES,
184
+ "CatchClause",
185
+ "SwitchStatement",
186
+ "Program",
187
+ "BlockStatement",
188
+ "StaticBlock",
189
+ "ClassExpression"
190
+ ]);
191
+ /**
192
+ * The names a scope binds for its whole extent, hoisting included: a function its parameters, its
193
+ * own name and every `var`, `let`, `const`, class and function its body declares; a block, a
194
+ * `switch` or a program what it declares (a program and a class static block also their `var`s, a
195
+ * program its imports); a class expression its own name; a loop its head's declarations; a catch clause its parameter (test/og-dollar.test.ts, test/free-vars-patterns.test.ts).
196
+ */
197
+ function scope_bindings(node) {
198
+ const out = /* @__PURE__ */ new Set();
199
+ if (FUNCTION_TYPES.has(node.type)) {
200
+ const fn = node;
201
+ if (fn.id) out.add(fn.id.name);
202
+ for (const p of fn.params) collect_pattern_names(p, out);
203
+ if (fn.body?.type === "BlockStatement") {
204
+ lexical_names(fn.body.body, out);
205
+ var_names(fn.body, out);
206
+ }
207
+ } else if (node.type === "BlockStatement") lexical_names(node.body, out);
208
+ else if (node.type === "ClassExpression") {
209
+ if (node.id) out.add(node.id.name);
210
+ } else if (node.type === "Program" || node.type === "StaticBlock") {
211
+ lexical_names(node.body, out);
212
+ var_names(node, out);
213
+ } else if (node.type === "SwitchStatement") for (const c of node.cases ?? []) lexical_names(c.consequent, out);
214
+ else if (node.type === "CatchClause") collect_pattern_names(node.param, out);
215
+ else if (LOOP_TYPES.has(node.type)) {
216
+ const head = node.type === "ForStatement" ? node.init : node.left;
217
+ if (head?.type === "VariableDeclaration") for (const d of head.declarations) collect_pattern_names(d.id, out);
218
+ }
219
+ return out;
220
+ }
221
+ /** The names `expr` reads from outside itself, in source order: what a hoisted closure must be
222
+ * handed (`import.meta.og.$`'s captures). */
223
+ function free_references(expr) {
224
+ const sink = {
225
+ refs: /* @__PURE__ */ new Set(),
226
+ mutated: /* @__PURE__ */ new Set(),
227
+ stores: /* @__PURE__ */ new Map()
228
+ };
229
+ add_expression_refs(expr, /* @__PURE__ */ new Set(), sink);
230
+ return [...sink.refs];
231
+ }
232
+ function add_pattern_refs(pattern, bound, sink) {
233
+ if (!pattern) return;
234
+ switch (pattern.type) {
235
+ case "AssignmentPattern":
236
+ case "AssignmentExpression":
237
+ add_expression_refs(pattern.right, bound, sink);
238
+ add_pattern_refs(pattern.left, bound, sink);
239
+ break;
240
+ case "ObjectPattern":
241
+ case "ObjectExpression":
242
+ for (const prop of pattern.properties) if (prop.type === "RestElement" || prop.type === "SpreadElement") add_pattern_refs(prop.argument, bound, sink);
243
+ else {
244
+ if (prop.computed) add_expression_refs(prop.key, bound, sink);
245
+ add_pattern_refs(prop.value, bound, sink);
246
+ }
247
+ break;
248
+ case "ArrayPattern":
249
+ case "ArrayExpression":
250
+ for (const el of pattern.elements) add_pattern_refs(el, bound, sink);
251
+ break;
252
+ case "RestElement":
253
+ case "SpreadElement": add_pattern_refs(pattern.argument, bound, sink);
254
+ }
255
+ }
256
+ function let_directive_names(node) {
257
+ const names = /* @__PURE__ */ new Set();
258
+ for (const attr of node.attributes ?? []) if (attr.type === "LetDirective") {
259
+ if (attr.expression) collect_pattern_names(attr.expression, names);
260
+ else names.add(attr.name);
261
+ }
262
+ return names;
263
+ }
264
+ function add_attribute_refs(node, bound, sink) {
265
+ const add_value_refs = (value) => {
266
+ if (Array.isArray(value)) {
267
+ for (const part of value) if (part.type === "ExpressionTag") add_expression_refs(part.expression, bound, sink);
268
+ } else if (value?.type === "ExpressionTag") add_expression_refs(value.expression, bound, sink);
269
+ };
270
+ const add_name_ref = (name) => {
271
+ const root = name.split(".")[0];
272
+ if (root && !bound.has(root)) sink.refs.add(root);
273
+ };
274
+ for (const attr of node.attributes ?? []) switch (attr.type) {
275
+ case "Attribute":
276
+ add_value_refs(attr.value);
277
+ break;
278
+ case "StyleDirective":
279
+ if (attr.value === true) add_name_ref(attr.name);
280
+ else add_value_refs(attr.value);
281
+ break;
282
+ case "UseDirective":
283
+ case "TransitionDirective":
284
+ case "AnimateDirective":
285
+ add_name_ref(attr.name);
286
+ if (attr.expression) add_expression_refs(attr.expression, bound, sink);
287
+ break;
288
+ case "SpreadAttribute":
289
+ add_expression_refs(attr.expression, bound, sink);
290
+ break;
291
+ case "LetDirective": {
292
+ const own = new Set(bound);
293
+ collect_pattern_names(attr.expression, own);
294
+ add_pattern_refs(attr.expression, own, sink);
295
+ break;
296
+ }
297
+ case "BindDirective":
298
+ if (attr.expression) {
299
+ add_expression_refs(attr.expression, bound, sink);
300
+ const root = attr.expression.type === "Identifier" ? attr.expression.name : member_root(attr.expression);
301
+ if (root && !bound.has(root)) sink.mutated.add(root);
302
+ }
303
+ break;
304
+ default: if (attr.expression) add_expression_refs(attr.expression, bound, sink);
305
+ }
306
+ }
307
+ function sibling_bindings(nodes) {
308
+ const names = /* @__PURE__ */ new Set();
309
+ for (const n of nodes) if (n.type === "SnippetBlock" && n.expression) names.add(n.expression.name);
310
+ else if (n.type === "ConstTag") for (const d of n.declaration.declarations) collect_pattern_names(d.id, names);
311
+ return names;
312
+ }
313
+ function fragment_nodes(fragment) {
314
+ return fragment?.nodes ?? [];
315
+ }
316
+ function walk_template(nodes, outer_bound, sink) {
317
+ const bound = new Set(outer_bound);
318
+ for (const name of sibling_bindings(nodes)) bound.add(name);
319
+ for (const node of nodes) switch (node.type) {
320
+ case "Text":
321
+ case "Comment": break;
322
+ case "ExpressionTag":
323
+ case "HtmlTag":
324
+ case "RenderTag":
325
+ add_expression_refs(node.expression, bound, sink);
326
+ break;
327
+ case "ConstTag":
328
+ for (const d of node.declaration.declarations) {
329
+ add_pattern_refs(d.id, bound, sink);
330
+ add_expression_refs(d.init, bound, sink);
331
+ }
332
+ break;
333
+ case "DebugTag":
334
+ for (const id of node.identifiers ?? []) add_expression_refs(id, bound, sink);
335
+ break;
336
+ case "IfBlock":
337
+ add_expression_refs(node.test, bound, sink);
338
+ walk_template(fragment_nodes(node.consequent), bound, sink);
339
+ if (node.alternate) walk_template(fragment_nodes(node.alternate), bound, sink);
340
+ break;
341
+ case "EachBlock": {
342
+ add_expression_refs(node.expression, bound, sink);
343
+ const each_bound = new Set(bound);
344
+ collect_pattern_names(node.context, each_bound);
345
+ if (node.index) each_bound.add(node.index);
346
+ add_pattern_refs(node.context, each_bound, sink);
347
+ if (node.key) add_expression_refs(node.key, each_bound, sink);
348
+ walk_template(fragment_nodes(node.body), each_bound, sink);
349
+ if (node.fallback) walk_template(fragment_nodes(node.fallback), bound, sink);
350
+ break;
351
+ }
352
+ case "AwaitBlock":
353
+ add_expression_refs(node.expression, bound, sink);
354
+ if (node.pending) walk_template(fragment_nodes(node.pending), bound, sink);
355
+ if (node.then) {
356
+ const then_bound = new Set(bound);
357
+ if (node.value) collect_pattern_names(node.value, then_bound);
358
+ add_pattern_refs(node.value, then_bound, sink);
359
+ walk_template(fragment_nodes(node.then), then_bound, sink);
360
+ }
361
+ if (node.catch) {
362
+ const catch_bound = new Set(bound);
363
+ if (node.error) collect_pattern_names(node.error, catch_bound);
364
+ add_pattern_refs(node.error, catch_bound, sink);
365
+ walk_template(fragment_nodes(node.catch), catch_bound, sink);
366
+ }
367
+ break;
368
+ case "KeyBlock":
369
+ add_expression_refs(node.expression, bound, sink);
370
+ walk_template(fragment_nodes(node.fragment), bound, sink);
371
+ break;
372
+ case "SnippetBlock": {
373
+ const snip_bound = new Set(bound);
374
+ for (const p of node.parameters ?? []) collect_pattern_names(p, snip_bound);
375
+ for (const p of node.parameters ?? []) add_pattern_refs(p, snip_bound, sink);
376
+ walk_template(fragment_nodes(node.body), snip_bound, sink);
377
+ break;
378
+ }
379
+ case "Component":
380
+ case "SvelteComponent": {
381
+ if (node.type === "SvelteComponent") add_expression_refs(node.expression, bound, sink);
382
+ else {
383
+ const root = String(node.name || "").split(".")[0];
384
+ if (root && !bound.has(root)) sink.refs.add(root);
385
+ }
386
+ add_attribute_refs(node, bound, sink);
387
+ const el_bound1 = new Set(bound);
388
+ for (const name of let_directive_names(node)) el_bound1.add(name);
389
+ if (node.fragment) walk_template(fragment_nodes(node.fragment), el_bound1, sink);
390
+ break;
391
+ }
392
+ case "RegularElement":
393
+ case "SvelteElement":
394
+ case "SvelteSelf":
395
+ case "SvelteFragment":
396
+ case "SvelteBoundary":
397
+ case "SlotElement":
398
+ case "TitleElement": {
399
+ if (node.tag) add_expression_refs(node.tag, bound, sink);
400
+ add_attribute_refs(node, bound, sink);
401
+ const el_bound = new Set(bound);
402
+ for (const name of let_directive_names(node)) el_bound.add(name);
403
+ if (node.fragment) walk_template(fragment_nodes(node.fragment), el_bound, sink);
404
+ break;
405
+ }
406
+ default: if (node.fragment) walk_template(fragment_nodes(node.fragment), bound, sink);
407
+ }
408
+ }
409
+ /** Collect all snippet names defined anywhere in a subtree (for cross-boundary error detection). */
410
+ function collectSnippetNames(nodes) {
411
+ const out = /* @__PURE__ */ new Set();
412
+ const visit = (list) => {
413
+ for (const n of list ?? []) {
414
+ if (n.type === "SnippetBlock" && n.expression) out.add(n.expression.name);
415
+ for (const k of [
416
+ "consequent",
417
+ "alternate",
418
+ "body",
419
+ "fallback",
420
+ "pending",
421
+ "then",
422
+ "catch",
423
+ "fragment"
424
+ ]) if (n[k]?.nodes) visit(n[k].nodes);
425
+ }
426
+ };
427
+ visit(nodes);
428
+ return out;
429
+ }
430
+ /**
431
+ * @param nodes hoisted subtree top-level nodes
432
+ * @returns free identifier names + free mutation targets + `$store` read sites
433
+ */
434
+ function collectCaptureInfo(nodes) {
435
+ const sink = {
436
+ refs: /* @__PURE__ */ new Set(),
437
+ mutated: /* @__PURE__ */ new Set(),
438
+ stores: /* @__PURE__ */ new Map()
439
+ };
440
+ walk_template(nodes, /* @__PURE__ */ new Set(), sink);
441
+ return {
442
+ free: sink.refs,
443
+ mutated: sink.mutated,
444
+ stores: sink.stores
445
+ };
446
+ }
447
+ /**
448
+ * @param nodes hoisted subtree top-level nodes
449
+ * @returns free identifier names
450
+ */
451
+ function collectFreeIdentifiers(nodes) {
452
+ return collectCaptureInfo(nodes).free;
453
+ }
454
+ export { collectCaptureInfo, collectFreeIdentifiers, collectSnippetNames, collect_pattern_names, free_references, scope_bindings };
package/dist/fs.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /** A directory entry as the directory itself lists it: a link is a `link`, not what it points at
2
+ * (`stat` follows it). */
3
+ export interface FsEntry {
4
+ readonly name: string;
5
+ readonly kind: "file" | "dir" | "link" | "other";
6
+ }
7
+ /**
8
+ * THE FILE SEAM. Every read of an app's files goes through one `Fs` on the `CompileCtx`, so a whole
9
+ * compile can run on files held in memory (the compiler DST harness edits them and compares a dev
10
+ * session with a cold one). `node_fs` is the disk; `memory_fs` is a map. test/fs-seam.test.ts counts
11
+ * the direct `node:fs` calls left in the compiler, each with its reason.
12
+ */
13
+ export interface Fs {
14
+ /** The file's text (UTF-8, as stored: a byte-order mark is kept), or `null` when it can't be read. */
15
+ read(abs: string): string | null;
16
+ /** The directory's entries, or `null` when it can't be listed. */
17
+ list(dir: string): readonly FsEntry[] | null;
18
+ /** What is at `abs`, links followed; `null` when nothing (or a dangling link) is. */
19
+ stat(abs: string): "file" | "dir" | null;
20
+ }
21
+ /** The disk. */
22
+ export declare const node_fs: Fs;
23
+ export interface MemoryFs extends Fs {
24
+ /** Write a file (its directories appear with it), or remove it with `null` (an emptied
25
+ * directory goes too). */
26
+ set(abs: string, text: string | null): void;
27
+ /** Every file, sorted by path. */
28
+ files(): string[];
29
+ }
30
+ /** Files held in memory, by absolute path. Directories are the paths' parents; listings are sorted. */
31
+ export declare function memory_fs(initial?: Record<string, string>): MemoryFs;
package/dist/fs.js ADDED
@@ -0,0 +1,82 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ // src/fs.ts
4
+ const kind_of = (e) => {
5
+ if (e.isFile()) return "file";
6
+ if (e.isDirectory()) return "dir";
7
+ return e.isSymbolicLink() ? "link" : "other";
8
+ };
9
+ /** The disk. */
10
+ const node_fs = {
11
+ read(abs) {
12
+ try {
13
+ return fs.readFileSync(abs, "utf-8");
14
+ } catch {
15
+ return null;
16
+ }
17
+ },
18
+ list(dir) {
19
+ try {
20
+ return fs.readdirSync(dir, { withFileTypes: true }).map((e) => ({
21
+ name: e.name,
22
+ kind: kind_of(e)
23
+ }));
24
+ } catch {
25
+ return null;
26
+ }
27
+ },
28
+ stat(abs) {
29
+ try {
30
+ const st = fs.statSync(abs);
31
+ if (st.isFile()) return "file";
32
+ return st.isDirectory() ? "dir" : null;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+ };
38
+ /** Files held in memory, by absolute path. Directories are the paths' parents; listings are sorted. */
39
+ function memory_fs(initial = {}) {
40
+ const files = /* @__PURE__ */ new Map();
41
+ const norm = (p) => path.resolve(p);
42
+ for (const [k, v] of Object.entries(initial)) files.set(norm(k), v);
43
+ const is_dir = (abs) => {
44
+ const prefix = abs.endsWith(path.sep) ? abs : abs + path.sep;
45
+ for (const f of files.keys()) if (f.startsWith(prefix)) return true;
46
+ return false;
47
+ };
48
+ return {
49
+ read: (abs) => files.get(norm(abs)) ?? null,
50
+ list(dir) {
51
+ const d = norm(dir);
52
+ if (!is_dir(d)) return null;
53
+ const prefix = d.endsWith(path.sep) ? d : d + path.sep;
54
+ const out = /* @__PURE__ */ new Map();
55
+ for (const f of files.keys()) {
56
+ if (!f.startsWith(prefix)) continue;
57
+ const rest = f.slice(prefix.length);
58
+ const cut = rest.indexOf(path.sep);
59
+ if (cut < 0) out.set(rest, "file");
60
+ else out.set(rest.slice(0, cut), "dir");
61
+ }
62
+ return [...out].sort(([a], [b]) => {
63
+ if (a < b) return -1;
64
+ return a > b ? 1 : 0;
65
+ }).map(([name, kind]) => ({
66
+ name,
67
+ kind
68
+ }));
69
+ },
70
+ stat(abs) {
71
+ const p = norm(abs);
72
+ if (files.has(p)) return "file";
73
+ return is_dir(p) ? "dir" : null;
74
+ },
75
+ set(abs, text) {
76
+ if (text === null) files.delete(norm(abs));
77
+ else files.set(norm(abs), text);
78
+ },
79
+ files: () => [...files.keys()].sort()
80
+ };
81
+ }
82
+ export { memory_fs, node_fs };
package/dist/ids.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ /** Generated sticky entry — static-imports only the features selected from build marks. */
2
+ export declare const V_RUNTIME_ENTRY: string;
3
+ export declare const V_SERVER_MANIFEST: string;
4
+ /** The server regions' loaders (`id → () => import(entry)`), reached only through the manifest's
5
+ * `load_server_regions()` — see link/server-manifest.ts for why they live one dynamic import away. */
6
+ export declare const V_SERVER_REGIONS: string;
7
+ export declare const V_TRANSPORT: string;
8
+ export declare const V_TRANSPORTABLES: string;
9
+ /** the string the profiler maps module exports until the build fills it (build-time only: never in
10
+ * runtime code, so the one literal in the output is the one to replace) */
11
+ export declare const PROFILER_MAPS_PLACEHOLDER = "__ogygia_profiler_maps_placeholder__";
12
+ /** the filled maps payload's mark: gzipped JSON, base64 (devtools' build/profiler-maps.ts writes it, the
13
+ * profiler's embedded-maps reads it) */
14
+ export declare const PROFILER_MAPS_GZ_PREFIX = "gz:";
15
+ /** The region realm's per-file families (declared in ./virtual/core.ts), by their id under the
16
+ * realm: a prefix ends in `/`, and the rest of the id names the file. */
17
+ export declare const REGION_FAMILY: {
18
+ readonly entry: "entry/";
19
+ readonly binding: "binding/";
20
+ readonly lazy: "lazy/";
21
+ readonly wrapper: "wrapper/";
22
+ readonly fouc_css: "fouc-css/";
23
+ readonly fouc_scoped: "fouc-scoped/";
24
+ readonly registry_stub: "registry-stub/";
25
+ readonly client_binding_stub: "client-binding-stub";
26
+ };
27
+ /** A region family's specifier (a prefix, for the per-file ones). */
28
+ export declare const region_family: (k: keyof typeof REGION_FAMILY) => string;
29
+ /** Resolve a virtual id to its `\0`-prefixed resolved form (Vite/rollup convention). */
30
+ export declare const RESOLVED: (id: string) => string;
31
+ /** Virtual region ENTRY module id — JS re-export of the real component (not a thin .svelte). */
32
+ export declare const islandVirtualId: (iid: string) => string;
33
+ /**
34
+ * Region-binding module id. A `with { region: 'raw' }` import is rewritten to import this JS
35
+ * module, whose source is leg-split by the plugin `load` hook: the SSR leg carries the server
36
+ * signer (so `region()` can mint a capability), the client leg is metadata-only (no server
37
+ * code crosses into the browser bundle).
38
+ */
39
+ export declare const regionBindingVirtualId: (iid: string) => string;
40
+ /**
41
+ * The wake region wrapper's CLIENT-leg component source — the leg-split twin of the wrapper: the SSR
42
+ * wrapper imports the region entry (it must render), the client wrapper imports THIS, a module that
43
+ * imports the entry only when the document rendered the region (emit.ts `lazy_entry_source`). It is
44
+ * how a csr=true host's page graph stops at the wrapper, the same rule the csr=false registry stub
45
+ * applies one level up: what a page ships is decided by what it RENDERED, never by its import graph.
46
+ */
47
+ export declare const lazyEntryVirtualId: (iid: string) => string;
48
+ /** The wake region wrapper's component id. */
49
+ export declare const wrapperVirtualId: (iid: string) => string;
package/dist/ids.js ADDED
@@ -0,0 +1,52 @@
1
+ import { specifier } from "./virtual/specifier.js";
2
+ // src/ids.ts
3
+ /** Generated sticky entry — static-imports only the features selected from build marks. */
4
+ const V_RUNTIME_ENTRY = specifier("boot", "runtime-entry");
5
+ const V_SERVER_MANIFEST = specifier("server", "server-manifest");
6
+ /** The server regions' loaders (`id → () => import(entry)`), reached only through the manifest's
7
+ * `load_server_regions()` — see link/server-manifest.ts for why they live one dynamic import away. */
8
+ const V_SERVER_REGIONS = specifier("server", "server-regions");
9
+ const V_TRANSPORT = specifier("region", "transport");
10
+ const V_TRANSPORTABLES = specifier("region", "transportables");
11
+ /** the string the profiler maps module exports until the build fills it (build-time only: never in
12
+ * runtime code, so the one literal in the output is the one to replace) */
13
+ const PROFILER_MAPS_PLACEHOLDER = "__ogygia_profiler_maps_placeholder__";
14
+ /** the filled maps payload's mark: gzipped JSON, base64 (devtools' build/profiler-maps.ts writes it, the
15
+ * profiler's embedded-maps reads it) */
16
+ const PROFILER_MAPS_GZ_PREFIX = "gz:";
17
+ /** The region realm's per-file families (declared in ./virtual/core.ts), by their id under the
18
+ * realm: a prefix ends in `/`, and the rest of the id names the file. */
19
+ const REGION_FAMILY = {
20
+ entry: "entry/",
21
+ binding: "binding/",
22
+ lazy: "lazy/",
23
+ wrapper: "wrapper/",
24
+ fouc_css: "fouc-css/",
25
+ fouc_scoped: "fouc-scoped/",
26
+ registry_stub: "registry-stub/",
27
+ client_binding_stub: "client-binding-stub"
28
+ };
29
+ /** A region family's specifier (a prefix, for the per-file ones). */
30
+ const region_family = (k) => specifier("region", REGION_FAMILY[k]);
31
+ /** Resolve a virtual id to its `\0`-prefixed resolved form (Vite/rollup convention). */
32
+ const RESOLVED = (id) => `\0${id}`;
33
+ /** Virtual region ENTRY module id — JS re-export of the real component (not a thin .svelte). */
34
+ const islandVirtualId = (iid) => `${region_family("entry")}${iid}.js`;
35
+ /**
36
+ * Region-binding module id. A `with { region: 'raw' }` import is rewritten to import this JS
37
+ * module, whose source is leg-split by the plugin `load` hook: the SSR leg carries the server
38
+ * signer (so `region()` can mint a capability), the client leg is metadata-only (no server
39
+ * code crosses into the browser bundle).
40
+ */
41
+ const regionBindingVirtualId = (iid) => `${region_family("binding")}${iid}.js`;
42
+ /**
43
+ * The wake region wrapper's CLIENT-leg component source — the leg-split twin of the wrapper: the SSR
44
+ * wrapper imports the region entry (it must render), the client wrapper imports THIS, a module that
45
+ * imports the entry only when the document rendered the region (emit.ts `lazy_entry_source`). It is
46
+ * how a csr=true host's page graph stops at the wrapper, the same rule the csr=false registry stub
47
+ * applies one level up: what a page ships is decided by what it RENDERED, never by its import graph.
48
+ */
49
+ const lazyEntryVirtualId = (iid) => `${region_family("lazy")}${iid}.js`;
50
+ /** The wake region wrapper's component id. */
51
+ const wrapperVirtualId = (iid) => `${region_family("wrapper")}${iid}.svelte`;
52
+ export { PROFILER_MAPS_GZ_PREFIX, PROFILER_MAPS_PLACEHOLDER, REGION_FAMILY, RESOLVED, V_RUNTIME_ENTRY, V_SERVER_MANIFEST, V_SERVER_REGIONS, V_TRANSPORT, V_TRANSPORTABLES, islandVirtualId, lazyEntryVirtualId, regionBindingVirtualId, region_family, wrapperVirtualId };