@vue/language-core 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/out/generators/script.d.ts +14 -0
- package/out/generators/script.js +881 -0
- package/out/generators/template.d.ts +16 -0
- package/out/generators/template.js +1389 -0
- package/out/index.d.ts +12 -0
- package/out/index.js +30 -0
- package/out/languageModule.d.ts +5 -0
- package/out/languageModule.js +91 -0
- package/out/parsers/scriptRanges.d.ts +15 -0
- package/out/parsers/scriptRanges.js +58 -0
- package/out/parsers/scriptSetupRanges.d.ts +32 -0
- package/out/parsers/scriptSetupRanges.js +295 -0
- package/out/plugins/file-html.d.ts +3 -0
- package/out/plugins/file-html.js +80 -0
- package/out/plugins/file-md.d.ts +3 -0
- package/out/plugins/file-md.js +62 -0
- package/out/plugins/file-vue.d.ts +3 -0
- package/out/plugins/file-vue.js +39 -0
- package/out/plugins/vue-sfc-customblocks.d.ts +3 -0
- package/out/plugins/vue-sfc-customblocks.js +31 -0
- package/out/plugins/vue-sfc-scripts.d.ts +3 -0
- package/out/plugins/vue-sfc-scripts.js +39 -0
- package/out/plugins/vue-sfc-styles.d.ts +3 -0
- package/out/plugins/vue-sfc-styles.js +31 -0
- package/out/plugins/vue-sfc-template.d.ts +3 -0
- package/out/plugins/vue-sfc-template.js +27 -0
- package/out/plugins/vue-template-html.d.ts +3 -0
- package/out/plugins/vue-template-html.js +165 -0
- package/out/plugins/vue-tsx.d.ts +14 -0
- package/out/plugins/vue-tsx.js +158 -0
- package/out/plugins.d.ts +23 -0
- package/out/plugins.js +52 -0
- package/out/sourceFile.d.ts +71 -0
- package/out/sourceFile.js +528 -0
- package/out/types.d.ts +100 -0
- package/out/types.js +3 -0
- package/out/utils/directorySharedTypes.d.ts +6 -0
- package/out/utils/directorySharedTypes.js +169 -0
- package/out/utils/parseCssClassNames.d.ts +4 -0
- package/out/utils/parseCssClassNames.js +19 -0
- package/out/utils/parseCssVars.d.ts +5 -0
- package/out/utils/parseCssVars.js +26 -0
- package/out/utils/parseSfc.d.ts +2 -0
- package/out/utils/parseSfc.js +135 -0
- package/out/utils/shared.d.ts +1 -0
- package/out/utils/shared.js +8 -0
- package/out/utils/transform.d.ts +8 -0
- package/out/utils/transform.js +182 -0
- package/out/utils/ts.d.ts +8 -0
- package/out/utils/ts.js +196 -0
- package/out/utils/vue2TemplateCompiler.d.ts +3 -0
- package/out/utils/vue2TemplateCompiler.js +101 -0
- package/package.json +29 -0
package/out/plugins.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultVueLanguagePlugins = void 0;
|
|
4
|
+
const useHtmlFilePlugin = require("./plugins/file-html");
|
|
5
|
+
const useMdFilePlugin = require("./plugins/file-md");
|
|
6
|
+
const useVueFilePlugin = require("./plugins/file-vue");
|
|
7
|
+
const useVueSfcCustomBlocks = require("./plugins/vue-sfc-customblocks");
|
|
8
|
+
const useVueSfcScriptsFormat = require("./plugins/vue-sfc-scripts");
|
|
9
|
+
const useVueSfcStyles = require("./plugins/vue-sfc-styles");
|
|
10
|
+
const useVueSfcTemplate = require("./plugins/vue-sfc-template");
|
|
11
|
+
const useHtmlTemplatePlugin = require("./plugins/vue-template-html");
|
|
12
|
+
const vue_tsx_1 = require("./plugins/vue-tsx");
|
|
13
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
14
|
+
const CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
|
15
|
+
function getDefaultVueLanguagePlugins(ts, compilerOptions, vueCompilerOptions) {
|
|
16
|
+
const plugins = [
|
|
17
|
+
useMdFilePlugin,
|
|
18
|
+
useHtmlFilePlugin,
|
|
19
|
+
useVueFilePlugin,
|
|
20
|
+
useHtmlTemplatePlugin,
|
|
21
|
+
useVueSfcStyles,
|
|
22
|
+
useVueSfcCustomBlocks,
|
|
23
|
+
useVueSfcScriptsFormat,
|
|
24
|
+
useVueSfcTemplate,
|
|
25
|
+
vue_tsx_1.default,
|
|
26
|
+
...vueCompilerOptions.plugins,
|
|
27
|
+
];
|
|
28
|
+
const pluginCtx = {
|
|
29
|
+
modules: {
|
|
30
|
+
'@vue/compiler-dom': vueCompilerOptions.target < 3 ? CompilerVue2 : CompilerDOM,
|
|
31
|
+
typescript: ts,
|
|
32
|
+
},
|
|
33
|
+
compilerOptions,
|
|
34
|
+
vueCompilerOptions,
|
|
35
|
+
};
|
|
36
|
+
const pluginInstances = plugins
|
|
37
|
+
.map(plugin => plugin(pluginCtx))
|
|
38
|
+
.sort((a, b) => {
|
|
39
|
+
const aOrder = a.order ?? 0;
|
|
40
|
+
const bOrder = b.order ?? 0;
|
|
41
|
+
return aOrder - bOrder;
|
|
42
|
+
});
|
|
43
|
+
return pluginInstances.filter((plugin) => {
|
|
44
|
+
const valid = plugin.version >= 1 && plugin.version < 2;
|
|
45
|
+
if (!valid) {
|
|
46
|
+
console.warn(`Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected 1.x but got ${JSON.stringify(plugin.version)}`);
|
|
47
|
+
}
|
|
48
|
+
return valid;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.getDefaultVueLanguagePlugins = getDefaultVueLanguagePlugins;
|
|
52
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FileCapabilities, VirtualFile, FileKind, FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
|
|
2
|
+
import { Mapping, Segment } from '@volar/source-map';
|
|
3
|
+
import * as CompilerDom from '@vue/compiler-dom';
|
|
4
|
+
import { SFCBlock, SFCParseResult, SFCScriptBlock, SFCStyleBlock, SFCTemplateBlock } from '@vue/compiler-sfc';
|
|
5
|
+
import { ComputedRef } from '@vue/reactivity';
|
|
6
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
7
|
+
import { Sfc, SfcBlock, VueLanguagePlugin } from './types';
|
|
8
|
+
export declare class VueEmbeddedFile {
|
|
9
|
+
fileName: string;
|
|
10
|
+
parentFileName?: string;
|
|
11
|
+
kind: FileKind;
|
|
12
|
+
capabilities: FileCapabilities;
|
|
13
|
+
content: Segment<FileRangeCapabilities>[];
|
|
14
|
+
mirrorBehaviorMappings: Mapping<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]>[];
|
|
15
|
+
constructor(fileName: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class VueFile implements VirtualFile {
|
|
18
|
+
fileName: string;
|
|
19
|
+
snapshot: ts.IScriptSnapshot;
|
|
20
|
+
private ts;
|
|
21
|
+
private plugins;
|
|
22
|
+
parsedSfcCache: {
|
|
23
|
+
snapshot: ts.IScriptSnapshot;
|
|
24
|
+
sfc: SFCParseResult;
|
|
25
|
+
plugin: ReturnType<VueLanguagePlugin>;
|
|
26
|
+
} | undefined;
|
|
27
|
+
compiledSFCTemplateCache: {
|
|
28
|
+
template: string;
|
|
29
|
+
snapshot: ts.IScriptSnapshot;
|
|
30
|
+
result: CompilerDom.CodegenResult;
|
|
31
|
+
plugin: ReturnType<VueLanguagePlugin>;
|
|
32
|
+
} | undefined;
|
|
33
|
+
capabilities: FileCapabilities;
|
|
34
|
+
kind: FileKind;
|
|
35
|
+
mappings: Mapping<FileRangeCapabilities>[];
|
|
36
|
+
get compiledSFCTemplate(): {
|
|
37
|
+
errors: CompilerDom.CompilerError[];
|
|
38
|
+
warnings: CompilerDom.CompilerError[];
|
|
39
|
+
ast: CompilerDom.RootNode | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
get mainScriptName(): string;
|
|
42
|
+
get embeddedFiles(): VirtualFile[];
|
|
43
|
+
parsedSfc: SFCParseResult | undefined;
|
|
44
|
+
sfc: Sfc;
|
|
45
|
+
_sfcBlocks: ComputedRef<Record<string, SfcBlock>>;
|
|
46
|
+
_compiledSfcTemplate: ComputedRef<{
|
|
47
|
+
errors: CompilerDom.CompilerError[];
|
|
48
|
+
warnings: CompilerDom.CompilerError[];
|
|
49
|
+
ast: CompilerDom.RootNode | undefined;
|
|
50
|
+
} | undefined>;
|
|
51
|
+
_pluginEmbeddedFiles: ComputedRef<{
|
|
52
|
+
file: VueEmbeddedFile;
|
|
53
|
+
snapshot: ts.IScriptSnapshot;
|
|
54
|
+
mappings: Mapping<FileRangeCapabilities>[];
|
|
55
|
+
}[]>[];
|
|
56
|
+
_allEmbeddedFiles: ComputedRef<{
|
|
57
|
+
file: VueEmbeddedFile;
|
|
58
|
+
snapshot: ts.IScriptSnapshot;
|
|
59
|
+
mappings: Mapping<FileRangeCapabilities>[];
|
|
60
|
+
}[]>;
|
|
61
|
+
_embeddedFiles: ComputedRef<VirtualFile[]>;
|
|
62
|
+
constructor(fileName: string, snapshot: ts.IScriptSnapshot, ts: typeof import('typescript/lib/tsserverlibrary'), plugins: ReturnType<VueLanguagePlugin>[]);
|
|
63
|
+
update(newScriptSnapshot: ts.IScriptSnapshot): void;
|
|
64
|
+
parseSfc(): SFCParseResult | undefined;
|
|
65
|
+
updateTemplate(block: SFCTemplateBlock | null): void;
|
|
66
|
+
updateScript(block: SFCScriptBlock | null): void;
|
|
67
|
+
updateScriptSetup(block: SFCScriptBlock | null): void;
|
|
68
|
+
updateStyles(blocks: SFCStyleBlock[]): void;
|
|
69
|
+
updateCustomBlocks(blocks: SFCBlock[]): void;
|
|
70
|
+
updateBlock<T extends object>(oldBlock: T, newBlock: T): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VueFile = exports.VueEmbeddedFile = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const source_map_1 = require("@volar/source-map");
|
|
6
|
+
const reactivity_1 = require("@vue/reactivity");
|
|
7
|
+
const muggle = require("muggle-string");
|
|
8
|
+
class VueEmbeddedFile {
|
|
9
|
+
constructor(fileName) {
|
|
10
|
+
this.fileName = fileName;
|
|
11
|
+
this.kind = language_core_1.FileKind.TextFile;
|
|
12
|
+
this.capabilities = {};
|
|
13
|
+
this.content = [];
|
|
14
|
+
this.mirrorBehaviorMappings = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.VueEmbeddedFile = VueEmbeddedFile;
|
|
18
|
+
class VueFile {
|
|
19
|
+
get compiledSFCTemplate() {
|
|
20
|
+
return this._compiledSfcTemplate.value;
|
|
21
|
+
}
|
|
22
|
+
get mainScriptName() {
|
|
23
|
+
return this._allEmbeddedFiles.value.find(e => e.file.fileName.replace(this.fileName, '').match(/^\.(js|ts)x?$/))?.file.fileName ?? '';
|
|
24
|
+
}
|
|
25
|
+
get embeddedFiles() {
|
|
26
|
+
return this._embeddedFiles.value;
|
|
27
|
+
}
|
|
28
|
+
// functions
|
|
29
|
+
constructor(fileName, snapshot, ts, plugins) {
|
|
30
|
+
this.fileName = fileName;
|
|
31
|
+
this.snapshot = snapshot;
|
|
32
|
+
this.ts = ts;
|
|
33
|
+
this.plugins = plugins;
|
|
34
|
+
this.capabilities = language_core_1.FileCapabilities.full;
|
|
35
|
+
this.kind = language_core_1.FileKind.TextFile;
|
|
36
|
+
this.mappings = [];
|
|
37
|
+
// refs
|
|
38
|
+
this.sfc = (0, reactivity_1.reactive)({
|
|
39
|
+
template: null,
|
|
40
|
+
script: null,
|
|
41
|
+
scriptSetup: null,
|
|
42
|
+
styles: [],
|
|
43
|
+
customBlocks: [],
|
|
44
|
+
templateAst: (0, reactivity_1.computed)(() => {
|
|
45
|
+
return this._compiledSfcTemplate.value?.ast;
|
|
46
|
+
}),
|
|
47
|
+
scriptAst: (0, reactivity_1.computed)(() => {
|
|
48
|
+
if (this.sfc.script) {
|
|
49
|
+
return this.ts.createSourceFile(this.fileName + '.' + this.sfc.script.lang, this.sfc.script.content, this.ts.ScriptTarget.Latest);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
scriptSetupAst: (0, reactivity_1.computed)(() => {
|
|
53
|
+
if (this.sfc.scriptSetup) {
|
|
54
|
+
return this.ts.createSourceFile(this.fileName + '.' + this.sfc.scriptSetup.lang, this.sfc.scriptSetup.content, this.ts.ScriptTarget.Latest);
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
...{
|
|
58
|
+
// backward compatible
|
|
59
|
+
getTemplateAst: () => {
|
|
60
|
+
return this.compiledSFCTemplate?.ast;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
}) /* avoid Sfc unwrap in .d.ts by reactive */;
|
|
64
|
+
// computed
|
|
65
|
+
this._sfcBlocks = (0, reactivity_1.computed)(() => {
|
|
66
|
+
const blocks = {};
|
|
67
|
+
if (this.sfc.template) {
|
|
68
|
+
blocks[this.sfc.template.name] = this.sfc.template;
|
|
69
|
+
}
|
|
70
|
+
if (this.sfc.script) {
|
|
71
|
+
blocks[this.sfc.script.name] = this.sfc.script;
|
|
72
|
+
}
|
|
73
|
+
if (this.sfc.scriptSetup) {
|
|
74
|
+
blocks[this.sfc.scriptSetup.name] = this.sfc.scriptSetup;
|
|
75
|
+
}
|
|
76
|
+
for (const block of this.sfc.styles) {
|
|
77
|
+
blocks[block.name] = block;
|
|
78
|
+
}
|
|
79
|
+
for (const block of this.sfc.customBlocks) {
|
|
80
|
+
blocks[block.name] = block;
|
|
81
|
+
}
|
|
82
|
+
return blocks;
|
|
83
|
+
});
|
|
84
|
+
this._compiledSfcTemplate = (0, reactivity_1.computed)(() => {
|
|
85
|
+
if (this.compiledSFCTemplateCache?.template === this.sfc.template?.content) {
|
|
86
|
+
return {
|
|
87
|
+
errors: [],
|
|
88
|
+
warnings: [],
|
|
89
|
+
ast: this.compiledSFCTemplateCache?.result.ast,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (this.sfc.template) {
|
|
93
|
+
// incremental update
|
|
94
|
+
if (this.compiledSFCTemplateCache?.plugin.updateSFCTemplate) {
|
|
95
|
+
const change = this.snapshot.getChangeRange(this.compiledSFCTemplateCache.snapshot);
|
|
96
|
+
if (change) {
|
|
97
|
+
(0, reactivity_1.pauseTracking)();
|
|
98
|
+
const templateOffset = this.sfc.template.startTagEnd;
|
|
99
|
+
(0, reactivity_1.resetTracking)();
|
|
100
|
+
const newText = this.snapshot.getText(change.span.start, change.span.start + change.newLength);
|
|
101
|
+
const newResult = this.compiledSFCTemplateCache.plugin.updateSFCTemplate(this.compiledSFCTemplateCache.result, {
|
|
102
|
+
start: change.span.start - templateOffset,
|
|
103
|
+
end: change.span.start + change.span.length - templateOffset,
|
|
104
|
+
newText,
|
|
105
|
+
});
|
|
106
|
+
if (newResult) {
|
|
107
|
+
this.compiledSFCTemplateCache.template = this.sfc.template.content;
|
|
108
|
+
this.compiledSFCTemplateCache.snapshot = this.snapshot;
|
|
109
|
+
this.compiledSFCTemplateCache.result = newResult;
|
|
110
|
+
return {
|
|
111
|
+
errors: [],
|
|
112
|
+
warnings: [],
|
|
113
|
+
ast: newResult.ast,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const errors = [];
|
|
119
|
+
const warnings = [];
|
|
120
|
+
let options = {
|
|
121
|
+
onError: (err) => errors.push(err),
|
|
122
|
+
onWarn: (err) => warnings.push(err),
|
|
123
|
+
expressionPlugins: ['typescript'],
|
|
124
|
+
};
|
|
125
|
+
for (const plugin of this.plugins) {
|
|
126
|
+
if (plugin.resolveTemplateCompilerOptions) {
|
|
127
|
+
options = plugin.resolveTemplateCompilerOptions(options);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const plugin of this.plugins) {
|
|
131
|
+
let result;
|
|
132
|
+
try {
|
|
133
|
+
result = plugin.compileSFCTemplate?.(this.sfc.template.lang, this.sfc.template.content, options);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
const err = e;
|
|
137
|
+
errors.push(err);
|
|
138
|
+
}
|
|
139
|
+
if (result || errors.length) {
|
|
140
|
+
if (result && !errors.length && !warnings.length) {
|
|
141
|
+
this.compiledSFCTemplateCache = {
|
|
142
|
+
template: this.sfc.template.content,
|
|
143
|
+
snapshot: this.snapshot,
|
|
144
|
+
result: result,
|
|
145
|
+
plugin,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.compiledSFCTemplateCache = undefined;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
errors,
|
|
153
|
+
warnings,
|
|
154
|
+
ast: result?.ast,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
this._pluginEmbeddedFiles = this.plugins.map((plugin) => {
|
|
161
|
+
const embeddedFiles = {};
|
|
162
|
+
const files = (0, reactivity_1.computed)(() => {
|
|
163
|
+
try {
|
|
164
|
+
if (plugin.getEmbeddedFileNames) {
|
|
165
|
+
const embeddedFileNames = plugin.getEmbeddedFileNames(this.fileName, this.sfc);
|
|
166
|
+
for (const oldFileName of Object.keys(embeddedFiles)) {
|
|
167
|
+
if (!embeddedFileNames.includes(oldFileName)) {
|
|
168
|
+
delete embeddedFiles[oldFileName];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const embeddedFileName of embeddedFileNames) {
|
|
172
|
+
if (!embeddedFiles[embeddedFileName]) {
|
|
173
|
+
embeddedFiles[embeddedFileName] = (0, reactivity_1.computed)(() => {
|
|
174
|
+
const file = new VueEmbeddedFile(embeddedFileName);
|
|
175
|
+
for (const plugin of this.plugins) {
|
|
176
|
+
if (plugin.resolveEmbeddedFile) {
|
|
177
|
+
try {
|
|
178
|
+
plugin.resolveEmbeddedFile(this.fileName, this.sfc, file);
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
console.error(e);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return file;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
console.error(e);
|
|
193
|
+
}
|
|
194
|
+
return Object.values(embeddedFiles);
|
|
195
|
+
});
|
|
196
|
+
return (0, reactivity_1.computed)(() => {
|
|
197
|
+
return files.value.map(_file => {
|
|
198
|
+
const file = _file.value;
|
|
199
|
+
const mappings = (0, source_map_1.buildMappings)(file.content);
|
|
200
|
+
for (const mapping of mappings) {
|
|
201
|
+
if (mapping.source !== undefined) {
|
|
202
|
+
const block = this._sfcBlocks.value[mapping.source];
|
|
203
|
+
if (block) {
|
|
204
|
+
mapping.sourceRange = [
|
|
205
|
+
mapping.sourceRange[0] + block.startTagEnd,
|
|
206
|
+
mapping.sourceRange[1] + block.startTagEnd,
|
|
207
|
+
];
|
|
208
|
+
mapping.source = undefined;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const newText = (0, source_map_1.toString)(file.content);
|
|
213
|
+
const changeRanges = new Map();
|
|
214
|
+
const snapshot = {
|
|
215
|
+
getText: (start, end) => newText.slice(start, end),
|
|
216
|
+
getLength: () => newText.length,
|
|
217
|
+
getChangeRange(oldSnapshot) {
|
|
218
|
+
if (!changeRanges.has(oldSnapshot)) {
|
|
219
|
+
changeRanges.set(oldSnapshot, undefined);
|
|
220
|
+
const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
|
|
221
|
+
for (let start = 0; start < oldText.length && start < newText.length; start++) {
|
|
222
|
+
if (oldText[start] !== newText[start]) {
|
|
223
|
+
let end = oldText.length;
|
|
224
|
+
for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
|
|
225
|
+
if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
end--;
|
|
229
|
+
}
|
|
230
|
+
let length = end - start;
|
|
231
|
+
let newLength = length + (newText.length - oldText.length);
|
|
232
|
+
if (newLength < 0) {
|
|
233
|
+
length -= newLength;
|
|
234
|
+
newLength = 0;
|
|
235
|
+
}
|
|
236
|
+
changeRanges.set(oldSnapshot, {
|
|
237
|
+
span: { start, length },
|
|
238
|
+
newLength,
|
|
239
|
+
});
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return changeRanges.get(oldSnapshot);
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
file,
|
|
249
|
+
snapshot,
|
|
250
|
+
mappings,
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
this._allEmbeddedFiles = (0, reactivity_1.computed)(() => {
|
|
256
|
+
const all = [];
|
|
257
|
+
for (const embeddedFiles of this._pluginEmbeddedFiles) {
|
|
258
|
+
for (const embedded of embeddedFiles.value) {
|
|
259
|
+
all.push(embedded);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return all;
|
|
263
|
+
});
|
|
264
|
+
this._embeddedFiles = (0, reactivity_1.computed)(() => {
|
|
265
|
+
const embeddedFiles = [];
|
|
266
|
+
let remain = [...this._allEmbeddedFiles.value];
|
|
267
|
+
while (remain.length) {
|
|
268
|
+
const beforeLength = remain.length;
|
|
269
|
+
consumeRemain();
|
|
270
|
+
if (beforeLength === remain.length) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (const { file, snapshot, mappings } of remain) {
|
|
275
|
+
embeddedFiles.push({
|
|
276
|
+
...file,
|
|
277
|
+
snapshot,
|
|
278
|
+
mappings,
|
|
279
|
+
embeddedFiles: [],
|
|
280
|
+
});
|
|
281
|
+
console.error('Unable to resolve embedded: ' + file.parentFileName + ' -> ' + file.fileName);
|
|
282
|
+
}
|
|
283
|
+
return embeddedFiles;
|
|
284
|
+
function consumeRemain() {
|
|
285
|
+
for (let i = remain.length - 1; i >= 0; i--) {
|
|
286
|
+
const { file, snapshot, mappings } = remain[i];
|
|
287
|
+
if (!file.parentFileName) {
|
|
288
|
+
embeddedFiles.push({
|
|
289
|
+
...file,
|
|
290
|
+
snapshot,
|
|
291
|
+
mappings,
|
|
292
|
+
embeddedFiles: [],
|
|
293
|
+
});
|
|
294
|
+
remain.splice(i, 1);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const parent = findParentStructure(file.parentFileName, embeddedFiles);
|
|
298
|
+
if (parent) {
|
|
299
|
+
parent.embeddedFiles.push({
|
|
300
|
+
...file,
|
|
301
|
+
snapshot,
|
|
302
|
+
mappings,
|
|
303
|
+
embeddedFiles: [],
|
|
304
|
+
});
|
|
305
|
+
remain.splice(i, 1);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function findParentStructure(fileName, current) {
|
|
311
|
+
for (const child of current) {
|
|
312
|
+
if (child.fileName === fileName) {
|
|
313
|
+
return child;
|
|
314
|
+
}
|
|
315
|
+
let parent = findParentStructure(fileName, child.embeddedFiles);
|
|
316
|
+
if (parent) {
|
|
317
|
+
return parent;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
this.update(snapshot);
|
|
323
|
+
}
|
|
324
|
+
update(newScriptSnapshot) {
|
|
325
|
+
this.snapshot = newScriptSnapshot;
|
|
326
|
+
this.parsedSfc = this.parseSfc();
|
|
327
|
+
if (this.parsedSfc) {
|
|
328
|
+
this.updateTemplate(this.parsedSfc.descriptor.template);
|
|
329
|
+
this.updateScript(this.parsedSfc.descriptor.script);
|
|
330
|
+
this.updateScriptSetup(this.parsedSfc.descriptor.scriptSetup);
|
|
331
|
+
this.updateStyles(this.parsedSfc.descriptor.styles);
|
|
332
|
+
this.updateCustomBlocks(this.parsedSfc.descriptor.customBlocks);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
this.updateTemplate(null);
|
|
336
|
+
this.updateScript(null);
|
|
337
|
+
this.updateScriptSetup(null);
|
|
338
|
+
this.updateStyles([]);
|
|
339
|
+
this.updateCustomBlocks([]);
|
|
340
|
+
}
|
|
341
|
+
const str = [[this.snapshot.getText(0, this.snapshot.getLength()), undefined, 0, language_core_1.FileRangeCapabilities.full]];
|
|
342
|
+
for (const block of [
|
|
343
|
+
this.sfc.script,
|
|
344
|
+
this.sfc.scriptSetup,
|
|
345
|
+
this.sfc.template,
|
|
346
|
+
...this.sfc.styles,
|
|
347
|
+
...this.sfc.customBlocks,
|
|
348
|
+
]) {
|
|
349
|
+
if (block) {
|
|
350
|
+
muggle.replaceSourceRange(str, undefined, block.startTagEnd, block.endTagStart, [
|
|
351
|
+
block.content,
|
|
352
|
+
undefined,
|
|
353
|
+
block.startTagEnd,
|
|
354
|
+
block.name === 'template'
|
|
355
|
+
? { completion: true } // fix vue-autoinsert-parentheses not working
|
|
356
|
+
: {},
|
|
357
|
+
]);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
this.mappings = str.map((m) => {
|
|
361
|
+
const text = m[0];
|
|
362
|
+
const start = m[2];
|
|
363
|
+
const end = start + text.length;
|
|
364
|
+
return {
|
|
365
|
+
sourceRange: [start, end],
|
|
366
|
+
generatedRange: [start, end],
|
|
367
|
+
data: m[3],
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
parseSfc() {
|
|
372
|
+
// incremental update
|
|
373
|
+
if (this.parsedSfcCache?.plugin.updateSFC) {
|
|
374
|
+
const change = this.snapshot.getChangeRange(this.parsedSfcCache.snapshot);
|
|
375
|
+
if (change) {
|
|
376
|
+
const newSfc = this.parsedSfcCache.plugin.updateSFC(this.parsedSfcCache.sfc, {
|
|
377
|
+
start: change.span.start,
|
|
378
|
+
end: change.span.start + change.span.length,
|
|
379
|
+
newText: this.snapshot.getText(change.span.start, change.span.start + change.newLength),
|
|
380
|
+
});
|
|
381
|
+
if (newSfc) {
|
|
382
|
+
this.parsedSfcCache.snapshot = this.snapshot;
|
|
383
|
+
this.parsedSfcCache.sfc = newSfc;
|
|
384
|
+
return newSfc;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
for (const plugin of this.plugins) {
|
|
389
|
+
const sfc = plugin.parseSFC?.(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()));
|
|
390
|
+
if (sfc) {
|
|
391
|
+
if (!sfc.errors.length) {
|
|
392
|
+
this.parsedSfcCache = {
|
|
393
|
+
snapshot: this.snapshot,
|
|
394
|
+
sfc,
|
|
395
|
+
plugin,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
return sfc;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
updateTemplate(block) {
|
|
403
|
+
const newData = block ? {
|
|
404
|
+
name: 'template',
|
|
405
|
+
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<' + block.type),
|
|
406
|
+
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
|
|
407
|
+
startTagEnd: block.loc.start.offset,
|
|
408
|
+
endTagStart: block.loc.end.offset,
|
|
409
|
+
content: block.content,
|
|
410
|
+
lang: block.lang ?? 'html',
|
|
411
|
+
attrs: block.attrs,
|
|
412
|
+
} : null;
|
|
413
|
+
if (this.sfc.template && newData) {
|
|
414
|
+
this.updateBlock(this.sfc.template, newData);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
this.sfc.template = newData;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
updateScript(block) {
|
|
421
|
+
const newData = block ? {
|
|
422
|
+
name: 'script',
|
|
423
|
+
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<' + block.type),
|
|
424
|
+
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
|
|
425
|
+
startTagEnd: block.loc.start.offset,
|
|
426
|
+
endTagStart: block.loc.end.offset,
|
|
427
|
+
content: block.content,
|
|
428
|
+
lang: block.lang ?? 'js',
|
|
429
|
+
src: block.src,
|
|
430
|
+
srcOffset: block.src ? this.snapshot.getText(0, block.loc.start.offset).lastIndexOf(block.src) - block.loc.start.offset : -1,
|
|
431
|
+
attrs: block.attrs,
|
|
432
|
+
} : null;
|
|
433
|
+
if (this.sfc.script && newData) {
|
|
434
|
+
this.updateBlock(this.sfc.script, newData);
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
this.sfc.script = newData;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
updateScriptSetup(block) {
|
|
441
|
+
const newData = block ? {
|
|
442
|
+
name: 'scriptSetup',
|
|
443
|
+
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<' + block.type),
|
|
444
|
+
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
|
|
445
|
+
startTagEnd: block.loc.start.offset,
|
|
446
|
+
endTagStart: block.loc.end.offset,
|
|
447
|
+
content: block.content,
|
|
448
|
+
lang: block.lang ?? 'js',
|
|
449
|
+
generic: typeof block.attrs.generic === 'string' ? block.attrs.generic : undefined,
|
|
450
|
+
genericOffset: typeof block.attrs.generic === 'string' ? this.snapshot.getText(0, block.loc.start.offset).lastIndexOf(block.attrs.generic) - block.loc.start.offset : -1,
|
|
451
|
+
attrs: block.attrs,
|
|
452
|
+
} : null;
|
|
453
|
+
if (this.sfc.scriptSetup && newData) {
|
|
454
|
+
this.updateBlock(this.sfc.scriptSetup, newData);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
this.sfc.scriptSetup = newData;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
updateStyles(blocks) {
|
|
461
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
462
|
+
const block = blocks[i];
|
|
463
|
+
const newData = {
|
|
464
|
+
name: 'style_' + i,
|
|
465
|
+
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<' + block.type),
|
|
466
|
+
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
|
|
467
|
+
startTagEnd: block.loc.start.offset,
|
|
468
|
+
endTagStart: block.loc.end.offset,
|
|
469
|
+
content: block.content,
|
|
470
|
+
lang: block.lang ?? 'css',
|
|
471
|
+
module: typeof block.module === 'string' ? block.module : block.module ? '$style' : undefined,
|
|
472
|
+
scoped: !!block.scoped,
|
|
473
|
+
attrs: block.attrs,
|
|
474
|
+
};
|
|
475
|
+
if (this.sfc.styles.length > i) {
|
|
476
|
+
this.updateBlock(this.sfc.styles[i], newData);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
this.sfc.styles.push(newData);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
while (this.sfc.styles.length > blocks.length) {
|
|
483
|
+
this.sfc.styles.pop();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
updateCustomBlocks(blocks) {
|
|
487
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
488
|
+
const block = blocks[i];
|
|
489
|
+
const newData = {
|
|
490
|
+
name: 'customBlock_' + i,
|
|
491
|
+
start: this.snapshot.getText(0, block.loc.start.offset).lastIndexOf('<' + block.type),
|
|
492
|
+
end: block.loc.end.offset + this.snapshot.getText(block.loc.end.offset, this.snapshot.getLength()).indexOf('>') + 1,
|
|
493
|
+
startTagEnd: block.loc.start.offset,
|
|
494
|
+
endTagStart: block.loc.end.offset,
|
|
495
|
+
content: block.content,
|
|
496
|
+
lang: block.lang ?? 'txt',
|
|
497
|
+
type: block.type,
|
|
498
|
+
attrs: block.attrs,
|
|
499
|
+
};
|
|
500
|
+
if (this.sfc.customBlocks.length > i) {
|
|
501
|
+
this.updateBlock(this.sfc.customBlocks[i], newData);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
this.sfc.customBlocks.push(newData);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
while (this.sfc.customBlocks.length > blocks.length) {
|
|
508
|
+
this.sfc.customBlocks.pop();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
updateBlock(oldBlock, newBlock) {
|
|
512
|
+
for (const key in newBlock) {
|
|
513
|
+
if (typeof oldBlock[key] === 'object' && typeof newBlock[key] === 'object') {
|
|
514
|
+
this.updateBlock(oldBlock[key], newBlock[key]);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
oldBlock[key] = newBlock[key];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const key in oldBlock) {
|
|
521
|
+
if (!(key in newBlock)) {
|
|
522
|
+
delete oldBlock[key];
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
exports.VueFile = VueFile;
|
|
528
|
+
//# sourceMappingURL=sourceFile.js.map
|