@codegraft/vue 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 +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/vue-splitter.d.ts +10 -0
- package/dist/vue-splitter.d.ts.map +1 -0
- package/dist/vue-splitter.js +75 -0
- package/dist/vue-splitter.js.map +1 -0
- package/package.json +51 -0
- package/wasm/tree-sitter-vue.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Joël Charles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @codegraft/vue
|
|
2
|
+
|
|
3
|
+
Vue SFC support for [Codegraft](../../README.md). `vueSplitter` splits a `.vue` file into
|
|
4
|
+
zones so a Codegraft codemod applies per section:
|
|
5
|
+
|
|
6
|
+
| Section | Grammar |
|
|
7
|
+
|---|---|
|
|
8
|
+
| `<template>` | `html` |
|
|
9
|
+
| `<script>` / `<script setup>` | `typescript` / `tsx` / `javascript` (by `lang`) |
|
|
10
|
+
| `<style>` | `css` |
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { vueSplitter } from '@codegraft/vue'
|
|
14
|
+
|
|
15
|
+
const transform = await codemod.forTarget(vueSplitter)
|
|
16
|
+
// or, in @codegraft/unplugin: codegraft({ codemod, context, splitters: [vueSplitter] })
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Vendored grammar wasm
|
|
20
|
+
|
|
21
|
+
No vue grammar ships a prebuilt WebAssembly, so `wasm/tree-sitter-vue.wasm` is
|
|
22
|
+
**vendored** here — WASI-built from the maintained
|
|
23
|
+
[`tree-sitter-grammars/tree-sitter-vue`](https://github.com/tree-sitter-grammars/tree-sitter-vue)
|
|
24
|
+
(MIT). The package owns its grammar with no `tree-sitter-vue` dependency.
|
|
25
|
+
|
|
26
|
+
To regenerate it (WASI via `tree-sitter-cli`'s bundled wasi-sdk — no Docker/emscripten;
|
|
27
|
+
needs network):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm --filter @codegraft/vue regen-wasm # or: regen-wasm <git-ref>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
WASI matters: `web-tree-sitter` ≥ 0.26 only loads WASI-built grammars, and the older
|
|
34
|
+
`tree-sitter-wasms` (emscripten) build is rejected.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ZoneSplitter } from '@codegraft/core';
|
|
2
|
+
/**
|
|
3
|
+
* Splits a Vue SFC into its sections by walking the `tree-sitter-vue` CST (never by
|
|
4
|
+
* regex, so `</script>`-like text inside the template can't confuse it). `<template>`
|
|
5
|
+
* becomes an `html` zone, `<script>`/`<script setup>` a `typescript`/`tsx`/`javascript`
|
|
6
|
+
* zone (by `lang`), and `<style>` a `css` zone — each carrying the exact document offset
|
|
7
|
+
* of its content.
|
|
8
|
+
*/
|
|
9
|
+
export declare const vueSplitter: ZoneSplitter;
|
|
10
|
+
//# sourceMappingURL=vue-splitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-splitter.d.ts","sourceRoot":"","sources":["../src/vue-splitter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAU9D;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,YAiBzB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { Parser, assert } from '@codegraft/core/internal';
|
|
3
|
+
// The vue grammar wasm is vendored in this package (tree-sitter-vue ships no prebuilt
|
|
4
|
+
// wasm), so @codegraft/vue owns its grammar with no tree-sitter-vue dependency.
|
|
5
|
+
const VUE_WASM = fileURLToPath(new URL('../wasm/tree-sitter-vue.wasm', import.meta.url));
|
|
6
|
+
const VUE_GRAMMAR = 'vue'; // internal parser cache key; not a public GrammarId
|
|
7
|
+
/**
|
|
8
|
+
* Splits a Vue SFC into its sections by walking the `tree-sitter-vue` CST (never by
|
|
9
|
+
* regex, so `</script>`-like text inside the template can't confuse it). `<template>`
|
|
10
|
+
* becomes an `html` zone, `<script>`/`<script setup>` a `typescript`/`tsx`/`javascript`
|
|
11
|
+
* zone (by `lang`), and `<style>` a `css` zone — each carrying the exact document offset
|
|
12
|
+
* of its content.
|
|
13
|
+
*/
|
|
14
|
+
export const vueSplitter = {
|
|
15
|
+
id: 'vue',
|
|
16
|
+
grammars: ['html', 'typescript', 'tsx', 'javascript', 'css'],
|
|
17
|
+
async init() {
|
|
18
|
+
await Parser.loadGrammar(VUE_GRAMMAR, VUE_WASM);
|
|
19
|
+
},
|
|
20
|
+
split(source) {
|
|
21
|
+
const root = Parser.parse(source, VUE_GRAMMAR).rootNode;
|
|
22
|
+
const zones = [];
|
|
23
|
+
for (const section of namedChildren(root)) {
|
|
24
|
+
const zone = sectionZone(section, source);
|
|
25
|
+
if (zone)
|
|
26
|
+
zones.push(zone);
|
|
27
|
+
}
|
|
28
|
+
return zones;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
function sectionZone(section, source) {
|
|
32
|
+
switch (section.type) {
|
|
33
|
+
case 'template_element': {
|
|
34
|
+
const startTag = childByType(section, 'start_tag');
|
|
35
|
+
const endTag = childByType(section, 'end_tag');
|
|
36
|
+
assert(startTag && endTag, 'a <template> element must have start and end tags');
|
|
37
|
+
// content lives between the tags
|
|
38
|
+
return {
|
|
39
|
+
language: 'html',
|
|
40
|
+
source: source.slice(startTag.endIndex, endTag.startIndex),
|
|
41
|
+
startOffset: startTag.endIndex,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
case 'script_element': {
|
|
45
|
+
const body = childByType(section, 'raw_text');
|
|
46
|
+
if (!body)
|
|
47
|
+
return null; // empty <script>
|
|
48
|
+
const startTag = childByType(section, 'start_tag');
|
|
49
|
+
return { language: scriptLanguage(startTag?.text ?? ''), source: body.text, startOffset: body.startIndex };
|
|
50
|
+
}
|
|
51
|
+
case 'style_element': {
|
|
52
|
+
const body = childByType(section, 'raw_text');
|
|
53
|
+
if (!body)
|
|
54
|
+
return null;
|
|
55
|
+
return { language: 'css', source: body.text, startOffset: body.startIndex };
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function scriptLanguage(startTag) {
|
|
62
|
+
const lang = /\blang\s*=\s*["']([^"']+)["']/.exec(startTag)?.[1];
|
|
63
|
+
if (lang === 'ts')
|
|
64
|
+
return 'typescript';
|
|
65
|
+
if (lang === 'tsx' || lang === 'jsx')
|
|
66
|
+
return 'tsx';
|
|
67
|
+
return 'javascript'; // default, and lang="js"
|
|
68
|
+
}
|
|
69
|
+
function namedChildren(node) {
|
|
70
|
+
return node.namedChildren.filter((c) => c !== null);
|
|
71
|
+
}
|
|
72
|
+
function childByType(node, type) {
|
|
73
|
+
return namedChildren(node).find((c) => c.type === type) ?? null;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=vue-splitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-splitter.js","sourceRoot":"","sources":["../src/vue-splitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAa,MAAM,0BAA0B,CAAA;AAEpE,sFAAsF;AACtF,gFAAgF;AAChF,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,8BAA8B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACxF,MAAM,WAAW,GAAG,KAAK,CAAA,CAAC,oDAAoD;AAI9E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAiB;IACvC,EAAE,EAAE,KAAK;IACT,QAAQ,EAAE,CAAC,MAAM,EAAE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C,IAAI,IAAI,CAAA;AACjE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codegraft/vue",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Vue SFC support for Codegraft: vueSplitter splits a .vue file into <template>/<script>/<style> zones.",
|
|
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/vue"
|
|
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
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.13"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@codegraft/core": "0.1.0-beta.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"tree-sitter-css": "^0.25.0",
|
|
33
|
+
"tree-sitter-html": "^0.23.0",
|
|
34
|
+
"tree-sitter-javascript": "^0.25.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"tree-sitter-css": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"tree-sitter-html": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"tree-sitter-javascript": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -b",
|
|
49
|
+
"regen-wasm": "bash scripts/regen-wasm.sh"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
Binary file
|