@vue/language-core 2.0.4 → 2.0.6

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,41 @@ 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
+ if (!localVars.has(propVariableName)) {
946
+ accessedGlobalVariables.add(propVariableName);
947
+ yield _ts('__VLS_ctx.');
948
+ }
949
+ yield* generateCamelized(prop.exp.loc.source, prop.exp.loc.start.offset, caps_all);
950
+ if (mode === 'normal') {
951
+ yield _ts([
952
+ '',
953
+ 'template',
954
+ prop.exp.loc.end.offset,
955
+ (0, utils_1.disableAllFeatures)({
956
+ __hint: {
957
+ setting: 'vue.inlayHints.vBindShorthand',
958
+ label: `="${propVariableName}"`,
959
+ tooltip: [
960
+ `This is a shorthand for \`${prop.exp.loc.source}="${propVariableName}"\`.`,
961
+ 'To hide this hint, set `vue.inlayHints.vBindShorthand` to `false` in IDE settings.',
962
+ '[More info](https://github.com/vuejs/core/pull/9451)',
963
+ ].join('\n\n'),
964
+ },
965
+ })
966
+ ]);
967
+ }
968
+ }
941
969
  }
942
970
  }
943
971
  else {
@@ -1130,13 +1158,13 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1130
1158
  yield _ts('__VLS_normalizeSlot(');
1131
1159
  yield _ts(['', 'template', node.loc.start.offset, presetInfos.diagnosticOnly]);
1132
1160
  yield _ts(`${slotsAssignName ?? '__VLS_slots'}[`);
1133
- yield _ts(['', 'template', node.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1161
+ yield _ts(['', 'template', node.loc.start.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1134
1162
  yield _ts(slotNameExpNode?.content ?? `('${getSlotName()?.[0] ?? 'default'}' as const)`);
1135
- 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 })]);
1136
1164
  yield _ts(']');
1137
- yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1165
+ yield _ts(['', 'template', node.loc.end.offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1138
1166
  yield _ts(')?.(');
1139
- yield _ts(['', 'template', startTagOffset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1167
+ yield _ts(['', 'template', startTagOffset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1140
1168
  yield _ts('{\n');
1141
1169
  }
1142
1170
  else {
@@ -1269,7 +1297,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1269
1297
  if (needToUnicode(content)) {
1270
1298
  yield _ts(['', 'template', start, info]);
1271
1299
  yield _ts(toUnicode(content));
1272
- yield _ts(['', 'template', end, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1300
+ yield _ts(['', 'template', end, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1273
1301
  }
1274
1302
  else {
1275
1303
  yield _ts([content, 'template', start, info]);
@@ -1289,7 +1317,7 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1289
1317
  offset,
1290
1318
  i === 0
1291
1319
  ? info
1292
- : (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }),
1320
+ : (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }),
1293
1321
  ]);
1294
1322
  }
1295
1323
  offset += part.length + 1;
@@ -1320,9 +1348,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1320
1348
  else {
1321
1349
  yield _ts(['', 'template', offset, info]);
1322
1350
  yield _ts('"');
1323
- yield* generateCamelized(code, offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true }));
1351
+ yield* generateCamelized(code, offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true }));
1324
1352
  yield _ts('"');
1325
- yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1353
+ yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1326
1354
  }
1327
1355
  }
1328
1356
  else {
@@ -1403,9 +1431,9 @@ function* generate(ts, compilerOptions, vueCompilerOptions, template, shouldGene
1403
1431
  else {
1404
1432
  yield _ts(['', 'template', offset, info]);
1405
1433
  yield _ts('"');
1406
- yield _ts([code, 'template', offset, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1434
+ yield _ts([code, 'template', offset, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1407
1435
  yield _ts('"');
1408
- yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMappping: true })]);
1436
+ yield _ts(['', 'template', offset + code.length, (0, utils_1.disableAllFeatures)({ __combineLastMapping: true })]);
1409
1437
  }
1410
1438
  }
1411
1439
  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
  });
@@ -1,4 +1,4 @@
1
- import { Mapping } from '@volar/language-core';
1
+ import { CodeMapping } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
- import type { Sfc, VueCodeInformation } from '../types';
4
- export declare function computedMappings(snapshot: () => ts.IScriptSnapshot, sfc: Sfc): () => Mapping<VueCodeInformation>[];
3
+ import type { Sfc } from '../types';
4
+ export declare function computedMappings(snapshot: () => ts.IScriptSnapshot, sfc: Sfc): () => CodeMapping[];
@@ -18,7 +18,7 @@ function computedMappings(snapshot, sfc) {
18
18
  (0, language_core_1.replaceSourceRange)(str, undefined, block.startTagEnd, block.endTagStart, '\n\n');
19
19
  }
20
20
  }
21
- return str
21
+ const mappings = str
22
22
  .filter(s => typeof s !== 'string')
23
23
  .map((m) => {
24
24
  const text = m[0];
@@ -30,6 +30,36 @@ function computedMappings(snapshot, sfc) {
30
30
  data: m[3],
31
31
  };
32
32
  });
33
+ // fix folding range end position failed to mapping
34
+ for (const block of [
35
+ sfc.script,
36
+ sfc.scriptSetup,
37
+ sfc.template,
38
+ ...sfc.styles,
39
+ ...sfc.customBlocks,
40
+ ]) {
41
+ const offsets = [];
42
+ if (block) {
43
+ let content = block.content;
44
+ if (content.endsWith('\r\n')) {
45
+ content = content.slice(0, -2);
46
+ }
47
+ else if (content.endsWith('\n')) {
48
+ content = content.slice(0, -1);
49
+ }
50
+ const offset = content.lastIndexOf('\n') + 1;
51
+ offsets.push(block.startTagEnd + offset);
52
+ }
53
+ if (offsets.length) {
54
+ mappings.push({
55
+ sourceOffsets: offsets,
56
+ generatedOffsets: offsets,
57
+ lengths: offsets.map(() => 0),
58
+ data: (0, utils_1.disableAllFeatures)({ structure: true }),
59
+ });
60
+ }
61
+ }
62
+ return mappings;
33
63
  });
34
64
  }
35
65
  exports.computedMappings = computedMappings;
@@ -14,12 +14,12 @@ export declare class VueGeneratedCode implements VirtualCode {
14
14
  _snapshot: Signal<ts.IScriptSnapshot>;
15
15
  getVueSfc: () => import("@vue/compiler-sfc").SFCParseResult | undefined;
16
16
  sfc: import("../types").Sfc;
17
- getMappings: () => import("@volar/language-core").Mapping<import("../types").VueCodeInformation>[];
17
+ getMappings: () => import("@volar/language-core").CodeMapping[];
18
18
  getEmbeddedCodes: () => VirtualCode[];
19
19
  codegenStacks: Stack[];
20
20
  get embeddedCodes(): VirtualCode[];
21
21
  get snapshot(): ts.IScriptSnapshot;
22
- get mappings(): import("@volar/language-core").Mapping<import("../types").VueCodeInformation>[];
22
+ get mappings(): import("@volar/language-core").CodeMapping[];
23
23
  constructor(fileName: string, languageId: string, initSnapshot: ts.IScriptSnapshot, vueCompilerOptions: VueCompilerOptions, plugins: ReturnType<VueLanguagePlugin>[], ts: typeof import('typescript'), codegenStack: boolean);
24
24
  update(newSnapshot: ts.IScriptSnapshot): void;
25
25
  }
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.6",
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.2",
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": "feb990ccec85f6330bba37c8b1d1287f0980274c"
38
38
  }