@codegraft/core 0.1.0-beta.11 → 0.1.0-beta.13
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.
- package/README.md +5 -3
- package/dist/collection.d.ts +11 -13
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +32 -64
- package/dist/collection.js.map +1 -1
- package/dist/containers.d.ts +1 -4
- package/dist/containers.d.ts.map +1 -1
- package/dist/containers.js +1 -6
- package/dist/containers.js.map +1 -1
- package/dist/format.d.ts +3 -39
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +8 -105
- package/dist/format.js.map +1 -1
- package/dist/formatter.d.ts +15 -54
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +44 -192
- package/dist/formatter.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +5 -2
- package/dist/parser.js.map +1 -1
- package/dist/rich-node.d.ts +1 -1
- package/dist/rich-node.d.ts.map +1 -1
- package/dist/types.d.ts +5 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -6
- package/{LICENSE → vendor/web-tree-sitter/LICENSE} +2 -2
- package/vendor/web-tree-sitter/web-tree-sitter.d.ts +1021 -0
- package/vendor/web-tree-sitter/web-tree-sitter.js +4006 -0
- package/vendor/web-tree-sitter/web-tree-sitter.wasm +0 -0
package/dist/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,iGAAiG;AACjG,yGAAyG;AAEzG,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,C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AI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAE,CAAC,CAAC,CAAC,CAAA;AAC3D,CAAC"}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { RichNode } from './types.js';
|
|
2
2
|
import type { EditCollector } from './edit-collector.js';
|
|
3
|
-
import { type FormatStyle } from './format.js';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* buffer.
|
|
4
|
+
* How an edit is *rendered* once the codemod has decided *what* to edit. Built per-apply from the
|
|
5
|
+
* source and its detected line ending; the {@link Collection} delegates rendering to it while the
|
|
6
|
+
* {@link EditCollector} it drives stays a pure edit buffer.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* (
|
|
8
|
+
* Scope is deliberately narrow — just enough that edits are **syntactically valid**: re-indent an
|
|
9
|
+
* inserted snippet to its anchor line, and give an appended/prepended element the separator its
|
|
10
|
+
* container needs (`,` / `;` / a line break). Cosmetics — exact indent, blank lines, brace padding,
|
|
11
|
+
* inline-vs-multiline reflow — are left to a downstream formatter, which sees the output anyway.
|
|
13
12
|
*/
|
|
14
13
|
export declare class Formatter {
|
|
15
14
|
#private;
|
|
16
|
-
constructor(collector: EditCollector, source: string,
|
|
15
|
+
constructor(collector: EditCollector, source: string, eol: string);
|
|
17
16
|
/** The line ending — for inserting whole statements (`ensureImport`). */
|
|
18
17
|
get eol(): string;
|
|
19
18
|
/** The leading whitespace of the line containing `index` — for restoring a displaced node's indent. */
|
|
@@ -21,53 +20,15 @@ export declare class Formatter {
|
|
|
21
20
|
/** `text` re-indented to the line at `index` (single-line text is unchanged) — for a replaced or
|
|
22
21
|
* inserted snippet. */
|
|
23
22
|
reindent(text: string, index: number): string;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
23
|
+
/** The offset just past the line break following `index` (trailing spaces/tabs + one `\n`), or
|
|
24
|
+
* `index` itself when `index` is not at end of line — so `remove({ separator })` can drop a
|
|
25
|
+
* statement's now-empty line, the newline-container analogue of dropping a list element's comma. */
|
|
26
|
+
endOfLine(index: number): number;
|
|
27
|
+
/** Append `text` as the last element of `node` with a valid separator: a line break in a
|
|
28
|
+
* block/class body, a `,`/`;` after the last element of a delimited list, or as the sole element
|
|
29
|
+
* of an empty container. */
|
|
26
30
|
append(node: RichNode, text: string): void;
|
|
27
31
|
/** Prepend `text` as the first element of `node` — the mirror of {@link append}. */
|
|
28
32
|
prepend(node: RichNode, text: string): void;
|
|
29
|
-
/** Delete `[start, end)`, collapsing whitespace the way Prettier would: when the span owns its
|
|
30
|
-
* line(s) — only indentation before `start`, only whitespace after `end` up to the line break —
|
|
31
|
-
* drop the whole lines so no blank line is left; otherwise an in-line delete that also clears one
|
|
32
|
-
* residual separating space, so a removed mid-list element (`[1, two(), 3]`) leaves `[1, 3]`, not
|
|
33
|
-
* `[1, 3]`.
|
|
34
|
-
*
|
|
35
|
-
* In the own-line case the content, the leading indent, and the trailing line break are removed
|
|
36
|
-
* separately so the deletion composes after an abutting edit: a prior `unwrap`/`dropDirective` that
|
|
37
|
-
* already consumed the run up to `start` leaves the content abutting it (no overlap, so it lands),
|
|
38
|
-
* while the leading-indent removal it overlaps is dropped on its own (first-wins) instead of taking
|
|
39
|
-
* the whole line removal down with it.
|
|
40
|
-
*
|
|
41
|
-
* `collapse.before`/`collapse.after` (the node was the last / first surviving element of its
|
|
42
|
-
* container) additionally drop the run of blank lines directly above / below: a blank separator
|
|
43
|
-
* left against the container's closing / opening delimiter, which Prettier strips. Each is its own
|
|
44
|
-
* edit, abutting (not overlapping) the line removal, so a prior edit on the line is unaffected. */
|
|
45
|
-
removeNode(start: number, end: number, collapse?: {
|
|
46
|
-
before?: boolean;
|
|
47
|
-
after?: boolean;
|
|
48
|
-
}): void;
|
|
49
|
-
/** Delete `[start, end)` where `end` begins a following node, collapsing the lines before it: when
|
|
50
|
-
* `start` opens its own line and `end` sits on a later line, drop `[start's line, end's line)` so
|
|
51
|
-
* the leading run (a directive comment and any comments stacked under it) vanishes whole-line while
|
|
52
|
-
* `end`'s own line — its indentation included — is left for a later edit to collapse independently.
|
|
53
|
-
* Otherwise (an inline `start`, or `end` on the same line) a plain `[start, end)` delete. Used by
|
|
54
|
-
* `dropDirective` so it composes with a following `remove`. */
|
|
55
|
-
removeLeadingTo(start: number, end: number): void;
|
|
56
|
-
/** Delete the whole lines `[start, end)` touches — leading indentation through the trailing newline,
|
|
57
|
-
* so nothing blank is left. With `collapseBlankBefore`, also absorb whole blank lines immediately
|
|
58
|
-
* above (a separator before a dropped block). The explicit whole-line removal `remove({ wholeLines })`
|
|
59
|
-
* asks for, where collapsing per node isn't enough. */
|
|
60
|
-
removeWholeLines(start: number, end: number, collapseBlankBefore?: boolean): void;
|
|
61
|
-
/** Register a dedent of the lifted range `[from, to)` by `dedent` columns: every continuation line
|
|
62
|
-
* (the lines after the first) loses up to `dedent` leading-whitespace columns. Used by `unwrap`,
|
|
63
|
-
* whose kept statements drop a level — their first line inherits the wrapper's indent for free,
|
|
64
|
-
* but the rest keep their deeper source indent.
|
|
65
|
-
*
|
|
66
|
-
* Deferred to {@link flush} rather than applied now so it yields (first-wins) to the codemod's own
|
|
67
|
-
* edits on the kept nodes: a kept statement removed or replaced in the same pass wins the overlap,
|
|
68
|
-
* so only lines that actually survive get dedented. A no-op unless `dedent` is positive. */
|
|
69
|
-
deferReindent(from: number, to: number, dedent: number): void;
|
|
70
|
-
/** Apply every {@link deferReindent}, once, after the codemod has recorded its explicit edits. */
|
|
71
|
-
flush(): void;
|
|
72
33
|
}
|
|
73
34
|
//# sourceMappingURL=formatter.d.ts.map
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAIxD;;;;;;;;;GASG;AACH,qBAAa,SAAS;;gBAKR,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAMjE,yEAAyE;IACzE,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,uGAAuG;IACvG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI/B;4BACwB;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAI7C;;yGAEqG;IACrG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAMhC;;iCAE6B;IAC7B,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAY1C,oFAAoF;IACpF,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAe5C"}
|
package/dist/formatter.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import { reindent, indentOf
|
|
2
|
-
import { openDelimiter,
|
|
1
|
+
import { reindent, indentOf } from './format.js';
|
|
2
|
+
import { openDelimiter, NEWLINE_CONTAINERS, SEMI_CONTAINERS } from './containers.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* buffer.
|
|
4
|
+
* How an edit is *rendered* once the codemod has decided *what* to edit. Built per-apply from the
|
|
5
|
+
* source and its detected line ending; the {@link Collection} delegates rendering to it while the
|
|
6
|
+
* {@link EditCollector} it drives stays a pure edit buffer.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* (
|
|
8
|
+
* Scope is deliberately narrow — just enough that edits are **syntactically valid**: re-indent an
|
|
9
|
+
* inserted snippet to its anchor line, and give an appended/prepended element the separator its
|
|
10
|
+
* container needs (`,` / `;` / a line break). Cosmetics — exact indent, blank lines, brace padding,
|
|
11
|
+
* inline-vs-multiline reflow — are left to a downstream formatter, which sees the output anyway.
|
|
12
12
|
*/
|
|
13
13
|
export class Formatter {
|
|
14
14
|
#collector;
|
|
15
15
|
#source;
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
* explicit edits so they yield to them (see {@link deferReindent}). */
|
|
19
|
-
#deferred = [];
|
|
20
|
-
constructor(collector, source, style) {
|
|
16
|
+
#eol;
|
|
17
|
+
constructor(collector, source, eol) {
|
|
21
18
|
this.#collector = collector;
|
|
22
19
|
this.#source = source;
|
|
23
|
-
this.#
|
|
20
|
+
this.#eol = eol;
|
|
24
21
|
}
|
|
25
22
|
/** The line ending — for inserting whole statements (`ensureImport`). */
|
|
26
23
|
get eol() {
|
|
27
|
-
return this.#
|
|
24
|
+
return this.#eol;
|
|
28
25
|
}
|
|
29
26
|
/** The leading whitespace of the line containing `index` — for restoring a displaced node's indent. */
|
|
30
27
|
indentAt(index) {
|
|
@@ -33,193 +30,48 @@ export class Formatter {
|
|
|
33
30
|
/** `text` re-indented to the line at `index` (single-line text is unchanged) — for a replaced or
|
|
34
31
|
* inserted snippet. */
|
|
35
32
|
reindent(text, index) {
|
|
36
|
-
return reindent(text, indentOf(this.#source, index), this.#
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
33
|
+
return reindent(text, indentOf(this.#source, index), this.#eol);
|
|
34
|
+
}
|
|
35
|
+
/** The offset just past the line break following `index` (trailing spaces/tabs + one `\n`), or
|
|
36
|
+
* `index` itself when `index` is not at end of line — so `remove({ separator })` can drop a
|
|
37
|
+
* statement's now-empty line, the newline-container analogue of dropping a list element's comma. */
|
|
38
|
+
endOfLine(index) {
|
|
39
|
+
let i = index;
|
|
40
|
+
while (this.#source[i] === ' ' || this.#source[i] === '\t' || this.#source[i] === '\r')
|
|
41
|
+
i++;
|
|
42
|
+
return this.#source[i] === '\n' ? i + 1 : index;
|
|
43
|
+
}
|
|
44
|
+
/** Append `text` as the last element of `node` with a valid separator: a line break in a
|
|
45
|
+
* block/class body, a `,`/`;` after the last element of a delimited list, or as the sole element
|
|
46
|
+
* of an empty container. */
|
|
41
47
|
append(node, text) {
|
|
42
48
|
const elements = node.children;
|
|
43
49
|
if (NEWLINE_CONTAINERS.has(node.type)) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const at = elements.length ? elements[elements.length - 1] : openDelimiter(node);
|
|
51
|
+
this.#collector.insertRight(at.documentEndIndex, this.#eol + text);
|
|
52
|
+
}
|
|
53
|
+
else if (elements.length === 0) {
|
|
54
|
+
this.#collector.insertRight(openDelimiter(node).documentEndIndex, text);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.#collector.insertRight(elements[elements.length - 1].documentEndIndex, this.#separator(node) + text);
|
|
50
58
|
}
|
|
51
|
-
else if (elements.length === 0)
|
|
52
|
-
this.#fillContainer(node, text);
|
|
53
|
-
else
|
|
54
|
-
this.#appendElement(node, elements[elements.length - 1], text);
|
|
55
59
|
}
|
|
56
60
|
/** Prepend `text` as the first element of `node` — the mirror of {@link append}. */
|
|
57
61
|
prepend(node, text) {
|
|
58
62
|
const elements = node.children;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
else
|
|
63
|
-
this.#collector.insertRight(openDelimiter(node).documentEndIndex, this.#line(text, elements[0].documentStartIndex));
|
|
64
|
-
}
|
|
65
|
-
else if (elements.length === 0)
|
|
66
|
-
this.#fillContainer(node, text);
|
|
67
|
-
else
|
|
68
|
-
this.#prependElement(node, elements[0], text);
|
|
69
|
-
}
|
|
70
|
-
// —— removal: emit the collapse edits ——
|
|
71
|
-
/** Delete `[start, end)`, collapsing whitespace the way Prettier would: when the span owns its
|
|
72
|
-
* line(s) — only indentation before `start`, only whitespace after `end` up to the line break —
|
|
73
|
-
* drop the whole lines so no blank line is left; otherwise an in-line delete that also clears one
|
|
74
|
-
* residual separating space, so a removed mid-list element (`[1, two(), 3]`) leaves `[1, 3]`, not
|
|
75
|
-
* `[1, 3]`.
|
|
76
|
-
*
|
|
77
|
-
* In the own-line case the content, the leading indent, and the trailing line break are removed
|
|
78
|
-
* separately so the deletion composes after an abutting edit: a prior `unwrap`/`dropDirective` that
|
|
79
|
-
* already consumed the run up to `start` leaves the content abutting it (no overlap, so it lands),
|
|
80
|
-
* while the leading-indent removal it overlaps is dropped on its own (first-wins) instead of taking
|
|
81
|
-
* the whole line removal down with it.
|
|
82
|
-
*
|
|
83
|
-
* `collapse.before`/`collapse.after` (the node was the last / first surviving element of its
|
|
84
|
-
* container) additionally drop the run of blank lines directly above / below: a blank separator
|
|
85
|
-
* left against the container's closing / opening delimiter, which Prettier strips. Each is its own
|
|
86
|
-
* edit, abutting (not overlapping) the line removal, so a prior edit on the line is unaffected. */
|
|
87
|
-
removeNode(start, end, collapse = {}) {
|
|
88
|
-
const lineStart = lineStartOf(this.#source, start);
|
|
89
|
-
const newline = this.#source.indexOf('\n', end);
|
|
90
|
-
const lineEnd = newline === -1 ? this.#source.length : newline;
|
|
91
|
-
const ownsLines = this.#source.slice(lineStart, start).trim() === '' && this.#source.slice(end, lineEnd).trim() === '';
|
|
92
|
-
if (!ownsLines) {
|
|
93
|
-
// Inline hole: drop one separating space when both sides are spaced (a mid-list element), so no
|
|
94
|
-
// double space is left. Never at a list edge (one side non-space) or across a line break.
|
|
95
|
-
const trim = isHSpace(this.#source[end]) && isHSpace(this.#source[start - 1]) ? 1 : 0;
|
|
96
|
-
this.#collector.remove(start, end + trim);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this.#collector.remove(start, end); // the content — abuts any prior edit at `start`, so it lands
|
|
100
|
-
this.#collector.remove(lineStart, start); // leading indent — may be already gone under a prior edit
|
|
101
|
-
const lineBreakEnd = newline === -1 ? this.#source.length : newline + 1;
|
|
102
|
-
this.#collector.remove(end, lineBreakEnd); // trailing line break
|
|
103
|
-
// Collapse a blank-line separator the removal leaves dangling against a container edge: `before`
|
|
104
|
-
// the run above the node (against the close), `after` the run below (against the open). With no
|
|
105
|
-
// such run each helper returns the offset it was given, so the remove is a no-op.
|
|
106
|
-
if (collapse.before)
|
|
107
|
-
this.#collector.remove(blankRunStart(this.#source, lineStart), lineStart);
|
|
108
|
-
if (collapse.after)
|
|
109
|
-
this.#collector.remove(lineBreakEnd, blankRunEnd(this.#source, lineBreakEnd));
|
|
110
|
-
}
|
|
111
|
-
/** Delete `[start, end)` where `end` begins a following node, collapsing the lines before it: when
|
|
112
|
-
* `start` opens its own line and `end` sits on a later line, drop `[start's line, end's line)` so
|
|
113
|
-
* the leading run (a directive comment and any comments stacked under it) vanishes whole-line while
|
|
114
|
-
* `end`'s own line — its indentation included — is left for a later edit to collapse independently.
|
|
115
|
-
* Otherwise (an inline `start`, or `end` on the same line) a plain `[start, end)` delete. Used by
|
|
116
|
-
* `dropDirective` so it composes with a following `remove`. */
|
|
117
|
-
removeLeadingTo(start, end) {
|
|
118
|
-
const startLine = lineStartOf(this.#source, start);
|
|
119
|
-
const endLine = lineStartOf(this.#source, end);
|
|
120
|
-
if (endLine > startLine && this.#source.slice(startLine, start).trim() === '')
|
|
121
|
-
this.#collector.remove(startLine, endLine);
|
|
122
|
-
else
|
|
123
|
-
this.#collector.remove(start, end);
|
|
124
|
-
}
|
|
125
|
-
/** Delete the whole lines `[start, end)` touches — leading indentation through the trailing newline,
|
|
126
|
-
* so nothing blank is left. With `collapseBlankBefore`, also absorb whole blank lines immediately
|
|
127
|
-
* above (a separator before a dropped block). The explicit whole-line removal `remove({ wholeLines })`
|
|
128
|
-
* asks for, where collapsing per node isn't enough. */
|
|
129
|
-
removeWholeLines(start, end, collapseBlankBefore = false) {
|
|
130
|
-
const [from, to] = wholeLineRange(this.#source, start, end, collapseBlankBefore);
|
|
131
|
-
this.#collector.remove(from, to);
|
|
132
|
-
}
|
|
133
|
-
// —— unwrap reindent (deferred) ——
|
|
134
|
-
/** Register a dedent of the lifted range `[from, to)` by `dedent` columns: every continuation line
|
|
135
|
-
* (the lines after the first) loses up to `dedent` leading-whitespace columns. Used by `unwrap`,
|
|
136
|
-
* whose kept statements drop a level — their first line inherits the wrapper's indent for free,
|
|
137
|
-
* but the rest keep their deeper source indent.
|
|
138
|
-
*
|
|
139
|
-
* Deferred to {@link flush} rather than applied now so it yields (first-wins) to the codemod's own
|
|
140
|
-
* edits on the kept nodes: a kept statement removed or replaced in the same pass wins the overlap,
|
|
141
|
-
* so only lines that actually survive get dedented. A no-op unless `dedent` is positive. */
|
|
142
|
-
deferReindent(from, to, dedent) {
|
|
143
|
-
if (dedent > 0)
|
|
144
|
-
this.#deferred.push({ from, to, dedent });
|
|
145
|
-
}
|
|
146
|
-
/** Apply every {@link deferReindent}, once, after the codemod has recorded its explicit edits. */
|
|
147
|
-
flush() {
|
|
148
|
-
for (const { from, to, dedent } of this.#deferred)
|
|
149
|
-
this.#dedentLifted(from, to, dedent);
|
|
150
|
-
this.#deferred.length = 0;
|
|
151
|
-
}
|
|
152
|
-
// —— internals ——
|
|
153
|
-
/** Strip up to `dedent` leading-whitespace columns from each continuation line of `[from, to)`
|
|
154
|
-
* (blank lines skipped). Whitespace-only edits at line starts, so they compose with edits to the
|
|
155
|
-
* kept nodes' content; a line already consumed by another edit drops out via first-wins. */
|
|
156
|
-
#dedentLifted(from, to, dedent) {
|
|
157
|
-
for (let nl = this.#source.indexOf('\n', from); nl !== -1 && nl < to; nl = this.#source.indexOf('\n', nl + 1)) {
|
|
158
|
-
const lineStart = nl + 1;
|
|
159
|
-
let i = lineStart;
|
|
160
|
-
while (isHSpace(this.#source[i]))
|
|
161
|
-
i++;
|
|
162
|
-
if (i > lineStart)
|
|
163
|
-
this.#collector.remove(lineStart, lineStart + Math.min(dedent, i - lineStart));
|
|
63
|
+
const newline = NEWLINE_CONTAINERS.has(node.type);
|
|
64
|
+
if (newline || elements.length === 0) {
|
|
65
|
+
this.#collector.insertRight(openDelimiter(node).documentEndIndex, newline ? this.#eol + text : text);
|
|
164
66
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
#line(text, index) {
|
|
168
|
-
const indent = indentOf(this.#source, index);
|
|
169
|
-
return this.#style.eol + indent + reindent(text, indent, this.#style.eol);
|
|
170
|
-
}
|
|
171
|
-
/** Open an empty `{}` block onto its own indented line — `{}` → `{⏎ text⏎}`. */
|
|
172
|
-
#fillBlock(node, text) {
|
|
173
|
-
const blockIndent = indentOf(this.#source, node.documentStartIndex);
|
|
174
|
-
const indent = blockIndent + this.#style.indentUnit;
|
|
175
|
-
const eol = this.#style.eol;
|
|
176
|
-
this.#collector.insertRight(openDelimiter(node).documentEndIndex, eol + indent + reindent(text, indent, eol) + eol + blockIndent);
|
|
177
|
-
}
|
|
178
|
-
/** Fill an empty delimited container with its sole element: a brace container is padded
|
|
179
|
-
* (`{}` → `{ text }`); an array / argument list is not (`[]` → `[text]`). */
|
|
180
|
-
#fillContainer(node, text) {
|
|
181
|
-
const open = openDelimiter(node);
|
|
182
|
-
const pad = open.text === '{' ? ' ' : '';
|
|
183
|
-
this.#collector.insertRight(open.documentEndIndex, pad + text + pad);
|
|
184
|
-
}
|
|
185
|
-
/** Append `text` after the last element `last` of a delimited container. A multi-line container
|
|
186
|
-
* places it on a fresh line at the elements' indent, mirroring the trailing-separator style —
|
|
187
|
-
* extend an existing trailing `sep`, add the mandatory `,` a comma list omits, or rely on the
|
|
188
|
-
* newline alone for a `;` list (where the separator between members is optional); an inline one
|
|
189
|
-
* stays on one line. */
|
|
190
|
-
#appendElement(node, last, text) {
|
|
191
|
-
const sep = this.#separatorFor(node);
|
|
192
|
-
if (!isMultiline(node)) {
|
|
193
|
-
this.#collector.insertRight(last.documentEndIndex, `${sep} ${text}`);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const trailing = trailingSeparator(last, sep);
|
|
197
|
-
const line = this.#line(text, last.documentStartIndex);
|
|
198
|
-
if (trailing)
|
|
199
|
-
this.#collector.insertRight(trailing.documentEndIndex, line + sep);
|
|
200
|
-
else if (sep === ';')
|
|
201
|
-
this.#collector.insertRight(last.documentEndIndex, line);
|
|
202
|
-
else
|
|
203
|
-
this.#collector.insertRight(last.documentEndIndex, sep + line);
|
|
204
|
-
}
|
|
205
|
-
/** Prepend `text` before the first element `first` — the mirror of {@link #appendElement}. The new
|
|
206
|
-
* element is always followed by the old first, so a multi-line container puts it on a fresh line
|
|
207
|
-
* after the open delimiter, separator-terminated (`;` only where the body terminates members with
|
|
208
|
-
* one); an inline one inserts before the first element so brace padding stays intact
|
|
209
|
-
* (`{ a }` → `{ x, a }`). */
|
|
210
|
-
#prependElement(node, first, text) {
|
|
211
|
-
const sep = this.#separatorFor(node);
|
|
212
|
-
if (!isMultiline(node)) {
|
|
213
|
-
this.#collector.insertLeft(first.documentStartIndex, `${text}${sep} `);
|
|
214
|
-
return;
|
|
67
|
+
else {
|
|
68
|
+
this.#collector.insertLeft(elements[0].documentStartIndex, text + this.#separator(node));
|
|
215
69
|
}
|
|
216
|
-
const terminate = sep === ',' || trailingSeparator(first, sep) !== null;
|
|
217
|
-
this.#collector.insertRight(openDelimiter(node).documentEndIndex, this.#line(text, first.documentStartIndex) + (terminate ? sep : ''));
|
|
218
70
|
}
|
|
219
|
-
/** The
|
|
220
|
-
*
|
|
221
|
-
#
|
|
222
|
-
return SEMI_CONTAINERS.has(node.type) ? ';' : ',';
|
|
71
|
+
/** The separator placed between a delimited container's elements — `; ` for a TS interface /
|
|
72
|
+
* object type, else `, `. */
|
|
73
|
+
#separator(node) {
|
|
74
|
+
return SEMI_CONTAINERS.has(node.type) ? '; ' : ', ';
|
|
223
75
|
}
|
|
224
76
|
}
|
|
225
77
|
//# sourceMappingURL=formatter.js.map
|
package/dist/formatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEpF;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IACX,UAAU,CAAe;IACzB,OAAO,CAAQ;IACf,IAAI,CAAQ;IAErB,YAAY,SAAwB,EAAE,MAAc,EAAE,GAAW;QAC/D,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;IACjB,CAAC;IAED,yEAAyE;IACzE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,uGAAuG;IACvG,QAAQ,CAAC,KAAa;QACpB,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACtC,CAAC;IAED;4BACwB;IACxB,QAAQ,CAAC,IAAY,EAAE,KAAa;QAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;IACjE,CAAC;IAED;;yGAEqG;IACrG,SAAS,CAAC,KAAa;QACrB,IAAI,CAAC,GAAG,KAAK,CAAA;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,C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,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,OAAO,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACtG,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,EAAE,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1F,CAAC;IACH,CAAC;IAED;kCAC8B;IAC9B,UAAU,CAAC,IAAc;QACvB,OAAO,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;IACrD,CAAC;CACF"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { Parser } from './parser.js';
|
|
|
2
2
|
export { EXTENSION_GRAMMAR } from './extensions.js';
|
|
3
3
|
export { wrapNode } from './rich-node.js';
|
|
4
4
|
export { assert } from './assert.js';
|
|
5
|
-
export type { Node, Tree } from 'web-tree-sitter';
|
|
5
|
+
export type { Node, Tree } from '../vendor/web-tree-sitter/web-tree-sitter.js';
|
|
6
6
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,8CAA8C,CAAA"}
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from '../vendor/web-tree-sitter/web-tree-sitter.js';
|
|
2
2
|
import type { GrammarId } from './types.js';
|
|
3
3
|
/** Idempotent. Loads the web-tree-sitter WASM runtime once per process. */
|
|
4
4
|
declare function init(): Promise<void>;
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkC,KAAK,IAAI,EAAE,MAAM,8CAA8C,CAAA;AACxG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAqC3C,2EAA2E;AAC3E,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAGnC;AAED;;;;GAIG;AACH,iBAAe,WAAW,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASnF;AAcD;oFACoF;AACpF,iBAAS,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAQ3D;AAED;;;wCAGwC;AACxC,iBAAS,UAAU,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBtE;AAED,kFAAkF;AAClF,eAAO,MAAM,MAAM;;;;;CAA2C,CAAA"}
|
package/dist/parser.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
|
|
3
|
+
// web-tree-sitter is vendored (scripts/regen-web-tree-sitter.mjs), not a runtime dependency. The glue
|
|
4
|
+
// self-locates its wasm sibling via `import.meta.url`, so importing the vendored file is all it needs
|
|
5
|
+
// — no peer, no `locateFile`.
|
|
6
|
+
import { Language, Parser as TreeSitter } from '../vendor/web-tree-sitter/web-tree-sitter.js';
|
|
4
7
|
import { assert } from './assert.js';
|
|
5
8
|
/**
|
|
6
9
|
* Every built-in grammar ships **vendored** as wasm under `wasm/`, so a consumer of `@codegraft/*`
|
|
@@ -12,7 +15,7 @@ import { assert } from './assert.js';
|
|
|
12
15
|
* - `tsx` — rebuilt from `tree-sitter-typescript`'s grammar source, because its npm wasm is ABI-14
|
|
13
16
|
* and loads without the supertype metadata `find('expression')` needs; see `scripts/regen-ts-wasm.sh`.
|
|
14
17
|
* - `html`/`css` — copied verbatim from their npm packages (already ABI-current with supertypes);
|
|
15
|
-
* see `scripts/regen-builtin-wasm.
|
|
18
|
+
* see `scripts/regen-builtin-wasm.mjs`.
|
|
16
19
|
* - `yaml` — vendored from `@tree-sitter-grammars/tree-sitter-yaml` (the bare package ships no wasm).
|
|
17
20
|
*/
|
|
18
21
|
const VENDORED_WASM = {
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO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,MAAM,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;gBACxC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;oBAAE,SAAQ;gBACpC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;gBACb,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAC,0CAA0C;YACrF,CAAC;QACH,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/rich-node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Node } from 'web-tree-sitter';
|
|
1
|
+
import type { Node } from '../vendor/web-tree-sitter/web-tree-sitter.js';
|
|
2
2
|
import type { GrammarId, RichNode } from './types.js';
|
|
3
3
|
/** Wrap a parsed tree's root. Children are created lazily as the tree is walked. */
|
|
4
4
|
export declare function wrapNode(node: Node, language: GrammarId, startOffset: number): RichNode;
|
package/dist/rich-node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-node.d.ts","sourceRoot":"","sources":["../src/rich-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rich-node.d.ts","sourceRoot":"","sources":["../src/rich-node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8CAA8C,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAwG5D,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,CAEvF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NodeTypeAll, FieldName } from './generated/node-types.js';
|
|
2
|
-
import type { FormatOptions } from './format.js';
|
|
3
2
|
/**
|
|
4
3
|
* A real tree-sitter grammar. SFC *file formats* have no id of their own — a {@link ZoneSplitter}
|
|
5
4
|
* maps each section to one of these. `'vue'` is the exception: it is a real tree-sitter grammar
|
|
@@ -99,15 +98,15 @@ export interface SourceMap {
|
|
|
99
98
|
* and is constrained to a record so it can flow into the body and `transform(src, ctx)`.
|
|
100
99
|
*/
|
|
101
100
|
export interface Transformer<Ctx extends Record<string, unknown> = Record<string, unknown>> {
|
|
102
|
-
/** Apply the codemod to `source`.
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
transform(source: string, context: Ctx
|
|
101
|
+
/** Apply the codemod to `source`. Edits are rendered just enough to stay syntactically valid — an
|
|
102
|
+
* inserted snippet re-indented to its anchor line (EOL detected from the source), an appended
|
|
103
|
+
* element given its container's separator. Cosmetic layout is a downstream formatter's job. */
|
|
104
|
+
transform(source: string, context: Ctx): string;
|
|
106
105
|
/** Like {@link transform} but also returns a source map (`options.source` names the input in the
|
|
107
106
|
* map). Used by build-pipeline integrations such as `@codegraft/unplugin`. */
|
|
108
107
|
transformWithMap(source: string, context: Ctx, options?: {
|
|
109
108
|
source?: string;
|
|
110
|
-
}
|
|
109
|
+
}): {
|
|
111
110
|
code: string;
|
|
112
111
|
map: SourceMap;
|
|
113
112
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types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MAAM,EAAE,OAAO,CAAC;IACxF;;oGAEgG;IAChG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,CAAA;IAC/C;mFAC+E;IAC/E,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,CAAA;CAChH;AAED,uEAAuE;AACvE,MAAM,WAAW,eAAe,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5F,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,YAAY,CAAA;IACzC,2DAA2D;IAC3D,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;CAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codegraft/core",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"description": "Tree-sitter runtime for Codegraft: parser, RichNode, comment attachment, zone splitting, the Collection, scope resolver, and edit application.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"bugs": "https://github.com/magne4000/codegraft/issues",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"wasm"
|
|
17
|
+
"wasm",
|
|
18
|
+
"vendor/web-tree-sitter"
|
|
18
19
|
],
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
@@ -30,18 +31,19 @@
|
|
|
30
31
|
"node": ">=22.13"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"magic-string": "^0.30.0"
|
|
34
|
-
"web-tree-sitter": "^0.26.9"
|
|
34
|
+
"magic-string": "^0.30.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"tree-sitter-css": "^0.25.0",
|
|
38
38
|
"tree-sitter-html": "^0.23.0",
|
|
39
|
-
"tree-sitter-javascript": "^0.25.0"
|
|
39
|
+
"tree-sitter-javascript": "^0.25.0",
|
|
40
|
+
"web-tree-sitter": "^0.26.9"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsc -b",
|
|
43
44
|
"regen-ts-wasm": "bash scripts/regen-ts-wasm.sh",
|
|
44
|
-
"regen-builtin-wasm": "
|
|
45
|
+
"regen-builtin-wasm": "node scripts/regen-builtin-wasm.mjs",
|
|
46
|
+
"regen-web-tree-sitter": "node scripts/regen-web-tree-sitter.mjs",
|
|
45
47
|
"regen-node-types": "node scripts/regen-node-types.mjs"
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2018 Max Brunsfeld
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|