@vue/language-core 1.8.10 → 1.8.11

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.
@@ -252,7 +252,7 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
252
252
  if (!scriptSetupRanges)
253
253
  return;
254
254
  codes.push([
255
- sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
255
+ sfc.scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
256
256
  'scriptSetup',
257
257
  0,
258
258
  language_core_1.FileRangeCapabilities.full,
@@ -433,7 +433,20 @@ function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htm
433
433
  const definePropProposalA = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
434
434
  const definePropProposalB = sfc.scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
435
435
  if (vueCompilerOptions.target >= 3.3) {
436
- codes.push(`const { defineProps, defineEmits, defineExpose, defineOptions, defineSlots, defineModel, withDefaults } = await import('${vueCompilerOptions.lib}');\n`);
436
+ const bindings = new Set(scriptSetupRanges.bindings.map(range => sfc.scriptSetup.content.substring(range.start, range.end)));
437
+ codes.push('const { ');
438
+ for (const [macro, aliases] of Object.entries(vueCompilerOptions.macros)) {
439
+ for (const alias of aliases) {
440
+ if (!bindings.has(alias)) {
441
+ codes.push(macro);
442
+ if (alias !== macro) {
443
+ codes.push(` : ${alias}`);
444
+ }
445
+ codes.push(`, `);
446
+ }
447
+ }
448
+ }
449
+ codes.push(`} = await import('${vueCompilerOptions.lib}');\n`);
437
450
  }
438
451
  if (definePropProposalA) {
439
452
  codes.push(`
@@ -95,6 +95,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
95
95
  const identifiers = new Set();
96
96
  const scopedClasses = [];
97
97
  const blockConditions = [];
98
+ const hasSlotElements = new Set();
98
99
  let hasSlot = false;
99
100
  let elementIndex = 0;
100
101
  let ignoreStart;
@@ -312,7 +313,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
312
313
  }
313
314
  }
314
315
  codes.push([
315
- '// @ts-expect-error',
316
+ '// @ts-expect-error __VLS_TS_EXPECT_ERROR',
316
317
  'template',
317
318
  [expectedErrorNode.loc.start.offset, expectedErrorNode.loc.end.offset],
318
319
  {
@@ -636,6 +637,9 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
636
637
  //#endregion
637
638
  const slotDir = node.props.find(p => p.type === 7 /* CompilerDOM.NodeTypes.DIRECTIVE */ && p.name === 'slot');
638
639
  if (slotDir && componentCtxVar) {
640
+ if (parentEl) {
641
+ hasSlotElements.add(parentEl);
642
+ }
639
643
  const slotBlockVars = [];
640
644
  codes.push(`{\n`);
641
645
  let hasProps = false;
@@ -712,6 +716,18 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
712
716
  prev = childNode;
713
717
  }
714
718
  resolveComment();
719
+ // fix https://github.com/vuejs/language-tools/issues/932
720
+ if (!hasSlotElements.has(node) && node.children.length) {
721
+ codes.push(`(${componentCtxVar}.slots!)`, ...createPropertyAccessCode([
722
+ 'default',
723
+ 'template',
724
+ [
725
+ node.children[0].loc.start.offset,
726
+ node.children[node.children.length - 1].loc.end.offset,
727
+ ],
728
+ { references: true },
729
+ ]), ';\n');
730
+ }
715
731
  }
716
732
  codes.push(`}\n`);
717
733
  }
@@ -65,7 +65,7 @@ function parseScriptSetupRanges(ts, ast, vueCompilerOptions) {
65
65
  if (ts.isCallExpression(node)
66
66
  && ts.isIdentifier(node.expression)) {
67
67
  const callText = node.expression.getText(ast);
68
- if (callText === 'defineModel') {
68
+ if (vueCompilerOptions.macros.defineModel.includes(callText)) {
69
69
  let name;
70
70
  let options;
71
71
  if (node.arguments.length >= 2) {
package/out/types.d.ts CHANGED
@@ -23,6 +23,8 @@ export interface VueCompilerOptions {
23
23
  defineSlots: string[];
24
24
  defineEmits: string[];
25
25
  defineExpose: string[];
26
+ defineModel: string[];
27
+ defineOptions: string[];
26
28
  withDefaults: string[];
27
29
  };
28
30
  plugins: VueLanguagePlugin[];
package/out/utils/ts.js CHANGED
@@ -225,12 +225,15 @@ function resolveVueCompilerOptions(vueOptions) {
225
225
  optionsWrapper: vueOptions.optionsWrapper ?? (target >= 2.7
226
226
  ? [`(await import('${lib}')).defineComponent(`, `)`]
227
227
  : [`(await import('vue')).default.extend(`, `)`]),
228
- macros: vueOptions.macros ?? {
228
+ macros: {
229
229
  defineProps: ['defineProps'],
230
230
  defineSlots: ['defineSlots'],
231
231
  defineEmits: ['defineEmits'],
232
232
  defineExpose: ['defineExpose'],
233
+ defineModel: ['defineModel'],
234
+ defineOptions: ['defineOptions'],
233
235
  withDefaults: ['withDefaults'],
236
+ ...vueOptions.macros,
234
237
  },
235
238
  plugins: vueOptions.plugins ?? [],
236
239
  hooks: vueOptions.hooks ?? [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.10",
3
+ "version": "1.8.11",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "97d60fa475b653fe435a7fae6e2a626821658351"
37
+ "gitHead": "cce193dcc182aad5d02f630fa3ae8a793d443680"
38
38
  }