@vue/language-core 2.0.0 → 2.0.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/index.d.ts +13 -0
- package/index.js +31 -0
- package/lib/generators/script.d.ts +13 -0
- package/lib/generators/script.js +1060 -0
- package/lib/generators/template.d.ts +9 -0
- package/lib/generators/template.js +1567 -0
- package/lib/generators/utils.d.ts +6 -0
- package/lib/generators/utils.js +58 -0
- package/lib/languageModule.d.ts +5 -0
- package/lib/languageModule.js +114 -0
- package/lib/parsers/scriptRanges.d.ts +15 -0
- package/lib/parsers/scriptRanges.js +63 -0
- package/lib/parsers/scriptSetupRanges.d.ts +57 -0
- package/lib/parsers/scriptSetupRanges.js +298 -0
- package/lib/plugins/file-html.d.ts +3 -0
- package/lib/plugins/file-html.js +81 -0
- package/lib/plugins/file-md.d.ts +3 -0
- package/lib/plugins/file-md.js +71 -0
- package/lib/plugins/file-vue.d.ts +3 -0
- package/lib/plugins/file-vue.js +47 -0
- package/lib/plugins/vue-sfc-customblocks.d.ts +3 -0
- package/lib/plugins/vue-sfc-customblocks.js +28 -0
- package/lib/plugins/vue-sfc-scripts.d.ts +3 -0
- package/lib/plugins/vue-sfc-scripts.js +36 -0
- package/lib/plugins/vue-sfc-styles.d.ts +3 -0
- package/lib/plugins/vue-sfc-styles.js +28 -0
- package/lib/plugins/vue-sfc-template.d.ts +3 -0
- package/lib/plugins/vue-sfc-template.js +29 -0
- package/lib/plugins/vue-template-html.d.ts +3 -0
- package/lib/plugins/vue-template-html.js +169 -0
- package/lib/plugins/vue-tsx.d.ts +80 -0
- package/lib/plugins/vue-tsx.js +212 -0
- package/lib/plugins.d.ts +37 -0
- package/lib/plugins.js +64 -0
- package/lib/types.d.ts +142 -0
- package/lib/types.js +5 -0
- package/lib/utils/parseCssClassNames.d.ts +4 -0
- package/lib/utils/parseCssClassNames.js +19 -0
- package/lib/utils/parseCssVars.d.ts +5 -0
- package/lib/utils/parseCssVars.js +28 -0
- package/lib/utils/parseSfc.d.ts +2 -0
- package/lib/utils/parseSfc.js +121 -0
- package/lib/utils/shared.d.ts +3 -0
- package/lib/utils/shared.js +20 -0
- package/lib/utils/transform.d.ts +8 -0
- package/lib/utils/transform.js +195 -0
- package/lib/utils/ts.d.ts +8 -0
- package/lib/utils/ts.js +225 -0
- package/lib/utils/vue2TemplateCompiler.d.ts +2 -0
- package/lib/utils/vue2TemplateCompiler.js +89 -0
- package/lib/virtualFile/computedFiles.d.ts +3 -0
- package/lib/virtualFile/computedFiles.js +217 -0
- package/lib/virtualFile/computedMappings.d.ts +4 -0
- package/lib/virtualFile/computedMappings.js +36 -0
- package/lib/virtualFile/computedSfc.d.ts +4 -0
- package/lib/virtualFile/computedSfc.js +197 -0
- package/lib/virtualFile/computedVueSfc.d.ts +4 -0
- package/lib/virtualFile/computedVueSfc.js +41 -0
- package/lib/virtualFile/embeddedFile.d.ts +12 -0
- package/lib/virtualFile/embeddedFile.js +15 -0
- package/lib/virtualFile/vueFile.d.ts +25 -0
- package/lib/virtualFile/vueFile.js +43 -0
- package/package.json +4 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedFiles = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const computeds_1 = require("computeds");
|
|
6
|
+
const embeddedFile_1 = require("./embeddedFile");
|
|
7
|
+
function computedFiles(plugins, fileName, sfc, codegenStack) {
|
|
8
|
+
const nameToBlock = (0, computeds_1.computed)(() => {
|
|
9
|
+
const blocks = {};
|
|
10
|
+
if (sfc.template) {
|
|
11
|
+
blocks[sfc.template.name] = sfc.template;
|
|
12
|
+
}
|
|
13
|
+
if (sfc.script) {
|
|
14
|
+
blocks[sfc.script.name] = sfc.script;
|
|
15
|
+
}
|
|
16
|
+
if (sfc.scriptSetup) {
|
|
17
|
+
blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
|
|
18
|
+
}
|
|
19
|
+
for (const block of sfc.styles) {
|
|
20
|
+
blocks[block.name] = block;
|
|
21
|
+
}
|
|
22
|
+
for (const block of sfc.customBlocks) {
|
|
23
|
+
blocks[block.name] = block;
|
|
24
|
+
}
|
|
25
|
+
return blocks;
|
|
26
|
+
});
|
|
27
|
+
const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack));
|
|
28
|
+
const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
|
|
29
|
+
const structuredResult = (0, computeds_1.computed)(() => {
|
|
30
|
+
const embeddedCodes = [];
|
|
31
|
+
let remain = [...flatResult()];
|
|
32
|
+
while (remain.length) {
|
|
33
|
+
const beforeLength = remain.length;
|
|
34
|
+
consumeRemain();
|
|
35
|
+
if (beforeLength === remain.length) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const { file, snapshot, mappings, codegenStacks } of remain) {
|
|
40
|
+
embeddedCodes.push({
|
|
41
|
+
id: file.id,
|
|
42
|
+
languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
|
|
43
|
+
linkedCodeMappings: file.linkedCodeMappings,
|
|
44
|
+
snapshot,
|
|
45
|
+
mappings,
|
|
46
|
+
codegenStacks,
|
|
47
|
+
embeddedCodes: [],
|
|
48
|
+
});
|
|
49
|
+
console.error('Unable to resolve embedded: ' + file.parentCodeId + ' -> ' + file.id);
|
|
50
|
+
}
|
|
51
|
+
return embeddedCodes;
|
|
52
|
+
function consumeRemain() {
|
|
53
|
+
for (let i = remain.length - 1; i >= 0; i--) {
|
|
54
|
+
const { file, snapshot, mappings, codegenStacks } = remain[i];
|
|
55
|
+
if (!file.parentCodeId) {
|
|
56
|
+
embeddedCodes.push({
|
|
57
|
+
id: file.id,
|
|
58
|
+
languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
|
|
59
|
+
linkedCodeMappings: file.linkedCodeMappings,
|
|
60
|
+
snapshot,
|
|
61
|
+
mappings,
|
|
62
|
+
codegenStacks,
|
|
63
|
+
embeddedCodes: [],
|
|
64
|
+
});
|
|
65
|
+
remain.splice(i, 1);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const parent = findParentStructure(file.parentCodeId, embeddedCodes);
|
|
69
|
+
if (parent) {
|
|
70
|
+
parent.embeddedCodes ??= [];
|
|
71
|
+
parent.embeddedCodes.push({
|
|
72
|
+
id: file.id,
|
|
73
|
+
languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
|
|
74
|
+
linkedCodeMappings: file.linkedCodeMappings,
|
|
75
|
+
snapshot,
|
|
76
|
+
mappings,
|
|
77
|
+
codegenStacks,
|
|
78
|
+
embeddedCodes: [],
|
|
79
|
+
});
|
|
80
|
+
remain.splice(i, 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function findParentStructure(id, current) {
|
|
86
|
+
for (const child of current) {
|
|
87
|
+
if (child.id === id) {
|
|
88
|
+
return child;
|
|
89
|
+
}
|
|
90
|
+
let parent = findParentStructure(id, child.embeddedCodes ?? []);
|
|
91
|
+
if (parent) {
|
|
92
|
+
return parent;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return structuredResult;
|
|
98
|
+
}
|
|
99
|
+
exports.computedFiles = computedFiles;
|
|
100
|
+
function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack) {
|
|
101
|
+
const embeddedFiles = {};
|
|
102
|
+
const files = (0, computeds_1.computed)(() => {
|
|
103
|
+
try {
|
|
104
|
+
if (!plugin.getEmbeddedCodes) {
|
|
105
|
+
return Object.values(embeddedFiles);
|
|
106
|
+
}
|
|
107
|
+
const fileInfos = plugin.getEmbeddedCodes(fileName, sfc);
|
|
108
|
+
for (const oldId of Object.keys(embeddedFiles)) {
|
|
109
|
+
if (!fileInfos.some(file => file.id === oldId)) {
|
|
110
|
+
delete embeddedFiles[oldId];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const fileInfo of fileInfos) {
|
|
114
|
+
if (!embeddedFiles[fileInfo.id]) {
|
|
115
|
+
embeddedFiles[fileInfo.id] = (0, computeds_1.computed)(() => {
|
|
116
|
+
const [content, stacks] = codegenStack ? (0, language_core_1.track)([]) : [[], []];
|
|
117
|
+
const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content, stacks);
|
|
118
|
+
for (const plugin of plugins) {
|
|
119
|
+
if (!plugin.resolveEmbeddedCode) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
plugin.resolveEmbeddedCode(fileName, sfc, file);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
console.error(e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const newText = (0, language_core_1.toString)(file.content);
|
|
130
|
+
const changeRanges = new Map();
|
|
131
|
+
const snapshot = {
|
|
132
|
+
getText: (start, end) => newText.slice(start, end),
|
|
133
|
+
getLength: () => newText.length,
|
|
134
|
+
getChangeRange(oldSnapshot) {
|
|
135
|
+
if (!changeRanges.has(oldSnapshot)) {
|
|
136
|
+
changeRanges.set(oldSnapshot, undefined);
|
|
137
|
+
const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
138
|
+
const changeRange = fullDiffTextChangeRange(oldText, newText);
|
|
139
|
+
if (changeRange) {
|
|
140
|
+
changeRanges.set(oldSnapshot, changeRange);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return changeRanges.get(oldSnapshot);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
file,
|
|
148
|
+
snapshot,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
console.error(e);
|
|
156
|
+
}
|
|
157
|
+
return Object.values(embeddedFiles);
|
|
158
|
+
});
|
|
159
|
+
return (0, computeds_1.computed)(() => {
|
|
160
|
+
return files().map(_file => {
|
|
161
|
+
const { file, snapshot } = _file();
|
|
162
|
+
const mappings = (0, language_core_1.buildMappings)(file.content);
|
|
163
|
+
let lastValidMapping;
|
|
164
|
+
for (const mapping of mappings) {
|
|
165
|
+
if (mapping.source !== undefined) {
|
|
166
|
+
const block = nameToBlock()[mapping.source];
|
|
167
|
+
if (block) {
|
|
168
|
+
mapping.sourceOffsets = mapping.sourceOffsets.map(offset => offset + block.startTagEnd);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// ignore
|
|
172
|
+
}
|
|
173
|
+
mapping.source = undefined;
|
|
174
|
+
}
|
|
175
|
+
if (mapping.data.__combineLastMappping) {
|
|
176
|
+
lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets);
|
|
177
|
+
lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets);
|
|
178
|
+
lastValidMapping.lengths.push(...mapping.lengths);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
lastValidMapping = mapping;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
file,
|
|
187
|
+
snapshot,
|
|
188
|
+
mappings: mappings.filter(mapping => !mapping.data.__combineLastMappping),
|
|
189
|
+
codegenStacks: (0, language_core_1.buildStacks)(file.content, file.contentStacks),
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function fullDiffTextChangeRange(oldText, newText) {
|
|
195
|
+
for (let start = 0; start < oldText.length && start < newText.length; start++) {
|
|
196
|
+
if (oldText[start] !== newText[start]) {
|
|
197
|
+
let end = oldText.length;
|
|
198
|
+
for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
|
|
199
|
+
if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
end--;
|
|
203
|
+
}
|
|
204
|
+
let length = end - start;
|
|
205
|
+
let newLength = length + (newText.length - oldText.length);
|
|
206
|
+
if (newLength < 0) {
|
|
207
|
+
length -= newLength;
|
|
208
|
+
newLength = 0;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
span: { start, length },
|
|
212
|
+
newLength,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=computedFiles.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Mapping } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { Sfc, VueCodeInformation } from '../types';
|
|
4
|
+
export declare function computedMappings(snapshot: () => ts.IScriptSnapshot, sfc: Sfc): () => Mapping<VueCodeInformation>[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedMappings = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const computeds_1 = require("computeds");
|
|
6
|
+
const utils_1 = require("../generators/utils");
|
|
7
|
+
function computedMappings(snapshot, sfc) {
|
|
8
|
+
return (0, computeds_1.computed)(() => {
|
|
9
|
+
const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, (0, utils_1.enableAllFeatures)({})]];
|
|
10
|
+
for (const block of [
|
|
11
|
+
sfc.script,
|
|
12
|
+
sfc.scriptSetup,
|
|
13
|
+
sfc.template,
|
|
14
|
+
...sfc.styles,
|
|
15
|
+
...sfc.customBlocks,
|
|
16
|
+
]) {
|
|
17
|
+
if (block) {
|
|
18
|
+
(0, language_core_1.replaceSourceRange)(str, undefined, block.startTagEnd, block.endTagStart, '\n\n');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return str
|
|
22
|
+
.filter(s => typeof s !== 'string')
|
|
23
|
+
.map((m) => {
|
|
24
|
+
const text = m[0];
|
|
25
|
+
const start = m[2];
|
|
26
|
+
return {
|
|
27
|
+
sourceOffsets: [start],
|
|
28
|
+
generatedOffsets: [start],
|
|
29
|
+
lengths: [text.length],
|
|
30
|
+
data: m[3],
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.computedMappings = computedMappings;
|
|
36
|
+
//# sourceMappingURL=computedMappings.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
4
|
+
export declare function computedSfc(ts: typeof import('typescript'), plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot, parsed: () => SFCParseResult | undefined): Sfc;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedSfc = void 0;
|
|
4
|
+
const computeds_1 = require("computeds");
|
|
5
|
+
const parseCssClassNames_1 = require("../utils/parseCssClassNames");
|
|
6
|
+
const parseCssVars_1 = require("../utils/parseCssVars");
|
|
7
|
+
function computedSfc(ts, plugins, fileName, snapshot, parsed) {
|
|
8
|
+
const untrackedSnapshot = () => {
|
|
9
|
+
(0, computeds_1.pauseTracking)();
|
|
10
|
+
const res = snapshot();
|
|
11
|
+
(0, computeds_1.resetTracking)();
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
14
|
+
const template = computedNullableSfcBlock('template', 'html', (0, computeds_1.computed)(() => parsed()?.descriptor.template ?? undefined), (_block, base) => {
|
|
15
|
+
const compiledAst = computedTemplateAst(base);
|
|
16
|
+
return mergeObject(base, {
|
|
17
|
+
get ast() { return compiledAst()?.ast; },
|
|
18
|
+
get errors() { return compiledAst()?.errors; },
|
|
19
|
+
get warnings() { return compiledAst()?.warnings; },
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const script = computedNullableSfcBlock('script', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.script ?? undefined), (block, base) => {
|
|
23
|
+
const src = (0, computeds_1.computed)(() => block().src);
|
|
24
|
+
const srcOffset = (0, computeds_1.computed)(() => {
|
|
25
|
+
const _src = src();
|
|
26
|
+
return _src ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_src) - base.startTagEnd : -1;
|
|
27
|
+
});
|
|
28
|
+
const ast = (0, computeds_1.computed)(() => ts.createSourceFile(fileName + '.' + base.lang, base.content, 99));
|
|
29
|
+
return mergeObject(base, {
|
|
30
|
+
get src() { return src(); },
|
|
31
|
+
get srcOffset() { return srcOffset(); },
|
|
32
|
+
get ast() { return ast(); },
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
const scriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, computeds_1.computed)(() => parsed()?.descriptor.scriptSetup ?? undefined), (block, base) => {
|
|
36
|
+
const generic = (0, computeds_1.computed)(() => {
|
|
37
|
+
const _block = block();
|
|
38
|
+
return typeof _block.attrs.generic === 'string' ? _block.attrs.generic : undefined;
|
|
39
|
+
});
|
|
40
|
+
const genericOffset = (0, computeds_1.computed)(() => {
|
|
41
|
+
const _generic = generic();
|
|
42
|
+
return _generic !== undefined ? untrackedSnapshot().getText(0, base.startTagEnd).lastIndexOf(_generic) - base.startTagEnd : -1;
|
|
43
|
+
});
|
|
44
|
+
const ast = (0, computeds_1.computed)(() => ts.createSourceFile(fileName + '.' + base.lang, base.content, 99));
|
|
45
|
+
return mergeObject(base, {
|
|
46
|
+
get generic() { return generic(); },
|
|
47
|
+
get genericOffset() { return genericOffset(); },
|
|
48
|
+
get ast() { return ast(); },
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const styles = (0, computeds_1.computedArray)((0, computeds_1.computed)(() => parsed()?.descriptor.styles ?? []), (block, i) => {
|
|
52
|
+
const base = computedSfcBlock('style_' + i, 'css', block);
|
|
53
|
+
const module = (0, computeds_1.computed)(() => typeof block().module === 'string' ? block().module : block().module ? '$style' : undefined);
|
|
54
|
+
const scoped = (0, computeds_1.computed)(() => !!block().scoped);
|
|
55
|
+
const cssVars = (0, computeds_1.computed)(() => [...(0, parseCssVars_1.parseCssVars)(base.content)]);
|
|
56
|
+
const classNames = (0, computeds_1.computed)(() => [...(0, parseCssClassNames_1.parseCssClassNames)(base.content)]);
|
|
57
|
+
return (0, computeds_1.computed)(() => mergeObject(base, {
|
|
58
|
+
get module() { return module(); },
|
|
59
|
+
get scoped() { return scoped(); },
|
|
60
|
+
get cssVars() { return cssVars(); },
|
|
61
|
+
get classNames() { return classNames(); },
|
|
62
|
+
}));
|
|
63
|
+
});
|
|
64
|
+
const customBlocks = (0, computeds_1.computedArray)((0, computeds_1.computed)(() => parsed()?.descriptor.customBlocks ?? []), (block, i) => {
|
|
65
|
+
const base = computedSfcBlock('customBlock_' + i, 'txt', block);
|
|
66
|
+
const type = (0, computeds_1.computed)(() => block().type);
|
|
67
|
+
return (0, computeds_1.computed)(() => mergeObject(base, {
|
|
68
|
+
get type() { return type(); },
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
get template() { return template(); },
|
|
73
|
+
get script() { return script(); },
|
|
74
|
+
get scriptSetup() { return scriptSetup(); },
|
|
75
|
+
get styles() { return styles; },
|
|
76
|
+
get customBlocks() { return customBlocks; },
|
|
77
|
+
get templateAst() { return template()?.ast; },
|
|
78
|
+
get scriptAst() { return script()?.ast; },
|
|
79
|
+
get scriptSetupAst() { return scriptSetup()?.ast; },
|
|
80
|
+
};
|
|
81
|
+
function computedTemplateAst(base) {
|
|
82
|
+
let cache;
|
|
83
|
+
return (0, computeds_1.computed)(() => {
|
|
84
|
+
if (cache?.template === base.content) {
|
|
85
|
+
return {
|
|
86
|
+
errors: [],
|
|
87
|
+
warnings: [],
|
|
88
|
+
ast: cache?.result.ast,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// incremental update
|
|
92
|
+
if (cache?.plugin.updateSFCTemplate) {
|
|
93
|
+
const change = untrackedSnapshot().getChangeRange(cache.snapshot);
|
|
94
|
+
if (change) {
|
|
95
|
+
(0, computeds_1.pauseTracking)();
|
|
96
|
+
const templateOffset = base.startTagEnd;
|
|
97
|
+
(0, computeds_1.resetTracking)();
|
|
98
|
+
const newText = untrackedSnapshot().getText(change.span.start, change.span.start + change.newLength);
|
|
99
|
+
const newResult = cache.plugin.updateSFCTemplate(cache.result, {
|
|
100
|
+
start: change.span.start - templateOffset,
|
|
101
|
+
end: change.span.start + change.span.length - templateOffset,
|
|
102
|
+
newText,
|
|
103
|
+
});
|
|
104
|
+
if (newResult) {
|
|
105
|
+
cache.template = base.content;
|
|
106
|
+
cache.snapshot = untrackedSnapshot();
|
|
107
|
+
cache.result = newResult;
|
|
108
|
+
return {
|
|
109
|
+
errors: [],
|
|
110
|
+
warnings: [],
|
|
111
|
+
ast: newResult.ast,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const errors = [];
|
|
117
|
+
const warnings = [];
|
|
118
|
+
let options = {
|
|
119
|
+
onError: (err) => errors.push(err),
|
|
120
|
+
onWarn: (err) => warnings.push(err),
|
|
121
|
+
expressionPlugins: ['typescript'],
|
|
122
|
+
};
|
|
123
|
+
for (const plugin of plugins) {
|
|
124
|
+
if (plugin.resolveTemplateCompilerOptions) {
|
|
125
|
+
options = plugin.resolveTemplateCompilerOptions(options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const plugin of plugins) {
|
|
129
|
+
let result;
|
|
130
|
+
try {
|
|
131
|
+
result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
const err = e;
|
|
135
|
+
errors.push(err);
|
|
136
|
+
}
|
|
137
|
+
if (result || errors.length) {
|
|
138
|
+
if (result && !errors.length && !warnings.length) {
|
|
139
|
+
cache = {
|
|
140
|
+
template: base.content,
|
|
141
|
+
snapshot: untrackedSnapshot(),
|
|
142
|
+
result: result,
|
|
143
|
+
plugin,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
cache = undefined;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
errors,
|
|
151
|
+
warnings,
|
|
152
|
+
ast: result?.ast,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
errors,
|
|
158
|
+
warnings,
|
|
159
|
+
ast: undefined,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function computedNullableSfcBlock(name, defaultLang, block, resolve) {
|
|
164
|
+
const hasBlock = (0, computeds_1.computed)(() => !!block());
|
|
165
|
+
return (0, computeds_1.computed)(() => {
|
|
166
|
+
if (!hasBlock()) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const _block = (0, computeds_1.computed)(() => block());
|
|
170
|
+
return resolve(_block, computedSfcBlock(name, defaultLang, _block));
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function computedSfcBlock(name, defaultLang, block) {
|
|
174
|
+
const lang = (0, computeds_1.computed)(() => block().lang ?? defaultLang);
|
|
175
|
+
const attrs = (0, computeds_1.computed)(() => block().attrs); // TODO: computed it
|
|
176
|
+
const content = (0, computeds_1.computed)(() => block().content);
|
|
177
|
+
const startTagEnd = (0, computeds_1.computed)(() => block().loc.start.offset);
|
|
178
|
+
const endTagStart = (0, computeds_1.computed)(() => block().loc.end.offset);
|
|
179
|
+
const start = (0, computeds_1.computed)(() => untrackedSnapshot().getText(0, startTagEnd()).lastIndexOf('<' + block().type));
|
|
180
|
+
const end = (0, computeds_1.computed)(() => endTagStart() + untrackedSnapshot().getText(endTagStart(), untrackedSnapshot().getLength()).indexOf('>') + 1);
|
|
181
|
+
return {
|
|
182
|
+
name,
|
|
183
|
+
get lang() { return lang(); },
|
|
184
|
+
get attrs() { return attrs(); },
|
|
185
|
+
get content() { return content(); },
|
|
186
|
+
get startTagEnd() { return startTagEnd(); },
|
|
187
|
+
get endTagStart() { return endTagStart(); },
|
|
188
|
+
get start() { return start(); },
|
|
189
|
+
get end() { return end(); },
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.computedSfc = computedSfc;
|
|
194
|
+
function mergeObject(a, b) {
|
|
195
|
+
return Object.defineProperties(a, Object.getOwnPropertyDescriptors(b));
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=computedSfc.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { VueLanguagePlugin } from '../types';
|
|
4
|
+
export declare function computedVueSfc(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedVueSfc = void 0;
|
|
4
|
+
const computeds_1 = require("computeds");
|
|
5
|
+
function computedVueSfc(plugins, fileName, snapshot) {
|
|
6
|
+
let cache;
|
|
7
|
+
return (0, computeds_1.computed)(() => {
|
|
8
|
+
// incremental update
|
|
9
|
+
if (cache?.plugin.updateSFC) {
|
|
10
|
+
const change = snapshot().getChangeRange(cache.snapshot);
|
|
11
|
+
if (change) {
|
|
12
|
+
const newSfc = cache.plugin.updateSFC(cache.sfc, {
|
|
13
|
+
start: change.span.start,
|
|
14
|
+
end: change.span.start + change.span.length,
|
|
15
|
+
newText: snapshot().getText(change.span.start, change.span.start + change.newLength),
|
|
16
|
+
});
|
|
17
|
+
if (newSfc) {
|
|
18
|
+
cache.snapshot = snapshot();
|
|
19
|
+
// force dirty
|
|
20
|
+
cache.sfc = JSON.parse(JSON.stringify(newSfc));
|
|
21
|
+
return cache.sfc;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const plugin of plugins) {
|
|
26
|
+
const sfc = plugin.parseSFC?.(fileName, snapshot().getText(0, snapshot().getLength()));
|
|
27
|
+
if (sfc) {
|
|
28
|
+
if (!sfc.errors.length) {
|
|
29
|
+
cache = {
|
|
30
|
+
snapshot: snapshot(),
|
|
31
|
+
sfc,
|
|
32
|
+
plugin,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return sfc;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.computedVueSfc = computedVueSfc;
|
|
41
|
+
//# sourceMappingURL=computedVueSfc.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Mapping, StackNode } from '@volar/language-core';
|
|
2
|
+
import type { Code } from '../types';
|
|
3
|
+
export declare class VueEmbeddedCode {
|
|
4
|
+
id: string;
|
|
5
|
+
lang: string;
|
|
6
|
+
content: Code[];
|
|
7
|
+
contentStacks: StackNode[];
|
|
8
|
+
parentCodeId?: string;
|
|
9
|
+
linkedCodeMappings: Mapping[];
|
|
10
|
+
embeddedCodes: VueEmbeddedCode[];
|
|
11
|
+
constructor(id: string, lang: string, content: Code[], contentStacks: StackNode[]);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueEmbeddedCode = void 0;
|
|
4
|
+
class VueEmbeddedCode {
|
|
5
|
+
constructor(id, lang, content, contentStacks) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.lang = lang;
|
|
8
|
+
this.content = content;
|
|
9
|
+
this.contentStacks = contentStacks;
|
|
10
|
+
this.linkedCodeMappings = [];
|
|
11
|
+
this.embeddedCodes = [];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.VueEmbeddedCode = VueEmbeddedCode;
|
|
15
|
+
//# sourceMappingURL=embeddedFile.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Stack, VirtualCode } from '@volar/language-core';
|
|
2
|
+
import { Signal } from 'computeds';
|
|
3
|
+
import type * as ts from 'typescript';
|
|
4
|
+
import type { VueCompilerOptions, VueLanguagePlugin } from '../types';
|
|
5
|
+
export declare class VueGeneratedCode implements VirtualCode {
|
|
6
|
+
fileName: string;
|
|
7
|
+
languageId: string;
|
|
8
|
+
initSnapshot: ts.IScriptSnapshot;
|
|
9
|
+
vueCompilerOptions: VueCompilerOptions;
|
|
10
|
+
plugins: ReturnType<VueLanguagePlugin>[];
|
|
11
|
+
ts: typeof import('typescript');
|
|
12
|
+
codegenStack: boolean;
|
|
13
|
+
id: string;
|
|
14
|
+
_snapshot: Signal<ts.IScriptSnapshot>;
|
|
15
|
+
getVueSfc: () => import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
16
|
+
sfc: import("../types").Sfc;
|
|
17
|
+
getMappings: () => import("@volar/language-core").Mapping<import("../types").VueCodeInformation>[];
|
|
18
|
+
getEmbeddedCodes: () => VirtualCode[];
|
|
19
|
+
codegenStacks: Stack[];
|
|
20
|
+
get embeddedCodes(): VirtualCode[];
|
|
21
|
+
get snapshot(): ts.IScriptSnapshot;
|
|
22
|
+
get mappings(): import("@volar/language-core").Mapping<import("../types").VueCodeInformation>[];
|
|
23
|
+
constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript'), codegenStack: boolean);
|
|
24
|
+
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueGeneratedCode = void 0;
|
|
4
|
+
const computeds_1 = require("computeds");
|
|
5
|
+
const computedFiles_1 = require("./computedFiles");
|
|
6
|
+
const computedMappings_1 = require("./computedMappings");
|
|
7
|
+
const computedSfc_1 = require("./computedSfc");
|
|
8
|
+
const computedVueSfc_1 = require("./computedVueSfc");
|
|
9
|
+
class VueGeneratedCode {
|
|
10
|
+
get embeddedCodes() {
|
|
11
|
+
return this.getEmbeddedCodes();
|
|
12
|
+
}
|
|
13
|
+
get snapshot() {
|
|
14
|
+
return this._snapshot();
|
|
15
|
+
}
|
|
16
|
+
get mappings() {
|
|
17
|
+
return this.getMappings();
|
|
18
|
+
}
|
|
19
|
+
constructor(fileName, languageId, initSnapshot, vueCompilerOptions, plugins, ts, codegenStack) {
|
|
20
|
+
this.fileName = fileName;
|
|
21
|
+
this.languageId = languageId;
|
|
22
|
+
this.initSnapshot = initSnapshot;
|
|
23
|
+
this.vueCompilerOptions = vueCompilerOptions;
|
|
24
|
+
this.plugins = plugins;
|
|
25
|
+
this.ts = ts;
|
|
26
|
+
this.codegenStack = codegenStack;
|
|
27
|
+
// sources
|
|
28
|
+
this.id = 'main';
|
|
29
|
+
// computeds
|
|
30
|
+
this.getVueSfc = (0, computedVueSfc_1.computedVueSfc)(this.plugins, this.fileName, () => this._snapshot());
|
|
31
|
+
this.sfc = (0, computedSfc_1.computedSfc)(this.ts, this.plugins, this.fileName, () => this._snapshot(), this.getVueSfc);
|
|
32
|
+
this.getMappings = (0, computedMappings_1.computedMappings)(() => this._snapshot(), this.sfc);
|
|
33
|
+
this.getEmbeddedCodes = (0, computedFiles_1.computedFiles)(this.plugins, this.fileName, this.sfc, this.codegenStack);
|
|
34
|
+
// others
|
|
35
|
+
this.codegenStacks = [];
|
|
36
|
+
this._snapshot = (0, computeds_1.signal)(initSnapshot);
|
|
37
|
+
}
|
|
38
|
+
update(newSnapshot) {
|
|
39
|
+
this._snapshot.set(newSnapshot);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.VueGeneratedCode = VueGeneratedCode;
|
|
43
|
+
//# sourceMappingURL=vueFile.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts"
|
|
8
8
|
],
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"optional": true
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b377d5f990ffe7ef44f0d1871fcb8b5c2deafad1"
|
|
38
38
|
}
|