@vue/language-core 2.0.15 → 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.
@@ -98,10 +98,10 @@ function* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRange
98
98
  if (options.vueCompilerOptions.target >= 3.5) {
99
99
  // https://github.com/vuejs/core/pull/10801
100
100
  if (scriptSetupRanges.props.define?.typeArg) {
101
- yield `__typeProps: typeof __VLS_typeProps,${common_1.newLine}`;
101
+ yield `__typeProps: __VLS_typeProps,${common_1.newLine}`;
102
102
  }
103
103
  if (scriptSetupRanges.emits.define?.typeArg) {
104
- yield `__typeEmits: typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
104
+ yield `__typeEmits: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
105
105
  }
106
106
  }
107
107
  }
@@ -142,16 +142,16 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
142
142
  }
143
143
  }
144
144
  if (scriptSetupRanges.slots.define) {
145
- if (!scriptSetupRanges.slots.name) {
146
- setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
147
- }
148
- else if (scriptSetupRanges.slots.isObjectBindingPattern) {
145
+ if (scriptSetupRanges.slots.isObjectBindingPattern) {
149
146
  setupCodeModifies.push([
150
147
  [`__VLS_slots;\nconst __VLS_slots = `],
151
148
  scriptSetupRanges.slots.define.start,
152
149
  scriptSetupRanges.slots.define.start,
153
150
  ]);
154
151
  }
152
+ else if (!scriptSetupRanges.slots.name) {
153
+ setupCodeModifies.push([[`const __VLS_slots = `], scriptSetupRanges.slots.define.start, scriptSetupRanges.slots.define.start]);
154
+ }
155
155
  }
156
156
  if (scriptSetupRanges.emits.define && !scriptSetupRanges.emits.name) {
157
157
  setupCodeModifies.push([[`const __VLS_emit = `], scriptSetupRanges.emits.define.start, scriptSetupRanges.emits.define.start]);
@@ -13,7 +13,8 @@ function* generateElementChildren(options, ctx, node, currentComponent, componen
13
13
  }
14
14
  yield* ctx.generateAutoImportCompletion();
15
15
  // fix https://github.com/vuejs/language-tools/issues/932
16
- if (!ctx.hasSlotElements.has(node)
16
+ if (componentCtxVar
17
+ && !ctx.hasSlotElements.has(node)
17
18
  && node.children.length
18
19
  && node.tagType !== CompilerDOM.ElementTypes.ELEMENT
19
20
  && node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
@@ -29,41 +29,40 @@ function* generateSlotOutlet(options, ctx, node, currentComponent, componentCtxV
29
29
  yield `)?.(`;
30
30
  yield* (0, common_1.wrapWith)(startTagOffset, startTagOffset + node.tag.length, ctx.codeFeatures.verification, `{${common_1.newLine}`, ...(0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true), `}`);
31
31
  yield `)${common_1.endOfLine}`;
32
- return;
33
32
  }
34
33
  else {
35
34
  yield `var ${varSlot} = {${common_1.newLine}`;
36
35
  yield* (0, elementProps_1.generateElementProps)(options, ctx, node, node.props.filter(prop => prop !== nameProp), true);
37
36
  yield `}${common_1.endOfLine}`;
38
- }
39
- if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
40
- && nameProp.value) {
41
- ctx.slots.push({
42
- name: nameProp.value.content,
43
- loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
44
- tagRange: [startTagOffset, startTagOffset + node.tag.length],
45
- varName: varSlot,
46
- nodeLoc: node.loc,
47
- });
48
- }
49
- else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
50
- && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
51
- const slotExpVar = ctx.getInternalVariable();
52
- yield `var ${slotExpVar} = `;
53
- yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
54
- yield ` as const${common_1.endOfLine}`;
55
- ctx.dynamicSlots.push({
56
- expVar: slotExpVar,
57
- varName: varSlot,
58
- });
59
- }
60
- else {
61
- ctx.slots.push({
62
- name: 'default',
63
- tagRange: [startTagOffset, startTagOffset + node.tag.length],
64
- varName: varSlot,
65
- nodeLoc: node.loc,
66
- });
37
+ if (nameProp?.type === CompilerDOM.NodeTypes.ATTRIBUTE
38
+ && nameProp.value) {
39
+ ctx.slots.push({
40
+ name: nameProp.value.content,
41
+ loc: nameProp.loc.start.offset + nameProp.loc.source.indexOf(nameProp.value.content, nameProp.name.length),
42
+ tagRange: [startTagOffset, startTagOffset + node.tag.length],
43
+ varName: varSlot,
44
+ nodeLoc: node.loc,
45
+ });
46
+ }
47
+ else if (nameProp?.type === CompilerDOM.NodeTypes.DIRECTIVE
48
+ && nameProp.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
49
+ const slotExpVar = ctx.getInternalVariable();
50
+ yield `var ${slotExpVar} = `;
51
+ yield* (0, interpolation_1.generateInterpolation)(options, ctx, nameProp.exp.content, nameProp.exp, nameProp.exp.loc.start.offset, ctx.codeFeatures.all, '(', ')');
52
+ yield ` as const${common_1.endOfLine}`;
53
+ ctx.dynamicSlots.push({
54
+ expVar: slotExpVar,
55
+ varName: varSlot,
56
+ });
57
+ }
58
+ else {
59
+ ctx.slots.push({
60
+ name: 'default',
61
+ tagRange: [startTagOffset, startTagOffset + node.tag.length],
62
+ varName: varSlot,
63
+ nodeLoc: node.loc,
64
+ });
65
+ }
67
66
  }
68
67
  yield* ctx.generateAutoImportCompletion();
69
68
  yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
package/lib/plugins.d.ts CHANGED
@@ -22,5 +22,5 @@ export declare function getBasePlugins(pluginContext: Parameters<VueLanguagePlug
22
22
  id: string;
23
23
  lang: string;
24
24
  }[];
25
- 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;
26
26
  }[];
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[];
@@ -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: resolveCommonLanguageId(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: resolveCommonLanguageId(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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "2.0.15",
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.12",
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": "095f44449d71cd5a4730306c9c8c40df4d44dce3"
37
+ "gitHead": "95b78c38cbf75481ebb59e11956b592346f01d92"
38
38
  }