@vue/language-core 2.0.14 → 2.0.16

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 (38) hide show
  1. package/lib/codegen/script/component.d.ts +1 -1
  2. package/lib/codegen/script/component.js +12 -4
  3. package/lib/codegen/script/globalTypes.js +1 -1
  4. package/lib/codegen/script/internalComponent.js +1 -1
  5. package/lib/codegen/script/scriptSetup.js +52 -19
  6. package/lib/codegen/script/template.js +5 -2
  7. package/lib/codegen/template/context.js +0 -1
  8. package/lib/codegen/template/element.d.ts +2 -1
  9. package/lib/codegen/template/element.js +101 -48
  10. package/lib/codegen/template/elementChildren.d.ts +2 -2
  11. package/lib/codegen/template/elementChildren.js +9 -3
  12. package/lib/codegen/template/elementEvents.d.ts +2 -0
  13. package/lib/codegen/template/elementEvents.js +47 -31
  14. package/lib/codegen/template/elementProps.js +33 -8
  15. package/lib/codegen/template/index.d.ts +10 -10
  16. package/lib/codegen/template/index.js +12 -99
  17. package/lib/codegen/template/slotOutlet.d.ts +1 -1
  18. package/lib/codegen/template/slotOutlet.js +31 -32
  19. package/lib/codegen/template/templateChild.d.ts +1 -1
  20. package/lib/codegen/template/templateChild.js +14 -10
  21. package/lib/codegen/template/vFor.d.ts +1 -1
  22. package/lib/codegen/template/vFor.js +2 -2
  23. package/lib/codegen/template/vIf.d.ts +1 -1
  24. package/lib/codegen/template/vIf.js +2 -2
  25. package/lib/languageModule.d.ts +1 -2
  26. package/lib/languageModule.js +30 -12
  27. package/lib/parsers/scriptSetupRanges.d.ts +1 -0
  28. package/lib/parsers/scriptSetupRanges.js +6 -1
  29. package/lib/plugins/file-html.js +63 -66
  30. package/lib/plugins/file-md.js +47 -50
  31. package/lib/plugins/vue-tsx.d.ts +1 -0
  32. package/lib/plugins.d.ts +3 -2
  33. package/lib/plugins.js +18 -9
  34. package/lib/types.d.ts +3 -0
  35. package/lib/utils/ts.js +20 -3
  36. package/lib/virtualFile/computedFiles.d.ts +1 -0
  37. package/lib/virtualFile/computedFiles.js +51 -34
  38. package/package.json +3 -3
@@ -6,74 +6,71 @@ const plugin = () => {
6
6
  return {
7
7
  version: 2,
8
8
  parseSFC(fileName, content) {
9
- if (fileName.endsWith('.html')) {
10
- let sfc = {
11
- descriptor: {
12
- filename: fileName,
13
- source: content,
14
- template: null,
15
- script: null,
16
- scriptSetup: null,
17
- styles: [],
18
- customBlocks: [],
19
- cssVars: [],
20
- shouldForceReload: () => false,
21
- slotted: false,
22
- },
23
- errors: [],
24
- };
25
- let templateContent = content;
26
- for (const match of content.matchAll(sfcBlockReg)) {
27
- const matchText = match[0];
28
- const tag = match[1];
29
- const attrs = match[2];
30
- const lang = attrs.match(langReg)?.[2];
31
- const content = match[3];
32
- const contentStart = match.index + matchText.indexOf(content);
33
- if (tag === 'style') {
34
- sfc.descriptor.styles.push({
35
- attrs: {},
36
- content,
37
- loc: {
38
- start: { column: -1, line: -1, offset: contentStart },
39
- end: { column: -1, line: -1, offset: contentStart + content.length },
40
- source: content,
41
- },
42
- type: 'style',
43
- lang,
44
- });
45
- }
46
- // ignore `<script src="...">`
47
- else if (tag === 'script' && attrs.indexOf('src=') === -1) {
48
- let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
49
- sfc.descriptor[type] = {
50
- attrs: {},
51
- content,
52
- loc: {
53
- start: { column: -1, line: -1, offset: contentStart },
54
- end: { column: -1, line: -1, offset: contentStart + content.length },
55
- source: content,
56
- },
57
- type: 'script',
58
- lang,
59
- };
60
- }
61
- templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
9
+ let sfc = {
10
+ descriptor: {
11
+ filename: fileName,
12
+ source: content,
13
+ template: null,
14
+ script: null,
15
+ scriptSetup: null,
16
+ styles: [],
17
+ customBlocks: [],
18
+ cssVars: [],
19
+ shouldForceReload: () => false,
20
+ slotted: false,
21
+ },
22
+ errors: [],
23
+ };
24
+ let templateContent = content;
25
+ for (const match of content.matchAll(sfcBlockReg)) {
26
+ const matchText = match[0];
27
+ const tag = match[1];
28
+ const attrs = match[2];
29
+ const lang = attrs.match(langReg)?.[2];
30
+ const content = match[3];
31
+ const contentStart = match.index + matchText.indexOf(content);
32
+ if (tag === 'style') {
33
+ sfc.descriptor.styles.push({
34
+ attrs: {},
35
+ content,
36
+ loc: {
37
+ start: { column: -1, line: -1, offset: contentStart },
38
+ end: { column: -1, line: -1, offset: contentStart + content.length },
39
+ source: content,
40
+ },
41
+ type: 'style',
42
+ lang,
43
+ });
62
44
  }
63
- sfc.descriptor.template = {
64
- attrs: {},
65
- content: templateContent,
66
- loc: {
67
- start: { column: -1, line: -1, offset: 0 },
68
- end: { column: -1, line: -1, offset: templateContent.length },
69
- source: templateContent,
70
- },
71
- type: 'template',
72
- ast: {},
73
- };
74
- return sfc;
45
+ // ignore `<script src="...">`
46
+ else if (tag === 'script' && attrs.indexOf('src=') === -1) {
47
+ let type = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
48
+ sfc.descriptor[type] = {
49
+ attrs: {},
50
+ content,
51
+ loc: {
52
+ start: { column: -1, line: -1, offset: contentStart },
53
+ end: { column: -1, line: -1, offset: contentStart + content.length },
54
+ source: content,
55
+ },
56
+ type: 'script',
57
+ lang,
58
+ };
59
+ }
60
+ templateContent = templateContent.substring(0, match.index) + ' '.repeat(matchText.length) + templateContent.substring(match.index + matchText.length);
75
61
  }
76
- ;
62
+ sfc.descriptor.template = {
63
+ attrs: {},
64
+ content: templateContent,
65
+ loc: {
66
+ start: { column: -1, line: -1, offset: 0 },
67
+ end: { column: -1, line: -1, offset: templateContent.length },
68
+ source: templateContent,
69
+ },
70
+ type: 'template',
71
+ ast: {},
72
+ };
73
+ return sfc;
77
74
  }
78
75
  };
79
76
  };
@@ -12,58 +12,55 @@ const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
12
12
  const plugin = () => {
13
13
  return {
14
14
  version: 2,
15
- parseSFC(fileName, content) {
16
- if (fileName.endsWith('.md')) {
17
- content = content
18
- // code block
19
- .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
20
- // inline code block
21
- .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
22
- // # \<script setup>
23
- .replace(scriptSetupReg, match => ' '.repeat(match.length))
24
- // <<< https://vitepress.dev/guide/markdown#import-code-snippets
25
- .replace(codeSnippetImportReg, match => ' '.repeat(match.length));
26
- const codes = [];
27
- for (const match of content.matchAll(sfcBlockReg)) {
28
- if (match.index !== undefined) {
29
- const matchText = match[0];
30
- codes.push([matchText, undefined, match.index]);
31
- codes.push('\n\n');
32
- content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
33
- }
34
- }
35
- content = content
36
- // angle bracket: <http://foo.com>
37
- .replace(angleBracketReg, match => ' '.repeat(match.length))
38
- // [foo](http://foo.com)
39
- .replace(linkReg, match => ' '.repeat(match.length));
40
- codes.push('<template>\n');
41
- codes.push([content, undefined, 0]);
42
- codes.push('\n</template>');
43
- const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
44
- const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
45
- if (sfc.descriptor.template) {
46
- transformRange(sfc.descriptor.template);
47
- }
48
- if (sfc.descriptor.script) {
49
- transformRange(sfc.descriptor.script);
50
- }
51
- if (sfc.descriptor.scriptSetup) {
52
- transformRange(sfc.descriptor.scriptSetup);
53
- }
54
- for (const style of sfc.descriptor.styles) {
55
- transformRange(style);
56
- }
57
- for (const customBlock of sfc.descriptor.customBlocks) {
58
- transformRange(customBlock);
59
- }
60
- return sfc;
61
- function transformRange(block) {
62
- block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
63
- block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
15
+ parseSFC(_fileName, content) {
16
+ content = content
17
+ // code block
18
+ .replace(codeblockReg, (match, quotes) => quotes + ' '.repeat(match.length - quotes.length * 2) + quotes)
19
+ // inline code block
20
+ .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
21
+ // # \<script setup>
22
+ .replace(scriptSetupReg, match => ' '.repeat(match.length))
23
+ // <<< https://vitepress.dev/guide/markdown#import-code-snippets
24
+ .replace(codeSnippetImportReg, match => ' '.repeat(match.length));
25
+ const codes = [];
26
+ for (const match of content.matchAll(sfcBlockReg)) {
27
+ if (match.index !== undefined) {
28
+ const matchText = match[0];
29
+ codes.push([matchText, undefined, match.index]);
30
+ codes.push('\n\n');
31
+ content = content.substring(0, match.index) + ' '.repeat(matchText.length) + content.substring(match.index + matchText.length);
64
32
  }
65
33
  }
66
- ;
34
+ content = content
35
+ // angle bracket: <http://foo.com>
36
+ .replace(angleBracketReg, match => ' '.repeat(match.length))
37
+ // [foo](http://foo.com)
38
+ .replace(linkReg, match => ' '.repeat(match.length));
39
+ codes.push('<template>\n');
40
+ codes.push([content, undefined, 0]);
41
+ codes.push('\n</template>');
42
+ const file2VueSourceMap = new language_core_1.SourceMap((0, language_core_1.buildMappings)(codes));
43
+ const sfc = (0, parseSfc_1.parse)((0, language_core_1.toString)(codes));
44
+ if (sfc.descriptor.template) {
45
+ transformRange(sfc.descriptor.template);
46
+ }
47
+ if (sfc.descriptor.script) {
48
+ transformRange(sfc.descriptor.script);
49
+ }
50
+ if (sfc.descriptor.scriptSetup) {
51
+ transformRange(sfc.descriptor.scriptSetup);
52
+ }
53
+ for (const style of sfc.descriptor.styles) {
54
+ transformRange(style);
55
+ }
56
+ for (const customBlock of sfc.descriptor.customBlocks) {
57
+ transformRange(customBlock);
58
+ }
59
+ return sfc;
60
+ function transformRange(block) {
61
+ block.loc.start.offset = file2VueSourceMap.getSourceOffset(block.loc.start.offset)?.[0] ?? -1;
62
+ block.loc.end.offset = file2VueSourceMap.getSourceOffset(block.loc.end.offset)?.[0] ?? -1;
63
+ }
67
64
  }
68
65
  };
69
66
  };
@@ -30,6 +30,7 @@ export declare const tsCodegen: WeakMap<Sfc, {
30
30
  };
31
31
  slots: {
32
32
  name?: string | undefined;
33
+ isObjectBindingPattern?: boolean | undefined;
33
34
  define?: (import("../types").TextRange & {
34
35
  arg?: import("../types").TextRange | undefined;
35
36
  typeArg?: import("../types").TextRange | undefined;
package/lib/plugins.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type VueLanguagePlugin } from './types';
2
- export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
2
+ export * from './plugins/shared';
3
+ export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
3
4
  version: 2;
4
5
  name?: string | undefined;
5
6
  order?: number | undefined;
@@ -21,5 +22,5 @@ export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<V
21
22
  id: string;
22
23
  lang: string;
23
24
  }[];
24
- resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./virtualFile/embeddedFile").VueEmbeddedCode): void;
25
+ resolveEmbeddedCode?(fileName: string, sfc: import("./types").Sfc, embeddedFile: import("./types").VueEmbeddedCode): void;
25
26
  }[];
package/lib/plugins.js CHANGED
@@ -1,9 +1,20 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultVueLanguagePlugins = void 0;
4
- const file_html_1 = require("./plugins/file-html");
5
- const file_md_1 = require("./plugins/file-md");
6
- const file_vue_1 = require("./plugins/file-vue");
17
+ exports.getBasePlugins = void 0;
7
18
  const vue_sfc_customblocks_1 = require("./plugins/vue-sfc-customblocks");
8
19
  const vue_sfc_scripts_1 = require("./plugins/vue-sfc-scripts");
9
20
  const vue_sfc_styles_1 = require("./plugins/vue-sfc-styles");
@@ -13,11 +24,9 @@ const vue_template_inline_css_1 = require("./plugins/vue-template-inline-css");
13
24
  const vue_template_inline_ts_1 = require("./plugins/vue-template-inline-ts");
14
25
  const vue_tsx_1 = require("./plugins/vue-tsx");
15
26
  const types_1 = require("./types");
16
- function getDefaultVueLanguagePlugins(pluginContext) {
27
+ __exportStar(require("./plugins/shared"), exports);
28
+ function getBasePlugins(pluginContext) {
17
29
  const plugins = [
18
- file_md_1.default, // .md for VitePress
19
- file_html_1.default, // .html for PetiteVue
20
- file_vue_1.default, // .vue and others for Vue
21
30
  vue_template_html_1.default,
22
31
  vue_template_inline_css_1.default,
23
32
  vue_template_inline_ts_1.default,
@@ -53,5 +62,5 @@ function getDefaultVueLanguagePlugins(pluginContext) {
53
62
  return valid;
54
63
  });
55
64
  }
56
- exports.getDefaultVueLanguagePlugins = getDefaultVueLanguagePlugins;
65
+ exports.getBasePlugins = getBasePlugins;
57
66
  //# sourceMappingURL=plugins.js.map
package/lib/types.d.ts CHANGED
@@ -4,6 +4,7 @@ import type * as ts from 'typescript';
4
4
  import type { VueEmbeddedCode } from './virtualFile/embeddedFile';
5
5
  import type { CodeInformation, Segment } from '@volar/language-core';
6
6
  export type { SFCParseResult } from '@vue/compiler-sfc';
7
+ export { VueEmbeddedCode };
7
8
  export type RawVueCompilerOptions = Partial<Omit<VueCompilerOptions, 'target' | 'plugins'>> & {
8
9
  target?: 'auto' | 2 | 2.7 | 3 | 3.3;
9
10
  plugins?: string[];
@@ -26,6 +27,8 @@ export interface VueCompilerOptions {
26
27
  target: number;
27
28
  lib: string;
28
29
  extensions: string[];
30
+ vitePressExtensions: string[];
31
+ petiteVueExtensions: string[];
29
32
  jsxSlots: boolean;
30
33
  strictTemplates: boolean;
31
34
  skipTemplateCodegen: boolean;
package/lib/utils/ts.js CHANGED
@@ -16,7 +16,11 @@ function createParsedCommandLineByJson(ts, parseConfigHost, rootDir, json, confi
16
16
  catch (err) { }
17
17
  }
18
18
  const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
19
- const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, resolvedVueOptions.extensions.map(extension => ({
19
+ const parsed = ts.parseJsonConfigFileContent(json, proxyHost.host, rootDir, {}, configFileName, undefined, [
20
+ ...resolvedVueOptions.extensions,
21
+ ...resolvedVueOptions.vitePressExtensions,
22
+ ...resolvedVueOptions.petiteVueExtensions,
23
+ ].map(extension => ({
20
24
  extension: extension.slice(1),
21
25
  isMixedContent: true,
22
26
  scriptKind: ts.ScriptKind.Deferred,
@@ -47,7 +51,11 @@ function createParsedCommandLine(ts, parseConfigHost, tsConfigPath) {
47
51
  catch (err) { }
48
52
  }
49
53
  const resolvedVueOptions = resolveVueCompilerOptions(vueOptions);
50
- const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, resolvedVueOptions.extensions.map(extension => ({
54
+ const parsed = ts.parseJsonSourceFileConfigFileContent(config, proxyHost.host, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, [
55
+ ...resolvedVueOptions.extensions,
56
+ ...resolvedVueOptions.vitePressExtensions,
57
+ ...resolvedVueOptions.petiteVueExtensions,
58
+ ].map(extension => ({
51
59
  extension: extension.slice(1),
52
60
  isMixedContent: true,
53
61
  scriptKind: ts.ScriptKind.Deferred,
@@ -121,7 +129,14 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
121
129
  const resolvedPath = resolvePath(pluginPath);
122
130
  if (resolvedPath) {
123
131
  const plugin = require(resolvedPath);
124
- plugin.__moduleName = pluginPath;
132
+ if (Array.isArray(plugin)) {
133
+ for (let i = 0; i < plugin.length; i++) {
134
+ plugin[i].__moduleName = `${pluginPath} (${i})`;
135
+ }
136
+ }
137
+ else {
138
+ plugin.__moduleName = pluginPath;
139
+ }
125
140
  return plugin;
126
141
  }
127
142
  else {
@@ -158,6 +173,8 @@ function resolveVueCompilerOptions(vueOptions) {
158
173
  ...vueOptions,
159
174
  target,
160
175
  extensions: vueOptions.extensions ?? ['.vue'],
176
+ vitePressExtensions: vueOptions.vitePressExtensions ?? [],
177
+ petiteVueExtensions: vueOptions.petiteVueExtensions ?? [],
161
178
  lib,
162
179
  jsxSlots: vueOptions.jsxSlots ?? false,
163
180
  strictTemplates: vueOptions.strictTemplates ?? false,
@@ -1,3 +1,4 @@
1
1
  import { VirtualCode } from '@volar/language-core';
2
2
  import type { Sfc, VueLanguagePlugin } from '../types';
3
3
  export declare function computedFiles(plugins: ReturnType<VueLanguagePlugin>[], fileName: string, sfc: Sfc): () => VirtualCode[];
4
+ export declare function resolveCommonLanguageId(lang: string): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computedFiles = void 0;
3
+ exports.resolveCommonLanguageId = exports.computedFiles = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const computeds_1 = require("computeds");
6
6
  const embeddedFile_1 = require("./embeddedFile");
@@ -24,7 +24,7 @@ function computedFiles(plugins, fileName, sfc) {
24
24
  }
25
25
  return blocks;
26
26
  });
27
- const pluginsResult = plugins.map(plugin => computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock));
27
+ const pluginsResult = plugins.map(plugin => computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock));
28
28
  const flatResult = (0, computeds_1.computed)(() => pluginsResult.map(r => r()).flat());
29
29
  const structuredResult = (0, computeds_1.computed)(() => {
30
30
  const embeddedCodes = [];
@@ -36,18 +36,18 @@ function computedFiles(plugins, fileName, sfc) {
36
36
  break;
37
37
  }
38
38
  }
39
- for (const { file } of remain) {
40
- console.error('Unable to resolve embedded: ' + file.parentCodeId + ' -> ' + file.id);
39
+ for (const { code } of remain) {
40
+ console.error('Unable to resolve embedded: ' + code.parentCodeId + ' -> ' + code.id);
41
41
  }
42
42
  return embeddedCodes;
43
43
  function consumeRemain() {
44
44
  for (let i = remain.length - 1; i >= 0; i--) {
45
- const { file, snapshot, mappings } = remain[i];
46
- if (!file.parentCodeId) {
45
+ const { code, snapshot, mappings } = remain[i];
46
+ if (!code.parentCodeId) {
47
47
  embeddedCodes.push({
48
- id: file.id,
49
- languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
50
- linkedCodeMappings: file.linkedCodeMappings,
48
+ id: code.id,
49
+ languageId: resolveCommonLanguageId(code.lang),
50
+ linkedCodeMappings: code.linkedCodeMappings,
51
51
  snapshot,
52
52
  mappings,
53
53
  embeddedCodes: [],
@@ -55,13 +55,13 @@ function computedFiles(plugins, fileName, sfc) {
55
55
  remain.splice(i, 1);
56
56
  }
57
57
  else {
58
- const parent = findParentStructure(file.parentCodeId, embeddedCodes);
58
+ const parent = findParentStructure(code.parentCodeId, embeddedCodes);
59
59
  if (parent) {
60
60
  parent.embeddedCodes ??= [];
61
61
  parent.embeddedCodes.push({
62
- id: file.id,
63
- languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
64
- linkedCodeMappings: file.linkedCodeMappings,
62
+ id: code.id,
63
+ languageId: resolveCommonLanguageId(code.lang),
64
+ linkedCodeMappings: code.linkedCodeMappings,
65
65
  snapshot,
66
66
  mappings,
67
67
  embeddedCodes: [],
@@ -86,36 +86,37 @@ function computedFiles(plugins, fileName, sfc) {
86
86
  return structuredResult;
87
87
  }
88
88
  exports.computedFiles = computedFiles;
89
- function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
90
- const embeddedFiles = {};
91
- const files = (0, computeds_1.computed)(() => {
89
+ function computedPluginEmbeddedCodes(plugins, plugin, fileName, sfc, nameToBlock) {
90
+ const computeds = new Map();
91
+ const getComputedKey = (code) => code.id + '__' + code.lang;
92
+ const codes = (0, computeds_1.computed)(() => {
92
93
  try {
93
94
  if (!plugin.getEmbeddedCodes) {
94
- return Object.values(embeddedFiles);
95
+ return [...computeds.values()];
95
96
  }
96
- const fileInfos = plugin.getEmbeddedCodes(fileName, sfc);
97
- for (const oldId of Object.keys(embeddedFiles)) {
98
- if (!fileInfos.some(file => file.id === oldId)) {
99
- delete embeddedFiles[oldId];
97
+ const embeddedCodeInfos = plugin.getEmbeddedCodes(fileName, sfc);
98
+ for (const oldId of computeds.keys()) {
99
+ if (!embeddedCodeInfos.some(code => getComputedKey(code) === oldId)) {
100
+ computeds.delete(oldId);
100
101
  }
101
102
  }
102
- for (const fileInfo of fileInfos) {
103
- if (!embeddedFiles[fileInfo.id]) {
104
- embeddedFiles[fileInfo.id] = (0, computeds_1.computed)(() => {
103
+ for (const codeInfo of embeddedCodeInfos) {
104
+ if (!computeds.has(getComputedKey(codeInfo))) {
105
+ computeds.set(getComputedKey(codeInfo), (0, computeds_1.computed)(() => {
105
106
  const content = [];
106
- const file = new embeddedFile_1.VueEmbeddedCode(fileInfo.id, fileInfo.lang, content);
107
+ const code = new embeddedFile_1.VueEmbeddedCode(codeInfo.id, codeInfo.lang, content);
107
108
  for (const plugin of plugins) {
108
109
  if (!plugin.resolveEmbeddedCode) {
109
110
  continue;
110
111
  }
111
112
  try {
112
- plugin.resolveEmbeddedCode(fileName, sfc, file);
113
+ plugin.resolveEmbeddedCode(fileName, sfc, code);
113
114
  }
114
115
  catch (e) {
115
116
  console.error(e);
116
117
  }
117
118
  }
118
- const newText = (0, language_core_1.toString)(file.content);
119
+ const newText = (0, language_core_1.toString)(code.content);
119
120
  const changeRanges = new Map();
120
121
  const snapshot = {
121
122
  getText: (start, end) => newText.slice(start, end),
@@ -133,22 +134,22 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
133
134
  },
134
135
  };
135
136
  return {
136
- file,
137
+ code,
137
138
  snapshot,
138
139
  };
139
- });
140
+ }));
140
141
  }
141
142
  }
142
143
  }
143
144
  catch (e) {
144
145
  console.error(e);
145
146
  }
146
- return Object.values(embeddedFiles);
147
+ return [...computeds.values()];
147
148
  });
148
149
  return (0, computeds_1.computed)(() => {
149
- return files().map(_file => {
150
- const { file, snapshot } = _file();
151
- const mappings = (0, language_core_1.buildMappings)(file.content);
150
+ return codes().map(_file => {
151
+ const { code, snapshot } = _file();
152
+ const mappings = (0, language_core_1.buildMappings)(code.content);
152
153
  const newMappings = [];
153
154
  let lastValidMapping;
154
155
  for (let i = 0; i < mappings.length; i++) {
@@ -185,7 +186,7 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock) {
185
186
  newMappings.push(mapping);
186
187
  }
187
188
  return {
188
- file,
189
+ code,
189
190
  snapshot,
190
191
  mappings: newMappings,
191
192
  };
@@ -215,4 +216,20 @@ function fullDiffTextChangeRange(oldText, newText) {
215
216
  }
216
217
  }
217
218
  }
219
+ function resolveCommonLanguageId(lang) {
220
+ switch (lang) {
221
+ case 'js': return 'javascript';
222
+ case 'cjs': return 'javascript';
223
+ case 'mjs': return 'javascript';
224
+ case 'ts': return 'typescript';
225
+ case 'cts': return 'typescript';
226
+ case 'mts': return 'typescript';
227
+ case 'jsx': return 'javascriptreact';
228
+ case 'tsx': return 'typescriptreact';
229
+ case 'pug': return 'jade';
230
+ case 'md': return 'markdown';
231
+ }
232
+ return lang;
233
+ }
234
+ exports.resolveCommonLanguageId = resolveCommonLanguageId;
218
235
  //# sourceMappingURL=computedFiles.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-core"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.2.0-alpha.10",
15
+ "@volar/language-core": "~2.2.0",
16
16
  "@vue/compiler-dom": "^3.4.0",
17
17
  "@vue/shared": "^3.4.0",
18
18
  "computeds": "^0.0.1",
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "ce1412067f88b7f9af03a2d3e04c220b4921c363"
37
+ "gitHead": "95b78c38cbf75481ebb59e11956b592346f01d92"
38
38
  }