@codegraft/core 0.1.0-beta.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/assert.d.ts +8 -0
  4. package/dist/assert.d.ts.map +1 -0
  5. package/dist/assert.js +11 -0
  6. package/dist/assert.js.map +1 -0
  7. package/dist/collection.d.ts +164 -0
  8. package/dist/collection.d.ts.map +1 -0
  9. package/dist/collection.js +570 -0
  10. package/dist/collection.js.map +1 -0
  11. package/dist/comment-attachment.d.ts +25 -0
  12. package/dist/comment-attachment.d.ts.map +1 -0
  13. package/dist/comment-attachment.js +94 -0
  14. package/dist/comment-attachment.js.map +1 -0
  15. package/dist/edit-collector.d.ts +31 -0
  16. package/dist/edit-collector.d.ts.map +1 -0
  17. package/dist/edit-collector.js +75 -0
  18. package/dist/edit-collector.js.map +1 -0
  19. package/dist/evaluate.d.ts +15 -0
  20. package/dist/evaluate.d.ts.map +1 -0
  21. package/dist/evaluate.js +95 -0
  22. package/dist/evaluate.js.map +1 -0
  23. package/dist/extensions.d.ts +3 -0
  24. package/dist/extensions.d.ts.map +1 -0
  25. package/dist/extensions.js +19 -0
  26. package/dist/extensions.js.map +1 -0
  27. package/dist/generated/node-types.d.ts +31 -0
  28. package/dist/generated/node-types.d.ts.map +1 -0
  29. package/dist/generated/node-types.js +5 -0
  30. package/dist/generated/node-types.js.map +1 -0
  31. package/dist/helpers.d.ts +13 -0
  32. package/dist/helpers.d.ts.map +1 -0
  33. package/dist/helpers.js +27 -0
  34. package/dist/helpers.js.map +1 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +4 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/internal.d.ts +6 -0
  40. package/dist/internal.d.ts.map +1 -0
  41. package/dist/internal.js +9 -0
  42. package/dist/internal.js.map +1 -0
  43. package/dist/parser.d.ts +30 -0
  44. package/dist/parser.d.ts.map +1 -0
  45. package/dist/parser.js +125 -0
  46. package/dist/parser.js.map +1 -0
  47. package/dist/resolver.d.ts +27 -0
  48. package/dist/resolver.d.ts.map +1 -0
  49. package/dist/resolver.js +241 -0
  50. package/dist/resolver.js.map +1 -0
  51. package/dist/rich-node.d.ts +5 -0
  52. package/dist/rich-node.d.ts.map +1 -0
  53. package/dist/rich-node.js +101 -0
  54. package/dist/rich-node.js.map +1 -0
  55. package/dist/types.d.ts +112 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/types.js +2 -0
  58. package/dist/types.js.map +1 -0
  59. package/dist/zone-splitter.d.ts +12 -0
  60. package/dist/zone-splitter.d.ts.map +1 -0
  61. package/dist/zone-splitter.js +23 -0
  62. package/dist/zone-splitter.js.map +1 -0
  63. package/package.json +62 -0
  64. package/wasm/tree-sitter-tsx.wasm +0 -0
  65. package/wasm/tree-sitter-typescript.wasm +0 -0
  66. package/wasm/tree-sitter-yaml.wasm +0 -0
@@ -0,0 +1,570 @@
1
+ var _a;
2
+ import { Parser } from './parser.js';
3
+ import { splitAndParse } from './zone-splitter.js';
4
+ import { attachComments, COMMENT_TYPES } from './comment-attachment.js';
5
+ import { EditCollector } from './edit-collector.js';
6
+ import { evaluate as evaluateNode } from './evaluate.js';
7
+ import { createResolver } from './resolver.js';
8
+ import { assert } from './assert.js';
9
+ /**
10
+ * A jscodeshift-style selection of CST nodes bound to one transform run. Query methods
11
+ * (`find`/`filter`/`closest`/`parent`/`children`/`first`/`at`) return new Collections; edit
12
+ * methods (`replaceWith`/`remove`/…) record magic-string edits and return `this`. Single-node
13
+ * accessors (`node`/`text`/`type`/`field`/`evaluate`) assert the collection holds exactly one
14
+ * node — the shape you get inside `forEach`, after `first()`/`at()`, or from `field()`.
15
+ *
16
+ * The grammar parameter `G` types the node-type and field-name strings (`NodeTypeOf<G>` etc.) and
17
+ * is carried through navigation. It defaults to every built-in grammar — annotate `root` (e.g.
18
+ * `(root: Collection<'tsx'>) => …`) to narrow `find`/`field` to one grammar's vocabulary.
19
+ */
20
+ export class Collection {
21
+ #nodes;
22
+ #session;
23
+ constructor(nodes, session) {
24
+ this.#nodes = nodes;
25
+ this.#session = session;
26
+ }
27
+ // ---- query ----
28
+ /** Descendants (not self) of node type `type` — a concrete type or a grammar supertype
29
+ * (e.g. `expression`), optionally filtered by field predicates. */
30
+ find(type, attrs) {
31
+ const out = [];
32
+ const seen = new Set();
33
+ const walk = (node) => {
34
+ for (const child of node.children) {
35
+ if (isType(child, type) && !seen.has(child) && matches(child, attrs)) {
36
+ seen.add(child);
37
+ out.push(child);
38
+ }
39
+ walk(child);
40
+ }
41
+ };
42
+ for (const node of this.#nodes)
43
+ walk(node);
44
+ return this.#select(out);
45
+ }
46
+ /** Comment nodes in the subtree (which `find`/`children` omit), optionally only those matching
47
+ * `pattern` — the entry point for transforms that act on directive comments themselves. */
48
+ findComments(pattern) {
49
+ const out = [];
50
+ const walk = (node) => {
51
+ for (const child of node.allChildren) {
52
+ if (COMMENT_TYPES[child.language].has(child.type) && (!pattern || pattern.test(child.text)))
53
+ out.push(child);
54
+ walk(child);
55
+ }
56
+ };
57
+ for (const node of this.#nodes)
58
+ walk(node);
59
+ return this.#select(out);
60
+ }
61
+ filter(predicate) {
62
+ return this.#select(this.#nodes.filter((n) => predicate(new _a([n], this.#session))));
63
+ }
64
+ /** Nearest ancestor (not self) of `type` — concrete or a grammar supertype — per selected node. */
65
+ closest(type) {
66
+ return this.#select(dedupe(this.#nodes.map((n) => ancestorOfType(n, type)).filter(present)));
67
+ }
68
+ parent() {
69
+ return this.#select(dedupe(this.#nodes.map((n) => n.parent).filter(present)));
70
+ }
71
+ children() {
72
+ return this.#select(this.#nodes.flatMap((n) => n.children));
73
+ }
74
+ /** All named siblings of each selected node (excluding itself). */
75
+ siblings() {
76
+ return this.#select(dedupe(this.#nodes.flatMap((n) => n.parent?.children.filter((c) => c !== n) ?? [])));
77
+ }
78
+ nextSibling() {
79
+ return this.#select(this.#nodes.map((n) => siblingAt(n, 1)).filter(present));
80
+ }
81
+ prevSibling() {
82
+ return this.#select(this.#nodes.map((n) => siblingAt(n, -1)).filter(present));
83
+ }
84
+ /** Every ancestor of each selected node (innermost first), optionally of node type `type`. */
85
+ ancestors(type) {
86
+ const out = [];
87
+ for (const n of this.#nodes) {
88
+ for (let cur = n.parent; cur; cur = cur.parent)
89
+ if (!type || isType(cur, type))
90
+ out.push(cur);
91
+ }
92
+ return this.#select(dedupe(out));
93
+ }
94
+ /** Nearest enclosing scope (ancestor-or-self): a function, block, loop, catch, or the program. */
95
+ closestScope() {
96
+ return this.#select(dedupe(this.#nodes.map(scopeOf).filter(present)));
97
+ }
98
+ first() {
99
+ return this.#select(this.#nodes.slice(0, 1));
100
+ }
101
+ at(index) {
102
+ const node = this.#nodes.at(index);
103
+ return this.#select(node ? [node] : []);
104
+ }
105
+ size() {
106
+ return this.#nodes.length;
107
+ }
108
+ forEach(fn) {
109
+ for (const node of this.#nodes)
110
+ fn(new _a([node], this.#session));
111
+ return this;
112
+ }
113
+ map(fn) {
114
+ return this.#nodes.map((node) => fn(new _a([node], this.#session)));
115
+ }
116
+ nodes() {
117
+ return [...this.#nodes];
118
+ }
119
+ /** Whether every selected node is of `type` (concrete or supertype); false for an empty selection. */
120
+ isOfType(type) {
121
+ return this.#nodes.length > 0 && this.#nodes.every((n) => isType(n, type));
122
+ }
123
+ /** The distinct node types in the selection. */
124
+ getTypes() {
125
+ return [...new Set(this.#nodes.map((n) => n.type))];
126
+ }
127
+ // ---- single-node accessors (assert exactly one) ----
128
+ get node() {
129
+ return this.#single();
130
+ }
131
+ get text() {
132
+ return this.#single().text;
133
+ }
134
+ get type() {
135
+ return this.#single().type;
136
+ }
137
+ /** The field child as a (0-or-1) Collection, e.g. `node.field('condition')`. */
138
+ field(name) {
139
+ const child = this.#single().child(name);
140
+ return this.#select(child ? [child] : []);
141
+ }
142
+ /** Evaluate this node as a build-time expression against `context` (see core `evaluate`). */
143
+ evaluate(context) {
144
+ return evaluateNode(this.#single(), context);
145
+ }
146
+ // ---- scope (JS/TS/TSX; confident-or-abstain) ----
147
+ /** Every occurrence (declaration + references) of the binding this node declares, or `null`
148
+ * when not confidently resolvable — the safe signal to skip a rename. */
149
+ references() {
150
+ const node = this.#single();
151
+ const refs = this.#session.resolver(node)?.references(node);
152
+ return refs ? this.#select(refs) : null;
153
+ }
154
+ /** The declaration this reference resolves to, or `null` for a global / when uncertain. */
155
+ definition() {
156
+ const node = this.#single();
157
+ const def = this.#session.resolver(node)?.definition(node);
158
+ return def ? this.#select([def]) : null;
159
+ }
160
+ /** The declaration `name` resolves to from this node's position; `null` for a global / abstain. */
161
+ lookup(name) {
162
+ const node = this.#single();
163
+ const decl = this.#session.resolver(node)?.lookup(node, name);
164
+ return decl ? this.#select([decl]) : null;
165
+ }
166
+ /** Every binding visible at this node (inner shadows outer), or `null` when abstaining. */
167
+ bindingsInScope() {
168
+ const node = this.#single();
169
+ const bindings = this.#session.resolver(node)?.bindingsInScope(node);
170
+ return bindings ? this.#select(bindings) : null;
171
+ }
172
+ // ---- construction ----
173
+ /** Build a code string, interpolating values (a `Collection` contributes its text), validated
174
+ * against the grammar of the first selected node — a syntax error asserts rather than emitting
175
+ * malformed code. Validates as a standalone snippet, so build whole expressions or statements
176
+ * and let `append`/`prepend` add separators. The result feeds any insert/replace. */
177
+ code(strings, ...values) {
178
+ const built = strings.reduce((acc, s, i) => acc + s + (i < values.length ? snippet(values[i]) : ''), '');
179
+ const language = this.#firstNode().language;
180
+ assert(!Parser.parse(built, language).rootNode.hasError, `code\`\`: invalid ${language} snippet: ${built}`);
181
+ return built;
182
+ }
183
+ // ---- edits ----
184
+ /** Replace each selected node with `text`, or with the string a callback derives from it. */
185
+ replaceWith(text) {
186
+ for (const node of this.#nodes) {
187
+ this.#session.collector.overwrite(node.documentStartIndex, node.documentEndIndex, this.#text(text, node));
188
+ }
189
+ return this;
190
+ }
191
+ /** Overwrite a field child's text (literal or derived from its current text); no-op where the
192
+ * field is absent, mirroring `field()` returning an empty selection. */
193
+ setField(name, text) {
194
+ for (const node of this.#nodes) {
195
+ const field = node.child(name);
196
+ if (!field)
197
+ continue;
198
+ const next = typeof text === 'function' ? text(field.text) : text;
199
+ this.#session.collector.overwrite(field.documentStartIndex, field.documentEndIndex, next);
200
+ }
201
+ return this;
202
+ }
203
+ /**
204
+ * Remove each selected node.
205
+ * - `separator`: also drop the trailing `,` of a list element, leaving no array hole / dangling comma.
206
+ * - `wholeLines`: remove the whole lines the node spans (a full-line comment, a YAML entry), so no
207
+ * blank line is left; `collapseBlankBefore` additionally absorbs a blank-line separator directly above.
208
+ */
209
+ remove(options) {
210
+ for (const node of this.#nodes) {
211
+ if (options?.wholeLines) {
212
+ this.#session.collector.removeLines(node.documentStartIndex, node.documentEndIndex, options.collapseBlankBefore);
213
+ continue;
214
+ }
215
+ let end = node.documentEndIndex;
216
+ if (options?.separator) {
217
+ const comma = trailingSeparator(node);
218
+ if (comma)
219
+ end = comma.documentEndIndex;
220
+ }
221
+ this.#session.collector.remove(node.documentStartIndex, end);
222
+ }
223
+ return this;
224
+ }
225
+ /**
226
+ * Narrow-delete: keep `keep` (a 0+-node selection within this node) and drop the wrapper
227
+ * around it — remove `[this.start, firstKept.start)` and `[lastKept.end, this.end)`. The
228
+ * kept range stays editable, so edits made to nodes inside it in the same pass still compose
229
+ * (this is what lets nested conditionals collapse in one pass). Empty `keep` removes the whole
230
+ * node.
231
+ */
232
+ unwrap(keep) {
233
+ const wrapper = this.#single();
234
+ const kept = keep.#nodes;
235
+ if (kept.length === 0) {
236
+ this.#session.collector.remove(wrapper.documentStartIndex, wrapper.documentEndIndex);
237
+ return this;
238
+ }
239
+ this.#session.collector.remove(wrapper.documentStartIndex, kept[0].documentStartIndex);
240
+ this.#session.collector.remove(kept[kept.length - 1].documentEndIndex, wrapper.documentEndIndex);
241
+ return this;
242
+ }
243
+ // ---- insertion ----
244
+ /** Insert `text` (literal or derived per node) immediately before each selected node. */
245
+ insertBefore(text) {
246
+ for (const node of this.#nodes)
247
+ this.#session.collector.insertLeft(node.documentStartIndex, this.#text(text, node));
248
+ return this;
249
+ }
250
+ /** Insert `text` (literal or derived per node) immediately after each selected node. */
251
+ insertAfter(text) {
252
+ for (const node of this.#nodes)
253
+ this.#session.collector.insertRight(node.documentEndIndex, this.#text(text, node));
254
+ return this;
255
+ }
256
+ /** Surround each selected node with `before`…`after`. */
257
+ wrap(before, after) {
258
+ for (const node of this.#nodes) {
259
+ this.#session.collector.insertLeft(node.documentStartIndex, before);
260
+ this.#session.collector.insertRight(node.documentEndIndex, after);
261
+ }
262
+ return this;
263
+ }
264
+ /** Append `text` as the last element of each container node (array/object/argument list/block):
265
+ * after the last element with the right separator, or just inside an empty container. */
266
+ append(text) {
267
+ for (const node of this.#nodes) {
268
+ const elements = node.children;
269
+ if (elements.length === 0)
270
+ this.#session.collector.insertRight(openDelimiter(node).documentEndIndex, text);
271
+ else
272
+ this.#session.collector.insertRight(elements[elements.length - 1].documentEndIndex, separatorFor(node) + text);
273
+ }
274
+ return this;
275
+ }
276
+ /** Prepend `text` as the first element of each container node. */
277
+ prepend(text) {
278
+ for (const node of this.#nodes) {
279
+ const open = openDelimiter(node).documentEndIndex;
280
+ const elements = node.children;
281
+ this.#session.collector.insertRight(open, elements.length === 0 ? text : text + separatorFor(node));
282
+ }
283
+ return this;
284
+ }
285
+ /** Insert a top-level import once: a no-op if a statement importing the same module already
286
+ * exists. Placed after the last existing import, else before the first node. */
287
+ ensureImport(statement) {
288
+ const source = importSource(statement);
289
+ const imports = this.find('import_statement').#nodes;
290
+ if (imports.some((imp) => importSource(imp.text) === source))
291
+ return this;
292
+ if (imports.length === 0)
293
+ return this.prependToFile(statement + '\n');
294
+ this.#session.collector.insertRight(imports[imports.length - 1].documentEndIndex, '\n' + statement);
295
+ return this;
296
+ }
297
+ /** Insert `text` at the very start of the first selected node (typically the file). */
298
+ prependToFile(text) {
299
+ this.#session.collector.insertLeft(this.#firstNode().documentStartIndex, text);
300
+ return this;
301
+ }
302
+ /** Move this node's text to just before `target` (delete here, re-insert there). */
303
+ moveBefore(target) {
304
+ return this.#move(target, (dest, text) => this.#session.collector.insertLeft(dest.documentStartIndex, text));
305
+ }
306
+ /** Move this node's text to just after `target`. */
307
+ moveAfter(target) {
308
+ return this.#move(target, (dest, text) => this.#session.collector.insertRight(dest.documentEndIndex, text));
309
+ }
310
+ // ---- comments ----
311
+ /** Add a leading comment line above each selected node (pass the full comment, e.g. `// note`). */
312
+ addLeadingComment(text) {
313
+ for (const node of this.#nodes)
314
+ this.#session.collector.insertLeft(node.documentStartIndex, text + '\n');
315
+ return this;
316
+ }
317
+ /** Add a trailing comment after each selected node, on the same line. */
318
+ addTrailingComment(text) {
319
+ for (const node of this.#nodes)
320
+ this.#session.collector.insertRight(node.documentEndIndex, ' ' + text);
321
+ return this;
322
+ }
323
+ /** Remove each node's comments, keeping the node. Leading comments take the gap up to the node;
324
+ * trailing/inner comments are removed by their own range (residual whitespace is Prettier's job —
325
+ * note that a same-line trailing comment often attaches as an `inner` comment). */
326
+ removeComments() {
327
+ for (const node of this.#nodes) {
328
+ const lead = node.leadingComments;
329
+ if (lead.length)
330
+ this.#session.collector.remove(lead[0].documentStartIndex, node.documentStartIndex);
331
+ for (const c of [...node.trailingComments, ...node.innerComments]) {
332
+ this.#session.collector.remove(c.documentStartIndex, c.documentEndIndex);
333
+ }
334
+ }
335
+ return this;
336
+ }
337
+ /** Rewrite each node's first leading comment with `fn(its text)`; no-op where there is none. */
338
+ mapLeadingComment(fn) {
339
+ for (const node of this.#nodes) {
340
+ const comment = node.leadingComments[0];
341
+ if (comment)
342
+ this.#session.collector.overwrite(comment.documentStartIndex, comment.documentEndIndex, fn(comment.text));
343
+ }
344
+ return this;
345
+ }
346
+ /** The first leading comment matching `pattern`, as a `RegExpMatchArray` (use a capture group
347
+ * to extract the expression), or `null`. Read it, then `dropDirective` to strip it. */
348
+ directive(pattern) {
349
+ for (const comment of this.#single().leadingComments) {
350
+ const match = comment.text.match(pattern);
351
+ if (match)
352
+ return match;
353
+ }
354
+ return null;
355
+ }
356
+ /** Remove a matching leading directive comment (and the gap up to this node), keeping the node
357
+ * itself. Compose with `remove()` to drop both. */
358
+ dropDirective(pattern) {
359
+ const node = this.#single();
360
+ const comment = node.leadingComments.find((c) => pattern.test(c.text));
361
+ if (comment)
362
+ this.#session.collector.remove(comment.documentStartIndex, node.documentStartIndex);
363
+ return this;
364
+ }
365
+ /** Evaluate a string expression (e.g. a directive's captured text) against `context`. Parsed as
366
+ * TypeScript — available because a namespaced codemod ensures that grammar. */
367
+ evaluateExpression(expression, context) {
368
+ return evaluateNode(expression, context);
369
+ }
370
+ // ---- internals ----
371
+ #text(arg, node) {
372
+ return typeof arg === 'function' ? arg(new _a([node], this.#session)) : arg;
373
+ }
374
+ /** Capture this node's text, delete it, and re-insert it at `target` via `place`. */
375
+ #move(target, place) {
376
+ const node = this.#single();
377
+ const dest = target.#single();
378
+ assert(node.documentEndIndex <= dest.documentStartIndex || dest.documentEndIndex <= node.documentStartIndex, 'move source and target overlap');
379
+ const text = node.text;
380
+ this.#session.collector.remove(node.documentStartIndex, node.documentEndIndex);
381
+ place(dest, text);
382
+ return this;
383
+ }
384
+ #select(nodes) {
385
+ return new _a(nodes, this.#session);
386
+ }
387
+ #single() {
388
+ assert(this.#nodes.length === 1, `expected a single node, got ${this.#nodes.length}`);
389
+ return this.#nodes[0];
390
+ }
391
+ #firstNode() {
392
+ assert(this.#nodes.length > 0, 'collection is empty');
393
+ return this.#nodes.reduce((a, b) => (b.documentStartIndex < a.documentStartIndex ? b : a));
394
+ }
395
+ }
396
+ _a = Collection;
397
+ /** Stringify a `code\`\`` interpolation: a `Collection` yields its (single-node) text. */
398
+ function snippet(value) {
399
+ return value instanceof Collection ? value.text : String(value);
400
+ }
401
+ /** The `,` token immediately after `node` among its parent's children (comments skipped), or
402
+ * `null` — the separator `remove({ separator: true })` drops alongside a list element. */
403
+ function trailingSeparator(node) {
404
+ const siblings = node.parent?.allChildren;
405
+ if (!siblings)
406
+ return null;
407
+ const i = siblings.indexOf(node);
408
+ if (i === -1)
409
+ return null;
410
+ for (let j = i + 1; j < siblings.length; j++) {
411
+ const sib = siblings[j];
412
+ if (COMMENT_TYPES[sib.language].has(sib.type))
413
+ continue;
414
+ return sib.type === ',' ? sib : null;
415
+ }
416
+ return null;
417
+ }
418
+ /** The opening delimiter token (`[` / `{` / `(`) of a container node. */
419
+ function openDelimiter(node) {
420
+ const open = node.allChildren[0];
421
+ assert(open, `container '${node.type}' has no opening delimiter`);
422
+ return open;
423
+ }
424
+ const NEWLINE_CONTAINERS = new Set(['statement_block', 'class_body', 'program']);
425
+ /** Separator between a container's elements: newline for statement lists, comma otherwise. */
426
+ function separatorFor(node) {
427
+ return NEWLINE_CONTAINERS.has(node.type) ? '\n' : ', ';
428
+ }
429
+ /** The module specifier of an import statement's source text, for idempotent `ensureImport`. */
430
+ function importSource(statementText) {
431
+ const match = statementText.match(/from\s*['"]([^'"]+)['"]/) ?? statementText.match(/import\s*['"]([^'"]+)['"]/);
432
+ return match ? match[1] : null;
433
+ }
434
+ function matches(node, attrs) {
435
+ if (!attrs)
436
+ return true;
437
+ for (const [key, matcher] of Object.entries(attrs)) {
438
+ if (matcher === undefined)
439
+ continue;
440
+ if (typeof matcher === 'function') {
441
+ if (!matcher(node))
442
+ return false;
443
+ }
444
+ else if (matcher instanceof RegExp) {
445
+ if (!matcher.test(fieldText(node, key)))
446
+ return false;
447
+ }
448
+ else if (typeof matcher === 'string') {
449
+ if (fieldText(node, key) !== matcher)
450
+ return false;
451
+ }
452
+ else {
453
+ const child = node.child(key); // nested matchers: descend into the field child
454
+ if (!child || !matches(child, matcher))
455
+ return false;
456
+ }
457
+ }
458
+ return true;
459
+ }
460
+ // `key` is a field name or the `text` pseudo-key; only the field branch needs the FieldName cast.
461
+ function fieldText(node, key) {
462
+ return key === 'text' ? node.text : (node.child(key)?.text ?? '');
463
+ }
464
+ /** Match a node by concrete type or by a grammar supertype (e.g. `expression`). */
465
+ function isType(node, type) {
466
+ return node.type === type || Parser.subtypesOf(node.language, type).includes(node.type);
467
+ }
468
+ /** Nearest ancestor matching `type` (concrete or supertype), for `closest`. */
469
+ function ancestorOfType(node, type) {
470
+ for (let cur = node.parent; cur; cur = cur.parent)
471
+ if (isType(cur, type))
472
+ return cur;
473
+ return null;
474
+ }
475
+ /** The named sibling `delta` positions from `node`, or `null` past either end. */
476
+ function siblingAt(node, delta) {
477
+ const siblings = node.parent?.children;
478
+ const i = siblings?.indexOf(node) ?? -1;
479
+ return i === -1 ? null : (siblings[i + delta] ?? null);
480
+ }
481
+ // JS/TS scope boundaries — the structural notion behind `closestScope` (no resolver needed).
482
+ const SCOPE_NODES = new Set([
483
+ 'program',
484
+ 'statement_block',
485
+ 'function_declaration',
486
+ 'generator_function_declaration',
487
+ 'function_expression',
488
+ 'generator_function',
489
+ 'arrow_function',
490
+ 'method_definition',
491
+ 'for_statement',
492
+ 'for_in_statement',
493
+ 'catch_clause',
494
+ ]);
495
+ function scopeOf(node) {
496
+ for (let cur = node; cur; cur = cur.parent)
497
+ if (SCOPE_NODES.has(cur.type))
498
+ return cur;
499
+ return null;
500
+ }
501
+ const present = (x) => x !== null;
502
+ function dedupe(nodes) {
503
+ return [...new Set(nodes)];
504
+ }
505
+ /** The tree root a node belongs to (its zone's parsed root), for per-zone resolver caching. */
506
+ function rootOf(node) {
507
+ let cur = node;
508
+ while (cur.parent)
509
+ cur = cur.parent;
510
+ return cur;
511
+ }
512
+ /**
513
+ * Build a lazy transformer that runs an imperative `codemod(root, context)` against a target
514
+ * (a grammar or a {@link ZoneSplitter}): `init()` loads grammars once; the returned transformer
515
+ * is synchronous. The codemod receives a {@link Collection} over every zone's tree and records
516
+ * edits, which are emitted via magic-string.
517
+ *
518
+ * `namespace` opts into the scan-gate (a source not mentioning it is returned untouched,
519
+ * unparsed) and ensures the TypeScript grammar for `evaluate`'s string form.
520
+ */
521
+ export function createCodemodTransformer(target, codemod, options) {
522
+ const namespace = options?.namespace;
523
+ let pending = null;
524
+ async function build() {
525
+ await Parser.init();
526
+ const grammars = typeof target === 'string' ? [target] : target.grammars;
527
+ for (const grammar of grammars)
528
+ await Parser.loadGrammar(grammar);
529
+ if (typeof target !== 'string')
530
+ await target.init();
531
+ if (namespace !== undefined)
532
+ await Parser.loadGrammar('typescript');
533
+ function run(source, context) {
534
+ const collector = new EditCollector(source);
535
+ if (namespace !== undefined && !source.includes(namespace))
536
+ return collector;
537
+ const zones = splitAndParse(source, target);
538
+ for (const zone of zones)
539
+ attachComments(zone.tree);
540
+ // One resolver per zone tree, built on first use (only if the codemod asks for scope).
541
+ const resolvers = new Map();
542
+ const session = {
543
+ collector,
544
+ resolver(node) {
545
+ const treeRoot = rootOf(node);
546
+ if (!resolvers.has(treeRoot))
547
+ resolvers.set(treeRoot, createResolver(treeRoot));
548
+ return resolvers.get(treeRoot) ?? null;
549
+ },
550
+ };
551
+ codemod(new Collection(zones.map((zone) => zone.tree), session), context);
552
+ return collector;
553
+ }
554
+ return {
555
+ transform: (source, context) => run(source, context).toString(),
556
+ transformWithMap(source, context, options) {
557
+ const collector = run(source, context);
558
+ return { code: collector.toString(), map: collector.generateMap(options?.source ?? 'input') };
559
+ },
560
+ };
561
+ }
562
+ return {
563
+ target,
564
+ init() {
565
+ pending ??= build();
566
+ return pending;
567
+ },
568
+ };
569
+ }
570
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":";AASA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,eAAe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AAK,KAAK,EAAE,CAAA;YACnB,OAAO,OAAO,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { GrammarId, RichNode } from './types.js';
2
+ /**
3
+ * The node types that count as comments, per grammar — the single source of truth
4
+ * for "what is a comment node". Consumed by the attachment pass below and by
5
+ * `rich-node.ts` to keep comments out of `RichNode.children`.
6
+ *
7
+ * Every grammar Codegraft targets today names its comment node `comment`; the map is
8
+ * kept per-grammar so a future grammar with a different name slots in without
9
+ * touching either consumer.
10
+ */
11
+ export declare const COMMENT_TYPES: Record<GrammarId, ReadonlySet<string>>;
12
+ /**
13
+ * Classify every comment among its parent's named siblings onto the relevant RichNode's
14
+ * leading/trailing/inner array. Mutates in place; pure traversal, no parser dependency.
15
+ *
16
+ * - same row as the preceding node → trailing of it
17
+ * - in the contiguous comment run above a node → leading of that node
18
+ * - no following node, or a blank-line break → inner of the parent (it floats)
19
+ *
20
+ * The run is "contiguous" when each comment sits a row below the previous and the last a row above
21
+ * the node, so a stack of comments all lead it (topmost first) — which lets a directive stacked
22
+ * above another comment still attach to the node it gates.
23
+ */
24
+ export declare function attachComments(root: RichNode): void;
25
+ //# sourceMappingURL=comment-attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment-attachment.d.ts","sourceRoot":"","sources":["../src/comment-attachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErD;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAOhE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAEnD"}