@vue/language-core 1.8.2 → 1.8.4

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.
@@ -7,7 +7,7 @@ const shared_1 = require("@vue/shared");
7
7
  const path_1 = require("path");
8
8
  const shared_2 = require("../utils/shared");
9
9
  const transform_1 = require("../utils/transform");
10
- const sharedTypes = require("../utils/directorySharedTypes");
10
+ const sharedTypes = require("../utils/globalTypes");
11
11
  const muggle = require("muggle-string");
12
12
  function generate(ts, fileName, _sfc, lang, scriptRanges, scriptSetupRanges, htmlGen, compilerOptions, vueCompilerOptions, codegenStack) {
13
13
  const [codes, codeStacks] = codegenStack ? muggle.track([]) : [[], []];
@@ -730,10 +730,10 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
730
730
  codes.push(`};\n`);
731
731
  /* Components */
732
732
  codes.push('/* Components */\n');
733
- codes.push(`let __VLS_localComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption & typeof __VLS_ctx;\n`);
734
- codes.push(`let __VLS_otherComponents!: typeof __VLS_localComponents & __VLS_GlobalComponents;\n`);
733
+ codes.push(`let __VLS_otherComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & typeof __VLS_componentsOption;\n`);
735
734
  codes.push(`let __VLS_own!: __VLS_SelfComponent<typeof __VLS_name, typeof __VLS_internalComponent & typeof __VLS_publicComponent & (new () => { ${(0, shared_2.getSlotsPropertyName)(vueCompilerOptions.target)}: typeof __VLS_slots })>;\n`);
736
- codes.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);
735
+ codes.push(`let __VLS_localComponents!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);
736
+ codes.push(`let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents & typeof __VLS_ctx;\n`); // for html completion, TS references...
737
737
  /* Style Scoped */
738
738
  codes.push('/* Style Scoped */\n');
739
739
  codes.push('type __VLS_StyleScopedClasses = {}');
@@ -75,7 +75,7 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
75
75
  let ignoreStart;
76
76
  let expectedErrorStart;
77
77
  let expectedErrorNode;
78
- const componentVars = generateComponentVars();
78
+ generatePreResolveComponents();
79
79
  if (sfc.templateAst) {
80
80
  visitNode(sfc.templateAst, undefined, undefined, undefined);
81
81
  }
@@ -143,31 +143,34 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
143
143
  }
144
144
  codes.push('}\n');
145
145
  }
146
- function generateComponentVars() {
147
- const data = {};
148
- codes.push(`let __VLS_templateComponents!: {}\n`);
146
+ function toCanonicalComponentName(tagText) {
147
+ return validTsVar.test(tagText) ? tagText : (0, shared_1.capitalize)((0, shared_1.camelize)(tagText.replace(/:/g, '-')));
148
+ }
149
+ function getPossibleOriginalComponentName(tagText) {
150
+ return [...new Set([
151
+ // order is important: https://github.com/vuejs/language-tools/issues/2010
152
+ (0, shared_1.capitalize)((0, shared_1.camelize)(tagText)),
153
+ (0, shared_1.camelize)(tagText),
154
+ tagText,
155
+ ])];
156
+ }
157
+ function generatePreResolveComponents() {
158
+ codes.push(`let __VLS_resolvedLocalAndGlobalComponents!: {}\n`);
149
159
  for (const tagName in tagNames) {
150
160
  if (nativeTags.has(tagName))
151
161
  continue;
152
162
  const isNamespacedTag = tagName.indexOf('.') >= 0;
153
163
  if (isNamespacedTag)
154
164
  continue;
155
- const validName = validTsVar.test(tagName) ? tagName : (0, shared_1.capitalize)((0, shared_1.camelize)(tagName.replace(/:/g, '-')));
156
- codes.push(`& __VLS_WithComponent<'${validName}', typeof __VLS_components, `,
165
+ codes.push(`& __VLS_WithComponent<'${toCanonicalComponentName(tagName)}', typeof __VLS_localComponents, `,
157
166
  // order is important: https://github.com/vuejs/language-tools/issues/2010
158
167
  `"${(0, shared_1.capitalize)((0, shared_1.camelize)(tagName))}", `, `"${(0, shared_1.camelize)(tagName)}", `, `"${tagName}"`, '>\n');
159
- data[tagName] = validName;
160
168
  }
161
169
  codes.push(`;\n`);
162
170
  for (const tagName in tagNames) {
163
171
  const tagOffsets = tagNames[tagName];
164
172
  const tagRanges = tagOffsets.map(offset => [offset, offset + tagName.length]);
165
- const names = new Set(nativeTags.has(tagName) ? [tagName] : [
166
- // order is important: https://github.com/vuejs/language-tools/issues/2010
167
- (0, shared_1.capitalize)((0, shared_1.camelize)(tagName)),
168
- (0, shared_1.camelize)(tagName),
169
- tagName,
170
- ]);
173
+ const names = nativeTags.has(tagName) ? [tagName] : getPossibleOriginalComponentName(tagName);
171
174
  for (const name of names) {
172
175
  for (const tagRange of tagRanges) {
173
176
  codes.push(nativeTags.has(tagName) ? '({} as __VLS_IntrinsicElements)' : '__VLS_components', ...createPropertyAccessCode([
@@ -185,28 +188,30 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
185
188
  }
186
189
  }
187
190
  codes.push('\n');
188
- const validName = data[tagName];
189
- if (validName) {
190
- codes.push('// @ts-ignore\n', // #2304
191
- '[');
192
- for (const tagRange of tagRanges) {
193
- codes.push([
194
- validName,
195
- 'template',
196
- tagRange,
197
- {
198
- completion: {
199
- additional: true,
200
- autoImportOnly: true,
201
- },
191
+ if (nativeTags.has(tagName))
192
+ continue;
193
+ const isNamespacedTag = tagName.indexOf('.') >= 0;
194
+ if (isNamespacedTag)
195
+ continue;
196
+ codes.push('// @ts-ignore\n', // #2304
197
+ '[');
198
+ const validName = toCanonicalComponentName(tagName);
199
+ for (const tagRange of tagRanges) {
200
+ codes.push([
201
+ validName,
202
+ 'template',
203
+ tagRange,
204
+ {
205
+ completion: {
206
+ additional: true,
207
+ autoImportOnly: true,
202
208
  },
203
- ]);
204
- codes.push(',');
205
- }
206
- codes.push(`];\n`);
209
+ },
210
+ ]);
211
+ codes.push(',');
207
212
  }
213
+ codes.push(`];\n`);
208
214
  }
209
- return data;
210
215
  }
211
216
  function collectTagOffsets() {
212
217
  const tagOffsetsMap = {};
@@ -492,11 +497,12 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
492
497
  else if (dynamicTagExp) {
493
498
  codes.push(`const ${var_originalComponent} = `, ...createInterpolationCode(dynamicTagExp.loc.source, dynamicTagExp.loc, dynamicTagExp.loc.start.offset, capabilitiesPresets.all, '(', ')'), ';\n');
494
499
  }
495
- else if (componentVars[tag]) {
496
- codes.push(`const ${var_originalComponent} = __VLS_templateComponents['${componentVars[tag]}'];\n`);
497
- }
498
500
  else {
499
- codes.push(`const ${var_originalComponent} = {} as any;\n`);
501
+ codes.push(`let ${var_originalComponent}!: `);
502
+ for (const componentName of getPossibleOriginalComponentName(tag)) {
503
+ codes.push(`'${componentName}' extends keyof typeof __VLS_ctx ? typeof __VLS_ctx${validTsVar.test(componentName) ? `.${componentName}` : `['${componentName}']`} : `);
504
+ }
505
+ codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents['${toCanonicalComponentName(tag)}'];\n`);
500
506
  }
501
507
  codes.push(`const ${var_functionalComponent} = __VLS_asFunctionalComponent(`, `${var_originalComponent}, `);
502
508
  if (isIntrinsicElement) {
@@ -507,21 +513,26 @@ function generate(ts, compilerOptions, vueCompilerOptions, sourceTemplate, sourc
507
513
  }
508
514
  codes.push(');\n');
509
515
  for (const offset of tagOffsets) {
510
- if (isNamespacedTag) {
516
+ if (isNamespacedTag || dynamicTagExp) {
511
517
  continue;
512
518
  }
513
- else if (dynamicTagExp) {
514
- continue;
519
+ else if (isIntrinsicElement) {
520
+ codes.push(`({} as __VLS_IntrinsicElements).`);
521
+ codes.push([
522
+ tag,
523
+ 'template',
524
+ [offset, offset + tag.length],
525
+ {
526
+ ...capabilitiesPresets.tagHover,
527
+ ...capabilitiesPresets.diagnosticOnly,
528
+ },
529
+ ], ';\n');
515
530
  }
516
531
  else {
517
- if (isIntrinsicElement) {
518
- codes.push(`({} as __VLS_IntrinsicElements).`);
519
- }
520
- else {
521
- codes.push(`__VLS_templateComponents.`);
522
- }
532
+ const key = toCanonicalComponentName(tag);
533
+ codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
523
534
  codes.push([
524
- componentVars[tag] ?? tag,
535
+ key,
525
536
  'template',
526
537
  [offset, offset + tag.length],
527
538
  {
package/out/index.d.ts CHANGED
@@ -7,6 +7,6 @@ export * from './types';
7
7
  export * from './utils/ts';
8
8
  export * from './utils/parseSfc';
9
9
  export * as scriptRanges from './parsers/scriptRanges';
10
- export * as sharedTypes from './utils/directorySharedTypes';
10
+ export * as sharedTypes from './utils/globalTypes';
11
11
  export * from '@volar/language-core';
12
12
  export * from '@volar/source-map';
package/out/index.js CHANGED
@@ -24,7 +24,7 @@ __exportStar(require("./types"), exports);
24
24
  __exportStar(require("./utils/ts"), exports);
25
25
  __exportStar(require("./utils/parseSfc"), exports);
26
26
  exports.scriptRanges = require("./parsers/scriptRanges");
27
- exports.sharedTypes = require("./utils/directorySharedTypes");
27
+ exports.sharedTypes = require("./utils/globalTypes");
28
28
  __exportStar(require("@volar/language-core"), exports);
29
29
  __exportStar(require("@volar/source-map"), exports);
30
30
  //# sourceMappingURL=index.js.map
@@ -4,7 +4,7 @@ exports.createLanguages = exports.createLanguage = void 0;
4
4
  const path_1 = require("path");
5
5
  const plugins_1 = require("./plugins");
6
6
  const sourceFile_1 = require("./sourceFile");
7
- const sharedTypes = require("./utils/directorySharedTypes");
7
+ const sharedTypes = require("./utils/globalTypes");
8
8
  const ts_1 = require("./utils/ts");
9
9
  function createLanguage(compilerOptions = {}, _vueCompilerOptions = {}, ts = require('typescript'), codegenStack = false) {
10
10
  const vueCompilerOptions = (0, ts_1.resolveVueCompilerOptions)(_vueCompilerOptions);
@@ -0,0 +1,4 @@
1
+ import { VueCompilerOptions } from '../types';
2
+ export declare const baseName = "__VLS_types.d.ts";
3
+ export declare function getTypesCode(vueCompilerOptions: VueCompilerOptions): string;
4
+ export declare function genConstructorOverloads(name?: string, nums?: number): string;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genConstructorOverloads = exports.getTypesCode = exports.baseName = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.baseName = '__VLS_types.d.ts';
6
+ function getTypesCode(vueCompilerOptions) {
7
+ return `
8
+ // @ts-nocheck
9
+
10
+ type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<JSX.IntrinsicElements, Record<string, any>>>;
11
+ type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, JSX.Element>;
12
+
13
+ type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
14
+ type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
15
+
16
+ type __VLS_Prettify<T> = {
17
+ [K in keyof T]: T[K];
18
+ } & {};
19
+
20
+ type __VLS_GlobalComponents =
21
+ __VLS_PickNotAny<import('vue').GlobalComponents, {}>
22
+ & __VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>
23
+ & __VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>
24
+ & Pick<typeof import('${vueCompilerOptions.lib}'),
25
+ 'Transition'
26
+ | 'TransitionGroup'
27
+ | 'KeepAlive'
28
+ | 'Suspense'
29
+ | 'Teleport'
30
+ >;
31
+
32
+ // v-for
33
+ declare function __VLS_getVForSourceType(source: number): [number, number, number][];
34
+ declare function __VLS_getVForSourceType(source: string): [string, number, number][];
35
+ declare function __VLS_getVForSourceType<T extends any[]>(source: T): [
36
+ T[number], // item
37
+ number, // key
38
+ number, // index
39
+ ][];
40
+ declare function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
41
+ T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never, // item
42
+ number, // key
43
+ undefined, // index
44
+ ][];
45
+ declare function __VLS_getVForSourceType<T>(source: T): [
46
+ T[keyof T], // item
47
+ keyof T, // key
48
+ number, // index
49
+ ][];
50
+
51
+ declare function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
52
+ declare function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
53
+ declare function __VLS_directiveFunction<T>(dir: T):
54
+ T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (el: E, value: V) => void
55
+ : T;
56
+ declare function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
57
+ declare function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
58
+
59
+ type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
60
+ type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
61
+ N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0> : { [K in N0]: LocalComponents[N1] } :
62
+ N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0> : { [K in N0]: LocalComponents[N2] } :
63
+ N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0> : { [K in N0]: LocalComponents[N3] } :
64
+ N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0> : { [K in N0]: __VLS_GlobalComponents[N1] } :
65
+ N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0> : { [K in N0]: __VLS_GlobalComponents[N2] } :
66
+ N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0> : { [K in N0]: __VLS_GlobalComponents[N3] } :
67
+ ${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
68
+
69
+ type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
70
+ type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
71
+ type __VLS_EmitEvent<F, E> =
72
+ F extends {
73
+ (event: E, ...payload: infer P): any
74
+ } ? (...payload: P) => void
75
+ : F extends {
76
+ (event: E, ...payload: infer P): any
77
+ (...args: any): any
78
+ } ? (...payload: P) => void
79
+ : F extends {
80
+ (event: E, ...payload: infer P): any
81
+ (...args: any): any
82
+ (...args: any): any
83
+ } ? (...payload: P) => void
84
+ : F extends {
85
+ (event: E, ...payload: infer P): any
86
+ (...args: any): any
87
+ (...args: any): any
88
+ (...args: any): any
89
+ } ? (...payload: P) => void
90
+ : unknown | '[Type Warning] Volar could not infer $emit event more than 4 overloads without DefineComponent. see https://github.com/vuejs/language-tools/issues/60';
91
+ declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
92
+ T extends new (...args: any) => any
93
+ ? (props: (K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: {
94
+ attrs?: any,
95
+ slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: infer Slots } ? Slots : any,
96
+ emit?: K extends { $emit: infer Emit } ? Emit : any
97
+ }) => JSX.Element & { __ctx?: typeof ctx & { props?: typeof props; expose?(exposed: K): void; } }
98
+ : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
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
101
+ declare function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
102
+ declare function __VLS_pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): __VLS_FillingEventArg<
103
+ __VLS_PickNotAny<
104
+ __VLS_AsFunctionOrAny<E>,
105
+ __VLS_AsFunctionOrAny<__VLS_EmitEvent<Emit, K>>
106
+ >
107
+ > | undefined;
108
+ 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
111
+ >;
112
+ type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
113
+
114
+ declare function __VLS_componentProps<T, K>(comp: T, fnReturn: K):
115
+ __VLS_PickNotAny<K, {}> extends { __ctx: { props: infer P } } ? NonNullable<P>
116
+ : T extends (props: infer P, ...args: any) => any ? NonNullable<P> :
117
+ {};
118
+ `.trim();
119
+ }
120
+ exports.getTypesCode = getTypesCode;
121
+ // TODO: not working for overloads > n (n = 8)
122
+ // see: https://github.com/vuejs/language-tools/issues/60
123
+ function genConstructorOverloads(name = 'ConstructorOverloads', nums) {
124
+ let code = '';
125
+ code += `type ${name}<T> =\n`;
126
+ if (nums === undefined) {
127
+ for (let i = 8; i >= 1; i--) {
128
+ gen(i);
129
+ }
130
+ }
131
+ else if (nums > 0) {
132
+ gen(nums);
133
+ }
134
+ code += `// 0\n`;
135
+ code += `{};\n`;
136
+ return code;
137
+ function gen(i) {
138
+ code += `// ${i}\n`;
139
+ code += `T extends {\n`;
140
+ for (let j = 1; j <= i; j++) {
141
+ code += `(event: infer E${j}, ...payload: infer P${j}): void;\n`;
142
+ }
143
+ code += `} ? (\n`;
144
+ for (let j = 1; j <= i; j++) {
145
+ if (j > 1)
146
+ code += '& ';
147
+ code += `(E${j} extends string ? { [K${j} in E${j}]: (...payload: P${j}) => void } : {})\n`;
148
+ }
149
+ code += `) :\n`;
150
+ }
151
+ }
152
+ exports.genConstructorOverloads = genConstructorOverloads;
153
+ //# sourceMappingURL=globalTypes.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-core",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,8 +13,8 @@
13
13
  "directory": "packages/vue-language-core"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.7.9",
17
- "@volar/source-map": "1.7.9",
16
+ "@volar/language-core": "~1.8.0",
17
+ "@volar/source-map": "~1.8.0",
18
18
  "@vue/compiler-dom": "^3.3.0",
19
19
  "@vue/reactivity": "^3.3.0",
20
20
  "@vue/shared": "^3.3.0",
@@ -34,5 +34,5 @@
34
34
  "optional": true
35
35
  }
36
36
  },
37
- "gitHead": "de0fb3f1be30b495d17e2999aee24fb9ea3e7e0e"
37
+ "gitHead": "a62aa882911de149ae65f4c28eddfd93e1dee99d"
38
38
  }