@vue/language-core 2.0.14 → 2.0.15

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 +8 -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 +2 -2
  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 +2 -1
  33. package/lib/plugins.js +18 -9
  34. package/lib/types.d.ts +2 -0
  35. package/lib/utils/ts.js +20 -3
  36. package/lib/virtualFile/computedFiles.d.ts +1 -0
  37. package/lib/virtualFile/computedFiles.js +19 -3
  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;
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
@@ -26,6 +26,8 @@ export interface VueCompilerOptions {
26
26
  target: number;
27
27
  lib: string;
28
28
  extensions: string[];
29
+ vitePressExtensions: string[];
30
+ petiteVueExtensions: string[];
29
31
  jsxSlots: boolean;
30
32
  strictTemplates: boolean;
31
33
  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");
@@ -46,7 +46,7 @@ function computedFiles(plugins, fileName, sfc) {
46
46
  if (!file.parentCodeId) {
47
47
  embeddedCodes.push({
48
48
  id: file.id,
49
- languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
49
+ languageId: resolveCommonLanguageId(file.lang),
50
50
  linkedCodeMappings: file.linkedCodeMappings,
51
51
  snapshot,
52
52
  mappings,
@@ -60,7 +60,7 @@ function computedFiles(plugins, fileName, sfc) {
60
60
  parent.embeddedCodes ??= [];
61
61
  parent.embeddedCodes.push({
62
62
  id: file.id,
63
- languageId: (0, language_core_1.resolveCommonLanguageId)(`/dummy.${file.lang}`),
63
+ languageId: resolveCommonLanguageId(file.lang),
64
64
  linkedCodeMappings: file.linkedCodeMappings,
65
65
  snapshot,
66
66
  mappings,
@@ -215,4 +215,20 @@ function fullDiffTextChangeRange(oldText, newText) {
215
215
  }
216
216
  }
217
217
  }
218
+ function resolveCommonLanguageId(lang) {
219
+ switch (lang) {
220
+ case 'js': return 'javascript';
221
+ case 'cjs': return 'javascript';
222
+ case 'mjs': return 'javascript';
223
+ case 'ts': return 'typescript';
224
+ case 'cts': return 'typescript';
225
+ case 'mts': return 'typescript';
226
+ case 'jsx': return 'javascriptreact';
227
+ case 'tsx': return 'typescriptreact';
228
+ case 'pug': return 'jade';
229
+ case 'md': return 'markdown';
230
+ }
231
+ return lang;
232
+ }
233
+ exports.resolveCommonLanguageId = resolveCommonLanguageId;
218
234
  //# 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.15",
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-alpha.12",
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": "095f44449d71cd5a4730306c9c8c40df4d44dce3"
38
38
  }