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