@vue/language-core 3.1.8 → 3.2.1
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 +1 -1
- package/index.js +25 -3
- package/lib/codegen/codeFeatures.d.ts +18 -84
- package/lib/codegen/names.d.ts +2 -5
- package/lib/codegen/names.js +3 -6
- package/lib/codegen/script/component.js +37 -4
- package/lib/codegen/script/index.d.ts +4 -12
- package/lib/codegen/script/index.js +77 -22
- package/lib/codegen/script/scriptSetup.js +52 -14
- package/lib/codegen/script/template.js +71 -34
- package/lib/codegen/style/index.d.ts +9 -9
- package/lib/codegen/style/modules.js +34 -1
- package/lib/codegen/template/context.d.ts +7 -7
- package/lib/codegen/template/context.js +34 -1
- package/lib/codegen/template/element.js +48 -7
- package/lib/codegen/template/elementDirectives.js +36 -3
- package/lib/codegen/template/elementEvents.js +36 -3
- package/lib/codegen/template/elementProps.js +35 -2
- package/lib/codegen/template/index.d.ts +10 -10
- package/lib/codegen/template/index.js +34 -1
- package/lib/codegen/template/interpolation.d.ts +4 -3
- package/lib/codegen/template/interpolation.js +37 -4
- package/lib/codegen/template/slotOutlet.js +35 -2
- package/lib/codegen/template/templateChild.js +34 -1
- package/lib/codegen/template/vFor.js +37 -4
- package/lib/codegen/template/vIf.js +34 -1
- package/lib/codegen/template/vSlot.js +38 -5
- package/lib/compilerOptions.d.ts +7 -11
- package/lib/compilerOptions.js +48 -89
- package/lib/languagePlugin.js +34 -1
- package/lib/parsers/scriptRanges.d.ts +26 -16
- package/lib/parsers/scriptRanges.js +66 -64
- package/lib/parsers/scriptSetupRanges.d.ts +19 -24
- package/lib/parsers/scriptSetupRanges.js +13 -15
- package/lib/parsers/utils.d.ts +3 -6
- package/lib/parsers/utils.js +1 -0
- package/lib/plugins/vue-template-inline-css.js +34 -1
- package/lib/plugins/vue-template-inline-ts.js +34 -1
- package/lib/plugins/vue-tsx.d.ts +36 -114
- package/lib/plugins/vue-tsx.js +62 -33
- package/lib/plugins.js +17 -14
- package/lib/types.d.ts +8 -8
- package/lib/utils/collectBindings.d.ts +1 -1
- package/lib/utils/forEachTemplateNode.js +34 -1
- package/lib/utils/parseSfc.js +34 -1
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/shared.js +2 -1
- package/lib/virtualCode/embeddedCodes.js +6 -2
- package/lib/virtualCode/index.js +10 -1
- package/lib/virtualCode/ir.js +34 -1
- package/lib/virtualCode/normalize.js +37 -2
- package/package.json +4 -12
- package/types/props-fallback.d.ts +5 -0
- package/types/template-helpers.d.ts +146 -0
- package/types/vue-3.4-shims.d.ts +6 -0
- package/lib/codegen/globalTypes.d.ts +0 -3
- package/lib/codegen/globalTypes.js +0 -163
- package/lib/codegen/script/src.d.ts +0 -3
- package/lib/codegen/script/src.js +0 -43
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -2
- package/lib/codegen/utils/wrapWith.js +0 -15
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedSfc.js +0 -340
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.d.ts +0 -24
- package/lib/virtualFile/vueFile.js +0 -49
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateStyleImports = generateStyleImports;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const wrapWith_1 = require("../utils/wrapWith");
|
|
6
|
-
function* generateStyleImports(style) {
|
|
7
|
-
const features = {
|
|
8
|
-
navigation: true,
|
|
9
|
-
verification: true,
|
|
10
|
-
};
|
|
11
|
-
if (typeof style.src === 'object') {
|
|
12
|
-
yield `${utils_1.newLine} & typeof import(`;
|
|
13
|
-
yield* (0, wrapWith_1.wrapWith)('main', style.src.offset, style.src.offset + style.src.text.length, features, `'`, [style.src.text, 'main', style.src.offset, utils_1.combineLastMapping], `'`);
|
|
14
|
-
yield `).default`;
|
|
15
|
-
}
|
|
16
|
-
for (const { text, offset } of style.imports) {
|
|
17
|
-
yield `${utils_1.newLine} & typeof import('`;
|
|
18
|
-
yield [
|
|
19
|
-
text,
|
|
20
|
-
style.name,
|
|
21
|
-
offset,
|
|
22
|
-
features,
|
|
23
|
-
];
|
|
24
|
-
yield `').default`;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=imports.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
-
import type { Code } from '../../types';
|
|
3
|
-
import type { TemplateCodegenContext } from './context';
|
|
4
|
-
import type { TemplateCodegenOptions } from './index';
|
|
5
|
-
export declare function generateElementChildren(options: TemplateCodegenOptions, ctx: TemplateCodegenContext, children: (CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode)[], enterNode?: boolean): Generator<Code>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateElementChildren = generateElementChildren;
|
|
4
|
-
const templateChild_1 = require("./templateChild");
|
|
5
|
-
function* generateElementChildren(options, ctx, children, enterNode = true) {
|
|
6
|
-
yield* ctx.generateAutoImportCompletion();
|
|
7
|
-
for (const childNode of children) {
|
|
8
|
-
yield* (0, templateChild_1.generateTemplateChild)(options, ctx, childNode, enterNode);
|
|
9
|
-
}
|
|
10
|
-
yield* ctx.generateAutoImportCompletion();
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=elementChildren.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapWith = wrapWith;
|
|
4
|
-
function* wrapWith(source, startOffset, endOffset, features, ...codes) {
|
|
5
|
-
yield ['', source, startOffset, features];
|
|
6
|
-
let offset = 1;
|
|
7
|
-
for (const code of codes) {
|
|
8
|
-
if (typeof code !== 'string') {
|
|
9
|
-
offset++;
|
|
10
|
-
}
|
|
11
|
-
yield code;
|
|
12
|
-
}
|
|
13
|
-
yield ['', source, endOffset, { __combineOffset: offset }];
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=wrapWith.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { VirtualCode } from '@volar/language-core';
|
|
2
|
-
import type { Sfc, VueLanguagePluginReturn } from '../types';
|
|
3
|
-
export declare function computedEmbeddedCodes(plugins: VueLanguagePluginReturn[], fileName: string, sfc: Sfc): () => VirtualCode[];
|
|
4
|
-
export declare function resolveCommonLanguageId(lang: string): string;
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computedEmbeddedCodes = computedEmbeddedCodes;
|
|
4
|
-
exports.resolveCommonLanguageId = resolveCommonLanguageId;
|
|
5
|
-
const alien_signals_1 = require("alien-signals");
|
|
6
|
-
const muggle_string_1 = require("muggle-string");
|
|
7
|
-
const buildMappings_1 = require("../utils/buildMappings");
|
|
8
|
-
const embeddedFile_1 = require("./embeddedFile");
|
|
9
|
-
function computedEmbeddedCodes(plugins, fileName, sfc) {
|
|
10
|
-
const getNameToBlockMap = (0, alien_signals_1.computed)(() => {
|
|
11
|
-
const blocks = {};
|
|
12
|
-
if (sfc.template) {
|
|
13
|
-
blocks[sfc.template.name] = sfc.template;
|
|
14
|
-
}
|
|
15
|
-
if (sfc.script) {
|
|
16
|
-
blocks[sfc.script.name] = sfc.script;
|
|
17
|
-
}
|
|
18
|
-
if (sfc.scriptSetup) {
|
|
19
|
-
blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
|
|
20
|
-
}
|
|
21
|
-
for (const block of sfc.styles) {
|
|
22
|
-
blocks[block.name] = block;
|
|
23
|
-
}
|
|
24
|
-
for (const block of sfc.customBlocks) {
|
|
25
|
-
blocks[block.name] = block;
|
|
26
|
-
}
|
|
27
|
-
return blocks;
|
|
28
|
-
});
|
|
29
|
-
const getPluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, name => getNameToBlockMap()[name]));
|
|
30
|
-
const getFlatResult = (0, alien_signals_1.computed)(() => getPluginsResult.map(r => r()).flat());
|
|
31
|
-
const getStructuredResult = (0, alien_signals_1.computed)(() => {
|
|
32
|
-
const embeddedCodes = [];
|
|
33
|
-
let remain = [...getFlatResult()];
|
|
34
|
-
while (remain.length) {
|
|
35
|
-
const beforeLength = remain.length;
|
|
36
|
-
consumeRemain();
|
|
37
|
-
if (beforeLength === remain.length) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const { code } of remain) {
|
|
42
|
-
console.error('Unable to resolve embedded: ' + code.parentCodeId + ' -> ' + code.id);
|
|
43
|
-
}
|
|
44
|
-
return embeddedCodes;
|
|
45
|
-
function consumeRemain() {
|
|
46
|
-
for (let i = remain.length - 1; i >= 0; i--) {
|
|
47
|
-
const { code, snapshot, mappings } = remain[i];
|
|
48
|
-
if (!code.parentCodeId) {
|
|
49
|
-
embeddedCodes.push({
|
|
50
|
-
id: code.id,
|
|
51
|
-
languageId: resolveCommonLanguageId(code.lang),
|
|
52
|
-
linkedCodeMappings: code.linkedCodeMappings,
|
|
53
|
-
snapshot,
|
|
54
|
-
mappings,
|
|
55
|
-
embeddedCodes: [],
|
|
56
|
-
});
|
|
57
|
-
remain.splice(i, 1);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const parent = findParentStructure(code.parentCodeId, embeddedCodes);
|
|
61
|
-
if (parent) {
|
|
62
|
-
parent.embeddedCodes ??= [];
|
|
63
|
-
parent.embeddedCodes.push({
|
|
64
|
-
id: code.id,
|
|
65
|
-
languageId: resolveCommonLanguageId(code.lang),
|
|
66
|
-
linkedCodeMappings: code.linkedCodeMappings,
|
|
67
|
-
snapshot,
|
|
68
|
-
mappings,
|
|
69
|
-
embeddedCodes: [],
|
|
70
|
-
});
|
|
71
|
-
remain.splice(i, 1);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function findParentStructure(id, current) {
|
|
77
|
-
for (const child of current) {
|
|
78
|
-
if (child.id === id) {
|
|
79
|
-
return child;
|
|
80
|
-
}
|
|
81
|
-
let parent = findParentStructure(id, child.embeddedCodes ?? []);
|
|
82
|
-
if (parent) {
|
|
83
|
-
return parent;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return getStructuredResult;
|
|
89
|
-
}
|
|
90
|
-
function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, getBlockByName) {
|
|
91
|
-
const computeds = new Map();
|
|
92
|
-
const getComputedKey = (code) => code.id + '__' + code.lang;
|
|
93
|
-
const getCodes = (0, alien_signals_1.computed)(() => {
|
|
94
|
-
try {
|
|
95
|
-
if (!plugin.getEmbeddedCodes) {
|
|
96
|
-
return [...computeds.values()];
|
|
97
|
-
}
|
|
98
|
-
const embeddedCodeInfos = plugin.getEmbeddedCodes(fileName, sfc);
|
|
99
|
-
for (const oldId of computeds.keys()) {
|
|
100
|
-
if (!embeddedCodeInfos.some(code => getComputedKey(code) === oldId)) {
|
|
101
|
-
computeds.delete(oldId);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
for (const codeInfo of embeddedCodeInfos) {
|
|
105
|
-
if (!computeds.has(getComputedKey(codeInfo))) {
|
|
106
|
-
computeds.set(getComputedKey(codeInfo), (0, alien_signals_1.computed)(() => {
|
|
107
|
-
const content = [];
|
|
108
|
-
const code = new embeddedFile_1.VueEmbeddedCode(codeInfo.id, codeInfo.lang, content);
|
|
109
|
-
for (const plugin of plugins) {
|
|
110
|
-
if (!plugin.resolveEmbeddedCode) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
plugin.resolveEmbeddedCode(fileName, sfc, code);
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
console.error(e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const newText = (0, muggle_string_1.toString)(code.content);
|
|
121
|
-
const changeRanges = new Map();
|
|
122
|
-
const snapshot = {
|
|
123
|
-
getText: (start, end) => newText.slice(start, end),
|
|
124
|
-
getLength: () => newText.length,
|
|
125
|
-
getChangeRange(oldSnapshot) {
|
|
126
|
-
if (!changeRanges.has(oldSnapshot)) {
|
|
127
|
-
changeRanges.set(oldSnapshot, undefined);
|
|
128
|
-
const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
129
|
-
const changeRange = fullDiffTextChangeRange(oldText, newText);
|
|
130
|
-
if (changeRange) {
|
|
131
|
-
changeRanges.set(oldSnapshot, changeRange);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return changeRanges.get(oldSnapshot);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
return {
|
|
138
|
-
code,
|
|
139
|
-
snapshot,
|
|
140
|
-
};
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
console.error(e);
|
|
147
|
-
}
|
|
148
|
-
return [...computeds.values()];
|
|
149
|
-
});
|
|
150
|
-
return (0, alien_signals_1.computed)(() => {
|
|
151
|
-
return getCodes().map(_file => {
|
|
152
|
-
const { code, snapshot } = _file();
|
|
153
|
-
const mappings = (0, buildMappings_1.buildMappings)(code.content.map(segment => {
|
|
154
|
-
if (typeof segment === 'string') {
|
|
155
|
-
return segment;
|
|
156
|
-
}
|
|
157
|
-
const source = segment[1];
|
|
158
|
-
if (source === undefined) {
|
|
159
|
-
return segment;
|
|
160
|
-
}
|
|
161
|
-
const block = getBlockByName(source);
|
|
162
|
-
if (!block) {
|
|
163
|
-
// console.warn('Unable to find block: ' + source);
|
|
164
|
-
return segment;
|
|
165
|
-
}
|
|
166
|
-
return [
|
|
167
|
-
segment[0],
|
|
168
|
-
undefined,
|
|
169
|
-
segment[2] + block.startTagEnd,
|
|
170
|
-
segment[3],
|
|
171
|
-
];
|
|
172
|
-
}));
|
|
173
|
-
const newMappings = [];
|
|
174
|
-
const tokenMappings = new Map();
|
|
175
|
-
for (let i = 0; i < mappings.length; i++) {
|
|
176
|
-
const mapping = mappings[i];
|
|
177
|
-
if (mapping.data.__combineOffset !== undefined) {
|
|
178
|
-
const offsetMapping = mappings[i - mapping.data.__combineOffset];
|
|
179
|
-
if (typeof offsetMapping === 'string' || !offsetMapping) {
|
|
180
|
-
throw new Error('Invalid offset mapping, mappings: ' + mappings.length + ', i: ' + i + ', offset: '
|
|
181
|
-
+ mapping.data.__combineOffset);
|
|
182
|
-
}
|
|
183
|
-
offsetMapping.sourceOffsets.push(...mapping.sourceOffsets);
|
|
184
|
-
offsetMapping.generatedOffsets.push(...mapping.generatedOffsets);
|
|
185
|
-
offsetMapping.lengths.push(...mapping.lengths);
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
if (mapping.data.__linkedToken !== undefined) {
|
|
189
|
-
const token = mapping.data.__linkedToken;
|
|
190
|
-
if (tokenMappings.has(token)) {
|
|
191
|
-
const prevMapping = tokenMappings.get(token);
|
|
192
|
-
code.linkedCodeMappings.push({
|
|
193
|
-
sourceOffsets: [prevMapping.generatedOffsets[0]],
|
|
194
|
-
generatedOffsets: [mapping.generatedOffsets[0]],
|
|
195
|
-
lengths: [Number(token.description)],
|
|
196
|
-
data: undefined,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
tokenMappings.set(token, mapping);
|
|
201
|
-
}
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
newMappings.push(mapping);
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
code,
|
|
208
|
-
snapshot,
|
|
209
|
-
mappings: newMappings,
|
|
210
|
-
};
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
function fullDiffTextChangeRange(oldText, newText) {
|
|
215
|
-
for (let start = 0; start < oldText.length && start < newText.length; start++) {
|
|
216
|
-
if (oldText[start] !== newText[start]) {
|
|
217
|
-
let end = oldText.length;
|
|
218
|
-
for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
|
|
219
|
-
if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
end--;
|
|
223
|
-
}
|
|
224
|
-
let length = end - start;
|
|
225
|
-
let newLength = length + (newText.length - oldText.length);
|
|
226
|
-
if (newLength < 0) {
|
|
227
|
-
length -= newLength;
|
|
228
|
-
newLength = 0;
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
span: { start, length },
|
|
232
|
-
newLength,
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function resolveCommonLanguageId(lang) {
|
|
238
|
-
switch (lang) {
|
|
239
|
-
case 'js':
|
|
240
|
-
return 'javascript';
|
|
241
|
-
case 'cjs':
|
|
242
|
-
return 'javascript';
|
|
243
|
-
case 'mjs':
|
|
244
|
-
return 'javascript';
|
|
245
|
-
case 'ts':
|
|
246
|
-
return 'typescript';
|
|
247
|
-
case 'cts':
|
|
248
|
-
return 'typescript';
|
|
249
|
-
case 'mts':
|
|
250
|
-
return 'typescript';
|
|
251
|
-
case 'jsx':
|
|
252
|
-
return 'javascriptreact';
|
|
253
|
-
case 'tsx':
|
|
254
|
-
return 'typescriptreact';
|
|
255
|
-
case 'pug':
|
|
256
|
-
return 'jade';
|
|
257
|
-
case 'md':
|
|
258
|
-
return 'markdown';
|
|
259
|
-
}
|
|
260
|
-
return lang;
|
|
261
|
-
}
|
|
262
|
-
//# sourceMappingURL=computedEmbeddedCodes.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
|
-
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
3
|
-
import type * as ts from 'typescript';
|
|
4
|
-
import type { Sfc, VueLanguagePluginReturn } from '../types';
|
|
5
|
-
export declare const templateInlineTsAsts: WeakMap<CompilerDOM.RootNode, Map<string, ts.SourceFile>>;
|
|
6
|
-
export declare function computedSfc(ts: typeof import('typescript'), plugins: VueLanguagePluginReturn[], fileName: string, getSnapshot: () => ts.IScriptSnapshot, getParseResult: () => SFCParseResult | undefined): Sfc;
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.templateInlineTsAsts = void 0;
|
|
4
|
-
exports.computedSfc = computedSfc;
|
|
5
|
-
const CompilerDOM = require("@vue/compiler-dom");
|
|
6
|
-
const alien_signals_1 = require("alien-signals");
|
|
7
|
-
const signals_1 = require("../utils/signals");
|
|
8
|
-
exports.templateInlineTsAsts = new WeakMap();
|
|
9
|
-
function computedSfc(ts, plugins, fileName, getSnapshot, getParseResult) {
|
|
10
|
-
const getUntrackedSnapshot = () => {
|
|
11
|
-
const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
|
|
12
|
-
const res = getSnapshot();
|
|
13
|
-
(0, alien_signals_1.setActiveSub)(pausedSub);
|
|
14
|
-
return res;
|
|
15
|
-
};
|
|
16
|
-
const getContent = (0, alien_signals_1.computed)(() => {
|
|
17
|
-
return getSnapshot().getText(0, getSnapshot().getLength());
|
|
18
|
-
});
|
|
19
|
-
const getComments = (0, alien_signals_1.computed)(oldValue => {
|
|
20
|
-
const newValue = getParseResult()?.descriptor.comments ?? [];
|
|
21
|
-
if (oldValue?.length === newValue.length
|
|
22
|
-
&& oldValue.every((v, i) => v === newValue[i])) {
|
|
23
|
-
return oldValue;
|
|
24
|
-
}
|
|
25
|
-
return newValue;
|
|
26
|
-
});
|
|
27
|
-
const getTemplate = computedNullableSfcBlock('template', 'html', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.template ?? undefined), (_block, base) => {
|
|
28
|
-
const compiledAst = computedTemplateAst(base);
|
|
29
|
-
return mergeObject(base, {
|
|
30
|
-
get ast() {
|
|
31
|
-
return compiledAst().ast;
|
|
32
|
-
},
|
|
33
|
-
get errors() {
|
|
34
|
-
return compiledAst().errors;
|
|
35
|
-
},
|
|
36
|
-
get warnings() {
|
|
37
|
-
return compiledAst().warnings;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
const getScript = computedNullableSfcBlock('script', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.script ?? undefined), (block, base) => {
|
|
42
|
-
const getSrc = computedAttrValue('__src', base, block);
|
|
43
|
-
const getAst = (0, alien_signals_1.computed)(() => {
|
|
44
|
-
for (const plugin of plugins) {
|
|
45
|
-
const ast = plugin.compileSFCScript?.(base.lang, base.content);
|
|
46
|
-
if (ast) {
|
|
47
|
-
return ast;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
51
|
-
});
|
|
52
|
-
return mergeObject(base, {
|
|
53
|
-
get src() {
|
|
54
|
-
return getSrc();
|
|
55
|
-
},
|
|
56
|
-
get ast() {
|
|
57
|
-
return getAst();
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
const getOriginalScriptSetup = computedNullableSfcBlock('scriptSetup', 'js', (0, alien_signals_1.computed)(() => getParseResult()?.descriptor.scriptSetup ?? undefined), (block, base) => {
|
|
62
|
-
const getGeneric = computedAttrValue('__generic', base, block);
|
|
63
|
-
const getAst = (0, alien_signals_1.computed)(() => {
|
|
64
|
-
for (const plugin of plugins) {
|
|
65
|
-
const ast = plugin.compileSFCScript?.(base.lang, base.content);
|
|
66
|
-
if (ast) {
|
|
67
|
-
return ast;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return ts.createSourceFile(fileName + '.' + base.lang, '', 99);
|
|
71
|
-
});
|
|
72
|
-
return mergeObject(base, {
|
|
73
|
-
get generic() {
|
|
74
|
-
return getGeneric();
|
|
75
|
-
},
|
|
76
|
-
get ast() {
|
|
77
|
-
return getAst();
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
const hasScript = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.script);
|
|
82
|
-
const hasScriptSetup = (0, alien_signals_1.computed)(() => !!getParseResult()?.descriptor.scriptSetup);
|
|
83
|
-
const getScriptSetup = (0, alien_signals_1.computed)(() => {
|
|
84
|
-
if (!hasScript() && !hasScriptSetup()) {
|
|
85
|
-
// #region monkey fix: https://github.com/vuejs/language-tools/pull/2113
|
|
86
|
-
return {
|
|
87
|
-
content: '',
|
|
88
|
-
lang: 'ts',
|
|
89
|
-
name: '',
|
|
90
|
-
start: 0,
|
|
91
|
-
end: 0,
|
|
92
|
-
startTagEnd: 0,
|
|
93
|
-
endTagStart: 0,
|
|
94
|
-
generic: undefined,
|
|
95
|
-
genericOffset: 0,
|
|
96
|
-
attrs: {},
|
|
97
|
-
ast: ts.createSourceFile('', '', 99, false, ts.ScriptKind.TS),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return getOriginalScriptSetup();
|
|
101
|
-
});
|
|
102
|
-
const styles = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.styles ?? []), (getBlock, i) => {
|
|
103
|
-
const base = computedSfcBlock('style_' + i, 'css', getBlock);
|
|
104
|
-
const getSrc = computedAttrValue('__src', base, getBlock);
|
|
105
|
-
const getModule = computedAttrValue('__module', base, getBlock);
|
|
106
|
-
const getScoped = (0, alien_signals_1.computed)(() => !!getBlock().scoped);
|
|
107
|
-
const getIr = (0, alien_signals_1.computed)(() => {
|
|
108
|
-
for (const plugin of plugins) {
|
|
109
|
-
const ast = plugin.compileSFCStyle?.(base.lang, base.content);
|
|
110
|
-
if (ast) {
|
|
111
|
-
return ast;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const getImports = (0, signals_1.computedItems)(() => getIr()?.imports ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
116
|
-
const getBindings = (0, signals_1.computedItems)(() => getIr()?.bindings ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
117
|
-
const getClassNames = (0, signals_1.computedItems)(() => getIr()?.classNames ?? [], (oldItem, newItem) => oldItem.text === newItem.text && oldItem.offset === newItem.offset);
|
|
118
|
-
return () => mergeObject(base, {
|
|
119
|
-
get src() {
|
|
120
|
-
return getSrc();
|
|
121
|
-
},
|
|
122
|
-
get module() {
|
|
123
|
-
return getModule();
|
|
124
|
-
},
|
|
125
|
-
get scoped() {
|
|
126
|
-
return getScoped();
|
|
127
|
-
},
|
|
128
|
-
get imports() {
|
|
129
|
-
return getImports();
|
|
130
|
-
},
|
|
131
|
-
get bindings() {
|
|
132
|
-
return getBindings();
|
|
133
|
-
},
|
|
134
|
-
get classNames() {
|
|
135
|
-
return getClassNames();
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
const customBlocks = (0, signals_1.computedArray)((0, alien_signals_1.computed)(() => getParseResult()?.descriptor.customBlocks ?? []), (getBlock, i) => {
|
|
140
|
-
const base = computedSfcBlock('custom_block_' + i, 'txt', getBlock);
|
|
141
|
-
const getType = (0, alien_signals_1.computed)(() => getBlock().type);
|
|
142
|
-
return () => mergeObject(base, {
|
|
143
|
-
get type() {
|
|
144
|
-
return getType();
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
return {
|
|
149
|
-
get content() {
|
|
150
|
-
return getContent();
|
|
151
|
-
},
|
|
152
|
-
get comments() {
|
|
153
|
-
return getComments();
|
|
154
|
-
},
|
|
155
|
-
get template() {
|
|
156
|
-
return getTemplate();
|
|
157
|
-
},
|
|
158
|
-
get script() {
|
|
159
|
-
return getScript();
|
|
160
|
-
},
|
|
161
|
-
get scriptSetup() {
|
|
162
|
-
return getScriptSetup();
|
|
163
|
-
},
|
|
164
|
-
get styles() {
|
|
165
|
-
return styles;
|
|
166
|
-
},
|
|
167
|
-
get customBlocks() {
|
|
168
|
-
return customBlocks;
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
function computedTemplateAst(base) {
|
|
172
|
-
let cache;
|
|
173
|
-
let inlineTsAsts;
|
|
174
|
-
function updateInlineTsAsts(newAst, oldAst) {
|
|
175
|
-
let newTsAsts = exports.templateInlineTsAsts.get(newAst);
|
|
176
|
-
if (!newTsAsts) {
|
|
177
|
-
exports.templateInlineTsAsts.set(newAst, newTsAsts = new Map());
|
|
178
|
-
}
|
|
179
|
-
const oldTsAsts = oldAst && exports.templateInlineTsAsts.get(oldAst) || inlineTsAsts;
|
|
180
|
-
if (oldTsAsts) {
|
|
181
|
-
for (const [text, ast] of oldTsAsts) {
|
|
182
|
-
if (!ast.__volar_used) {
|
|
183
|
-
oldTsAsts.delete(text);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
newTsAsts.set(text, ast);
|
|
187
|
-
ast.__volar_used = false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
inlineTsAsts = new Map(newTsAsts);
|
|
192
|
-
}
|
|
193
|
-
return (0, alien_signals_1.computed)(() => {
|
|
194
|
-
if (cache?.template === base.content) {
|
|
195
|
-
return {
|
|
196
|
-
errors: [],
|
|
197
|
-
warnings: [],
|
|
198
|
-
ast: cache.result.ast,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
// incremental update
|
|
202
|
-
if (cache?.plugin.updateSFCTemplate) {
|
|
203
|
-
const change = getUntrackedSnapshot().getChangeRange(cache.snapshot);
|
|
204
|
-
if (change) {
|
|
205
|
-
const pausedSub = (0, alien_signals_1.setActiveSub)(undefined);
|
|
206
|
-
const templateOffset = base.startTagEnd;
|
|
207
|
-
(0, alien_signals_1.setActiveSub)(pausedSub);
|
|
208
|
-
const newText = getUntrackedSnapshot().getText(change.span.start, change.span.start + change.newLength);
|
|
209
|
-
const newResult = cache.plugin.updateSFCTemplate(cache.result, {
|
|
210
|
-
start: change.span.start - templateOffset,
|
|
211
|
-
end: change.span.start + change.span.length - templateOffset,
|
|
212
|
-
newText,
|
|
213
|
-
});
|
|
214
|
-
if (newResult) {
|
|
215
|
-
updateInlineTsAsts(newResult.ast, cache.result.ast);
|
|
216
|
-
cache.template = base.content;
|
|
217
|
-
cache.snapshot = getUntrackedSnapshot();
|
|
218
|
-
cache.result = newResult;
|
|
219
|
-
return {
|
|
220
|
-
errors: [],
|
|
221
|
-
warnings: [],
|
|
222
|
-
ast: newResult.ast,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const errors = [];
|
|
228
|
-
const warnings = [];
|
|
229
|
-
const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset();
|
|
230
|
-
let options = {
|
|
231
|
-
onError: err => errors.push(err),
|
|
232
|
-
onWarn: err => warnings.push(err),
|
|
233
|
-
expressionPlugins: ['typescript'],
|
|
234
|
-
nodeTransforms,
|
|
235
|
-
directiveTransforms,
|
|
236
|
-
};
|
|
237
|
-
for (const plugin of plugins) {
|
|
238
|
-
if (plugin.resolveTemplateCompilerOptions) {
|
|
239
|
-
options = plugin.resolveTemplateCompilerOptions(options);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
for (const plugin of plugins) {
|
|
243
|
-
let result;
|
|
244
|
-
try {
|
|
245
|
-
result = plugin.compileSFCTemplate?.(base.lang, base.content, options);
|
|
246
|
-
if (result) {
|
|
247
|
-
updateInlineTsAsts(result.ast, cache?.result.ast);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
const err = e;
|
|
252
|
-
errors.push(err);
|
|
253
|
-
}
|
|
254
|
-
if (result || errors.length) {
|
|
255
|
-
if (result && !errors.length && !warnings.length) {
|
|
256
|
-
cache = {
|
|
257
|
-
template: base.content,
|
|
258
|
-
snapshot: getUntrackedSnapshot(),
|
|
259
|
-
result: result,
|
|
260
|
-
plugin,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
cache = undefined;
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
errors,
|
|
268
|
-
warnings,
|
|
269
|
-
ast: result?.ast,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return {
|
|
274
|
-
errors,
|
|
275
|
-
warnings,
|
|
276
|
-
ast: undefined,
|
|
277
|
-
};
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function computedNullableSfcBlock(name, defaultLang, getBlock, resolve) {
|
|
281
|
-
const hasBlock = (0, alien_signals_1.computed)(() => !!getBlock());
|
|
282
|
-
return (0, alien_signals_1.computed)(() => {
|
|
283
|
-
if (!hasBlock()) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const _block = (0, alien_signals_1.computed)(() => getBlock());
|
|
287
|
-
return resolve(_block, computedSfcBlock(name, defaultLang, _block));
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
function computedSfcBlock(name, defaultLang, getBlock) {
|
|
291
|
-
const getLang = (0, alien_signals_1.computed)(() => getBlock().lang ?? defaultLang);
|
|
292
|
-
const getAttrs = (0, alien_signals_1.computed)(() => getBlock().attrs); // TODO: computed it
|
|
293
|
-
const getContent = (0, alien_signals_1.computed)(() => getBlock().content);
|
|
294
|
-
const getStartTagEnd = (0, alien_signals_1.computed)(() => getBlock().loc.start.offset);
|
|
295
|
-
const getEndTagStart = (0, alien_signals_1.computed)(() => getBlock().loc.end.offset);
|
|
296
|
-
const getStart = (0, alien_signals_1.computed)(() => getUntrackedSnapshot().getText(0, getStartTagEnd()).lastIndexOf('<' + getBlock().type));
|
|
297
|
-
const getEnd = (0, alien_signals_1.computed)(() => getEndTagStart()
|
|
298
|
-
+ getUntrackedSnapshot().getText(getEndTagStart(), getUntrackedSnapshot().getLength()).indexOf('>') + 1);
|
|
299
|
-
return {
|
|
300
|
-
name,
|
|
301
|
-
get lang() {
|
|
302
|
-
return getLang();
|
|
303
|
-
},
|
|
304
|
-
get attrs() {
|
|
305
|
-
return getAttrs();
|
|
306
|
-
},
|
|
307
|
-
get content() {
|
|
308
|
-
return getContent();
|
|
309
|
-
},
|
|
310
|
-
get startTagEnd() {
|
|
311
|
-
return getStartTagEnd();
|
|
312
|
-
},
|
|
313
|
-
get endTagStart() {
|
|
314
|
-
return getEndTagStart();
|
|
315
|
-
},
|
|
316
|
-
get start() {
|
|
317
|
-
return getStart();
|
|
318
|
-
},
|
|
319
|
-
get end() {
|
|
320
|
-
return getEnd();
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function computedAttrValue(key, base, getBlock) {
|
|
325
|
-
return (0, alien_signals_1.computed)(() => {
|
|
326
|
-
const val = getBlock()[key];
|
|
327
|
-
if (typeof val === 'object') {
|
|
328
|
-
return {
|
|
329
|
-
...val,
|
|
330
|
-
offset: base.start + val.offset,
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
return val;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function mergeObject(a, b) {
|
|
338
|
-
return Object.defineProperties(a, Object.getOwnPropertyDescriptors(b));
|
|
339
|
-
}
|
|
340
|
-
//# sourceMappingURL=computedSfc.js.map
|