@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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/out/generators/script.d.ts +14 -0
  3. package/out/generators/script.js +881 -0
  4. package/out/generators/template.d.ts +16 -0
  5. package/out/generators/template.js +1389 -0
  6. package/out/index.d.ts +12 -0
  7. package/out/index.js +30 -0
  8. package/out/languageModule.d.ts +5 -0
  9. package/out/languageModule.js +91 -0
  10. package/out/parsers/scriptRanges.d.ts +15 -0
  11. package/out/parsers/scriptRanges.js +58 -0
  12. package/out/parsers/scriptSetupRanges.d.ts +32 -0
  13. package/out/parsers/scriptSetupRanges.js +295 -0
  14. package/out/plugins/file-html.d.ts +3 -0
  15. package/out/plugins/file-html.js +80 -0
  16. package/out/plugins/file-md.d.ts +3 -0
  17. package/out/plugins/file-md.js +62 -0
  18. package/out/plugins/file-vue.d.ts +3 -0
  19. package/out/plugins/file-vue.js +39 -0
  20. package/out/plugins/vue-sfc-customblocks.d.ts +3 -0
  21. package/out/plugins/vue-sfc-customblocks.js +31 -0
  22. package/out/plugins/vue-sfc-scripts.d.ts +3 -0
  23. package/out/plugins/vue-sfc-scripts.js +39 -0
  24. package/out/plugins/vue-sfc-styles.d.ts +3 -0
  25. package/out/plugins/vue-sfc-styles.js +31 -0
  26. package/out/plugins/vue-sfc-template.d.ts +3 -0
  27. package/out/plugins/vue-sfc-template.js +27 -0
  28. package/out/plugins/vue-template-html.d.ts +3 -0
  29. package/out/plugins/vue-template-html.js +165 -0
  30. package/out/plugins/vue-tsx.d.ts +14 -0
  31. package/out/plugins/vue-tsx.js +158 -0
  32. package/out/plugins.d.ts +23 -0
  33. package/out/plugins.js +52 -0
  34. package/out/sourceFile.d.ts +71 -0
  35. package/out/sourceFile.js +528 -0
  36. package/out/types.d.ts +100 -0
  37. package/out/types.js +3 -0
  38. package/out/utils/directorySharedTypes.d.ts +6 -0
  39. package/out/utils/directorySharedTypes.js +169 -0
  40. package/out/utils/parseCssClassNames.d.ts +4 -0
  41. package/out/utils/parseCssClassNames.js +19 -0
  42. package/out/utils/parseCssVars.d.ts +5 -0
  43. package/out/utils/parseCssVars.js +26 -0
  44. package/out/utils/parseSfc.d.ts +2 -0
  45. package/out/utils/parseSfc.js +135 -0
  46. package/out/utils/shared.d.ts +1 -0
  47. package/out/utils/shared.js +8 -0
  48. package/out/utils/transform.d.ts +8 -0
  49. package/out/utils/transform.js +182 -0
  50. package/out/utils/ts.d.ts +8 -0
  51. package/out/utils/ts.js +196 -0
  52. package/out/utils/vue2TemplateCompiler.d.ts +3 -0
  53. package/out/utils/vue2TemplateCompiler.js +101 -0
  54. package/package.json +29 -0
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ const source_map_1 = require("@volar/source-map");
3
+ const parseSfc_1 = require("../utils/parseSfc");
4
+ const plugin = () => {
5
+ return {
6
+ version: 1,
7
+ parseSFC(fileName, content) {
8
+ if (fileName.endsWith('.md')) {
9
+ content = content
10
+ // code block
11
+ .replace(/```[\s\S]+?```/g, match => '```' + ' '.repeat(match.length - 6) + '```')
12
+ // inline code block
13
+ .replace(/`[^\n`]+?`/g, match => `\`${' '.repeat(match.length - 2)}\``)
14
+ // # \<script setup>
15
+ .replace(/\\\<[\s\S]+?\>\n?/g, match => ' '.repeat(match.length));
16
+ const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
17
+ const codes = [];
18
+ for (const match of content.matchAll(sfcBlockReg)) {
19
+ if (match.index !== undefined) {
20
+ const matchText = match[0];
21
+ codes.push([matchText, undefined, match.index]);
22
+ codes.push('\n\n');
23
+ content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
24
+ }
25
+ }
26
+ content = content
27
+ // angle bracket: <http://foo.com>
28
+ .replace(/\<\S*\:\S*\>/g, match => ' '.repeat(match.length))
29
+ // [foo](http://foo.com)
30
+ .replace(/\[[\s\S]*?\]\([\s\S]*?\)/g, match => ' '.repeat(match.length));
31
+ codes.push('<template>\n');
32
+ codes.push([content, undefined, 0]);
33
+ codes.push('\n</template>');
34
+ const file2VueSourceMap = new source_map_1.SourceMap((0, source_map_1.buildMappings)(codes));
35
+ const sfc = (0, parseSfc_1.parse)((0, source_map_1.toString)(codes));
36
+ if (sfc.descriptor.template) {
37
+ transformRange(sfc.descriptor.template);
38
+ }
39
+ if (sfc.descriptor.script) {
40
+ transformRange(sfc.descriptor.script);
41
+ }
42
+ if (sfc.descriptor.scriptSetup) {
43
+ transformRange(sfc.descriptor.scriptSetup);
44
+ }
45
+ for (const style of sfc.descriptor.styles) {
46
+ transformRange(style);
47
+ }
48
+ for (const customBlock of sfc.descriptor.customBlocks) {
49
+ transformRange(customBlock);
50
+ }
51
+ return sfc;
52
+ function transformRange(block) {
53
+ block.loc.start.offset = file2VueSourceMap.toSourceOffset(block.loc.start.offset)?.[0] ?? -1;
54
+ block.loc.end.offset = file2VueSourceMap.toSourceOffset(block.loc.end.offset)?.[0] ?? -1;
55
+ }
56
+ }
57
+ ;
58
+ }
59
+ };
60
+ };
61
+ module.exports = plugin;
62
+ //# sourceMappingURL=file-md.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ const parseSfc_1 = require("../utils/parseSfc");
3
+ const plugin = (_ctx) => {
4
+ return {
5
+ version: 1,
6
+ parseSFC(_fileName, content) {
7
+ return (0, parseSfc_1.parse)(content);
8
+ },
9
+ updateSFC(sfc, change) {
10
+ const blocks = [
11
+ sfc.descriptor.template,
12
+ sfc.descriptor.script,
13
+ sfc.descriptor.scriptSetup,
14
+ ...sfc.descriptor.styles,
15
+ ...sfc.descriptor.customBlocks,
16
+ ].filter((block) => !!block);
17
+ const hitBlock = blocks.find(block => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset);
18
+ if (!hitBlock) {
19
+ return;
20
+ }
21
+ hitBlock.content =
22
+ hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset)
23
+ + change.newText
24
+ + hitBlock.content.substring(change.end - hitBlock.loc.start.offset);
25
+ const lengthDiff = change.newText.length - (change.end - change.start);
26
+ for (const block of blocks) {
27
+ if (block.loc.start.offset > change.end) {
28
+ block.loc.start.offset += lengthDiff;
29
+ }
30
+ if (block.loc.end.offset >= change.end) {
31
+ block.loc.end.offset += lengthDiff;
32
+ }
33
+ }
34
+ return sfc;
35
+ },
36
+ };
37
+ };
38
+ module.exports = plugin;
39
+ //# sourceMappingURL=file-vue.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ const language_core_1 = require("@volar/language-core");
3
+ const plugin = () => {
4
+ return {
5
+ version: 1,
6
+ getEmbeddedFileNames(fileName, sfc) {
7
+ const names = [];
8
+ for (let i = 0; i < sfc.customBlocks.length; i++) {
9
+ const customBlock = sfc.customBlocks[i];
10
+ names.push(fileName + '.customBlock_' + customBlock.type + '_' + i + '.' + customBlock.lang);
11
+ }
12
+ return names;
13
+ },
14
+ resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
15
+ const match = embeddedFile.fileName.match(/^(.*)\.customBlock_([^_]+)_(\d+)\.([^.]+)$/);
16
+ if (match) {
17
+ const index = parseInt(match[3]);
18
+ const customBlock = sfc.customBlocks[index];
19
+ embeddedFile.capabilities = language_core_1.FileCapabilities.full;
20
+ embeddedFile.content.push([
21
+ customBlock.content,
22
+ customBlock.name,
23
+ 0,
24
+ language_core_1.FileRangeCapabilities.full,
25
+ ]);
26
+ }
27
+ },
28
+ };
29
+ };
30
+ module.exports = plugin;
31
+ //# sourceMappingURL=vue-sfc-customblocks.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ const language_core_1 = require("@volar/language-core");
3
+ const plugin = () => {
4
+ return {
5
+ version: 1,
6
+ getEmbeddedFileNames(fileName, sfc) {
7
+ const names = [];
8
+ if (sfc.script) {
9
+ names.push(fileName + '.script_format.' + sfc.script.lang);
10
+ }
11
+ if (sfc.scriptSetup) {
12
+ names.push(fileName + '.scriptSetup_format.' + sfc.scriptSetup.lang);
13
+ }
14
+ return names;
15
+ },
16
+ resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
17
+ const scriptMatch = embeddedFile.fileName.match(/^(.*)\.script_format\.([^.]+)$/);
18
+ const scriptSetupMatch = embeddedFile.fileName.match(/^(.*)\.scriptSetup_format\.([^.]+)$/);
19
+ const script = scriptMatch ? sfc.script : scriptSetupMatch ? sfc.scriptSetup : undefined;
20
+ if (script) {
21
+ embeddedFile.kind = language_core_1.FileKind.TextFile;
22
+ embeddedFile.capabilities = {
23
+ ...language_core_1.FileCapabilities.full,
24
+ diagnostic: false,
25
+ codeAction: false,
26
+ inlayHint: false,
27
+ };
28
+ embeddedFile.content.push([
29
+ script.content,
30
+ script.name,
31
+ 0,
32
+ {},
33
+ ]);
34
+ }
35
+ },
36
+ };
37
+ };
38
+ module.exports = plugin;
39
+ //# sourceMappingURL=vue-sfc-scripts.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ const language_core_1 = require("@volar/language-core");
3
+ const plugin = () => {
4
+ return {
5
+ version: 1,
6
+ getEmbeddedFileNames(fileName, sfc) {
7
+ const names = [];
8
+ for (let i = 0; i < sfc.styles.length; i++) {
9
+ const style = sfc.styles[i];
10
+ names.push(fileName + '.style_' + i + '.' + style.lang);
11
+ }
12
+ return names;
13
+ },
14
+ resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
15
+ const match = embeddedFile.fileName.match(/^(.*)\.style_(\d+)\.([^.]+)$/);
16
+ if (match) {
17
+ const index = parseInt(match[2]);
18
+ const style = sfc.styles[index];
19
+ embeddedFile.capabilities = language_core_1.FileCapabilities.full;
20
+ embeddedFile.content.push([
21
+ style.content,
22
+ style.name,
23
+ 0,
24
+ language_core_1.FileRangeCapabilities.full,
25
+ ]);
26
+ }
27
+ },
28
+ };
29
+ };
30
+ module.exports = plugin;
31
+ //# sourceMappingURL=vue-sfc-styles.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ const language_core_1 = require("@volar/language-core");
3
+ const plugin = () => {
4
+ return {
5
+ version: 1,
6
+ getEmbeddedFileNames(fileName, sfc) {
7
+ if (sfc.template) {
8
+ return [fileName + '.template.' + sfc.template.lang];
9
+ }
10
+ return [];
11
+ },
12
+ resolveEmbeddedFile(_fileName, sfc, embeddedFile) {
13
+ const match = embeddedFile.fileName.match(/^(.*)\.template\.([^.]+)$/);
14
+ if (match && sfc.template) {
15
+ embeddedFile.capabilities = language_core_1.FileCapabilities.full;
16
+ embeddedFile.content.push([
17
+ sfc.template.content,
18
+ sfc.template.name,
19
+ 0,
20
+ language_core_1.FileRangeCapabilities.full,
21
+ ]);
22
+ }
23
+ },
24
+ };
25
+ };
26
+ module.exports = plugin;
27
+ //# sourceMappingURL=vue-sfc-template.js.map
@@ -0,0 +1,3 @@
1
+ import { VueLanguagePlugin } from '../types';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ const plugin = ({ modules }) => {
3
+ return {
4
+ version: 1,
5
+ compileSFCTemplate(lang, template, options) {
6
+ if (lang === 'html') {
7
+ const compiler = modules['@vue/compiler-dom'];
8
+ return compiler.compile(template, options);
9
+ }
10
+ },
11
+ updateSFCTemplate(oldResult, change) {
12
+ const CompilerDOM = modules['@vue/compiler-dom'];
13
+ const lengthDiff = change.newText.length - (change.end - change.start);
14
+ let hitNodes = [];
15
+ if (tryUpdateNode(oldResult.ast) && hitNodes.length) {
16
+ hitNodes = hitNodes.sort((a, b) => a.loc.source.length - b.loc.source.length);
17
+ const hitNode = hitNodes[0];
18
+ if (hitNode.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
19
+ return oldResult;
20
+ }
21
+ }
22
+ function tryUpdateNode(node) {
23
+ if (withinChangeRange(node.loc)) {
24
+ hitNodes.push(node);
25
+ }
26
+ if (tryUpdateNodeLoc(node.loc)) {
27
+ if (node.type === 0 /* CompilerDOM.NodeTypes.ROOT */) {
28
+ for (const child of node.children) {
29
+ if (!tryUpdateNode(child)) {
30
+ return false;
31
+ }
32
+ }
33
+ }
34
+ else if (node.type === 1 /* CompilerDOM.NodeTypes.ELEMENT */) {
35
+ if (withinChangeRange(node.loc)) {
36
+ // if not self closing, should not hit tag name
37
+ const start = node.loc.start.offset + 2;
38
+ const end = node.loc.start.offset + node.loc.source.lastIndexOf('</');
39
+ if (!withinChangeRange({ start: { offset: start }, end: { offset: end }, source: '' })) {
40
+ return false;
41
+ }
42
+ }
43
+ for (const prop of node.props) {
44
+ if (!tryUpdateNode(prop)) {
45
+ return false;
46
+ }
47
+ }
48
+ for (const child of node.children) {
49
+ if (!tryUpdateNode(child)) {
50
+ return false;
51
+ }
52
+ }
53
+ }
54
+ else if (node.type === 6 /* CompilerDOM.NodeTypes.ATTRIBUTE */) {
55
+ if (node.value && !tryUpdateNode(node.value)) {
56
+ return false;
57
+ }
58
+ }
59
+ else if (node.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */) {
60
+ if (node.arg && withinChangeRange(node.arg.loc) && node.name === 'slot') {
61
+ return false;
62
+ }
63
+ if (node.exp && withinChangeRange(node.exp.loc) && node.name === 'for') { // #2266
64
+ return false;
65
+ }
66
+ if (node.arg && !tryUpdateNode(node.arg)) {
67
+ return false;
68
+ }
69
+ if (node.exp && !tryUpdateNode(node.exp)) {
70
+ return false;
71
+ }
72
+ }
73
+ else if (node.type === 12 /* CompilerDOM.NodeTypes.TEXT_CALL */) {
74
+ if (!tryUpdateNode(node.content)) {
75
+ return false;
76
+ }
77
+ }
78
+ else if (node.type === 8 /* CompilerDOM.NodeTypes.COMPOUND_EXPRESSION */) {
79
+ for (const childNode of node.children) {
80
+ if (typeof childNode === 'object') {
81
+ if (!tryUpdateNode(childNode)) {
82
+ return false;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ else if (node.type === 9 /* CompilerDOM.NodeTypes.IF */) {
88
+ for (const branch of node.branches) {
89
+ if (branch.condition && !tryUpdateNode(branch.condition)) {
90
+ return false;
91
+ }
92
+ for (const child of branch.children) {
93
+ if (!tryUpdateNode(child)) {
94
+ return false;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ else if (node.type === 11 /* CompilerDOM.NodeTypes.FOR */) {
100
+ for (const child of [
101
+ node.parseResult.source,
102
+ node.parseResult.value,
103
+ node.parseResult.key,
104
+ node.parseResult.index,
105
+ ]) {
106
+ if (child && !tryUpdateNode(child)) {
107
+ return false;
108
+ }
109
+ }
110
+ for (const child of node.children) {
111
+ if (!tryUpdateNode(child)) {
112
+ return false;
113
+ }
114
+ }
115
+ }
116
+ else if (node.type === 5 /* CompilerDOM.NodeTypes.INTERPOLATION */) {
117
+ if (!tryUpdateNode(node.content)) {
118
+ return false;
119
+ }
120
+ }
121
+ else if (node.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
122
+ if (withinChangeRange(node.loc)) { // TODO: review this (slot name?)
123
+ if (node.isStatic) {
124
+ return false;
125
+ }
126
+ else {
127
+ node.content = node.loc.source;
128
+ }
129
+ }
130
+ }
131
+ return true;
132
+ }
133
+ return false;
134
+ }
135
+ function tryUpdateNodeLoc(loc) {
136
+ delete loc.__endOffset;
137
+ if (withinChangeRange(loc)) {
138
+ loc.source =
139
+ loc.source.substring(0, change.start - loc.start.offset)
140
+ + change.newText
141
+ + loc.source.substring(change.end - loc.start.offset);
142
+ loc.__endOffset = loc.end.offset;
143
+ loc.end.offset += lengthDiff;
144
+ return true;
145
+ }
146
+ else if (change.end <= loc.start.offset) {
147
+ loc.__endOffset = loc.end.offset;
148
+ loc.start.offset += lengthDiff;
149
+ loc.end.offset += lengthDiff;
150
+ return true;
151
+ }
152
+ else if (change.start >= loc.end.offset) {
153
+ return true; // no need update
154
+ }
155
+ return false;
156
+ }
157
+ function withinChangeRange(loc) {
158
+ const originalLocEnd = loc.__endOffset ?? loc.end.offset;
159
+ return change.start >= loc.start.offset && change.end <= originalLocEnd;
160
+ }
161
+ },
162
+ };
163
+ };
164
+ module.exports = plugin;
165
+ //# sourceMappingURL=vue-template-html.js.map
@@ -0,0 +1,14 @@
1
+ import { Sfc, VueLanguagePlugin } from '../types';
2
+ import { TextRange } from '../types';
3
+ declare const plugin: VueLanguagePlugin;
4
+ export default plugin;
5
+ export declare function collectStyleCssClasses(sfc: Sfc, condition: (style: Sfc['styles'][number]) => boolean): {
6
+ style: (typeof sfc.styles)[number];
7
+ index: number;
8
+ classNameRanges: TextRange[];
9
+ classNames: string[];
10
+ }[];
11
+ export declare function collectCssVars(sfc: Sfc): {
12
+ style: (typeof sfc.styles)[number];
13
+ ranges: TextRange[];
14
+ }[];
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectCssVars = exports.collectStyleCssClasses = void 0;
4
+ const reactivity_1 = require("@vue/reactivity");
5
+ const script_1 = require("../generators/script");
6
+ const templateGen = require("../generators/template");
7
+ const scriptRanges_1 = require("../parsers/scriptRanges");
8
+ const scriptSetupRanges_1 = require("../parsers/scriptSetupRanges");
9
+ const language_core_1 = require("@volar/language-core");
10
+ const parseCssClassNames_1 = require("../utils/parseCssClassNames");
11
+ const parseCssVars_1 = require("../utils/parseCssVars");
12
+ const sharedTypes = require("../utils/directorySharedTypes");
13
+ const plugin = ({ modules, vueCompilerOptions, compilerOptions }) => {
14
+ const ts = modules.typescript;
15
+ const instances = new WeakMap();
16
+ const sharedTypesImport = sharedTypes.getImportName(compilerOptions);
17
+ return {
18
+ version: 1,
19
+ getEmbeddedFileNames(fileName, sfc) {
20
+ const tsx = useTsx(fileName, sfc);
21
+ const fileNames = [];
22
+ if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.value)) {
23
+ fileNames.push(fileName + '.' + tsx.lang.value);
24
+ }
25
+ if (sfc.template) {
26
+ fileNames.push(fileName + '.template_format.ts');
27
+ fileNames.push(fileName + '.template_style.css');
28
+ }
29
+ return fileNames;
30
+ },
31
+ resolveEmbeddedFile(fileName, sfc, embeddedFile) {
32
+ const _tsx = useTsx(fileName, sfc);
33
+ const suffix = embeddedFile.fileName.replace(fileName, '');
34
+ if (suffix === '.' + _tsx.lang.value) {
35
+ embeddedFile.kind = language_core_1.FileKind.TypeScriptHostFile;
36
+ embeddedFile.capabilities = {
37
+ ...language_core_1.FileCapabilities.full,
38
+ foldingRange: false,
39
+ documentFormatting: false,
40
+ documentSymbol: false,
41
+ };
42
+ const tsx = _tsx.tsxGen.value;
43
+ if (tsx) {
44
+ embeddedFile.content = [...tsx.codes];
45
+ embeddedFile.mirrorBehaviorMappings = [...tsx.mirrorBehaviorMappings];
46
+ }
47
+ }
48
+ else if (suffix.match(/^\.template_format\.ts$/)) {
49
+ embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
50
+ embeddedFile.kind = language_core_1.FileKind.TextFile;
51
+ embeddedFile.capabilities = {
52
+ ...language_core_1.FileCapabilities.full,
53
+ diagnostic: false,
54
+ foldingRange: false,
55
+ codeAction: false,
56
+ inlayHint: false,
57
+ };
58
+ if (_tsx.htmlGen.value) {
59
+ embeddedFile.content = [..._tsx.htmlGen.value.formatCodes];
60
+ }
61
+ for (const cssVar of _tsx.cssVars.value) {
62
+ embeddedFile.content.push('\n\n');
63
+ for (const range of cssVar.ranges) {
64
+ embeddedFile.content.push('(');
65
+ embeddedFile.content.push([
66
+ cssVar.style.content.substring(range.start, range.end),
67
+ cssVar.style.name,
68
+ range.start,
69
+ {},
70
+ ]);
71
+ embeddedFile.content.push(');\n');
72
+ }
73
+ }
74
+ }
75
+ else if (suffix.match(/^\.template_style\.css$/)) {
76
+ embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
77
+ if (_tsx.htmlGen.value) {
78
+ embeddedFile.content = [..._tsx.htmlGen.value.cssCodes];
79
+ }
80
+ // for color pickers support
81
+ embeddedFile.capabilities.documentSymbol = true;
82
+ }
83
+ },
84
+ };
85
+ function useTsx(fileName, sfc) {
86
+ if (!instances.has(sfc)) {
87
+ instances.set(sfc, createTsx(fileName, sfc));
88
+ }
89
+ return instances.get(sfc);
90
+ }
91
+ function createTsx(fileName, _sfc) {
92
+ const lang = (0, reactivity_1.computed)(() => {
93
+ return !_sfc.script && !_sfc.scriptSetup ? 'ts'
94
+ : _sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js' ? _sfc.scriptSetup.lang
95
+ : _sfc.script && _sfc.script.lang !== 'js' ? _sfc.script.lang
96
+ : 'js';
97
+ });
98
+ const cssVars = (0, reactivity_1.computed)(() => collectCssVars(_sfc));
99
+ const scriptRanges = (0, reactivity_1.computed)(() => _sfc.scriptAst
100
+ ? (0, scriptRanges_1.parseScriptRanges)(ts, _sfc.scriptAst, !!_sfc.scriptSetup, false)
101
+ : undefined);
102
+ const scriptSetupRanges = (0, reactivity_1.computed)(() => _sfc.scriptSetupAst
103
+ ? (0, scriptSetupRanges_1.parseScriptSetupRanges)(ts, _sfc.scriptSetupAst, vueCompilerOptions)
104
+ : undefined);
105
+ const cssModuleClasses = (0, reactivity_1.computed)(() => collectStyleCssClasses(_sfc, style => !!style.module));
106
+ const cssScopedClasses = (0, reactivity_1.computed)(() => collectStyleCssClasses(_sfc, style => {
107
+ const setting = vueCompilerOptions.experimentalResolveStyleCssClasses;
108
+ return (setting === 'scoped' && style.scoped) || setting === 'always';
109
+ }));
110
+ const htmlGen = (0, reactivity_1.computed)(() => {
111
+ if (!_sfc.templateAst)
112
+ return;
113
+ return templateGen.generate(ts, compilerOptions, vueCompilerOptions, _sfc.template?.content ?? '', _sfc.template?.lang ?? 'html', _sfc.templateAst, hasScriptSetupSlots.value, sharedTypesImport, Object.values(cssScopedClasses.value).map(style => style.classNames).flat());
114
+ });
115
+ const hasScriptSetupSlots = (0, reactivity_1.shallowRef)(false); // remove when https://github.com/vuejs/core/pull/5912 merged
116
+ const tsxGen = (0, reactivity_1.computed)(() => {
117
+ hasScriptSetupSlots.value = !!scriptSetupRanges.value?.slotsTypeArg;
118
+ return (0, script_1.generate)(ts, fileName, _sfc, lang.value, scriptRanges.value, scriptSetupRanges.value, cssVars.value, cssModuleClasses.value, cssScopedClasses.value, htmlGen.value, compilerOptions, vueCompilerOptions, sharedTypesImport);
119
+ });
120
+ return {
121
+ lang,
122
+ tsxGen,
123
+ htmlGen,
124
+ cssVars,
125
+ };
126
+ }
127
+ };
128
+ exports.default = plugin;
129
+ function collectStyleCssClasses(sfc, condition) {
130
+ const result = [];
131
+ for (let i = 0; i < sfc.styles.length; i++) {
132
+ const style = sfc.styles[i];
133
+ if (condition(style)) {
134
+ const classNameRanges = [...(0, parseCssClassNames_1.parseCssClassNames)(style.content)];
135
+ result.push({
136
+ style: style,
137
+ index: i,
138
+ classNameRanges: classNameRanges,
139
+ classNames: classNameRanges.map(range => style.content.substring(range.start + 1, range.end)),
140
+ });
141
+ }
142
+ }
143
+ return result;
144
+ }
145
+ exports.collectStyleCssClasses = collectStyleCssClasses;
146
+ function collectCssVars(sfc) {
147
+ const result = [];
148
+ for (let i = 0; i < sfc.styles.length; i++) {
149
+ const style = sfc.styles[i];
150
+ result.push({
151
+ style,
152
+ ranges: [...(0, parseCssVars_1.parseCssVars)(style.content)],
153
+ });
154
+ }
155
+ return result;
156
+ }
157
+ exports.collectCssVars = collectCssVars;
158
+ //# sourceMappingURL=vue-tsx.js.map
@@ -0,0 +1,23 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ import { VueCompilerOptions } from './types';
3
+ import * as CompilerDOM from '@vue/compiler-dom';
4
+ export declare function getDefaultVueLanguagePlugins(ts: typeof import('typescript/lib/tsserverlibrary'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): {
5
+ version: 1;
6
+ name?: string | undefined;
7
+ order?: number | undefined;
8
+ parseSFC?(fileName: string, content: string): import("@vue/compiler-sfc").SFCParseResult | undefined;
9
+ updateSFC?(oldResult: import("@vue/compiler-sfc").SFCParseResult, textChange: {
10
+ start: number;
11
+ end: number;
12
+ newText: string;
13
+ }): import("@vue/compiler-sfc").SFCParseResult | undefined;
14
+ resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
15
+ compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
16
+ updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
17
+ start: number;
18
+ end: number;
19
+ newText: string;
20
+ }): CompilerDOM.CodegenResult | undefined;
21
+ getEmbeddedFileNames?(fileName: string, sfc: import("./types").Sfc): string[];
22
+ resolveEmbeddedFile?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./sourceFile").VueEmbeddedFile): void;
23
+ }[];