@vue/language-core 2.0.4 → 2.0.5

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.
@@ -978,7 +978,7 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
978
978
  classNameWithDot.substring(1),
979
979
  'style_' + styleIndex,
980
980
  offset + 1,
981
- (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }),
981
+ (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
982
982
  ]);
983
983
  yield _(`'`);
984
984
  yield _([
@@ -195,7 +195,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
195
195
  '',
196
196
  'template',
197
197
  expectedErrorNode.loc.end.offset,
198
- (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }),
198
+ (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
199
199
  ]);
200
200
  yield _ts('\n;\n');
201
201
  }
@@ -225,7 +225,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
225
225
  else {
226
226
  yield _ts(['', 'template', slot.tagRange[0], (0, utils_1.mergeFeatureSettings)(presetInfos.slotNameExport, (0, utils_1.disableAllFeatures)({ __referencesCodeLens: true }))]);
227
227
  yield _ts('default');
228
- yield _ts(['', 'template', slot.tagRange[1], (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
228
+ yield _ts(['', 'template', slot.tagRange[1], (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
229
229
  }
230
230
  yield _ts(`?(_: typeof ${slot.varName}): any,\n`);
231
231
  }
@@ -673,7 +673,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
673
673
  yield _ts('.');
674
674
  yield _ts(['', 'template', slotDir.loc.start.offset, { ...presetInfos.slotName, completion: false }]);
675
675
  yield _ts('default');
676
- yield _ts(['', 'template', slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0), (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
676
+ yield _ts(['', 'template', slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#') ? '#'.length : slotDir.loc.source.startsWith('v-slot:') ? 'v-slot:'.length : 0), (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
677
677
  }
678
678
  yield _ts(['', 'template', (slotDir.arg ?? slotDir).loc.end.offset, presetInfos.diagnosticOnly]);
679
679
  if (hasProps) {
@@ -724,7 +724,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
724
724
  yield _ts(`(${componentCtxVar}.slots!).`);
725
725
  yield _ts(['', 'template', node.children[0].loc.start.offset, (0, utils_1.disableAllFeatures)({ navigation: true })]);
726
726
  yield _ts('default');
727
- yield _ts(['', 'template', node.children[node.children.length - 1].loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
727
+ yield _ts(['', 'template', node.children[node.children.length - 1].loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
728
728
  yield _ts(';\n');
729
729
  }
730
730
  }
@@ -772,17 +772,17 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
772
772
  yield _ts(`.`);
773
773
  yield _ts(startCode);
774
774
  yield _ts(`on`);
775
- yield* generateCamelized((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }));
775
+ yield* generateCamelized((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }));
776
776
  }
777
777
  else {
778
778
  yield _ts(`[`);
779
779
  yield _ts(startCode);
780
780
  yield _ts(`'`);
781
- yield _ts(['', 'template', prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
781
+ yield _ts(['', 'template', prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
782
782
  yield _ts('on');
783
- yield* generateCamelized((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }));
783
+ yield* generateCamelized((0, shared_1.capitalize)(prop.arg.loc.source), prop.arg.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }));
784
784
  yield _ts(`'`);
785
- yield _ts(['', 'template', prop.arg.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
785
+ yield _ts(['', 'template', prop.arg.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
786
786
  yield _ts(`]`);
787
787
  }
788
788
  yield _ts(`) };\n`);
@@ -931,13 +931,39 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
931
931
  })
932
932
  : caps_attr, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize);
933
933
  yield _ts(': (');
934
- if (prop.exp && !(prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY)) { // style='z-index: 2' will compile to {'z-index':'2'}
934
+ if (prop.exp && prop.exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'}
935
935
  const isShorthand = prop.arg?.loc.start.offset === prop.exp?.loc.start.offset; // vue 3.4+
936
- yield* generateInterpolation(prop.exp.loc.source, prop.exp.loc, prop.exp.loc.start.offset,
937
- // disable completion for shorthand expression
938
- isShorthand ? caps_attr : caps_all, '(', ')');
939
- if (!isShorthand && mode === 'normal') {
940
- yield* generateTsFormat(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal);
936
+ if (!isShorthand) {
937
+ yield* generateInterpolation(prop.exp.loc.source, prop.exp.loc, prop.exp.loc.start.offset, caps_all, '(', ')');
938
+ if (mode === 'normal') {
939
+ yield* generateTsFormat(prop.exp.loc.source, prop.exp.loc.start.offset, formatBrackets.normal);
940
+ }
941
+ }
942
+ else {
943
+ const propVariableName = (0, shared_1.camelize)(prop.exp.loc.source);
944
+ if (validTsVarReg.test(propVariableName)) {
945
+ yield _ts('__VLS_ctx.');
946
+ yield* generateCamelized(prop.exp.loc.source, prop.exp.loc.start.offset, caps_all);
947
+ if (mode === 'normal') {
948
+ yield _ts([
949
+ '',
950
+ 'template',
951
+ prop.exp.loc.end.offset,
952
+ (0, utils_1.disableAllFeatures)({
953
+ __hint: {
954
+ setting: 'vue.inlayHints.vbindShorthand',
955
+ label: `="${propVariableName}"`,
956
+ tooltip: [
957
+ `This is a shorthand for \`${prop.exp.loc.source}="${propVariableName}"\`.`,
958
+ 'To hide this hint, set `vue.inlayHints.vbindShorthand` to `false` in IDE settings.',
959
+ '[More info](https://github.com/vuejs/core/pull/9451)',
960
+ ].join('\n\n'),
961
+ },
962
+ })
963
+ ]);
964
+ }
965
+ accessedGlobalVariables.add(propVariableName);
966
+ }
941
967
  }
942
968
  }
943
969
  else {
@@ -1130,13 +1156,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1130
1156
  yield _ts('__VLS_normalizeSlot(');
1131
1157
  yield _ts(['', 'template', node.loc.start.offset, presetInfos.diagnosticOnly]);
1132
1158
  yield _ts(`${slotsAssignName ?? '__VLS_slots'}[`);
1133
- yield _ts(['', 'template', node.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1159
+ yield _ts(['', 'template', node.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1134
1160
  yield _ts(slotNameExpNode?.content ?? `('${getSlotName()?.[0] ?? 'default'}' as const)`);
1135
- yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1161
+ yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1136
1162
  yield _ts(']');
1137
- yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1163
+ yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1138
1164
  yield _ts(')?.(');
1139
- yield _ts(['', 'template', startTagOffset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1165
+ yield _ts(['', 'template', startTagOffset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1140
1166
  yield _ts('{\n');
1141
1167
  }
1142
1168
  else {
@@ -1269,7 +1295,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1269
1295
  if (needToUnicode(content)) {
1270
1296
  yield _ts(['', 'template', start, info]);
1271
1297
  yield _ts(toUnicode(content));
1272
- yield _ts(['', 'template', end, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1298
+ yield _ts(['', 'template', end, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1273
1299
  }
1274
1300
  else {
1275
1301
  yield _ts([content, 'template', start, info]);
@@ -1289,7 +1315,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1289
1315
  offset,
1290
1316
  i === 0
1291
1317
  ? info
1292
- : (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }),
1318
+ : (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
1293
1319
  ]);
1294
1320
  }
1295
1321
  offset += part.length + 1;
@@ -1320,9 +1346,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1320
1346
  else {
1321
1347
  yield _ts(['', 'template', offset, info]);
1322
1348
  yield _ts('"');
1323
- yield* generateCamelized(code, offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }));
1349
+ yield* generateCamelized(code, offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }));
1324
1350
  yield _ts('"');
1325
- yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1351
+ yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1326
1352
  }
1327
1353
  }
1328
1354
  else {
@@ -1403,9 +1429,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1403
1429
  else {
1404
1430
  yield _ts(['', 'template', offset, info]);
1405
1431
  yield _ts('"');
1406
- yield _ts([code, 'template', offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1432
+ yield _ts([code, 'template', offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1407
1433
  yield _ts('"');
1408
- yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1434
+ yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1409
1435
  }
1410
1436
  }
1411
1437
  function createTsAst(astHolder, text) {
@@ -2,4 +2,4 @@ import { type LanguagePlugin } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
3
  import type { VueCompilerOptions } from './types';
4
4
  import { VueGeneratedCode } from './virtualFile/vueFile';
5
- export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, compilerOptions?: ts.CompilerOptions, _vueCompilerOptions?: Partial<VueCompilerOptions>, codegenStack?: boolean, globalTypesHolder?: string): LanguagePlugin<VueGeneratedCode>;
5
+ export declare function createVueLanguagePlugin(ts: typeof import('typescript'), getFileName: (fileId: string) => string, isValidGlobalTypesHolder: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack?: boolean): LanguagePlugin<VueGeneratedCode>;
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createVueLanguagePlugin = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  const plugins_1 = require("./plugins");
6
- const ts_1 = require("./utils/ts");
7
6
  const vueFile_1 = require("./virtualFile/vueFile");
8
- const fileRegistries = [];
9
- function getVueFileRegistry(key, plugins) {
7
+ const CompilerDOM = require("@vue/compiler-dom");
8
+ const CompilerVue2 = require("./utils/vue2TemplateCompiler");
9
+ const normalFileRegistries = [];
10
+ const holderFileRegistries = [];
11
+ function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
12
+ const fileRegistries = isGlobalTypesHolder ? holderFileRegistries : normalFileRegistries;
10
13
  let fileRegistry = fileRegistries.find(r => r.key === key
11
14
  && r.plugins.length === plugins.length
12
15
  && r.plugins.every(plugin => plugins.includes(plugin)))?.files;
@@ -20,9 +23,8 @@ function getVueFileRegistry(key, plugins) {
20
23
  }
21
24
  return fileRegistry;
22
25
  }
23
- function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins, globalTypesHolder) {
26
+ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins) {
24
27
  const values = [
25
- globalTypesHolder,
26
28
  ...Object.keys(vueCompilerOptions)
27
29
  .sort()
28
30
  .filter(key => key !== 'plugins')
@@ -33,10 +35,23 @@ function getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins, global
33
35
  ];
34
36
  return JSON.stringify(values);
35
37
  }
36
- function createVueLanguagePlugin(ts, getFileName, compilerOptions = {}, _vueCompilerOptions = {}, codegenStack = false, globalTypesHolder) {
37
- const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
38
+ function createVueLanguagePlugin(ts, getFileName, isValidGlobalTypesHolder, compilerOptions, vueCompilerOptions, codegenStack = false) {
38
39
  const allowLanguageIds = new Set(['vue']);
39
- const pluginContext = (0, plugins_1.createPluginContext)(ts, compilerOptions, vueCompilerOptions, codegenStack, globalTypesHolder);
40
+ const pluginContext = {
41
+ modules: {
42
+ '@vue/compiler-dom': vueCompilerOptions.target < 3
43
+ ? {
44
+ ...CompilerDOM,
45
+ compile: CompilerVue2.compile,
46
+ }
47
+ : CompilerDOM,
48
+ typescript: ts,
49
+ },
50
+ compilerOptions,
51
+ vueCompilerOptions,
52
+ codegenStack,
53
+ globalTypesHolder: undefined,
54
+ };
40
55
  const plugins = (0, plugins_1.getDefaultVueLanguagePlugins)(pluginContext);
41
56
  if (vueCompilerOptions.extensions.includes('.md')) {
42
57
  allowLanguageIds.add('markdown');
@@ -44,46 +59,47 @@ function createVueLanguagePlugin(ts, getFileName, compilerOptions = {}, _vueComp
44
59
  if (vueCompilerOptions.extensions.includes('.html')) {
45
60
  allowLanguageIds.add('html');
46
61
  }
47
- let generatedCodeRegistry;
48
62
  return {
49
63
  createVirtualCode(fileId, languageId, snapshot) {
50
64
  if (allowLanguageIds.has(languageId)) {
51
65
  const fileName = getFileName(fileId);
52
- if (!generatedCodeRegistry) {
53
- pluginContext.globalTypesHolder ??= fileName;
54
- generatedCodeRegistry = getVueFileRegistry(getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins, pluginContext.globalTypesHolder), vueCompilerOptions.plugins);
66
+ if (!pluginContext.globalTypesHolder && isValidGlobalTypesHolder(fileName)) {
67
+ pluginContext.globalTypesHolder = fileName;
68
+ }
69
+ const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
70
+ const code = fileRegistry.get(fileId);
71
+ if (code) {
72
+ code.update(snapshot);
73
+ return code;
55
74
  }
56
- if (generatedCodeRegistry.has(fileId)) {
57
- const reusedResult = generatedCodeRegistry.get(fileId);
58
- reusedResult.update(snapshot);
59
- return reusedResult;
75
+ else {
76
+ const code = new vueFile_1.VueGeneratedCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
77
+ fileRegistry.set(fileId, code);
78
+ return code;
60
79
  }
61
- const vueFile = new vueFile_1.VueGeneratedCode(fileName, languageId, snapshot, vueCompilerOptions, plugins, ts, codegenStack);
62
- generatedCodeRegistry.set(fileId, vueFile);
63
- return vueFile;
64
80
  }
65
81
  },
66
- updateVirtualCode(_fileId, vueFile, snapshot) {
67
- vueFile.update(snapshot);
68
- return vueFile;
82
+ updateVirtualCode(_fileId, code, snapshot) {
83
+ code.update(snapshot);
84
+ return code;
69
85
  },
70
- disposeVirtualCode(fileId, vueFile, files) {
71
- generatedCodeRegistry?.delete(fileId);
72
- if (vueFile.fileName === pluginContext.globalTypesHolder) {
73
- if (generatedCodeRegistry?.size) {
74
- for (const [fileName, file] of generatedCodeRegistry) {
75
- pluginContext.globalTypesHolder = fileName;
76
- generatedCodeRegistry = getVueFileRegistry(getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins, pluginContext.globalTypesHolder), vueCompilerOptions.plugins);
77
- files?.set(fileId, file.languageId,
86
+ disposeVirtualCode(fileId, code, files) {
87
+ const isGlobalTypesHolder = code.fileName === pluginContext.globalTypesHolder;
88
+ const fileRegistry = getFileRegistry(isGlobalTypesHolder);
89
+ fileRegistry.delete(fileId);
90
+ if (isGlobalTypesHolder) {
91
+ pluginContext.globalTypesHolder = undefined;
92
+ const fileRegistry2 = getFileRegistry(false);
93
+ for (const [fileId, code] of fileRegistry2) {
94
+ if (isValidGlobalTypesHolder(code.fileName)) {
95
+ pluginContext.globalTypesHolder = code.fileName;
96
+ fileRegistry2.delete(fileId);
78
97
  // force dirty
79
- { ...file.snapshot });
98
+ files?.delete(fileId);
99
+ files?.set(fileId, code.languageId, code.snapshot);
80
100
  break;
81
101
  }
82
102
  }
83
- else {
84
- generatedCodeRegistry = undefined;
85
- pluginContext.globalTypesHolder = undefined;
86
- }
87
103
  }
88
104
  },
89
105
  typescript: {
@@ -109,6 +125,9 @@ function createVueLanguagePlugin(ts, getFileName, compilerOptions = {}, _vueComp
109
125
  },
110
126
  },
111
127
  };
128
+ function getFileRegistry(isGlobalTypesHolder) {
129
+ return getVueFileRegistry(isGlobalTypesHolder, getFileRegistryKey(compilerOptions, vueCompilerOptions, plugins), vueCompilerOptions.plugins);
130
+ }
112
131
  }
113
132
  exports.createVueLanguagePlugin = createVueLanguagePlugin;
114
133
  //# sourceMappingURL=languageModule.js.map
package/lib/plugins.d.ts CHANGED
@@ -1,16 +1,4 @@
1
- import * as CompilerDOM from '@vue/compiler-dom';
2
- import type * as ts from 'typescript';
3
- import { type VueCompilerOptions, type VueLanguagePlugin } from './types';
4
- export declare function createPluginContext(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, codegenStack: boolean, globalTypesHolder: string | undefined): {
5
- modules: {
6
- typescript: typeof import("typescript");
7
- '@vue/compiler-dom': typeof CompilerDOM;
8
- };
9
- compilerOptions: ts.CompilerOptions;
10
- vueCompilerOptions: VueCompilerOptions;
11
- codegenStack: boolean;
12
- globalTypesHolder: string | undefined;
13
- };
1
+ import { type VueLanguagePlugin } from './types';
14
2
  export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<VueLanguagePlugin>[0]): {
15
3
  version: 2;
16
4
  name?: string | undefined;
@@ -22,13 +10,13 @@ export declare function getDefaultVueLanguagePlugins(pluginContext: Parameters<V
22
10
  end: number;
23
11
  newText: string;
24
12
  }): import("@vue/compiler-sfc").SFCParseResult | undefined;
25
- resolveTemplateCompilerOptions?(options: CompilerDOM.CompilerOptions): CompilerDOM.CompilerOptions;
26
- compileSFCTemplate?(lang: string, template: string, options: CompilerDOM.CompilerOptions): CompilerDOM.CodegenResult | undefined;
27
- updateSFCTemplate?(oldResult: CompilerDOM.CodegenResult, textChange: {
13
+ resolveTemplateCompilerOptions?(options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CompilerOptions;
14
+ compileSFCTemplate?(lang: string, template: string, options: import("@vue/compiler-dom").CompilerOptions): import("@vue/compiler-dom").CodegenResult | undefined;
15
+ updateSFCTemplate?(oldResult: import("@vue/compiler-dom").CodegenResult, textChange: {
28
16
  start: number;
29
17
  end: number;
30
18
  newText: string;
31
- }): CompilerDOM.CodegenResult | undefined;
19
+ }): import("@vue/compiler-dom").CodegenResult | undefined;
32
20
  getEmbeddedCodes?(fileName: string, sfc: import("./types").Sfc): {
33
21
  id: string;
34
22
  lang: string;
package/lib/plugins.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultVueLanguagePlugins = exports.createPluginContext = void 0;
4
- const CompilerDOM = require("@vue/compiler-dom");
3
+ exports.getDefaultVueLanguagePlugins = void 0;
5
4
  const file_html_1 = require("./plugins/file-html");
6
5
  const file_md_1 = require("./plugins/file-md");
7
6
  const file_vue_1 = require("./plugins/file-vue");
@@ -12,26 +11,6 @@ const vue_sfc_template_1 = require("./plugins/vue-sfc-template");
12
11
  const vue_template_html_1 = require("./plugins/vue-template-html");
13
12
  const vue_tsx_1 = require("./plugins/vue-tsx");
14
13
  const types_1 = require("./types");
15
- const CompilerVue2 = require("./utils/vue2TemplateCompiler");
16
- function createPluginContext(ts, compilerOptions, vueCompilerOptions, codegenStack, globalTypesHolder) {
17
- const pluginCtx = {
18
- modules: {
19
- '@vue/compiler-dom': vueCompilerOptions.target < 3
20
- ? {
21
- ...CompilerDOM,
22
- compile: CompilerVue2.compile,
23
- }
24
- : CompilerDOM,
25
- typescript: ts,
26
- },
27
- compilerOptions,
28
- vueCompilerOptions,
29
- codegenStack,
30
- globalTypesHolder,
31
- };
32
- return pluginCtx;
33
- }
34
- exports.createPluginContext = createPluginContext;
35
14
  function getDefaultVueLanguagePlugins(pluginContext) {
36
15
  const plugins = [
37
16
  file_md_1.default, // .md for VitePress
@@ -46,7 +25,15 @@ function getDefaultVueLanguagePlugins(pluginContext) {
46
25
  ...pluginContext.vueCompilerOptions.plugins,
47
26
  ];
48
27
  const pluginInstances = plugins
49
- .map(plugin => plugin(pluginContext))
28
+ .map(plugin => {
29
+ try {
30
+ return plugin(pluginContext);
31
+ }
32
+ catch (err) {
33
+ console.warn('[Vue] Failed to create plugin', err);
34
+ }
35
+ })
36
+ .filter((plugin) => !!plugin)
50
37
  .sort((a, b) => {
51
38
  const aOrder = a.order ?? 0;
52
39
  const bOrder = b.order ?? 0;
@@ -55,7 +42,7 @@ function getDefaultVueLanguagePlugins(pluginContext) {
55
42
  return pluginInstances.filter((plugin) => {
56
43
  const valid = plugin.version === types_1.pluginVersion;
57
44
  if (!valid) {
58
- console.warn(`Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected ${JSON.stringify(types_1.pluginVersion)} but got ${JSON.stringify(plugin.version)}`);
45
+ console.warn(`[Vue] Plugin ${JSON.stringify(plugin.name)} API version incompatible, expected ${JSON.stringify(types_1.pluginVersion)} but got ${JSON.stringify(plugin.version)}`);
59
46
  }
60
47
  return valid;
61
48
  });
package/lib/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface VueCodeInformation extends CodeInformation {
18
18
  paddingRight?: boolean;
19
19
  paddingLeft?: boolean;
20
20
  };
21
- __combineLastMappping?: boolean;
21
+ __combineLastMapping?: boolean;
22
22
  }
23
23
  export type CodeAndStack = [code: Code, stack: string];
24
24
  export type Code = Segment<VueCodeInformation>;
package/lib/utils/ts.js CHANGED
@@ -121,11 +121,11 @@ function getPartialVueCompilerOptions(ts, tsConfigSourceFile) {
121
121
  return require(resolvedPath);
122
122
  }
123
123
  else {
124
- console.warn('Load plugin failed:', pluginPath);
124
+ console.warn('[Vue] Load plugin failed:', pluginPath);
125
125
  }
126
126
  }
127
127
  catch (error) {
128
- console.warn('Load plugin failed:', pluginPath, error);
128
+ console.warn('[Vue] Resolve plugin path failed:', pluginPath, error);
129
129
  }
130
130
  return [];
131
131
  })
@@ -172,7 +172,7 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
172
172
  }
173
173
  mapping.source = undefined;
174
174
  }
175
- if (mapping.data.__combineLastMappping) {
175
+ if (mapping.data.__combineLastMapping) {
176
176
  lastValidMapping.sourceOffsets.push(...mapping.sourceOffsets);
177
177
  lastValidMapping.generatedOffsets.push(...mapping.generatedOffsets);
178
178
  lastValidMapping.lengths.push(...mapping.lengths);
@@ -185,7 +185,7 @@ function computedPluginFiles(plugins, plugin, fileName, sfc, nameToBlock, codege
185
185
  return {
186
186
  file,
187
187
  snapshot,
188
- mappings: mappings.filter(mapping => !mapping.data.__combineLastMappping),
188
+ mappings: mappings.filter(mapping => !mapping.data.__combineLastMapping),
189
189
  codegenStacks: (0, language_core_1.buildStacks)(file.content, file.contentStacks),
190
190
  };
191
191
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
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.1.0",
15
+ "@volar/language-core": "~2.1.1",
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": "241300968fd3084c7c09139d05691a51a7800fdc"
37
+ "gitHead": "62b4fcb0d3f7153b5b2f5571af32f519117d8466"
38
38
  }