@codegraft/core 0.1.0-beta.7 → 0.1.0-beta.8
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/dist/format.d.ts +7 -2
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +17 -6
- package/dist/format.js.map +1 -1
- package/package.json +1 -1
package/dist/format.d.ts
CHANGED
|
@@ -7,7 +7,12 @@ export interface FormatStyle {
|
|
|
7
7
|
* dominate) and EOL (first line break) of `source`, defaulting to two spaces and `'\n'`. */
|
|
8
8
|
export declare function detectStyle(source: string): FormatStyle;
|
|
9
9
|
/** Re-indent a snippet for a line indented by `baseIndent`: the first line is left for the caller
|
|
10
|
-
* to position,
|
|
11
|
-
*
|
|
10
|
+
* to position, every following non-blank line is re-anchored to `baseIndent` (its indentation
|
|
11
|
+
* relative to the block's own base preserved), and line breaks become `eol`.
|
|
12
|
+
*
|
|
13
|
+
* The block's base is the least-indented continuation line — *not* the first line, which a node's
|
|
14
|
+
* `.text` leaves at column 0 even when the node sits deep in the source. Stripping that base before
|
|
15
|
+
* applying `baseIndent` re-anchors a "hanging" block (continuation lines still at their source
|
|
16
|
+
* indent) to the target, instead of stacking `baseIndent` on top of the indent already there. */
|
|
12
17
|
export declare function reindent(text: string, baseIndent: string, eol: string): string;
|
|
13
18
|
//# sourceMappingURL=format.d.ts.map
|
package/dist/format.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAIA,gGAAgG;AAChG,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;6FAC6F;AAC7F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAEvD;AA0CD
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAIA,gGAAgG;AAChG,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;6FAC6F;AAC7F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAEvD;AA0CD;;;;;;;kGAOkG;AAClG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAU9E"}
|
package/dist/format.js
CHANGED
|
@@ -47,14 +47,25 @@ function detectIndentUnit(source) {
|
|
|
47
47
|
return ' '.repeat(unit || 2);
|
|
48
48
|
}
|
|
49
49
|
/** Re-indent a snippet for a line indented by `baseIndent`: the first line is left for the caller
|
|
50
|
-
* to position,
|
|
51
|
-
*
|
|
50
|
+
* to position, every following non-blank line is re-anchored to `baseIndent` (its indentation
|
|
51
|
+
* relative to the block's own base preserved), and line breaks become `eol`.
|
|
52
|
+
*
|
|
53
|
+
* The block's base is the least-indented continuation line — *not* the first line, which a node's
|
|
54
|
+
* `.text` leaves at column 0 even when the node sits deep in the source. Stripping that base before
|
|
55
|
+
* applying `baseIndent` re-anchors a "hanging" block (continuation lines still at their source
|
|
56
|
+
* indent) to the target, instead of stacking `baseIndent` on top of the indent already there. */
|
|
52
57
|
export function reindent(text, baseIndent, eol) {
|
|
53
58
|
if (!text.includes('\n'))
|
|
54
59
|
return text;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
60
|
+
const lines = text.split(/\r\n|\n/);
|
|
61
|
+
let base = Infinity;
|
|
62
|
+
for (let i = 1; i < lines.length; i++) {
|
|
63
|
+
if (lines[i].trim() === '')
|
|
64
|
+
continue;
|
|
65
|
+
base = Math.min(base, /^[ \t]*/.exec(lines[i])[0].length);
|
|
66
|
+
}
|
|
67
|
+
if (base === Infinity)
|
|
68
|
+
base = 0; // a single-or-blank-continuation snippet: nothing to strip
|
|
69
|
+
return lines.map((line, i) => (i === 0 || line.trim() === '' ? line : baseIndent + line.slice(base))).join(eol);
|
|
59
70
|
}
|
|
60
71
|
//# sourceMappingURL=format.js.map
|
package/dist/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,iGAAiG;AACjG,mGAAmG;AAQnG;6FAC6F;AAC7F,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAA;AACzE,CAAC;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;AAC5C,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc;IACtC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,gCAAgC;IACxE,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;QACxD,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACvB,YAAY,GAAG,KAAK,CAAA;YACpB,SAAQ;QACV,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,CAAA;QACvC,IAAI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C,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjH,CAAC"}
|
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.8",
|
|
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",
|