@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.
- package/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/assert.d.ts +8 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +11 -0
- package/dist/assert.js.map +1 -0
- package/dist/collection.d.ts +164 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +570 -0
- package/dist/collection.js.map +1 -0
- package/dist/comment-attachment.d.ts +25 -0
- package/dist/comment-attachment.d.ts.map +1 -0
- package/dist/comment-attachment.js +94 -0
- package/dist/comment-attachment.js.map +1 -0
- package/dist/edit-collector.d.ts +31 -0
- package/dist/edit-collector.d.ts.map +1 -0
- package/dist/edit-collector.js +75 -0
- package/dist/edit-collector.js.map +1 -0
- package/dist/evaluate.d.ts +15 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +95 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/extensions.d.ts +3 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +19 -0
- package/dist/extensions.js.map +1 -0
- package/dist/generated/node-types.d.ts +31 -0
- package/dist/generated/node-types.d.ts.map +1 -0
- package/dist/generated/node-types.js +5 -0
- package/dist/generated/node-types.js.map +1 -0
- package/dist/helpers.d.ts +13 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +27 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +9 -0
- package/dist/internal.js.map +1 -0
- package/dist/parser.d.ts +30 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +125 -0
- package/dist/parser.js.map +1 -0
- package/dist/resolver.d.ts +27 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +241 -0
- package/dist/resolver.js.map +1 -0
- package/dist/rich-node.d.ts +5 -0
- package/dist/rich-node.d.ts.map +1 -0
- package/dist/rich-node.js +101 -0
- package/dist/rich-node.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/zone-splitter.d.ts +12 -0
- package/dist/zone-splitter.d.ts.map +1 -0
- package/dist/zone-splitter.js +23 -0
- package/dist/zone-splitter.js.map +1 -0
- package/package.json +62 -0
- package/wasm/tree-sitter-tsx.wasm +0 -0
- package/wasm/tree-sitter-typescript.wasm +0 -0
- package/wasm/tree-sitter-yaml.wasm +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-node.js","sourceRoot":"","sources":["../src/rich-node.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC;;;;;;;;GAQG;AACH,MAAM,YAAY;IACP,QAAQ,CAAW;IAC5B,0FAA0F;IACjF,eAAe,GAAe,EAAE,CAAA;IAChC,gBAAgB,GAAe,EAAE,CAAA;IACjC,aAAa,GAAe,EAAE,CAAA;IAE9B,KAAK,CAAM;IACX,YAAY,CAAQ;IACpB,OAAO,CAAiB;IACjC,YAAY,CAAiB;IAC7B,SAAS,CAAiB;IAE1B,YAAY,IAAU,EAAE,QAAmB,EAAE,WAAmB,EAAE,MAAuB;QACvF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAED,IAAI,IAAI;QACN,4FAA4F;QAC5F,OAAO,IAAI,CAAC,KAAK,CAAC,IAAmB,CAAA;IAC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,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;AAC5D,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { NodeTypeAll, FieldName } from './generated/node-types.js';
|
|
2
|
+
/** A real tree-sitter grammar. There is no id for SFC file formats — those are
|
|
3
|
+
* handled by a {@link ZoneSplitter}, which maps each section to one of these. */
|
|
4
|
+
export type GrammarId = 'javascript' | 'typescript' | 'tsx' | 'html' | 'css' | 'yaml';
|
|
5
|
+
/** Row/column position, mirroring tree-sitter's `Point`. */
|
|
6
|
+
export type Point = {
|
|
7
|
+
row: number;
|
|
8
|
+
column: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The open extension point for multi-zone file formats (Vue SFC, Astro, …). The
|
|
12
|
+
* only value today is `vueSplitter`, exported from `@codegraft/vue`; core stays
|
|
13
|
+
* ignorant of any concrete format.
|
|
14
|
+
*
|
|
15
|
+
* `init()` lets a splitter load whatever grammar it parses the shell with (Vue
|
|
16
|
+
* loads `tree-sitter-vue`), so `split()` can stay synchronous. The pipeline calls
|
|
17
|
+
* `init()` once, before the first `split()`.
|
|
18
|
+
*
|
|
19
|
+
* `split()` returns raw zone descriptors only — it does not parse zone *contents*;
|
|
20
|
+
* that is the pipeline's job (`splitAndParse`).
|
|
21
|
+
*/
|
|
22
|
+
export interface ZoneSplitter {
|
|
23
|
+
/** Identifier and the file extension it handles: `'vue'` → `.vue`. */
|
|
24
|
+
readonly id: string;
|
|
25
|
+
/** Which grammars this format can produce. */
|
|
26
|
+
readonly grammars: GrammarId[];
|
|
27
|
+
/** Idempotent; loads the splitter's own parsing grammar. */
|
|
28
|
+
init(): Promise<void>;
|
|
29
|
+
split(source: string): Array<{
|
|
30
|
+
language: GrammarId;
|
|
31
|
+
source: string;
|
|
32
|
+
startOffset: number;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lazy wrapper over the backing tree-sitter node. `children`/`allChildren` are cached;
|
|
37
|
+
* comment arrays are filled by the attachment pass. Offsets come in two frames:
|
|
38
|
+
* `startIndex`/`endIndex` are zone-relative, `documentStartIndex`/`documentEndIndex`
|
|
39
|
+
* absolute — so edits, always in document space, never need remapping.
|
|
40
|
+
*/
|
|
41
|
+
export interface RichNode {
|
|
42
|
+
readonly type: NodeTypeAll;
|
|
43
|
+
readonly isNamed: boolean;
|
|
44
|
+
readonly text: string;
|
|
45
|
+
/** Byte offset in the *zone* source. */
|
|
46
|
+
readonly startIndex: number;
|
|
47
|
+
readonly endIndex: number;
|
|
48
|
+
readonly startPosition: Point;
|
|
49
|
+
readonly endPosition: Point;
|
|
50
|
+
readonly parent: RichNode | null;
|
|
51
|
+
/** Named structural children: no punctuation, no comments. The surface pattern
|
|
52
|
+
* matching walks, so comments never perturb a match. */
|
|
53
|
+
readonly children: RichNode[];
|
|
54
|
+
/** Full CST: every child, including punctuation and comment nodes. */
|
|
55
|
+
readonly allChildren: RichNode[];
|
|
56
|
+
child(field: FieldName): RichNode | null;
|
|
57
|
+
childrenForField(field: FieldName): RichNode[];
|
|
58
|
+
readonly leadingComments: RichNode[];
|
|
59
|
+
readonly trailingComments: RichNode[];
|
|
60
|
+
readonly innerComments: RichNode[];
|
|
61
|
+
readonly language: GrammarId;
|
|
62
|
+
/** Absolute offset in the original document: `startIndex + zone.startOffset`. */
|
|
63
|
+
readonly documentStartIndex: number;
|
|
64
|
+
readonly documentEndIndex: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One parsed region of a document. A single-grammar file produces exactly one
|
|
68
|
+
* synthetic zone with `startOffset: 0`; an SFC produces one per section. Either way
|
|
69
|
+
* the rest of the pipeline sees only `Zone[]`.
|
|
70
|
+
*/
|
|
71
|
+
export interface Zone {
|
|
72
|
+
language: GrammarId;
|
|
73
|
+
/** Exact slice: `outerSource.slice(startOffset, startOffset + source.length)`. */
|
|
74
|
+
source: string;
|
|
75
|
+
startOffset: number;
|
|
76
|
+
tree: RichNode;
|
|
77
|
+
}
|
|
78
|
+
/** A source map, structurally compatible with magic-string's (kept here so this module
|
|
79
|
+
* stays import-free). */
|
|
80
|
+
export interface SourceMap {
|
|
81
|
+
version: number;
|
|
82
|
+
file?: string;
|
|
83
|
+
sources: string[];
|
|
84
|
+
sourcesContent?: (string | null)[];
|
|
85
|
+
names: string[];
|
|
86
|
+
mappings: string;
|
|
87
|
+
toString(): string;
|
|
88
|
+
toUrl(): string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Applies a codemod to a source string. Synchronous once built. `Ctx` is the run-context
|
|
92
|
+
* type the codemod is authored against (`defineCodemod<Ctx>`); it defaults to an open record
|
|
93
|
+
* and is constrained to a record so it can flow into the body and `transform(src, ctx)`.
|
|
94
|
+
*/
|
|
95
|
+
export interface Transformer<Ctx extends Record<string, unknown> = Record<string, unknown>> {
|
|
96
|
+
transform(source: string, context: Ctx): string;
|
|
97
|
+
/** Like {@link transform} but also returns a source map (`options.source` names the
|
|
98
|
+
* input in the map). Used by build-pipeline integrations such as `@codegraft/unplugin`. */
|
|
99
|
+
transformWithMap(source: string, context: Ctx, options?: {
|
|
100
|
+
source?: string;
|
|
101
|
+
}): {
|
|
102
|
+
code: string;
|
|
103
|
+
map: SourceMap;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** A {@link Transformer} that has not yet loaded its WASM grammars. */
|
|
107
|
+
export interface LazyTransformer<Ctx extends Record<string, unknown> = Record<string, unknown>> {
|
|
108
|
+
readonly target: GrammarId | ZoneSplitter;
|
|
109
|
+
/** Idempotent; WASM is loaded at most once per process. */
|
|
110
|
+
init(): Promise<Transformer<Ctx>>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,K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,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/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GrammarId, Zone, ZoneSplitter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turn any target into parsed `Zone[]` — the single pipeline the rest of the
|
|
4
|
+
* transform shares. A `GrammarId` becomes one synthetic zone covering the whole
|
|
5
|
+
* source (`startOffset: 0`); a `ZoneSplitter` is asked to `split()` the source into
|
|
6
|
+
* its sections. Either way each raw zone is parsed with its grammar and wrapped.
|
|
7
|
+
*
|
|
8
|
+
* Synchronous: grammar loading (and a `ZoneSplitter`'s own `init()`) happen earlier,
|
|
9
|
+
* in the transformer's `init()`, so by the time we get here every grammar is ready.
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitAndParse(source: string, target: GrammarId | ZoneSplitter): Zone[];
|
|
12
|
+
//# sourceMappingURL=zone-splitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone-splitter.d.ts","sourceRoot":"","sources":["../src/zone-splitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAI/D;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,YAAY,GAAG,IAAI,EAAE,CAYtF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Parser } from './parser.js';
|
|
2
|
+
import { wrapNode } from './rich-node.js';
|
|
3
|
+
/**
|
|
4
|
+
* Turn any target into parsed `Zone[]` — the single pipeline the rest of the
|
|
5
|
+
* transform shares. A `GrammarId` becomes one synthetic zone covering the whole
|
|
6
|
+
* source (`startOffset: 0`); a `ZoneSplitter` is asked to `split()` the source into
|
|
7
|
+
* its sections. Either way each raw zone is parsed with its grammar and wrapped.
|
|
8
|
+
*
|
|
9
|
+
* Synchronous: grammar loading (and a `ZoneSplitter`'s own `init()`) happen earlier,
|
|
10
|
+
* in the transformer's `init()`, so by the time we get here every grammar is ready.
|
|
11
|
+
*/
|
|
12
|
+
export function splitAndParse(source, target) {
|
|
13
|
+
const rawZones = typeof target === 'string'
|
|
14
|
+
? [{ language: target, source, startOffset: 0 }]
|
|
15
|
+
: target.split(source);
|
|
16
|
+
return rawZones.map((zone) => ({
|
|
17
|
+
language: zone.language,
|
|
18
|
+
source: zone.source,
|
|
19
|
+
startOffset: zone.startOffset,
|
|
20
|
+
tree: wrapNode(Parser.parse(zone.source, zone.language).rootNode, zone.language, zone.startOffset),
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=zone-splitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone-splitter.js","sourceRoot":"","sources":["../src/zone-splitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAAgC;IAC5E,MAAM,QAAQ,GACZ,OAAO,MAAM,KAAK,QAAQ;QACxB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;QAChD,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAE1B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC;KACnG,CAAC,CAAC,CAAA;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codegraft/core",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Tree-sitter runtime for Codegraft: parser, RichNode, comment attachment, zone splitting, the Collection, scope resolver, and edit application.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/magne4000/codegraft.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/magne4000/codegraft#readme",
|
|
14
|
+
"bugs": "https://github.com/magne4000/codegraft/issues",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"wasm"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./internal": {
|
|
25
|
+
"import": "./dist/internal.js",
|
|
26
|
+
"types": "./dist/internal.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.13"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"magic-string": "^0.30.0",
|
|
34
|
+
"web-tree-sitter": "^0.26.9"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"tree-sitter-css": "^0.25.0",
|
|
38
|
+
"tree-sitter-html": "^0.23.0",
|
|
39
|
+
"tree-sitter-javascript": "^0.25.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"tree-sitter-css": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"tree-sitter-html": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"tree-sitter-javascript": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"tree-sitter-css": "^0.25.0",
|
|
54
|
+
"tree-sitter-html": "^0.23.0",
|
|
55
|
+
"tree-sitter-javascript": "^0.25.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -b",
|
|
59
|
+
"regen-ts-wasm": "bash scripts/regen-ts-wasm.sh",
|
|
60
|
+
"regen-node-types": "node scripts/regen-node-types.mjs"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|