@vue/language-core 1.8.11 → 1.8.13

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.
@@ -60,6 +60,8 @@ const capabilitiesPresets = {
60
60
  };
61
61
  const formatBrackets = {
62
62
  normal: ['`${', '}`;'],
63
+ // fix https://github.com/vuejs/language-tools/issues/3572
64
+ params: ['(', ') => {}'],
63
65
  // fix https://github.com/vuejs/language-tools/issues/1210
64
66
  // fix https://github.com/vuejs/language-tools/issues/2305
65
67
  curly: ['0 +', '+ 0;'],
@@ -530,14 +532,12 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
530
532
  }
531
533
  codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents['${toCanonicalComponentName(tag)}'];\n`);
532
534
  }
533
- codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `);
534
535
  if (isIntrinsicElement) {
535
- codes.push('{}');
536
+ codes.push(`const ${var_functionalComponent} = __VLS_elementAsFunctionalComponent(${var_originalComponent});\n`);
536
537
  }
537
538
  else {
538
- codes.push(`new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '})');
539
+ codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `, `new ${var_originalComponent}({`, ...createPropsCode(node, props, 'extraReferences'), '})', ');\n');
539
540
  }
540
- codes.push(');\n');
541
541
  for (const offset of tagOffsets) {
542
542
  if (isNamespacedTag || dynamicTagExp) {
543
543
  continue;
@@ -568,24 +568,32 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
568
568
  ], ';\n');
569
569
  }
570
570
  }
571
- codes.push(`const ${var_componentInstance} = ${var_functionalComponent}(`,
572
- // diagnostic start
573
- tagOffsets.length ? ['', 'template', tagOffsets[0], capabilitiesPresets.diagnosticOnly]
574
- : dynamicTagExp ? ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly]
575
- : '', '{ ');
576
- if (!vueCompilerOptions.strictTemplates) {
577
- // fix https://github.com/vuejs/language-tools/issues/3318
578
- codes.push('...{ ');
579
- }
580
- codes.push(...createPropsCode(node, props, 'normal', propsFailedExps));
581
- if (!vueCompilerOptions.strictTemplates) {
582
- codes.push('}, ');
583
- }
584
- codes.push('}',
585
- // diagnostic end
586
- tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly]
587
- : dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly]
588
- : '', `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}));\n`);
571
+ if (vueCompilerOptions.strictTemplates) {
572
+ // with strictTemplates, generate once for props type-checking + instance type
573
+ codes.push(`const ${var_componentInstance} = ${var_functionalComponent}(`,
574
+ // diagnostic start
575
+ tagOffsets.length ? ['', 'template', tagOffsets[0], capabilitiesPresets.diagnosticOnly]
576
+ : dynamicTagExp ? ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly]
577
+ : '', '{ ', ...createPropsCode(node, props, 'normal', propsFailedExps), '}',
578
+ // diagnostic end
579
+ tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly]
580
+ : dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly]
581
+ : '', `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}));\n`);
582
+ }
583
+ else {
584
+ // without strictTemplates, this only for instacne type
585
+ codes.push(`const ${var_componentInstance} = ${var_functionalComponent}(`, '{ ', ...createPropsCode(node, props, 'extraReferences'), '}', `, ...__VLS_functionalComponentArgsRest(${var_functionalComponent}));\n`);
586
+ // and this for props type-checking
587
+ codes.push(`({} as (props: __VLS_FunctionalComponentProps<typeof ${var_originalComponent}, typeof ${var_componentInstance}> & Record<string, unknown>) => void)(`,
588
+ // diagnostic start
589
+ tagOffsets.length ? ['', 'template', tagOffsets[0], capabilitiesPresets.diagnosticOnly]
590
+ : dynamicTagExp ? ['', 'template', startTagOffset, capabilitiesPresets.diagnosticOnly]
591
+ : '', '{ ', ...createPropsCode(node, props, 'normal', propsFailedExps), '}',
592
+ // diagnostic end
593
+ tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly]
594
+ : dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly]
595
+ : '', `);\n`);
596
+ }
589
597
  if (tag !== 'template' && tag !== 'slot') {
590
598
  componentCtxVar = `__VLS_${elementIndex++}`;
591
599
  codes.push(`const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!;\n`);
@@ -644,9 +652,9 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
644
652
  codes.push(`{\n`);
645
653
  let hasProps = false;
646
654
  if (slotDir?.exp?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
647
- formatCodes.push(...createFormatCode(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.normal));
648
- const collectAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
649
- (0, transform_1.colletVars)(ts, collectAst, slotBlockVars);
655
+ formatCodes.push(...createFormatCode(slotDir.exp.content, slotDir.exp.loc.start.offset, formatBrackets.params));
656
+ const slotAst = createTsAst(slotDir, `(${slotDir.exp.content}) => {}`);
657
+ (0, transform_1.colletVars)(ts, slotAst, slotBlockVars);
650
658
  hasProps = true;
651
659
  if (slotDir.exp.content.indexOf(':') === -1) {
652
660
  codes.push('const [', [
@@ -737,7 +745,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
737
745
  && prop.name === 'on'
738
746
  && prop.arg?.type === 4 /* CompilerDOM.NodeTypes.SIMPLE_EXPRESSION */) {
739
747
  const eventVar = `__VLS_${elementIndex++}`;
740
- codes.push(`let ${eventVar} = { '${prop.arg.loc.source}': `, `__VLS_pickEvent(${componentCtxVar}.emit!, '${prop.arg.loc.source}' as const, __VLS_componentProps(${componentVar}, ${componentInstanceVar})`, ...createPropertyAccessCode([
748
+ codes.push(`let ${eventVar} = { '${prop.arg.loc.source}': `, `__VLS_pickEvent(${componentCtxVar}.emit!, '${prop.arg.loc.source}' as const, ({} as __VLS_FunctionalComponentProps<typeof ${componentVar}, typeof ${componentInstanceVar}>)`, ...createPropertyAccessCode([
741
749
  (0, shared_1.camelize)('on-' + prop.arg.loc.source),
742
750
  'template',
743
751
  [prop.arg.loc.start.offset, prop.arg.loc.end.offset],
@@ -8,6 +8,7 @@ const scriptSetupReg = /\\\<[\s\S]+?\>\n?/g;
8
8
  const sfcBlockReg = /\<(script|style)\b[\s\S]*?\>([\s\S]*?)\<\/\1\>/g;
9
9
  const angleBracketReg = /\<\S*\:\S*\>/g;
10
10
  const linkReg = /\[[\s\S]*?\]\([\s\S]*?\)/g;
11
+ const codeSnippetImportReg = /^\s*<<<\s*.+/gm;
11
12
  const plugin = () => {
12
13
  return {
13
14
  version: 1,
@@ -19,7 +20,9 @@ const plugin = () => {
19
20
  // inline code block
20
21
  .replace(inlineCodeblockReg, match => `\`${' '.repeat(match.length - 2)}\``)
21
22
  // # \<script setup>
22
- .replace(scriptSetupReg, match => ' '.repeat(match.length));
23
+ .replace(scriptSetupReg, match => ' '.repeat(match.length))
24
+ // <<< https://vitepress.dev/guide/markdown#import-code-snippets
25
+ .replace(codeSnippetImportReg, match => ' '.repeat(match.length));
23
26
  const codes = [];
24
27
  for (const match of content.matchAll(sfcBlockReg)) {
25
28
  if (match.index !== undefined) {
@@ -97,7 +97,8 @@ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any)
97
97
  }) => JSX.Element & { __ctx?: typeof ctx & { props?: typeof props; expose?(exposed: K): void; } }
98
98
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
99
99
  : T extends (...args: any) => any ? T
100
- : (_: T extends import('${vueCompilerOptions.lib}').VNode | import('${vueCompilerOptions.lib}').VNode[] | string ? {}: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } }; // IntrinsicElement
100
+ : (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
101
+ declare function __VLS_elementAsFunctionalComponent<T>(t: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
101
102
  declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
102
103
  declare function __VLS_pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): __VLS_FillingEventArg<
103
104
  __VLS_PickNotAny<
@@ -106,16 +107,16 @@ declare function __VLS_pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E):
106
107
  >
107
108
  > | undefined;
108
109
  declare function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
109
- K extends { __ctx?: infer Ctx } ? Ctx : any,
110
- T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
110
+ '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
111
+ , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
111
112
  >;
113
+ type __VLS_FunctionalComponentProps<T, K> =
114
+ '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
115
+ : T extends (props: infer P, ...args: any) => any ? P :
116
+ {};
112
117
  type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
113
118
 
114
119
  declare function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
115
- declare function __VLS_componentProps<T, K>(comp: T, fnReturn: K):
116
- __VLS_PickNotAny<K, {}> extends { __ctx: { props: infer P } } ? NonNullable<P>
117
- : T extends (props: infer P, ...args: any) => any ? NonNullable<P> :
118
- {};
119
120
  `.trim();
120
121
  }
121
122
  exports.getTypesCode = getTypesCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.11",
3
+ "version": "1.8.13",
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": "cce193dcc182aad5d02f630fa3ae8a793d443680"
37
+ "gitHead": "4d25501776edb5a0712c10c6921fffbdc9454a23"
38
38
  }