@mdsvex/language-core 0.1.0-next.1 → 0.1.0-next.2
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/_svelte_shims.d.ts +1 -0
- package/dist/completions.d.ts +51 -0
- package/dist/config.d.ts +48 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1253 -0
- package/dist/language_plugin.d.ts +53 -0
- package/dist/svelte_plugin.d.ts +14 -0
- package/package.json +16 -7
- package/CHANGELOG.md +0 -37
- package/src/_svelte_shims.ts +0 -1
- package/src/completions.ts +0 -242
- package/src/config.ts +0 -521
- package/src/index.ts +0 -31
- package/src/language_plugin.ts +0 -556
- package/src/svelte_plugin.ts +0 -183
- package/test/completions.spec.ts +0 -179
- package/test/config.spec.ts +0 -304
- package/test/language_plugin.spec.ts +0 -236
- package/test/language_service.spec.ts +0 -314
- package/test/ts_harness.ts +0 -168
- package/tsconfig.json +0 -11
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { create_pfm_language_plugin } from "../src/language_plugin";
|
|
3
|
-
import type { IScriptSnapshot, CodegenContext, VirtualCode, CodeMapping } from "@volar/language-core";
|
|
4
|
-
|
|
5
|
-
function snap(text: string): IScriptSnapshot {
|
|
6
|
-
return {
|
|
7
|
-
getText: (s, e) => text.slice(s, e),
|
|
8
|
-
getLength: () => text.length,
|
|
9
|
-
getChangeRange: () => undefined,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const dummyCtx: CodegenContext<string> = {
|
|
14
|
-
getAssociatedScript: () => undefined,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe("create_pfm_language_plugin", () => {
|
|
18
|
-
const plugin = create_pfm_language_plugin();
|
|
19
|
-
|
|
20
|
-
it("getLanguageId returns 'pfm' for .pfm files", () => {
|
|
21
|
-
expect(plugin.getLanguageId("file.pfm")).toBe("pfm");
|
|
22
|
-
expect(plugin.getLanguageId("/path/to/doc.pfm")).toBe("pfm");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("getLanguageId returns 'pfm' for .svx files, the default of the vite plugin", () => {
|
|
26
|
-
expect(plugin.getLanguageId("/path/to/doc.svx")).toBe("pfm");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("getLanguageId returns undefined for non-.pfm files", () => {
|
|
30
|
-
expect(plugin.getLanguageId("file.md")).toBeUndefined();
|
|
31
|
-
expect(plugin.getLanguageId("file.svelte")).toBeUndefined();
|
|
32
|
-
expect(plugin.getLanguageId("file.ts")).toBeUndefined();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("createVirtualCode returns undefined for non-pfm languageId", () => {
|
|
36
|
-
const result = plugin.createVirtualCode!(
|
|
37
|
-
"test.pfm",
|
|
38
|
-
"markdown",
|
|
39
|
-
snap("# Hello"),
|
|
40
|
-
dummyCtx,
|
|
41
|
-
);
|
|
42
|
-
expect(result).toBeUndefined();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("createVirtualCode produces valid VirtualCode for simple markdown", () => {
|
|
46
|
-
const vc = plugin.createVirtualCode!(
|
|
47
|
-
"test.pfm",
|
|
48
|
-
"pfm",
|
|
49
|
-
snap("# Hello\n\nWorld\n"),
|
|
50
|
-
dummyCtx,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
expect(vc).toBeDefined();
|
|
54
|
-
expect(vc!.id).toBe("root");
|
|
55
|
-
expect(vc!.languageId).toBe("pfm");
|
|
56
|
-
expect(vc!.mappings.length).toBeGreaterThan(0);
|
|
57
|
-
expect(vc!.embeddedCodes).toBeDefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("produces TypeScript embedded VirtualCode", () => {
|
|
61
|
-
const vc = plugin.createVirtualCode!(
|
|
62
|
-
"test.pfm",
|
|
63
|
-
"pfm",
|
|
64
|
-
snap("# Hello\n\nWorld\n"),
|
|
65
|
-
dummyCtx,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const tsCode = vc!.embeddedCodes!.find((c) => c.languageId === "typescript");
|
|
69
|
-
expect(tsCode).toBeDefined();
|
|
70
|
-
expect(tsCode!.id).toBe("ts");
|
|
71
|
-
expect(tsCode!.snapshot.getLength()).toBeGreaterThan(0);
|
|
72
|
-
expect(tsCode!.mappings.length).toBeGreaterThanOrEqual(0);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("TS VirtualCode contains svelte2tsx output", () => {
|
|
76
|
-
const vc = plugin.createVirtualCode!(
|
|
77
|
-
"test.pfm",
|
|
78
|
-
"pfm",
|
|
79
|
-
snap("---\ntitle: hello\n---\n\n# {title}\n"),
|
|
80
|
-
dummyCtx,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const tsCode = vc!.embeddedCodes!.find((c) => c.languageId === "typescript");
|
|
84
|
-
const tsText = tsCode!.snapshot.getText(0, tsCode!.snapshot.getLength());
|
|
85
|
-
|
|
86
|
-
// svelte2tsx produces a $$render function
|
|
87
|
-
expect(tsText).toContain("$$render");
|
|
88
|
-
// the title variable should appear
|
|
89
|
-
expect(tsText).toContain("title");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("mappings survive into the TS VirtualCode", () => {
|
|
93
|
-
const pfm = "---\ntitle: hello\ncount: 42\n---\n\n# {title}\n\n{count + 1}\n";
|
|
94
|
-
const vc = plugin.createVirtualCode!(
|
|
95
|
-
"test.pfm",
|
|
96
|
-
"pfm",
|
|
97
|
-
snap(pfm),
|
|
98
|
-
dummyCtx,
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const tsCode = vc!.embeddedCodes!.find((c) => c.languageId === "typescript");
|
|
102
|
-
const tsText = tsCode!.snapshot.getText(0, tsCode!.snapshot.getLength());
|
|
103
|
-
|
|
104
|
-
// should have composed PFM→TS mappings
|
|
105
|
-
expect(tsCode!.mappings.length).toBeGreaterThan(0);
|
|
106
|
-
|
|
107
|
-
// verify at least one mapping points back to PFM source correctly
|
|
108
|
-
let foundTitle = false;
|
|
109
|
-
for (const m of tsCode!.mappings) {
|
|
110
|
-
for (let i = 0; i < m.sourceOffsets.length; i++) {
|
|
111
|
-
const srcText = pfm.slice(
|
|
112
|
-
m.sourceOffsets[i],
|
|
113
|
-
m.sourceOffsets[i] + m.lengths[i],
|
|
114
|
-
);
|
|
115
|
-
if (srcText === "title") foundTitle = true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
expect(foundTitle).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("updateVirtualCode produces fresh VirtualCode", () => {
|
|
122
|
-
const vc1 = plugin.createVirtualCode!(
|
|
123
|
-
"test.pfm",
|
|
124
|
-
"pfm",
|
|
125
|
-
snap("---\nfoo: 1\n---\n\n{foo}\n"),
|
|
126
|
-
dummyCtx,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
const vc2 = plugin.updateVirtualCode!(
|
|
130
|
-
"test.pfm",
|
|
131
|
-
vc1!,
|
|
132
|
-
snap("---\nbar: 2\n---\n\n{bar}\n"),
|
|
133
|
-
dummyCtx,
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
expect(vc2).toBeDefined();
|
|
137
|
-
const tsCode = vc2!.embeddedCodes!.find((c) => c.languageId === "typescript");
|
|
138
|
-
const tsText = tsCode!.snapshot.getText(0, tsCode!.snapshot.getLength());
|
|
139
|
-
// svelte2tsx preserves expressions — "bar" should appear, "foo" should not
|
|
140
|
-
expect(tsText).toContain("bar");
|
|
141
|
-
expect(tsText).not.toContain("foo");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("handles complex PFM with imports and expressions", () => {
|
|
145
|
-
const pfm = `---
|
|
146
|
-
title: Hello World
|
|
147
|
-
count: 42
|
|
148
|
-
---
|
|
149
|
-
import Counter from "./Counter.svelte"
|
|
150
|
-
|
|
151
|
-
# {title}
|
|
152
|
-
|
|
153
|
-
<Counter value={count} />
|
|
154
|
-
|
|
155
|
-
The count is {count + 1}.
|
|
156
|
-
`;
|
|
157
|
-
const vc = plugin.createVirtualCode!(
|
|
158
|
-
"test.pfm",
|
|
159
|
-
"pfm",
|
|
160
|
-
snap(pfm),
|
|
161
|
-
dummyCtx,
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(vc).toBeDefined();
|
|
165
|
-
const tsCode = vc!.embeddedCodes!.find((c) => c.languageId === "typescript");
|
|
166
|
-
const tsText = tsCode!.snapshot.getText(0, tsCode!.snapshot.getLength());
|
|
167
|
-
|
|
168
|
-
expect(tsText).toContain("title");
|
|
169
|
-
expect(tsText).toContain("count");
|
|
170
|
-
expect(tsText).toContain("Counter");
|
|
171
|
-
expect(tsText).toContain("count + 1");
|
|
172
|
-
|
|
173
|
-
// all mappings should have valid offsets
|
|
174
|
-
for (const m of tsCode!.mappings) {
|
|
175
|
-
for (let i = 0; i < m.sourceOffsets.length; i++) {
|
|
176
|
-
expect(m.sourceOffsets[i]).toBeGreaterThanOrEqual(0);
|
|
177
|
-
expect(m.sourceOffsets[i] + m.lengths[i]).toBeLessThanOrEqual(pfm.length);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("blanks directive args in the markdown code, which would read them as link urls", () => {
|
|
183
|
-
const pfm = ":::Note[a *b*](tone=urgent)\nsee :kbd[F12](x=y) and [a link](/url)\n:::\n";
|
|
184
|
-
const vc = plugin.createVirtualCode!("test.svx", "pfm", snap(pfm), dummyCtx)!;
|
|
185
|
-
const md = vc.embeddedCodes.find((c) => c.languageId === "markdown")!;
|
|
186
|
-
expect(md.snapshot.getText(0, md.snapshot.getLength())).toBe(
|
|
187
|
-
`:::Note[a *b*]${" ".repeat("(tone=urgent)".length)}\n` +
|
|
188
|
-
`see :kbd[F12]${" ".repeat("(x=y)".length)} and [a link](/url)\n:::\n`,
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("carries the templates and the frontmatter the template key completes from", () => {
|
|
193
|
-
const config = {
|
|
194
|
-
load: () => null,
|
|
195
|
-
options_for: () => ({
|
|
196
|
-
stamp: "t",
|
|
197
|
-
options: {
|
|
198
|
-
compile: { templates: { docs: { specifier: "mdsvex:template/docs" } } },
|
|
199
|
-
resolve: (id: string) =>
|
|
200
|
-
id === "mdsvex:template/docs" ? "./lib/Docs.svelte" : undefined,
|
|
201
|
-
},
|
|
202
|
-
}),
|
|
203
|
-
};
|
|
204
|
-
const pfm = "---\ntemplate: docs\n---\n\n# x\n";
|
|
205
|
-
const vc = create_pfm_language_plugin({ config }).createVirtualCode!(
|
|
206
|
-
"test.svx",
|
|
207
|
-
"pfm",
|
|
208
|
-
snap(pfm),
|
|
209
|
-
dummyCtx,
|
|
210
|
-
)!;
|
|
211
|
-
expect(vc.templates).toEqual([{ name: "docs", file: "./lib/Docs.svelte" }]);
|
|
212
|
-
expect(pfm.slice(vc.frontmatter!.start, vc.frontmatter!.end)).toBe("template: docs\n");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("carries compile diagnostics on the root, which reports them", () => {
|
|
216
|
-
const config = {
|
|
217
|
-
load: () => null,
|
|
218
|
-
options_for: () => ({
|
|
219
|
-
stamp: "known",
|
|
220
|
-
options: {
|
|
221
|
-
compile: { directives: [{ specifier: "mdsvex:directives", names: ["box"] }] },
|
|
222
|
-
report_directives: true,
|
|
223
|
-
},
|
|
224
|
-
}),
|
|
225
|
-
};
|
|
226
|
-
const known = create_pfm_language_plugin({ config });
|
|
227
|
-
const pfm = "::box[x]\n\n::nope[y]\n";
|
|
228
|
-
const vc = known.createVirtualCode!("test.svx", "pfm", snap(pfm), dummyCtx)!;
|
|
229
|
-
expect(vc.diagnostics.map((d) => pfm.slice(d.start, d.end))).toEqual(["::nope"]);
|
|
230
|
-
expect(vc.mappings[0].data.verification).toBe(true);
|
|
231
|
-
expect(vc.mappings[0].data.completion).toBe(true);
|
|
232
|
-
// the same source under another config converts again
|
|
233
|
-
const unknown = create_pfm_language_plugin();
|
|
234
|
-
expect(unknown.createVirtualCode!("test.svx", "pfm", snap(pfm), dummyCtx)!.diagnostics).toEqual([]);
|
|
235
|
-
});
|
|
236
|
-
});
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { project } from "./ts_harness";
|
|
4
|
-
import type { Project } from "./ts_harness";
|
|
5
|
-
|
|
6
|
-
const svelte = (props: string, module = "") =>
|
|
7
|
-
[
|
|
8
|
-
...(module ? ['<script module lang="ts">', module, "</script>"] : []),
|
|
9
|
-
'<script lang="ts">',
|
|
10
|
-
" import type { Snippet } from 'svelte';",
|
|
11
|
-
` let p: { ${props} } = $props();`,
|
|
12
|
-
"</script>",
|
|
13
|
-
"<div></div>",
|
|
14
|
-
"",
|
|
15
|
-
].join("\n");
|
|
16
|
-
|
|
17
|
-
/** a vite app whose templates and replacements a manifest describes */
|
|
18
|
-
const APP: Record<string, string> = {
|
|
19
|
-
"src/lib/templates/Docs.svelte": svelte(
|
|
20
|
-
"title: string; draft?: boolean; children: Snippet",
|
|
21
|
-
[
|
|
22
|
-
" export { default as h2 } from '../Heading.svelte';",
|
|
23
|
-
" export * as directives from '../directives.ts';",
|
|
24
|
-
].join("\n"),
|
|
25
|
-
),
|
|
26
|
-
// no level prop, which the replacement still receives
|
|
27
|
-
"src/lib/Heading.svelte": svelte("id?: string; children?: Snippet"),
|
|
28
|
-
"src/lib/directives.ts": "export { default as Callout } from './Callout.svelte';\n",
|
|
29
|
-
"src/lib/Callout.svelte": svelte(
|
|
30
|
-
"kind: 'info' | 'warn'; label?: Snippet; children?: Snippet",
|
|
31
|
-
),
|
|
32
|
-
"src/lib/Img.svelte": svelte("src: string; alt: string"),
|
|
33
|
-
"src/lib/Pre.svelte": svelte("lang?: string; code: string; children?: Snippet"),
|
|
34
|
-
"src/lib/A.svelte": svelte("href: string; children?: Snippet"),
|
|
35
|
-
"src/lib/Badge.svelte": svelte("tone?: 'info' | 'warn'; children?: Snippet"),
|
|
36
|
-
"src/lib/markdown.ts": [
|
|
37
|
-
"export { default as img } from './Img.svelte';",
|
|
38
|
-
"export { default as pre } from './Pre.svelte';",
|
|
39
|
-
"export { default as a } from './A.svelte';",
|
|
40
|
-
"export * as directives from './root-directives.ts';",
|
|
41
|
-
"",
|
|
42
|
-
].join("\n"),
|
|
43
|
-
"src/lib/root-directives.ts": "export { default as badge } from './Badge.svelte';\n",
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
function manifest(root: string) {
|
|
47
|
-
const lib = root + "/src/lib/";
|
|
48
|
-
return JSON.stringify({
|
|
49
|
-
version: 1,
|
|
50
|
-
root,
|
|
51
|
-
extensions: [".svx"],
|
|
52
|
-
component_mode: "all",
|
|
53
|
-
frontmatter_parse: false,
|
|
54
|
-
directive_plugins: false,
|
|
55
|
-
select_template: false,
|
|
56
|
-
templates: {
|
|
57
|
-
docs: {
|
|
58
|
-
id: "mdsvex:template/docs",
|
|
59
|
-
file: lib + "templates/Docs.svelte",
|
|
60
|
-
components: ["h2"],
|
|
61
|
-
extra: null,
|
|
62
|
-
directives: [
|
|
63
|
-
{
|
|
64
|
-
id: "mdsvex:template-directives/docs",
|
|
65
|
-
file: lib + "directives.ts",
|
|
66
|
-
names: ["Callout"],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
components: [
|
|
72
|
-
{ id: "mdsvex:components", file: lib + "markdown.ts", names: ["img", "pre", "a"] },
|
|
73
|
-
],
|
|
74
|
-
directives: [
|
|
75
|
-
{ id: "mdsvex:directives", file: lib + "root-directives.ts", names: ["badge"] },
|
|
76
|
-
],
|
|
77
|
-
documents: {},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const VALID = `---
|
|
82
|
-
title: Hello
|
|
83
|
-
tags: [a, b]
|
|
84
|
-
nested:
|
|
85
|
-
deep: 1
|
|
86
|
-
template: docs
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
<script>
|
|
90
|
-
let n = $state(1);
|
|
91
|
-
let url = '/a.png';
|
|
92
|
-
</script>
|
|
93
|
-
|
|
94
|
-
## Heading {n}
|
|
95
|
-
|
|
96
|
-
Text  and <img src={url} alt="x" loading="lazy" /> and [l](/x "t").
|
|
97
|
-
|
|
98
|
-
<a href="/y" class="c">typed</a>
|
|
99
|
-
|
|
100
|
-
\`\`\`js title="x"
|
|
101
|
-
const a = 1;
|
|
102
|
-
\`\`\`
|
|
103
|
-
|
|
104
|
-
:::Callout[Heads *up*](kind=warn)
|
|
105
|
-
Body :badge[new](tone=info)
|
|
106
|
-
:::
|
|
107
|
-
|
|
108
|
-
{metadata.title} {metadata.nested.deep} {metadata.tags.length}
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
describe("with a plugin manifest", () => {
|
|
112
|
-
let p: Project;
|
|
113
|
-
beforeAll(() => {
|
|
114
|
-
p = project({
|
|
115
|
-
...APP,
|
|
116
|
-
"src/valid.svx": VALID,
|
|
117
|
-
"src/wrong.svx": [
|
|
118
|
-
"---",
|
|
119
|
-
"title: 3",
|
|
120
|
-
"draft: yes",
|
|
121
|
-
"extra: kept",
|
|
122
|
-
"template: docs",
|
|
123
|
-
"---",
|
|
124
|
-
"",
|
|
125
|
-
":::Callout[Hi](kind=warning)",
|
|
126
|
-
"body",
|
|
127
|
-
":::",
|
|
128
|
-
"",
|
|
129
|
-
"<img src={nope} alt=\"x\" />",
|
|
130
|
-
"",
|
|
131
|
-
"{title}",
|
|
132
|
-
"",
|
|
133
|
-
].join("\n"),
|
|
134
|
-
});
|
|
135
|
-
p.write("node_modules/.mdsvex/manifest.json", manifest(p.root));
|
|
136
|
-
});
|
|
137
|
-
afterAll(() => p.dispose());
|
|
138
|
-
|
|
139
|
-
it("reports nothing on a valid document", () => {
|
|
140
|
-
expect(p.diagnostics("src/valid.svx")).toEqual([]);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("checks frontmatter against the template, directive args and expressions", () => {
|
|
144
|
-
const found = p.diagnostics("src/wrong.svx").map((d) => [d.text, d.message]);
|
|
145
|
-
expect(found).toEqual([
|
|
146
|
-
["title", "Type 'number' is not assignable to type 'string'."],
|
|
147
|
-
["draft", "Type 'string' is not assignable to type 'boolean | undefined'."],
|
|
148
|
-
["kind", `Type '"warning"' is not assignable to type '"info" | "warn"'.`],
|
|
149
|
-
["nope", "Cannot find name 'nope'."],
|
|
150
|
-
// frontmatter is metadata, as compile makes it
|
|
151
|
-
["title", "Cannot find name 'title'."],
|
|
152
|
-
]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("hovers the replacement of a markdown element, typed element and directive", () => {
|
|
156
|
-
const doc = "src/valid.svx";
|
|
157
|
-
expect(p.hover(doc, "## Heading")).toContain("const h2: Component<");
|
|
158
|
-
expect(p.hover(doc, "![cat]")).toContain("const img: Component<");
|
|
159
|
-
expect(p.hover(doc, "img src", 1)).toContain("const img: Component<");
|
|
160
|
-
expect(p.hover(doc, "```js")).toContain("const pre: Component<");
|
|
161
|
-
expect(p.hover(doc, "Callout[", 1)).toContain("const Callout: Component<");
|
|
162
|
-
expect(p.hover(doc, "badge[")).toContain("const badge: Component<");
|
|
163
|
-
expect(p.hover(doc, "docs\n---")).toContain("Template_MDSVEX: Component<");
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("hovers frontmatter keys and directive args with their types", () => {
|
|
167
|
-
const doc = "src/valid.svx";
|
|
168
|
-
expect(p.hover(doc, "title:")).toBe("(property) title: string");
|
|
169
|
-
// the names of the configured templates, as only they or false compile
|
|
170
|
-
expect(p.hover(doc, "template:")).toBe('(property) template: false | "docs"');
|
|
171
|
-
expect(p.hover(doc, "tags:")).toBe("(property) tags: string[]");
|
|
172
|
-
// the prop the arg becomes, as the component declares it
|
|
173
|
-
expect(p.hover(doc, "kind=")).toBe('(property) kind: "info" | "warn"');
|
|
174
|
-
expect(p.hover(doc, "metadata.title", 9)).toBe("(property) title: string");
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("live expressions in code", () => {
|
|
179
|
-
const LIVE = [
|
|
180
|
-
"<script lang=\"ts\">",
|
|
181
|
-
" let install_command = 'pnpm add';",
|
|
182
|
-
" let count = 1;",
|
|
183
|
-
" let unread = 2;",
|
|
184
|
-
"</script>",
|
|
185
|
-
"",
|
|
186
|
-
"```sh",
|
|
187
|
-
"{install_command} @pkg/my-pkg # [!eval]",
|
|
188
|
-
"{count.nope} # [!eval]",
|
|
189
|
-
"```",
|
|
190
|
-
"",
|
|
191
|
-
"```js eval",
|
|
192
|
-
"run({install_command})",
|
|
193
|
-
"```",
|
|
194
|
-
"",
|
|
195
|
-
].join("\n");
|
|
196
|
-
let p: Project;
|
|
197
|
-
beforeAll(() => {
|
|
198
|
-
p = project({ ...APP, "src/live.svx": LIVE });
|
|
199
|
-
p.write("node_modules/.mdsvex/manifest.json", manifest(p.root));
|
|
200
|
-
});
|
|
201
|
-
afterAll(() => p.dispose());
|
|
202
|
-
|
|
203
|
-
it("checks a live expression", () => {
|
|
204
|
-
expect(p.diagnostics("src/live.svx").map((d) => [d.text, d.message])).toEqual([
|
|
205
|
-
["nope", "Property 'nope' does not exist on type 'number'."],
|
|
206
|
-
]);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("hovers a live expression", () => {
|
|
210
|
-
expect(p.hover("src/live.svx", "install_command} @")).toBe(
|
|
211
|
-
"let install_command: string",
|
|
212
|
-
);
|
|
213
|
-
expect(p.hover("src/live.svx", "install_command})")).toBe(
|
|
214
|
-
"let install_command: string",
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("renames through a live expression", () => {
|
|
219
|
-
const at = (needle: string) => LIVE.indexOf(needle);
|
|
220
|
-
expect(p.rename("src/live.svx", "install_command} @").sort()).toEqual(
|
|
221
|
-
[
|
|
222
|
-
["src/live.svx", at("install_command =")],
|
|
223
|
-
["src/live.svx", at("install_command} @")],
|
|
224
|
-
["src/live.svx", at("install_command})")],
|
|
225
|
-
].sort(),
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it("counts a live expression as a read", () => {
|
|
230
|
-
const unread = p
|
|
231
|
-
.suggestions("src/live.svx")
|
|
232
|
-
.filter((d) => d.code === 6133)
|
|
233
|
-
.map((d) => d.text);
|
|
234
|
-
expect(unread).toEqual(["unread"]);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("reads nothing live when the plugin renders code plain", () => {
|
|
238
|
-
const q = project({ ...APP, "src/live.svx": LIVE });
|
|
239
|
-
try {
|
|
240
|
-
q.write(
|
|
241
|
-
"node_modules/.mdsvex/manifest.json",
|
|
242
|
-
JSON.stringify({ ...JSON.parse(manifest(q.root)), highlight: false }),
|
|
243
|
-
);
|
|
244
|
-
expect(q.diagnostics("src/live.svx")).toEqual([]);
|
|
245
|
-
} finally {
|
|
246
|
-
q.dispose();
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
describe("without a config", () => {
|
|
252
|
-
let p: Project;
|
|
253
|
-
beforeAll(() => {
|
|
254
|
-
p = project({
|
|
255
|
-
"doc.pfm": [
|
|
256
|
-
"---",
|
|
257
|
-
"title: x",
|
|
258
|
-
"---",
|
|
259
|
-
"",
|
|
260
|
-
":::anything[x](a=b)",
|
|
261
|
-
"body :inline[y]",
|
|
262
|
-
":::",
|
|
263
|
-
"",
|
|
264
|
-
"::leaf[z]",
|
|
265
|
-
"",
|
|
266
|
-
"{metadata.title}",
|
|
267
|
-
"",
|
|
268
|
-
].join("\n"),
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
afterAll(() => p.dispose());
|
|
272
|
-
|
|
273
|
-
it("reports nothing, a directive no config names may be rendered at build", () => {
|
|
274
|
-
expect(p.diagnostics("doc.pfm")).toEqual([]);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe("with a mdsvex.config.json", () => {
|
|
279
|
-
let p: Project;
|
|
280
|
-
beforeAll(() => {
|
|
281
|
-
p = project({
|
|
282
|
-
...APP,
|
|
283
|
-
"package.json": JSON.stringify({ imports: { "#lib/*": "./src/lib/*" } }),
|
|
284
|
-
"mdsvex.config.json": JSON.stringify({
|
|
285
|
-
templates: { docs: "#lib/templates/Docs.svelte" },
|
|
286
|
-
components: "#lib/markdown.ts",
|
|
287
|
-
}),
|
|
288
|
-
"src/doc.svx": [
|
|
289
|
-
"---",
|
|
290
|
-
"draft: yes",
|
|
291
|
-
"template: docs",
|
|
292
|
-
"---",
|
|
293
|
-
"",
|
|
294
|
-
"## Two",
|
|
295
|
-
"",
|
|
296
|
-
":::Callout[x](kind=info)",
|
|
297
|
-
":::",
|
|
298
|
-
"",
|
|
299
|
-
"",
|
|
300
|
-
"",
|
|
301
|
-
].join("\n"),
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
afterAll(() => p.dispose());
|
|
305
|
-
|
|
306
|
-
it("resolves and scans the config itself", () => {
|
|
307
|
-
expect(p.diagnostics("src/doc.svx").map((d) => d.text)).toEqual(["draft"]);
|
|
308
|
-
expect(p.hover("src/doc.svx", "## Two")).toContain("const h2: Component<");
|
|
309
|
-
expect(p.hover("src/doc.svx", "Callout[", 1)).toContain(
|
|
310
|
-
"const Callout: Component<",
|
|
311
|
-
);
|
|
312
|
-
expect(p.hover("src/doc.svx", "![c]")).toContain("const img: Component<");
|
|
313
|
-
});
|
|
314
|
-
});
|