@vue/language-core 1.8.19 → 1.8.20
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/out/generators/script.d.ts +2 -1
- package/out/generators/script.js +111 -93
- package/out/generators/template.d.ts +1 -1
- package/out/generators/template.js +52 -58
- package/out/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/languageModule.d.ts +1 -1
- package/out/languageModule.js +2 -2
- package/out/plugins/vue-tsx.d.ts +9 -9
- package/out/plugins/vue-tsx.js +48 -28
- package/out/plugins.d.ts +1 -1
- package/out/types.d.ts +21 -6
- package/out/utils/globalTypes.js +7 -0
- package/out/utils/transform.d.ts +1 -1
- package/out/utils/transform.js +8 -8
- package/out/virtualFile/computedFiles.d.ts +4 -0
- package/out/virtualFile/computedFiles.js +227 -0
- package/out/virtualFile/computedMappings.d.ts +6 -0
- package/out/virtualFile/computedMappings.js +62 -0
- package/out/virtualFile/computedSfc.d.ts +5 -0
- package/out/virtualFile/computedSfc.js +197 -0
- package/out/virtualFile/computedVueSfc.d.ts +5 -0
- package/out/virtualFile/computedVueSfc.js +41 -0
- package/out/virtualFile/embeddedFile.d.ts +13 -0
- package/out/virtualFile/embeddedFile.js +16 -0
- package/out/virtualFile/vueFile.d.ts +28 -0
- package/out/virtualFile/vueFile.js +53 -0
- package/package.json +3 -3
- package/out/sourceFile.d.ts +0 -79
- package/out/sourceFile.js +0 -527
package/out/utils/transform.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.collectVars = exports.walkInterpolationFragment = void 0;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
function walkInterpolationFragment(ts, code, ast, cb, localVars, identifiers, vueOptions) {
|
|
6
6
|
let ctxVars = [];
|
|
@@ -99,7 +99,7 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
99
99
|
walkIdentifiers(ts, node.expression, cb, localVars, blockVars, false);
|
|
100
100
|
}
|
|
101
101
|
else if (ts.isVariableDeclaration(node)) {
|
|
102
|
-
|
|
102
|
+
collectVars(ts, node.name, blockVars);
|
|
103
103
|
for (const varName of blockVars) {
|
|
104
104
|
localVars.set(varName, (localVars.get(varName) ?? 0) + 1);
|
|
105
105
|
}
|
|
@@ -109,7 +109,7 @@ function walkIdentifiers(ts, node, cb, localVars, blockVars = [], isRoot = true)
|
|
|
109
109
|
else if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
110
110
|
const functionArgs = [];
|
|
111
111
|
for (const param of node.parameters) {
|
|
112
|
-
|
|
112
|
+
collectVars(ts, param.name, functionArgs);
|
|
113
113
|
if (param.type) {
|
|
114
114
|
walkIdentifiers(ts, param.type, cb, localVars, blockVars, false);
|
|
115
115
|
}
|
|
@@ -171,25 +171,25 @@ function walkIdentifiersInTypeReference(ts, node, cb) {
|
|
|
171
171
|
node.forEachChild(node => walkIdentifiersInTypeReference(ts, node, cb));
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function collectVars(ts, node, result) {
|
|
175
175
|
if (ts.isIdentifier(node)) {
|
|
176
176
|
result.push(node.text);
|
|
177
177
|
}
|
|
178
178
|
else if (ts.isObjectBindingPattern(node)) {
|
|
179
179
|
for (const el of node.elements) {
|
|
180
|
-
|
|
180
|
+
collectVars(ts, el.name, result);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
else if (ts.isArrayBindingPattern(node)) {
|
|
184
184
|
for (const el of node.elements) {
|
|
185
185
|
if (ts.isBindingElement(el)) {
|
|
186
|
-
|
|
186
|
+
collectVars(ts, el.name, result);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
else {
|
|
191
|
-
node.forEachChild(node =>
|
|
191
|
+
node.forEachChild(node => collectVars(ts, node, result));
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
exports.
|
|
194
|
+
exports.collectVars = collectVars;
|
|
195
195
|
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { VirtualFile } from '@volar/language-core';
|
|
2
|
+
import type { Sfc, VueLanguagePlugin } from '../types';
|
|
3
|
+
export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc, codegenStack: boolean): () => VirtualFile[];
|
|
4
|
+
//# sourceMappingURL=computedFiles.d.ts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.computedFiles = void 0;
|
|
27
|
+
const source_map_1 = require("@volar/source-map");
|
|
28
|
+
const muggle = __importStar(require("muggle-string"));
|
|
29
|
+
const embeddedFile_1 = require("./embeddedFile");
|
|
30
|
+
const computeds_1 = require("computeds");
|
|
31
|
+
function computedFiles(plugins, fileName, sfc, codegenStack) {
|
|
32
|
+
const nameToBlock = (0, computeds_1.computed)(() => {
|
|
33
|
+
const blocks = {};
|
|
34
|
+
if (sfc.template) {
|
|
35
|
+
blocks[sfc.template.name] = sfc.template;
|
|
36
|
+
}
|
|
37
|
+
if (sfc.script) {
|
|
38
|
+
blocks[sfc.script.name] = sfc.script;
|
|
39
|
+
}
|
|
40
|
+
if (sfc.scriptSetup) {
|
|
41
|
+
blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
|
|
42
|
+
}
|
|
43
|
+
for (const block of sfc.styles) {
|
|
44
|
+
blocks[block.name] = block;
|
|
45
|
+
}
|
|
46
|
+
for (const block of sfc.customBlocks) {
|
|
47
|
+
blocks[block.name] = block;
|
|
48
|
+
}
|
|
49
|
+
return blocks;
|
|
50
|
+
});
|
|
51
|
+
const pluginsResult = plugins.map(plugin => compiledPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack));
|
|
52
|
+
const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
|
|
53
|
+
const structuredResult = (0, computeds_1.computed)(() => {
|
|
54
|
+
const embeddedFiles = [];
|
|
55
|
+
let remain = [...flatResult()];
|
|
56
|
+
while (remain.length) {
|
|
57
|
+
const beforeLength = remain.length;
|
|
58
|
+
consumeRemain();
|
|
59
|
+
if (beforeLength === remain.length) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const { file, snapshot, mappings, codegenStacks } of remain) {
|
|
64
|
+
embeddedFiles.push({
|
|
65
|
+
...file,
|
|
66
|
+
snapshot,
|
|
67
|
+
mappings,
|
|
68
|
+
codegenStacks,
|
|
69
|
+
embeddedFiles: [],
|
|
70
|
+
});
|
|
71
|
+
console.error('Unable to resolve embedded: ' + file.parentFileName + ' -> ' + file.fileName);
|
|
72
|
+
}
|
|
73
|
+
return embeddedFiles;
|
|
74
|
+
function consumeRemain() {
|
|
75
|
+
for (let i = remain.length - 1; i >= 0; i--) {
|
|
76
|
+
const { file, snapshot, mappings, codegenStacks } = remain[i];
|
|
77
|
+
if (!file.parentFileName) {
|
|
78
|
+
embeddedFiles.push({
|
|
79
|
+
...file,
|
|
80
|
+
snapshot,
|
|
81
|
+
mappings,
|
|
82
|
+
codegenStacks,
|
|
83
|
+
embeddedFiles: [],
|
|
84
|
+
});
|
|
85
|
+
remain.splice(i, 1);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const parent = findParentStructure(file.parentFileName, embeddedFiles);
|
|
89
|
+
if (parent) {
|
|
90
|
+
parent.embeddedFiles.push({
|
|
91
|
+
...file,
|
|
92
|
+
snapshot,
|
|
93
|
+
mappings,
|
|
94
|
+
codegenStacks,
|
|
95
|
+
embeddedFiles: [],
|
|
96
|
+
});
|
|
97
|
+
remain.splice(i, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function findParentStructure(fileName, current) {
|
|
103
|
+
for (const child of current) {
|
|
104
|
+
if (child.fileName === fileName) {
|
|
105
|
+
return child;
|
|
106
|
+
}
|
|
107
|
+
let parent = findParentStructure(fileName, child.embeddedFiles);
|
|
108
|
+
if (parent) {
|
|
109
|
+
return parent;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return structuredResult;
|
|
115
|
+
}
|
|
116
|
+
exports.computedFiles = computedFiles;
|
|
117
|
+
function compiledPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack) {
|
|
118
|
+
const embeddedFiles = {};
|
|
119
|
+
const files = (0, computeds_1.computed)(() => {
|
|
120
|
+
try {
|
|
121
|
+
if (!plugin.getEmbeddedFileNames) {
|
|
122
|
+
return Object.values(embeddedFiles);
|
|
123
|
+
}
|
|
124
|
+
const embeddedFileNames = plugin.getEmbeddedFileNames(fileName, sfc);
|
|
125
|
+
for (const oldFileName of Object.keys(embeddedFiles)) {
|
|
126
|
+
if (!embeddedFileNames.includes(oldFileName)) {
|
|
127
|
+
delete embeddedFiles[oldFileName];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const embeddedFileName of embeddedFileNames) {
|
|
131
|
+
if (!embeddedFiles[embeddedFileName]) {
|
|
132
|
+
embeddedFiles[embeddedFileName] = (0, computeds_1.computed)(() => {
|
|
133
|
+
const [content, stacks] = codegenStack ? muggle.track([]) : [[], []];
|
|
134
|
+
const file = new embeddedFile_1.VueEmbeddedFile(embeddedFileName, content, stacks);
|
|
135
|
+
for (const plugin of plugins) {
|
|
136
|
+
if (!plugin.resolveEmbeddedFile) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
plugin.resolveEmbeddedFile(fileName, sfc, file);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.error(e);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const newText = (0, source_map_1.toString)(file.content);
|
|
147
|
+
const changeRanges = new Map();
|
|
148
|
+
const snapshot = {
|
|
149
|
+
getText: (start, end) => newText.slice(start, end),
|
|
150
|
+
getLength: () => newText.length,
|
|
151
|
+
getChangeRange(oldSnapshot) {
|
|
152
|
+
if (!changeRanges.has(oldSnapshot)) {
|
|
153
|
+
changeRanges.set(oldSnapshot, undefined);
|
|
154
|
+
const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
155
|
+
const changeRange = fullDiffTextChangeRange(oldText, newText);
|
|
156
|
+
if (changeRange) {
|
|
157
|
+
changeRanges.set(oldSnapshot, changeRange);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return changeRanges.get(oldSnapshot);
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
file,
|
|
165
|
+
snapshot,
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
console.error(e);
|
|
173
|
+
}
|
|
174
|
+
return Object.values(embeddedFiles);
|
|
175
|
+
});
|
|
176
|
+
return (0, computeds_1.computed)(() => {
|
|
177
|
+
return files().map(_file => {
|
|
178
|
+
const { file, snapshot } = _file();
|
|
179
|
+
const mappings = (0, source_map_1.buildMappings)(file.content);
|
|
180
|
+
for (const mapping of mappings) {
|
|
181
|
+
if (mapping.source !== undefined) {
|
|
182
|
+
const block = nameToBlock()[mapping.source];
|
|
183
|
+
if (block) {
|
|
184
|
+
mapping.sourceRange = [
|
|
185
|
+
mapping.sourceRange[0] + block.startTagEnd,
|
|
186
|
+
mapping.sourceRange[1] + block.startTagEnd,
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// ignore
|
|
191
|
+
}
|
|
192
|
+
mapping.source = undefined;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
file,
|
|
197
|
+
snapshot,
|
|
198
|
+
mappings,
|
|
199
|
+
codegenStacks: (0, source_map_1.buildStacks)(file.content, file.contentStacks),
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function fullDiffTextChangeRange(oldText, newText) {
|
|
205
|
+
for (let start = 0; start < oldText.length && start < newText.length; start++) {
|
|
206
|
+
if (oldText[start] !== newText[start]) {
|
|
207
|
+
let end = oldText.length;
|
|
208
|
+
for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
|
|
209
|
+
if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
end--;
|
|
213
|
+
}
|
|
214
|
+
let length = end - start;
|
|
215
|
+
let newLength = length + (newText.length - oldText.length);
|
|
216
|
+
if (newLength < 0) {
|
|
217
|
+
length -= newLength;
|
|
218
|
+
newLength = 0;
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
span: { start, length },
|
|
222
|
+
newLength,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=computedFiles.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileRangeCapabilities } from '@volar/language-core';
|
|
2
|
+
import { Mapping } from '@volar/source-map';
|
|
3
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import { Sfc } from '../types';
|
|
5
|
+
export declare function computedMappings(snapshot: () => ts.IScriptSnapshot, sfc: Sfc): () => Mapping<FileRangeCapabilities>[];
|
|
6
|
+
//# sourceMappingURL=computedMappings.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.computedMappings = void 0;
|
|
27
|
+
const language_core_1 = require("@volar/language-core");
|
|
28
|
+
const muggle = __importStar(require("muggle-string"));
|
|
29
|
+
const computeds_1 = require("computeds");
|
|
30
|
+
function computedMappings(snapshot, sfc) {
|
|
31
|
+
return (0, computeds_1.computed)(() => {
|
|
32
|
+
const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, language_core_1.FileRangeCapabilities.full]];
|
|
33
|
+
for (const block of [
|
|
34
|
+
sfc.script,
|
|
35
|
+
sfc.scriptSetup,
|
|
36
|
+
sfc.template,
|
|
37
|
+
...sfc.styles,
|
|
38
|
+
...sfc.customBlocks,
|
|
39
|
+
]) {
|
|
40
|
+
if (block) {
|
|
41
|
+
muggle.replaceSourceRange(str, undefined, block.startTagEnd, block.endTagStart, [
|
|
42
|
+
block.content,
|
|
43
|
+
undefined,
|
|
44
|
+
block.startTagEnd,
|
|
45
|
+
{},
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return str.map((m) => {
|
|
50
|
+
const text = m[0];
|
|
51
|
+
const start = m[2];
|
|
52
|
+
const end = start + text.length;
|
|
53
|
+
return {
|
|
54
|
+
sourceRange: [start, end],
|
|
55
|
+
generatedRange: [start, end],
|
|
56
|
+
data: m[3],
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.computedMappings = computedMappings;
|
|
62
|
+
//# sourceMappingURL=computedMappings.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import { Sfc, VueLanguagePlugin } from '../types';
|
|
4
|
+
export declare function computedSfc(ts: typeof import('typescript/lib/tsserverlibrary'), plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot, parsed: () => SFCParseResult | undefined): Sfc;
|
|
5
|
+
//# sourceMappingURL=computedSfc.d.ts.map
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computedSfc = void 0;
|
|
4
|
+
const parseCssClassNames_1 = require("../utils/parseCssClassNames");
|
|
5
|
+
const parseCssVars_1 = require("../utils/parseCssVars");
|
|
6
|
+
const computeds_1 = require("computeds");
|
|
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, ts.ScriptTarget.Latest));
|
|
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, ts.ScriptTarget.Latest));
|
|
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,5 @@
|
|
|
1
|
+
import type { SFCParseResult } from '@vue/compiler-sfc';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import { VueLanguagePlugin } from '../types';
|
|
4
|
+
export declare function computedVueSfc(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, snapshot: () => ts.IScriptSnapshot): () => SFCParseResult | undefined;
|
|
5
|
+
//# sourceMappingURL=computedVueSfc.d.ts.map
|
|
@@ -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,13 @@
|
|
|
1
|
+
import { FileCapabilities, FileKind, FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
|
|
2
|
+
import { Mapping, Segment, StackNode } from '@volar/source-map';
|
|
3
|
+
export declare class VueEmbeddedFile {
|
|
4
|
+
fileName: string;
|
|
5
|
+
content: Segment<FileRangeCapabilities>[];
|
|
6
|
+
contentStacks: StackNode[];
|
|
7
|
+
parentFileName?: string;
|
|
8
|
+
kind: FileKind;
|
|
9
|
+
capabilities: FileCapabilities;
|
|
10
|
+
mirrorBehaviorMappings: Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
|
|
11
|
+
constructor(fileName: string, content: Segment<FileRangeCapabilities>[], contentStacks: StackNode[]);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=embeddedFile.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueEmbeddedFile = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
class VueEmbeddedFile {
|
|
6
|
+
constructor(fileName, content, contentStacks) {
|
|
7
|
+
this.fileName = fileName;
|
|
8
|
+
this.content = content;
|
|
9
|
+
this.contentStacks = contentStacks;
|
|
10
|
+
this.kind = language_core_1.FileKind.TextFile;
|
|
11
|
+
this.capabilities = {};
|
|
12
|
+
this.mirrorBehaviorMappings = [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.VueEmbeddedFile = VueEmbeddedFile;
|
|
16
|
+
//# sourceMappingURL=embeddedFile.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FileCapabilities, FileKind, VirtualFile } from '@volar/language-core';
|
|
2
|
+
import { Stack } from '@volar/source-map';
|
|
3
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import { VueCompilerOptions, VueLanguagePlugin } from '../types';
|
|
5
|
+
import { Signal } from 'computeds';
|
|
6
|
+
export declare class VueFile implements VirtualFile {
|
|
7
|
+
fileName: string;
|
|
8
|
+
initSnapshot: ts.IScriptSnapshot;
|
|
9
|
+
vueCompilerOptions: VueCompilerOptions;
|
|
10
|
+
plugins: ReturnType<VueLanguagePlugin>[];
|
|
11
|
+
ts: typeof import('typescript/lib/tsserverlibrary');
|
|
12
|
+
codegenStack: boolean;
|
|
13
|
+
_snapshot: Signal<ts.IScriptSnapshot>;
|
|
14
|
+
getVueSfc: () => import("@vue/compiler-sfc").SFCParseResult | undefined;
|
|
15
|
+
sfc: import("../types").Sfc;
|
|
16
|
+
getMappings: () => import("@volar/source-map").Mapping<import("@volar/language-core").FileRangeCapabilities>[];
|
|
17
|
+
getMmbeddedFiles: () => VirtualFile[];
|
|
18
|
+
capabilities: FileCapabilities;
|
|
19
|
+
kind: FileKind;
|
|
20
|
+
codegenStacks: Stack[];
|
|
21
|
+
get embeddedFiles(): VirtualFile[];
|
|
22
|
+
get mainScriptName(): string;
|
|
23
|
+
get snapshot(): ts.IScriptSnapshot;
|
|
24
|
+
get mappings(): import("@volar/source-map").Mapping<import("@volar/language-core").FileRangeCapabilities>[];
|
|
25
|
+
constructor(fileName: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript/lib/tsserverlibrary'), codegenStack: boolean);
|
|
26
|
+
update(newSnapshot: ts.IScriptSnapshot): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=vueFile.d.ts.map
|