@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,77 @@
1
+ import { ModuleShape } from "./parse.js";
2
+ /** Which barrels a caller may go through, and how far. */
3
+ export interface Policy {
4
+ /** May this resolved module be treated as a barrel at all? */
5
+ candidate(id: string, spec: string): boolean;
6
+ /** Is this module a barrel even though it is impure? */
7
+ forced(id: string, spec: string): boolean;
8
+ /** Is this module kept whatever it looks like? */
9
+ kept(id: string, spec: string): boolean;
10
+ /** Follow a star into node_modules? */
11
+ follow_packages: boolean;
12
+ }
13
+ /** Every barrel, through packages too: what reaches a component's CSS (compiler/fouc-css.ts). */
14
+ export declare const EVERY_BARREL: Policy;
15
+ /** Resolve `spec` from `importer` to a file id, as `caller` resolves it; null when it cannot. */
16
+ export type Resolve<Caller> = (spec: string, importer: string, caller: Caller) => Promise<string | null>;
17
+ /** What a file change did: an edit leaves resolutions alone, a file added or removed does not. */
18
+ export type Change = "create" | "update" | "delete";
19
+ /** Where an importer can go for a name: `import { name } from id` (`default`: a default import),
20
+ * or `import * as local from id` (`namespace`). */
21
+ export type Leaf = {
22
+ id: string;
23
+ name: string;
24
+ } | {
25
+ id: string;
26
+ namespace: true;
27
+ };
28
+ export type Entry = Leaf | "own" | "ambiguous";
29
+ export interface ExportMap {
30
+ id: string;
31
+ /** the barrel's usable names */
32
+ entries: Map<string, Entry>;
33
+ /** pure barrel → the import can be dropped once every name moved; impure → kept for effects */
34
+ pure: boolean;
35
+ /** null: a barrel the policy goes through; else why it does not (`entries` is then empty) */
36
+ left: null | "impure" | "kept" | "outside-project";
37
+ /** some names could not be seen (a star into the unparsable): unknown names stay on the barrel */
38
+ opaque: boolean;
39
+ /** every module this map depends on: a change to any of them invalidates the map */
40
+ deps: Set<string>;
41
+ /** built while a neighbour was still being built by another walk: served, not cached */
42
+ provisional: boolean;
43
+ /** ids on the walk stack this build ran into (a cycle): the map lacks THEIR names, so it is
44
+ * cached only once the walk that owns them has closed the ring (the set is empty there) */
45
+ cycles: Set<string>;
46
+ }
47
+ interface FileChangeListener {
48
+ changed(id: string, change: Change): void;
49
+ }
50
+ /** One app's parsed module shapes, read once each and shared by every {@link ExportIndex}. */
51
+ export declare class Shapes {
52
+ #private;
53
+ /** `read`: the module's source, or null when it cannot be read (virtual, binary, missing). */
54
+ constructor(read: (id: string) => string | null);
55
+ /** The parsed shape of a module (cached), or null when it cannot be read or parsed. */
56
+ get(id: string): ModuleShape | null;
57
+ /** The file `id` changed: drop its shape, and everything every index built from it. */
58
+ invalidate(id: string, change?: Change): void;
59
+ /** (an index registers itself as it is built) */
60
+ depend(d: FileChangeListener): void;
61
+ }
62
+ /** One resolver's export index: its resolutions, and each policy's barrel maps. */
63
+ export declare class ExportIndex<Caller = void> implements FileChangeListener {
64
+ #private;
65
+ readonly shapes: Shapes;
66
+ constructor(resolve: Resolve<Caller>, shapes: Shapes);
67
+ /** A specifier resolved from `importer` (cached per importer and specifier). */
68
+ resolve(spec: string, importer: string, caller: Caller): Promise<string | null>;
69
+ /**
70
+ * The export map of a barrel, or null when the module is not a barrel `policy` lets the caller go
71
+ * through (not a candidate, impure and not forced, kept, unreadable). `spec` is the specifier the
72
+ * importer wrote: the policy sees both. Concurrent callers share one build.
73
+ */
74
+ map(id: string, spec: string, policy: Policy, caller: Caller): Promise<ExportMap | null>;
75
+ changed(id: string, change: Change): void;
76
+ }
77
+ export {};
@@ -0,0 +1,349 @@
1
+ import { analyze_exports } from "./parse.js";
2
+ import { STALE, flights } from "@ogygia/machine";
3
+ // src/exports/index.ts
4
+ /** Every barrel, through packages too: what reaches a component's CSS (compiler/fouc-css.ts). */
5
+ const EVERY_BARREL = {
6
+ candidate: () => true,
7
+ forced: () => false,
8
+ kept: () => false,
9
+ follow_packages: true
10
+ };
11
+ const STRIP_QUERY_RE = /[?#].*$/;
12
+ const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
13
+ const PARSABLE_RE = /\.(?:[cm]?[jt]sx?|svelte\.[jt]s)$/;
14
+ const BACKSLASH_G = /\\/g;
15
+ const slashed = (id) => id.replace(BACKSLASH_G, "/");
16
+ /** One app's parsed module shapes, read once each and shared by every {@link ExportIndex}. */
17
+ var Shapes = class {
18
+ #read;
19
+ #shapes = /* @__PURE__ */ new Map();
20
+ /** the indexes built over these shapes: they live as long as the app does */
21
+ #dependents = /* @__PURE__ */ new Set();
22
+ /** `read`: the module's source, or null when it cannot be read (virtual, binary, missing). */
23
+ constructor(read) {
24
+ this.#read = read;
25
+ }
26
+ /** The parsed shape of a module (cached), or null when it cannot be read or parsed. */
27
+ get(id) {
28
+ const clean = id.replace(STRIP_QUERY_RE, "");
29
+ const key = slashed(clean);
30
+ if (this.#shapes.has(key)) return this.#shapes.get(key);
31
+ let shape = null;
32
+ if (PARSABLE_RE.test(clean)) {
33
+ const code = this.#read(clean);
34
+ if (code != null) shape = analyze_exports(code, clean);
35
+ }
36
+ this.#shapes.set(key, shape);
37
+ return shape;
38
+ }
39
+ /** The file `id` changed: drop its shape, and everything every index built from it. */
40
+ invalidate(id, change = "update") {
41
+ const key = slashed(id.replace(STRIP_QUERY_RE, ""));
42
+ this.#shapes.delete(key);
43
+ for (const d of this.#dependents) d.changed(key, change);
44
+ }
45
+ /** (an index registers itself as it is built) */
46
+ depend(d) {
47
+ this.#dependents.add(d);
48
+ }
49
+ };
50
+ /** One resolver's export index: its resolutions, and each policy's barrel maps. */
51
+ var ExportIndex = class {
52
+ shapes;
53
+ #resolve;
54
+ /** One resolution per importer and specifier, as the caller that asked first resolves it. */
55
+ #resolved = flights.keyed()({
56
+ name: "exports-resolve",
57
+ key: ["importer", "spec"],
58
+ ignore: { caller: "every caller of one index resolves alike (the index is per resolver), so the first one answers" },
59
+ run: ({ importer, spec, caller }) => this.#resolve(spec, importer, caller),
60
+ keep: () => Infinity
61
+ });
62
+ /** each policy's walk over this index's shapes and resolutions, memoized per barrel id (a policy
63
+ * is one object per caller kind, made once: fouc-css's, and each plugin's through `b.exports`) */
64
+ #walks = /* @__PURE__ */ new Map();
65
+ constructor(resolve, shapes) {
66
+ this.#resolve = resolve;
67
+ this.shapes = shapes;
68
+ shapes.depend(this);
69
+ }
70
+ /** A specifier resolved from `importer` (cached per importer and specifier). */
71
+ async resolve(spec, importer, caller) {
72
+ for (;;) {
73
+ const got = await this.#resolved.get({
74
+ importer,
75
+ spec,
76
+ caller
77
+ });
78
+ if (got !== STALE) return got;
79
+ }
80
+ }
81
+ /**
82
+ * The export map of a barrel, or null when the module is not a barrel `policy` lets the caller go
83
+ * through (not a candidate, impure and not forced, kept, unreadable). `spec` is the specifier the
84
+ * importer wrote: the policy sees both. Concurrent callers share one build.
85
+ */
86
+ map(id, spec, policy, caller) {
87
+ let walk = this.#walks.get(policy);
88
+ if (walk === void 0) {
89
+ walk = new Walk(this, policy);
90
+ this.#walks.set(policy, walk);
91
+ }
92
+ return walk.map(id, spec, caller);
93
+ }
94
+ changed(id, change) {
95
+ const any = change !== "update";
96
+ if (any) this.#resolved.drop(() => true);
97
+ for (const walk of this.#walks.values()) walk.changed(id, any);
98
+ }
99
+ };
100
+ var Walk = class {
101
+ #index;
102
+ #policy;
103
+ #barrels = flights.keyed()({
104
+ name: "exports-barrel",
105
+ key: ["id"],
106
+ ignore: { build: "what the ask that starts the flight found of the file: a barrel is built once, as that caller resolves" },
107
+ run: async ({ id, build }) => build === null ? null : this.#build_of(id, build.shape, build.path),
108
+ keep: (map) => map !== null && (map.provisional || map.cycles.size > 0) ? 0 : Infinity
109
+ });
110
+ #building = /* @__PURE__ */ new Map();
111
+ constructor(index, policy) {
112
+ this.#index = index;
113
+ this.#policy = policy;
114
+ }
115
+ changed(id, any) {
116
+ this.#barrels.drop(({ id: k }, entry) => {
117
+ if (any || slashed(k) === id) return true;
118
+ const map = entry.kind === "kept" ? entry.answer : this.#building.get(k);
119
+ if (map == null) return false;
120
+ if (map.deps.has(id)) return true;
121
+ for (const d of map.deps) if (slashed(d) === id) return true;
122
+ return false;
123
+ });
124
+ }
125
+ async map(id, spec, caller) {
126
+ const clean = id.replace(STRIP_QUERY_RE, "");
127
+ if (clean !== id) return null;
128
+ if (this.#policy.kept(clean, spec)) return this.#left(clean, "kept");
129
+ if (!this.#policy.candidate(clean, spec)) return this.#left(clean, "outside-project");
130
+ for (;;) {
131
+ const got = await this.#barrels.get(this.#ask(clean, spec, caller));
132
+ if (got !== STALE) return got ?? this.#left(clean, "impure");
133
+ }
134
+ }
135
+ #left(id, left) {
136
+ const shape = this.#index.shapes.get(id);
137
+ if (!shape || !shape.exports.some((e) => e.kind !== "own")) return null;
138
+ return {
139
+ id,
140
+ entries: /* @__PURE__ */ new Map(),
141
+ pure: shape.pure,
142
+ left,
143
+ opaque: false,
144
+ deps: /* @__PURE__ */ new Set([id]),
145
+ provisional: false,
146
+ cycles: /* @__PURE__ */ new Set()
147
+ };
148
+ }
149
+ #ask(id, spec, caller) {
150
+ if (this.#barrels.peek({ id }) !== void 0) return {
151
+ id,
152
+ build: null
153
+ };
154
+ const shape = this.#index.shapes.get(id);
155
+ if (!shape || !shape.pure && !this.#policy.forced(id, spec)) return {
156
+ id,
157
+ build: null
158
+ };
159
+ return {
160
+ id,
161
+ build: {
162
+ shape,
163
+ path: {
164
+ stack: /* @__PURE__ */ new Set(),
165
+ caller
166
+ }
167
+ }
168
+ };
169
+ }
170
+ #resolve(spec, importer, path) {
171
+ return this.#index.resolve(spec, importer, path.caller);
172
+ }
173
+ async #build_of(id, shape, path) {
174
+ const map = {
175
+ id,
176
+ entries: /* @__PURE__ */ new Map(),
177
+ pure: shape.pure,
178
+ left: null,
179
+ opaque: false,
180
+ deps: /* @__PURE__ */ new Set([id]),
181
+ provisional: false,
182
+ cycles: /* @__PURE__ */ new Set()
183
+ };
184
+ this.#building.set(id, map);
185
+ try {
186
+ return await this.#build(map, shape, path);
187
+ } finally {
188
+ if (this.#building.get(id) === map) this.#building.delete(id);
189
+ }
190
+ }
191
+ async #build(map, shape, outer) {
192
+ const id = map.id;
193
+ const path = {
194
+ stack: /* @__PURE__ */ new Set([...outer.stack, id]),
195
+ caller: outer.caller
196
+ };
197
+ const stars = [];
198
+ const explicit = /* @__PURE__ */ new Set();
199
+ for (const rec of shape.exports) if (rec.kind === "own") {
200
+ map.entries.set(rec.exported, "own");
201
+ explicit.add(rec.exported);
202
+ } else if (rec.kind === "reexport") {
203
+ explicit.add(rec.exported);
204
+ const leaf = await this.#leaf(id, rec.source, rec.imported, map, path);
205
+ if (leaf) map.entries.set(rec.exported, leaf);
206
+ else map.opaque = true;
207
+ } else if (rec.kind === "star_ns") {
208
+ explicit.add(rec.exported);
209
+ const target = await this.#resolve(rec.source, id, path);
210
+ if (target) map.entries.set(rec.exported, {
211
+ id: target.replace(STRIP_QUERY_RE, ""),
212
+ namespace: true
213
+ });
214
+ else map.opaque = true;
215
+ } else stars.push({
216
+ source: rec.source,
217
+ type_only: rec.type_only
218
+ });
219
+ for (const star of stars) {
220
+ const target = await this.#resolve(star.source, id, path);
221
+ if (!target || target !== target.replace(STRIP_QUERY_RE, "")) {
222
+ map.opaque = true;
223
+ continue;
224
+ }
225
+ if (!this.#policy.follow_packages && NODE_MODULES_RE.test(target)) {
226
+ map.opaque = true;
227
+ continue;
228
+ }
229
+ map.deps.add(target);
230
+ const names = await this.#star_names(target, map, path);
231
+ if (!names) {
232
+ map.opaque = true;
233
+ continue;
234
+ }
235
+ for (const [name, leaf] of names) {
236
+ if (name === "default") continue;
237
+ if (explicit.has(name)) continue;
238
+ const existing = map.entries.get(name);
239
+ if (existing === void 0) map.entries.set(name, leaf);
240
+ else if (existing !== leaf && !same_leaf(existing, leaf)) map.entries.set(name, "ambiguous");
241
+ }
242
+ }
243
+ return map;
244
+ }
245
+ async #leaf(from, source, imported, map, path) {
246
+ const target = await this.#resolve(source, from, path);
247
+ if (!target) return null;
248
+ if (target !== target.replace(STRIP_QUERY_RE, "")) return null;
249
+ map.deps.add(target);
250
+ const inner = await this.#through(target, map, path);
251
+ if (inner) {
252
+ const e = inner.entries.get(imported);
253
+ if (e && e !== "own" && e !== "ambiguous") return e;
254
+ if (e === "ambiguous") return null;
255
+ }
256
+ return {
257
+ id: target,
258
+ name: imported
259
+ };
260
+ }
261
+ async #through(id, parent, path) {
262
+ if (this.#policy.kept(id, id)) return null;
263
+ const s = this.#barrels.peek({ id });
264
+ if (s?.kind === "kept") {
265
+ const m = s.answer;
266
+ if (m) for (const d of m.deps) parent.deps.add(d);
267
+ return m;
268
+ }
269
+ if (path.stack.has(id)) {
270
+ if (id !== parent.id) parent.cycles.add(id);
271
+ return null;
272
+ }
273
+ if (s !== void 0) {
274
+ parent.provisional = true;
275
+ return null;
276
+ }
277
+ const shape = this.#index.shapes.get(id);
278
+ if (!shape || !shape.pure) return null;
279
+ const built = await this.#barrels.get({
280
+ id,
281
+ build: {
282
+ shape,
283
+ path
284
+ }
285
+ });
286
+ if (built === STALE) {
287
+ parent.provisional = true;
288
+ return null;
289
+ }
290
+ if (built === null) return null;
291
+ if (built.provisional) parent.provisional = true;
292
+ for (const c of built.cycles) if (c !== parent.id) parent.cycles.add(c);
293
+ for (const d of built.deps) parent.deps.add(d);
294
+ return built;
295
+ }
296
+ async #star_names(target, parent, path, seen = /* @__PURE__ */ new Set([parent.id])) {
297
+ const out = /* @__PURE__ */ new Map();
298
+ if (seen.has(target)) return out;
299
+ seen.add(target);
300
+ const shape = this.#index.shapes.get(target);
301
+ if (!shape) return null;
302
+ if (shape.pure) {
303
+ const inner = await this.#through(target, parent, path);
304
+ if (!inner) return null;
305
+ if (inner.opaque) parent.opaque = true;
306
+ for (const [name, e] of inner.entries) if (e === "own") out.set(name, {
307
+ id: target,
308
+ name
309
+ });
310
+ else if (e !== "ambiguous") out.set(name, e);
311
+ return out;
312
+ }
313
+ for (const rec of shape.exports) if (rec.kind === "own") out.set(rec.exported, {
314
+ id: target,
315
+ name: rec.exported
316
+ });
317
+ else if (rec.kind === "reexport") {
318
+ const leaf = await this.#leaf(target, rec.source, rec.imported, parent, path);
319
+ if (leaf) out.set(rec.exported, leaf);
320
+ else parent.opaque = true;
321
+ } else if (rec.kind === "star_ns") {
322
+ const t = await this.#resolve(rec.source, target, path);
323
+ if (t) out.set(rec.exported, {
324
+ id: t.replace(STRIP_QUERY_RE, ""),
325
+ namespace: true
326
+ });
327
+ } else {
328
+ const t = await this.#resolve(rec.source, target, path);
329
+ if (!t) {
330
+ parent.opaque = true;
331
+ continue;
332
+ }
333
+ parent.deps.add(t);
334
+ const names = await this.#star_names(t, parent, path, seen);
335
+ if (!names) {
336
+ parent.opaque = true;
337
+ continue;
338
+ }
339
+ for (const [n, leaf] of names) if (n !== "default" && !out.has(n)) out.set(n, leaf);
340
+ }
341
+ return out;
342
+ }
343
+ };
344
+ function same_leaf(a, b) {
345
+ if (typeof a === "string" || typeof b === "string") return a === b;
346
+ if ("namespace" in a || "namespace" in b) return "namespace" in a && "namespace" in b && a.id === b.id;
347
+ return a.id === b.id && a.name === b.name;
348
+ }
349
+ export { EVERY_BARREL, ExportIndex, Shapes };
@@ -0,0 +1,65 @@
1
+ export interface ImportSpec {
2
+ /** `default` | `namespace` | `named` */
3
+ kind: "default" | "namespace" | "named";
4
+ /** the exported name asked for (`x` in `{ x as y }`, `default` for a default import) */
5
+ imported: string;
6
+ /** the local binding */
7
+ local: string;
8
+ /** `import { type T }` */
9
+ type_only: boolean;
10
+ }
11
+ export interface ImportDecl {
12
+ start: number;
13
+ end: number;
14
+ source: string;
15
+ /** the verbatim ` with { … }` clause (leading space included), '' when none */
16
+ attributes: string;
17
+ /** the attribute keys (`wake` in `with { wake: 'load' }`) — what a mark-aware caller inspects */
18
+ attribute_keys: string[];
19
+ /** `import type { … }` — the whole declaration is type-only */
20
+ type_only: boolean;
21
+ /** bare `import 'x'` */
22
+ side_effect: boolean;
23
+ specs: ImportSpec[];
24
+ }
25
+ /** What a barrel says about one of its exported names. */
26
+ export type ExportRecord = {
27
+ kind: "reexport";
28
+ exported: string;
29
+ imported: string;
30
+ source: string;
31
+ type_only: boolean;
32
+ } | {
33
+ kind: "star";
34
+ source: string;
35
+ type_only: boolean;
36
+ } | {
37
+ kind: "star_ns";
38
+ exported: string;
39
+ source: string;
40
+ } | {
41
+ kind: "own";
42
+ exported: string;
43
+ };
44
+ export interface ModuleShape {
45
+ imports: ImportDecl[];
46
+ exports: ExportRecord[];
47
+ /** A PURE barrel: nothing but imports, re-exports, type declarations and `export {}`. */
48
+ pure: boolean;
49
+ /** Own names (declared in this module) that are exported. */
50
+ own: Set<string>;
51
+ }
52
+ /**
53
+ * Every top-level import of the module, with ranges the rewriter overwrites. Declarations that
54
+ * cannot be rewritten (bare side-effect imports, namespace imports) are returned too, flagged, so
55
+ * a caller sees the whole picture. Null on a syntax error.
56
+ */
57
+ export declare function analyze_imports(code: string, id: string): ImportDecl[] | null;
58
+ /**
59
+ * The export shape of a module. `pure` is the barrel test: the module contributes NO code of its
60
+ * own — every statement is an import, a re-export, an `export {}` of imported bindings, a type
61
+ * declaration, or an empty export. A module with any own declaration, expression statement, or
62
+ * `export default <expr>` is IMPURE (it runs something), and is only rewritten when forced.
63
+ * Null on a syntax error (or a file oxc cannot read as a module).
64
+ */
65
+ export declare function analyze_exports(code: string, id: string): ModuleShape | null;