@vue/language-core 1.9.0-alpha.2 → 2.0.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.
Files changed (63) hide show
  1. package/package.json +6 -9
  2. package/out/generators/script.d.ts +0 -15
  3. package/out/generators/script.js +0 -887
  4. package/out/generators/template.d.ts +0 -21
  5. package/out/generators/template.js +0 -1506
  6. package/out/index.d.ts +0 -16
  7. package/out/index.js +0 -33
  8. package/out/languageModule.d.ts +0 -10
  9. package/out/languageModule.js +0 -99
  10. package/out/parsers/scriptRanges.d.ts +0 -16
  11. package/out/parsers/scriptRanges.js +0 -58
  12. package/out/parsers/scriptSetupRanges.d.ts +0 -49
  13. package/out/parsers/scriptSetupRanges.js +0 -291
  14. package/out/plugins/file-html.d.ts +0 -4
  15. package/out/plugins/file-html.js +0 -81
  16. package/out/plugins/file-md.d.ts +0 -4
  17. package/out/plugins/file-md.js +0 -71
  18. package/out/plugins/file-vue.d.ts +0 -4
  19. package/out/plugins/file-vue.js +0 -40
  20. package/out/plugins/vue-sfc-customblocks.d.ts +0 -4
  21. package/out/plugins/vue-sfc-customblocks.js +0 -33
  22. package/out/plugins/vue-sfc-scripts.d.ts +0 -4
  23. package/out/plugins/vue-sfc-scripts.js +0 -42
  24. package/out/plugins/vue-sfc-styles.d.ts +0 -4
  25. package/out/plugins/vue-sfc-styles.js +0 -33
  26. package/out/plugins/vue-sfc-template.d.ts +0 -4
  27. package/out/plugins/vue-sfc-template.js +0 -29
  28. package/out/plugins/vue-template-html.d.ts +0 -4
  29. package/out/plugins/vue-template-html.js +0 -169
  30. package/out/plugins/vue-tsx.d.ts +0 -73
  31. package/out/plugins/vue-tsx.js +0 -159
  32. package/out/plugins.d.ts +0 -25
  33. package/out/plugins.js +0 -58
  34. package/out/types.d.ts +0 -125
  35. package/out/types.js +0 -3
  36. package/out/utils/globalTypes.d.ts +0 -4
  37. package/out/utils/globalTypes.js +0 -135
  38. package/out/utils/parseCssClassNames.d.ts +0 -5
  39. package/out/utils/parseCssClassNames.js +0 -19
  40. package/out/utils/parseCssVars.d.ts +0 -6
  41. package/out/utils/parseCssVars.js +0 -28
  42. package/out/utils/parseSfc.d.ts +0 -3
  43. package/out/utils/parseSfc.js +0 -135
  44. package/out/utils/shared.d.ts +0 -4
  45. package/out/utils/shared.js +0 -20
  46. package/out/utils/transform.d.ts +0 -9
  47. package/out/utils/transform.js +0 -195
  48. package/out/utils/ts.d.ts +0 -9
  49. package/out/utils/ts.js +0 -237
  50. package/out/utils/vue2TemplateCompiler.d.ts +0 -3
  51. package/out/utils/vue2TemplateCompiler.js +0 -86
  52. package/out/virtualFile/computedFiles.d.ts +0 -4
  53. package/out/virtualFile/computedFiles.js +0 -204
  54. package/out/virtualFile/computedMappings.d.ts +0 -6
  55. package/out/virtualFile/computedMappings.js +0 -39
  56. package/out/virtualFile/computedSfc.d.ts +0 -5
  57. package/out/virtualFile/computedSfc.js +0 -197
  58. package/out/virtualFile/computedVueSfc.d.ts +0 -5
  59. package/out/virtualFile/computedVueSfc.js +0 -41
  60. package/out/virtualFile/embeddedFile.d.ts +0 -13
  61. package/out/virtualFile/embeddedFile.js +0 -16
  62. package/out/virtualFile/vueFile.d.ts +0 -28
  63. package/out/virtualFile/vueFile.js +0 -53
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compile = void 0;
4
- const CompilerDOM = require("@vue/compiler-dom");
5
- const Vue2TemplateCompiler = require('vue-template-compiler/build');
6
- function compile(template, options = {}) {
7
- const onError = options.onError;
8
- const onWarn = options.onWarn;
9
- options.onError = (error) => {
10
- if (error.code === 33 // :key binding allowed in v-for template child in vue 2
11
- || error.code === 29 // fix https://github.com/vuejs/language-tools/issues/1638
12
- ) {
13
- return;
14
- }
15
- if (onError) {
16
- onError(error);
17
- }
18
- else {
19
- throw error;
20
- }
21
- };
22
- const vue2Result = Vue2TemplateCompiler.compile(template, { outputSourceRange: true });
23
- for (const error of vue2Result.errors) {
24
- onError?.({
25
- code: 'vue-template-compiler',
26
- name: '',
27
- message: error.msg,
28
- loc: {
29
- source: '',
30
- start: { column: -1, line: -1, offset: error.start },
31
- end: { column: -1, line: -1, offset: error.end ?? error.start },
32
- },
33
- });
34
- }
35
- for (const error of vue2Result.tips) {
36
- onWarn?.({
37
- code: 'vue-template-compiler',
38
- name: '',
39
- message: error.msg,
40
- loc: {
41
- source: '',
42
- start: { column: -1, line: -1, offset: error.start },
43
- end: { column: -1, line: -1, offset: error.end ?? error.start },
44
- },
45
- });
46
- }
47
- return baseCompile(template, Object.assign({}, CompilerDOM.parserOptions, options, {
48
- nodeTransforms: [
49
- ...CompilerDOM.DOMNodeTransforms,
50
- ...(options.nodeTransforms || [])
51
- ],
52
- directiveTransforms: Object.assign({}, CompilerDOM.DOMDirectiveTransforms, options.directiveTransforms || {}),
53
- }));
54
- }
55
- exports.compile = compile;
56
- function baseCompile(template, options = {}) {
57
- const onError = options.onError || ((error) => { throw error; });
58
- const isModuleMode = options.mode === 'module';
59
- const prefixIdentifiers = options.prefixIdentifiers === true || isModuleMode;
60
- if (!prefixIdentifiers && options.cacheHandlers) {
61
- onError(CompilerDOM.createCompilerError(49));
62
- }
63
- if (options.scopeId && !isModuleMode) {
64
- onError(CompilerDOM.createCompilerError(50));
65
- }
66
- const ast = CompilerDOM.baseParse(template, options);
67
- const [nodeTransforms, directiveTransforms] = CompilerDOM.getBaseTransformPreset(prefixIdentifiers);
68
- // v-for > v-if in vue 2
69
- const transformIf = nodeTransforms[1];
70
- const transformFor = nodeTransforms[3];
71
- nodeTransforms[1] = transformFor;
72
- nodeTransforms[3] = transformIf;
73
- CompilerDOM.transform(ast, Object.assign({}, options, {
74
- prefixIdentifiers,
75
- nodeTransforms: [
76
- ...nodeTransforms,
77
- ...(options.nodeTransforms || []) // user transforms
78
- ],
79
- directiveTransforms: Object.assign({}, directiveTransforms, options.directiveTransforms || {} // user transforms
80
- )
81
- }));
82
- return CompilerDOM.generate(ast, Object.assign({}, options, {
83
- prefixIdentifiers
84
- }));
85
- }
86
- //# sourceMappingURL=vue2TemplateCompiler.js.map
@@ -1,4 +0,0 @@
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
@@ -1,204 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedFiles = void 0;
4
- const source_map_1 = require("@volar/source-map");
5
- const muggle = require("muggle-string");
6
- const embeddedFile_1 = require("./embeddedFile");
7
- const computeds_1 = require("computeds");
8
- function computedFiles(plugins, fileName, sfc, codegenStack) {
9
- const nameToBlock = (0, computeds_1.computed)(() => {
10
- const blocks = {};
11
- if (sfc.template) {
12
- blocks[sfc.template.name] = sfc.template;
13
- }
14
- if (sfc.script) {
15
- blocks[sfc.script.name] = sfc.script;
16
- }
17
- if (sfc.scriptSetup) {
18
- blocks[sfc.scriptSetup.name] = sfc.scriptSetup;
19
- }
20
- for (const block of sfc.styles) {
21
- blocks[block.name] = block;
22
- }
23
- for (const block of sfc.customBlocks) {
24
- blocks[block.name] = block;
25
- }
26
- return blocks;
27
- });
28
- const pluginsResult = plugins.map(plugin => compiledPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack));
29
- const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
30
- const structuredResult = (0, computeds_1.computed)(() => {
31
- const embeddedFiles = [];
32
- let remain = [...flatResult()];
33
- while (remain.length) {
34
- const beforeLength = remain.length;
35
- consumeRemain();
36
- if (beforeLength === remain.length) {
37
- break;
38
- }
39
- }
40
- for (const { file, snapshot, mappings, codegenStacks } of remain) {
41
- embeddedFiles.push({
42
- ...file,
43
- snapshot,
44
- mappings,
45
- codegenStacks,
46
- embeddedFiles: [],
47
- });
48
- console.error('Unable to resolve embedded: ' + file.parentFileName + ' -> ' + file.fileName);
49
- }
50
- return embeddedFiles;
51
- function consumeRemain() {
52
- for (let i = remain.length - 1; i >= 0; i--) {
53
- const { file, snapshot, mappings, codegenStacks } = remain[i];
54
- if (!file.parentFileName) {
55
- embeddedFiles.push({
56
- ...file,
57
- snapshot,
58
- mappings,
59
- codegenStacks,
60
- embeddedFiles: [],
61
- });
62
- remain.splice(i, 1);
63
- }
64
- else {
65
- const parent = findParentStructure(file.parentFileName, embeddedFiles);
66
- if (parent) {
67
- parent.embeddedFiles.push({
68
- ...file,
69
- snapshot,
70
- mappings,
71
- codegenStacks,
72
- embeddedFiles: [],
73
- });
74
- remain.splice(i, 1);
75
- }
76
- }
77
- }
78
- }
79
- function findParentStructure(fileName, current) {
80
- for (const child of current) {
81
- if (child.fileName === fileName) {
82
- return child;
83
- }
84
- let parent = findParentStructure(fileName, child.embeddedFiles);
85
- if (parent) {
86
- return parent;
87
- }
88
- }
89
- }
90
- });
91
- return structuredResult;
92
- }
93
- exports.computedFiles = computedFiles;
94
- function compiledPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codegenStack) {
95
- const embeddedFiles = {};
96
- const files = (0, computeds_1.computed)(() => {
97
- try {
98
- if (!plugin.getEmbeddedFileNames) {
99
- return Object.values(embeddedFiles);
100
- }
101
- const embeddedFileNames = plugin.getEmbeddedFileNames(fileName, sfc);
102
- for (const oldFileName of Object.keys(embeddedFiles)) {
103
- if (!embeddedFileNames.includes(oldFileName)) {
104
- delete embeddedFiles[oldFileName];
105
- }
106
- }
107
- for (const embeddedFileName of embeddedFileNames) {
108
- if (!embeddedFiles[embeddedFileName]) {
109
- embeddedFiles[embeddedFileName] = (0, computeds_1.computed)(() => {
110
- const [content, stacks] = codegenStack ? muggle.track([]) : [[], []];
111
- const file = new embeddedFile_1.VueEmbeddedFile(embeddedFileName, content, stacks);
112
- for (const plugin of plugins) {
113
- if (!plugin.resolveEmbeddedFile) {
114
- continue;
115
- }
116
- try {
117
- plugin.resolveEmbeddedFile(fileName, sfc, file);
118
- }
119
- catch (e) {
120
- console.error(e);
121
- }
122
- }
123
- const newText = (0, source_map_1.toString)(file.content);
124
- const changeRanges = new Map();
125
- const snapshot = {
126
- getText: (start, end) => newText.slice(start, end),
127
- getLength: () => newText.length,
128
- getChangeRange(oldSnapshot) {
129
- if (!changeRanges.has(oldSnapshot)) {
130
- changeRanges.set(oldSnapshot, undefined);
131
- const oldText = oldSnapshot.getText(0, oldSnapshot.getLength());
132
- const changeRange = fullDiffTextChangeRange(oldText, newText);
133
- if (changeRange) {
134
- changeRanges.set(oldSnapshot, changeRange);
135
- }
136
- }
137
- return changeRanges.get(oldSnapshot);
138
- },
139
- };
140
- return {
141
- file,
142
- snapshot,
143
- };
144
- });
145
- }
146
- }
147
- }
148
- catch (e) {
149
- console.error(e);
150
- }
151
- return Object.values(embeddedFiles);
152
- });
153
- return (0, computeds_1.computed)(() => {
154
- return files().map(_file => {
155
- const { file, snapshot } = _file();
156
- const mappings = (0, source_map_1.buildMappings)(file.content);
157
- for (const mapping of mappings) {
158
- if (mapping.source !== undefined) {
159
- const block = nameToBlock()[mapping.source];
160
- if (block) {
161
- mapping.sourceRange = [
162
- mapping.sourceRange[0] + block.startTagEnd,
163
- mapping.sourceRange[1] + block.startTagEnd,
164
- ];
165
- }
166
- else {
167
- // ignore
168
- }
169
- mapping.source = undefined;
170
- }
171
- }
172
- return {
173
- file,
174
- snapshot,
175
- mappings,
176
- codegenStacks: (0, source_map_1.buildStacks)(file.content, file.contentStacks),
177
- };
178
- });
179
- });
180
- }
181
- function fullDiffTextChangeRange(oldText, newText) {
182
- for (let start = 0; start < oldText.length && start < newText.length; start++) {
183
- if (oldText[start] !== newText[start]) {
184
- let end = oldText.length;
185
- for (let i = 0; i < oldText.length - start && i < newText.length - start; i++) {
186
- if (oldText[oldText.length - i - 1] !== newText[newText.length - i - 1]) {
187
- break;
188
- }
189
- end--;
190
- }
191
- let length = end - start;
192
- let newLength = length + (newText.length - oldText.length);
193
- if (newLength < 0) {
194
- length -= newLength;
195
- newLength = 0;
196
- }
197
- return {
198
- span: { start, length },
199
- newLength,
200
- };
201
- }
202
- }
203
- }
204
- //# sourceMappingURL=computedFiles.js.map
@@ -1,6 +0,0 @@
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
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedMappings = void 0;
4
- const language_core_1 = require("@volar/language-core");
5
- const muggle = require("muggle-string");
6
- const computeds_1 = require("computeds");
7
- function computedMappings(snapshot, sfc) {
8
- return (0, computeds_1.computed)(() => {
9
- const str = [[snapshot().getText(0, snapshot().getLength()), undefined, 0, language_core_1.FileRangeCapabilities.full]];
10
- for (const block of [
11
- sfc.script,
12
- sfc.scriptSetup,
13
- sfc.template,
14
- ...sfc.styles,
15
- ...sfc.customBlocks,
16
- ]) {
17
- if (block) {
18
- muggle.replaceSourceRange(str, undefined, block.startTagEnd, block.endTagStart, [
19
- block.content,
20
- undefined,
21
- block.startTagEnd,
22
- {},
23
- ]);
24
- }
25
- }
26
- return str.map((m) => {
27
- const text = m[0];
28
- const start = m[2];
29
- const end = start + text.length;
30
- return {
31
- sourceRange: [start, end],
32
- generatedRange: [start, end],
33
- data: m[3],
34
- };
35
- });
36
- });
37
- }
38
- exports.computedMappings = computedMappings;
39
- //# sourceMappingURL=computedMappings.js.map
@@ -1,5 +0,0 @@
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
@@ -1,197 +0,0 @@
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
@@ -1,5 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,28 +0,0 @@
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
- getEmbeddedFiles: () => 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