@vue/language-core 2.2.0 → 2.2.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.
Files changed (73) hide show
  1. package/index.d.ts +0 -1
  2. package/index.js +1 -2
  3. package/lib/codegen/codeFeatures.d.ts +83 -0
  4. package/lib/codegen/codeFeatures.js +71 -0
  5. package/lib/codegen/globalTypes.d.ts +3 -1
  6. package/lib/codegen/globalTypes.js +45 -37
  7. package/lib/codegen/localTypes.d.ts +1 -1
  8. package/lib/codegen/localTypes.js +4 -4
  9. package/lib/codegen/script/component.d.ts +1 -1
  10. package/lib/codegen/script/component.js +15 -11
  11. package/lib/codegen/script/componentSelf.d.ts +1 -1
  12. package/lib/codegen/script/componentSelf.js +2 -2
  13. package/lib/codegen/script/context.d.ts +1 -1
  14. package/lib/codegen/script/index.d.ts +1 -8
  15. package/lib/codegen/script/index.js +19 -45
  16. package/lib/codegen/script/scriptSetup.d.ts +1 -1
  17. package/lib/codegen/script/scriptSetup.js +78 -79
  18. package/lib/codegen/script/src.d.ts +2 -2
  19. package/lib/codegen/script/src.js +37 -38
  20. package/lib/codegen/script/template.d.ts +2 -3
  21. package/lib/codegen/script/template.js +12 -79
  22. package/lib/codegen/style/classProperty.d.ts +2 -0
  23. package/lib/codegen/style/classProperty.js +31 -0
  24. package/lib/codegen/style/modules.d.ts +3 -0
  25. package/lib/codegen/{script/styleModulesType.js → style/modules.js} +15 -15
  26. package/lib/codegen/style/scopedClasses.d.ts +4 -0
  27. package/lib/codegen/style/scopedClasses.js +32 -0
  28. package/lib/codegen/template/context.d.ts +122 -17
  29. package/lib/codegen/template/context.js +162 -92
  30. package/lib/codegen/template/element.d.ts +1 -1
  31. package/lib/codegen/template/element.js +86 -330
  32. package/lib/codegen/template/elementChildren.js +0 -13
  33. package/lib/codegen/template/elementDirectives.js +20 -12
  34. package/lib/codegen/template/elementEvents.d.ts +1 -1
  35. package/lib/codegen/template/elementEvents.js +15 -11
  36. package/lib/codegen/template/elementProps.d.ts +2 -1
  37. package/lib/codegen/template/elementProps.js +31 -33
  38. package/lib/codegen/template/index.d.ts +1 -0
  39. package/lib/codegen/template/index.js +53 -33
  40. package/lib/codegen/template/interpolation.js +13 -9
  41. package/lib/codegen/template/slotOutlet.js +44 -21
  42. package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
  43. package/lib/codegen/template/styleScopedClasses.js +146 -9
  44. package/lib/codegen/template/templateChild.js +69 -30
  45. package/lib/codegen/template/vFor.js +2 -2
  46. package/lib/codegen/template/vIf.js +3 -3
  47. package/lib/codegen/template/vSlot.d.ts +6 -0
  48. package/lib/codegen/template/vSlot.js +92 -0
  49. package/lib/codegen/utils/index.d.ts +13 -2
  50. package/lib/codegen/utils/index.js +33 -6
  51. package/lib/parsers/scriptSetupRanges.d.ts +5 -3
  52. package/lib/parsers/scriptSetupRanges.js +24 -35
  53. package/lib/parsers/vueCompilerOptions.d.ts +2 -2
  54. package/lib/plugins/file-md.js +3 -0
  55. package/lib/plugins/vue-template-inline-ts.js +56 -15
  56. package/lib/plugins/vue-tsx.d.ts +43 -32
  57. package/lib/plugins/vue-tsx.js +88 -68
  58. package/lib/types.d.ts +29 -16
  59. package/lib/utils/parseSfc.js +41 -16
  60. package/lib/utils/signals.d.ts +2 -0
  61. package/lib/utils/signals.js +54 -0
  62. package/lib/utils/ts.d.ts +14 -2
  63. package/lib/utils/ts.js +134 -88
  64. package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
  65. package/lib/virtualFile/computedEmbeddedCodes.js +14 -24
  66. package/lib/virtualFile/computedSfc.d.ts +1 -2
  67. package/lib/virtualFile/computedSfc.js +86 -96
  68. package/lib/virtualFile/computedVueSfc.d.ts +1 -2
  69. package/lib/virtualFile/computedVueSfc.js +7 -7
  70. package/lib/virtualFile/vueFile.d.ts +8 -11
  71. package/lib/virtualFile/vueFile.js +15 -9
  72. package/package.json +4 -4
  73. package/lib/codegen/script/styleModulesType.d.ts +0 -4
package/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from './lib/types';
7
7
  export * from './lib/utils/parseSfc';
8
8
  export * from './lib/utils/ts';
9
9
  export * from './lib/virtualFile/vueFile';
10
- export * as scriptRanges from './lib/parsers/scriptRanges';
11
10
  export { tsCodegen } from './lib/plugins/vue-tsx';
12
11
  export * from './lib/utils/shared';
13
12
  export * from '@volar/language-core';
package/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.tsCodegen = exports.scriptRanges = void 0;
17
+ exports.tsCodegen = void 0;
18
18
  __exportStar(require("./lib/codegen/globalTypes"), exports);
19
19
  __exportStar(require("./lib/codegen/template"), exports);
20
20
  __exportStar(require("./lib/languagePlugin"), exports);
@@ -24,7 +24,6 @@ __exportStar(require("./lib/types"), exports);
24
24
  __exportStar(require("./lib/utils/parseSfc"), exports);
25
25
  __exportStar(require("./lib/utils/ts"), exports);
26
26
  __exportStar(require("./lib/virtualFile/vueFile"), exports);
27
- exports.scriptRanges = require("./lib/parsers/scriptRanges");
28
27
  var vue_tsx_1 = require("./lib/plugins/vue-tsx");
29
28
  Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
30
29
  __exportStar(require("./lib/utils/shared"), exports);
@@ -0,0 +1,83 @@
1
+ import type { VueCodeInformation } from '../types';
2
+ declare const raw: {
3
+ all: {
4
+ verification: true;
5
+ completion: true;
6
+ semantic: true;
7
+ navigation: true;
8
+ };
9
+ none: {};
10
+ verification: {
11
+ verification: true;
12
+ };
13
+ completion: {
14
+ completion: true;
15
+ };
16
+ additionalCompletion: {
17
+ completion: {
18
+ isAdditional: true;
19
+ };
20
+ };
21
+ withoutCompletion: {
22
+ verification: true;
23
+ semantic: true;
24
+ navigation: true;
25
+ };
26
+ navigation: {
27
+ navigation: true;
28
+ };
29
+ navigationWithoutRename: {
30
+ navigation: {
31
+ shouldRename: () => false;
32
+ };
33
+ };
34
+ navigationAndCompletion: {
35
+ navigation: true;
36
+ completion: true;
37
+ };
38
+ navigationAndAdditionalCompletion: {
39
+ navigation: true;
40
+ completion: {
41
+ isAdditional: true;
42
+ };
43
+ };
44
+ navigationAndVerification: {
45
+ navigation: true;
46
+ verification: true;
47
+ };
48
+ withoutNavigation: {
49
+ verification: true;
50
+ completion: true;
51
+ semantic: true;
52
+ };
53
+ withoutHighlight: {
54
+ semantic: {
55
+ shouldHighlight: () => false;
56
+ };
57
+ verification: true;
58
+ navigation: true;
59
+ completion: true;
60
+ };
61
+ withoutHighlightAndNavigation: {
62
+ semantic: {
63
+ shouldHighlight: () => false;
64
+ };
65
+ verification: true;
66
+ completion: true;
67
+ };
68
+ withoutHighlightAndCompletion: {
69
+ semantic: {
70
+ shouldHighlight: () => false;
71
+ };
72
+ verification: true;
73
+ navigation: true;
74
+ };
75
+ withoutHighlightAndCompletionAndNavigation: {
76
+ semantic: {
77
+ shouldHighlight: () => false;
78
+ };
79
+ verification: true;
80
+ };
81
+ };
82
+ export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
83
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codeFeatures = void 0;
4
+ const raw = {
5
+ all: {
6
+ verification: true,
7
+ completion: true,
8
+ semantic: true,
9
+ navigation: true,
10
+ },
11
+ none: {},
12
+ verification: {
13
+ verification: true,
14
+ },
15
+ completion: {
16
+ completion: true,
17
+ },
18
+ additionalCompletion: {
19
+ completion: { isAdditional: true },
20
+ },
21
+ withoutCompletion: {
22
+ verification: true,
23
+ semantic: true,
24
+ navigation: true,
25
+ },
26
+ navigation: {
27
+ navigation: true,
28
+ },
29
+ navigationWithoutRename: {
30
+ navigation: { shouldRename: () => false },
31
+ },
32
+ navigationAndCompletion: {
33
+ navigation: true,
34
+ completion: true,
35
+ },
36
+ navigationAndAdditionalCompletion: {
37
+ navigation: true,
38
+ completion: { isAdditional: true },
39
+ },
40
+ navigationAndVerification: {
41
+ navigation: true,
42
+ verification: true,
43
+ },
44
+ withoutNavigation: {
45
+ verification: true,
46
+ completion: true,
47
+ semantic: true,
48
+ },
49
+ withoutHighlight: {
50
+ semantic: { shouldHighlight: () => false },
51
+ verification: true,
52
+ navigation: true,
53
+ completion: true,
54
+ },
55
+ withoutHighlightAndNavigation: {
56
+ semantic: { shouldHighlight: () => false },
57
+ verification: true,
58
+ completion: true,
59
+ },
60
+ withoutHighlightAndCompletion: {
61
+ semantic: { shouldHighlight: () => false },
62
+ verification: true,
63
+ navigation: true,
64
+ },
65
+ withoutHighlightAndCompletionAndNavigation: {
66
+ semantic: { shouldHighlight: () => false },
67
+ verification: true,
68
+ },
69
+ };
70
+ exports.codeFeatures = raw;
71
+ //# sourceMappingURL=codeFeatures.js.map
@@ -1 +1,3 @@
1
- export declare function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean): string;
1
+ import type { VueCompilerOptions } from '../types';
2
+ export declare function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
3
+ export declare function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }: VueCompilerOptions): string;
@@ -1,9 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalTypesFileName = getGlobalTypesFileName;
3
4
  exports.generateGlobalTypes = generateGlobalTypes;
4
5
  const shared_1 = require("../utils/shared");
5
- function generateGlobalTypes(lib, target, strictTemplates) {
6
- const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
6
+ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
7
+ return [
8
+ lib,
9
+ target,
10
+ checkUnknownProps,
11
+ checkUnknownEvents,
12
+ checkUnknownComponents,
13
+ ].map(v => {
14
+ if (typeof v === 'boolean') {
15
+ return v ? 1 : 0;
16
+ }
17
+ return v;
18
+ }).join('_') + '.d.ts';
19
+ }
20
+ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
21
+ const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
7
22
  let text = ``;
8
23
  if (target < 3.5) {
9
24
  text += `
@@ -19,11 +34,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
19
34
  const __VLS_unref: typeof import('${lib}').unref;
20
35
  const __VLS_placeholder: any;
21
36
 
22
- const __VLS_nativeElements = {
23
- ...{} as SVGElementTagNameMap,
24
- ...{} as HTMLElementTagNameMap,
25
- };
26
-
37
+ type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
27
38
  type __VLS_IntrinsicElements = ${(target >= 3.3
28
39
  ? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
29
40
  : `globalThis.JSX.IntrinsicElements;`)}
@@ -36,15 +47,16 @@ function generateGlobalTypes(lib, target, strictTemplates) {
36
47
  type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
37
48
  type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
38
49
  type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
39
- type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
40
- type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
50
+ type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
51
+ type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
41
52
  N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
42
53
  N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
43
54
  N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
55
+ Self extends object ? { [K in N0]: Self } :
44
56
  N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
45
57
  N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
46
58
  N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
47
- ${strictTemplates ? '{}' : '{ [K in N0]: unknown }'};
59
+ ${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
48
60
  type __VLS_FunctionalComponentProps<T, K> =
49
61
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
50
62
  : T extends (props: infer P, ...args: any) => any ? P :
@@ -64,7 +76,7 @@ function generateGlobalTypes(lib, target, strictTemplates) {
64
76
  : __VLS_IsFunction<Events, CamelizedEvent> extends true
65
77
  ? { [K in onEvent]?: Events[CamelizedEvent] }
66
78
  : Props
67
- )${strictTemplates ? '' : ' & Record<string, unknown>'};
79
+ )${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
68
80
  // fix https://github.com/vuejs/language-tools/issues/926
69
81
  type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
70
82
  type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
@@ -93,26 +105,19 @@ function generateGlobalTypes(lib, target, strictTemplates) {
93
105
  '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
94
106
  , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
95
107
  >>;
108
+ type __VLS_OmitStringIndex<T> = {
109
+ [K in keyof T as string extends K ? never : K]: T[K];
110
+ };
96
111
  type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
97
112
 
98
- function __VLS_getVForSourceType(source: number): [number, number, number][];
99
- function __VLS_getVForSourceType(source: string): [string, number, number][];
100
- function __VLS_getVForSourceType<T extends any[]>(source: T): [
101
- item: T[number],
102
- key: number,
113
+ function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
114
+ item: T extends number ? number
115
+ : T extends string ? string
116
+ : T extends any[] ? T[number]
117
+ : T extends Iterable<infer T1> ? T1
118
+ : any,
103
119
  index: number,
104
120
  ][];
105
- function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
106
- item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
107
- key: number,
108
- index: undefined,
109
- ][];
110
- // #3845
111
- function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
112
- item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
113
- key: number,
114
- index: undefined,
115
- ][];
116
121
  function __VLS_getVForSourceType<T>(source: T): [
117
122
  item: T[keyof T],
118
123
  key: keyof T,
@@ -126,22 +131,25 @@ function generateGlobalTypes(lib, target, strictTemplates) {
126
131
  ? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
127
132
  : T extends (...args: any) => any
128
133
  ? T
129
- : __VLS_unknownDirective;
130
- function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
134
+ : (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
131
135
  function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
132
136
  function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
133
137
  T extends new (...args: any) => any
134
- ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
135
- attrs?: any,
136
- slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
137
- emit?: K extends { $emit: infer Emit } ? Emit : any
138
- } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
138
+ ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
139
+ __ctx?: {
140
+ attrs?: any;
141
+ slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any;
142
+ emit?: K extends { $emit: infer Emit } ? Emit : any;
143
+ expose?(exposed: K): void;
144
+ props?: ${fnPropsType};
145
+ }
146
+ }
139
147
  : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
140
148
  : T extends (...args: any) => any ? T
141
- : (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
142
- function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
149
+ : (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
143
150
  function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
144
- function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
151
+ function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
152
+ function __VLS_asFunctionalSlot<S>(slot: S): (props: NonNullable<S> extends (props: infer P) => any ? P : {}) => void;
145
153
  function __VLS_tryAsConstant<const T>(t: T): T;
146
154
  }
147
155
  `;
@@ -6,7 +6,7 @@ export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptio
6
6
  readonly PrettifyLocal: string;
7
7
  readonly OmitKeepDiscriminatedUnion: string;
8
8
  readonly WithDefaults: string;
9
- readonly WithTemplateSlots: string;
9
+ readonly WithSlots: string;
10
10
  readonly PropsChildren: string;
11
11
  readonly TypePropsToOption: string;
12
12
  readonly OmitIndexSignature: string;
@@ -18,8 +18,8 @@ type __VLS_WithDefaults<P, D> = {
18
18
  };
19
19
  `.trimStart());
20
20
  const PrettifyLocal = defineHelper(`__VLS_PrettifyLocal`, () => `type __VLS_PrettifyLocal<T> = { [K in keyof T]: T[K]; } & {}${utils_1.endOfLine}`);
21
- const WithTemplateSlots = defineHelper(`__VLS_WithTemplateSlots`, () => `
22
- type __VLS_WithTemplateSlots<T, S> = T & {
21
+ const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
22
+ type __VLS_WithSlots<T, S> = T & {
23
23
  new(): {
24
24
  ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: S;
25
25
  ${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
@@ -62,7 +62,7 @@ type __VLS_TypePropsToOption<T> = {
62
62
  [PrettifyLocal.name]: PrettifyLocal,
63
63
  [OmitKeepDiscriminatedUnion.name]: OmitKeepDiscriminatedUnion,
64
64
  [WithDefaults.name]: WithDefaults,
65
- [WithTemplateSlots.name]: WithTemplateSlots,
65
+ [WithSlots.name]: WithSlots,
66
66
  [PropsChildren.name]: PropsChildren,
67
67
  [TypePropsToOption.name]: TypePropsToOption,
68
68
  [OmitIndexSignature.name]: OmitIndexSignature,
@@ -76,7 +76,7 @@ type __VLS_TypePropsToOption<T> = {
76
76
  get PrettifyLocal() { return PrettifyLocal.name; },
77
77
  get OmitKeepDiscriminatedUnion() { return OmitKeepDiscriminatedUnion.name; },
78
78
  get WithDefaults() { return WithDefaults.name; },
79
- get WithTemplateSlots() { return WithTemplateSlots.name; },
79
+ get WithSlots() { return WithSlots.name; },
80
80
  get PropsChildren() { return PropsChildren.name; },
81
81
  get TypePropsToOption() { return TypePropsToOption.name; },
82
82
  get OmitIndexSignature() { return OmitIndexSignature.name; },
@@ -1,7 +1,7 @@
1
1
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
2
2
  import type { Code, Sfc } from '../../types';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { ScriptCodegenOptions } from './index';
4
+ import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
6
6
  export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
7
7
  export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
@@ -4,12 +4,12 @@ exports.generateComponent = generateComponent;
4
4
  exports.generateComponentSetupReturns = generateComponentSetupReturns;
5
5
  exports.generateEmitsOption = generateEmitsOption;
6
6
  exports.generatePropsOption = generatePropsOption;
7
+ const codeFeatures_1 = require("../codeFeatures");
7
8
  const utils_1 = require("../utils");
8
- const index_1 = require("./index");
9
9
  function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
10
10
  if (options.sfc.script && options.scriptRanges?.exportDefault && options.scriptRanges.exportDefault.expression.start !== options.scriptRanges.exportDefault.args.start) {
11
11
  // use defineComponent() from user space code if it exist
12
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, index_1.codeFeatures.all);
12
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, options.scriptRanges.exportDefault.expression.start, options.scriptRanges.exportDefault.args.start, codeFeatures_1.codeFeatures.all);
13
13
  yield `{${utils_1.newLine}`;
14
14
  }
15
15
  else {
@@ -32,15 +32,19 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
32
32
  }
33
33
  yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
34
34
  }
35
- if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
36
- const { args } = options.scriptRanges.exportDefault;
37
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
35
+ if (options.vueCompilerOptions.target >= 3.5
36
+ && options.vueCompilerOptions.inferComponentDollarRefs
37
+ && options.templateCodegen?.templateRefs.size) {
38
+ yield `__typeRefs: {} as __VLS_TemplateRefs,${utils_1.newLine}`;
38
39
  }
39
- if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
40
- yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${utils_1.newLine}`;
40
+ if (options.vueCompilerOptions.target >= 3.5
41
+ && options.vueCompilerOptions.inferComponentDollarEl
42
+ && options.templateCodegen?.singleRootElTypes.length) {
43
+ yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
41
44
  }
42
- if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
43
- yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${utils_1.newLine}`;
45
+ if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
46
+ const { args } = options.scriptRanges.exportDefault;
47
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
44
48
  }
45
49
  yield `})`;
46
50
  }
@@ -122,12 +126,12 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
122
126
  if (scriptSetupRanges.defineProps?.arg) {
123
127
  const { arg } = scriptSetupRanges.defineProps;
124
128
  codes.push({
125
- optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
129
+ optionExp: (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
126
130
  typeOptionExp: undefined,
127
131
  });
128
132
  }
129
133
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
130
- let attrsType = `__VLS_TemplateResult['attrs']`;
134
+ let attrsType = `Partial<__VLS_InheritedAttrs>`;
131
135
  if (hasEmitsOption) {
132
136
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
133
137
  }
@@ -1,5 +1,5 @@
1
1
  import type { Code } from '../../types';
2
2
  import type { TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
- import { type ScriptCodegenOptions } from './index';
4
+ import type { ScriptCodegenOptions } from './index';
5
5
  export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentSelf = generateComponentSelf;
4
4
  const path = require("path-browserify");
5
+ const codeFeatures_1 = require("../codeFeatures");
5
6
  const utils_1 = require("../utils");
6
7
  const component_1 = require("./component");
7
- const index_1 = require("./index");
8
8
  const template_1 = require("./template");
9
9
  function* generateComponentSelf(options, ctx, templateCodegenCtx) {
10
10
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
@@ -50,7 +50,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
50
50
  }
51
51
  if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
52
52
  const { args } = options.scriptRanges.exportDefault;
53
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
53
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
54
54
  }
55
55
  yield `})${utils_1.endOfLine}`; // defineComponent {
56
56
  }
@@ -19,7 +19,7 @@ export declare function createScriptCodegenContext(options: ScriptCodegenOptions
19
19
  readonly PrettifyLocal: string;
20
20
  readonly OmitKeepDiscriminatedUnion: string;
21
21
  readonly WithDefaults: string;
22
- readonly WithTemplateSlots: string;
22
+ readonly WithSlots: string;
23
23
  readonly PropsChildren: string;
24
24
  readonly TypePropsToOption: string;
25
25
  readonly OmitIndexSignature: string;
@@ -2,16 +2,9 @@ import type { Mapping } from '@volar/language-core';
2
2
  import type * as ts from 'typescript';
3
3
  import type { ScriptRanges } from '../../parsers/scriptRanges';
4
4
  import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
5
- import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../types';
5
+ import type { Code, Sfc, VueCompilerOptions } from '../../types';
6
6
  import type { TemplateCodegenContext } from '../template/context';
7
7
  import { ScriptCodegenContext } from './context';
8
- export declare const codeFeatures: {
9
- all: VueCodeInformation;
10
- none: VueCodeInformation;
11
- verification: VueCodeInformation;
12
- navigation: VueCodeInformation;
13
- navigationWithoutRename: VueCodeInformation;
14
- };
15
8
  export interface ScriptCodegenOptions {
16
9
  ts: typeof ts;
17
10
  compilerOptions: ts.CompilerOptions;
@@ -1,39 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.codeFeatures = void 0;
4
3
  exports.generateScript = generateScript;
5
4
  exports.generateScriptSectionPartiallyEnding = generateScriptSectionPartiallyEnding;
6
5
  const path = require("path-browserify");
6
+ const codeFeatures_1 = require("../codeFeatures");
7
7
  const globalTypes_1 = require("../globalTypes");
8
8
  const utils_1 = require("../utils");
9
9
  const componentSelf_1 = require("./componentSelf");
10
10
  const context_1 = require("./context");
11
11
  const scriptSetup_1 = require("./scriptSetup");
12
12
  const src_1 = require("./src");
13
- const styleModulesType_1 = require("./styleModulesType");
14
13
  const template_1 = require("./template");
15
- exports.codeFeatures = {
16
- all: {
17
- verification: true,
18
- completion: true,
19
- semantic: true,
20
- navigation: true,
21
- },
22
- none: {},
23
- verification: {
24
- verification: true,
25
- },
26
- navigation: {
27
- navigation: true,
28
- },
29
- navigationWithoutRename: {
30
- navigation: {
31
- shouldRename() {
32
- return false;
33
- },
34
- },
35
- },
36
- };
37
14
  function* generateScript(options) {
38
15
  const ctx = (0, context_1.createScriptCodegenContext)(options);
39
16
  if (options.vueCompilerOptions.__setupedGlobalTypes) {
@@ -46,28 +23,30 @@ function* generateScript(options) {
46
23
  yield `/// <reference types="${relativePath}" />${utils_1.newLine}`;
47
24
  }
48
25
  else {
49
- yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${utils_1.newLine}`;
26
+ yield `/// <reference types=".vue-global-types/${(0, globalTypes_1.getGlobalTypesFileName)(options.vueCompilerOptions)}" />${utils_1.newLine}`;
50
27
  }
51
28
  }
52
29
  else {
53
30
  yield `/* placeholder */`;
54
31
  }
55
32
  if (options.sfc.script?.src) {
56
- yield* (0, src_1.generateSrc)(options.sfc.script, options.sfc.script.src);
33
+ yield* (0, src_1.generateSrc)(options.sfc.script.src);
34
+ }
35
+ if (options.sfc.scriptSetup && options.scriptSetupRanges) {
36
+ yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
57
37
  }
58
38
  if (options.sfc.script && options.scriptRanges) {
59
39
  const { exportDefault, classBlockEnd } = options.scriptRanges;
60
40
  const isExportRawObject = exportDefault
61
41
  && options.sfc.script.content[exportDefault.expression.start] === '{';
62
42
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
63
- yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
64
43
  if (exportDefault) {
65
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
44
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
66
45
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
67
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
46
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
68
47
  }
69
48
  else {
70
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
49
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
71
50
  yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
72
51
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
73
52
  }
@@ -92,31 +71,30 @@ function* generateScript(options) {
92
71
  ? options.vueCompilerOptions.optionsWrapper[1]
93
72
  : '[Missing optionsWrapper[1]]',
94
73
  });
95
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
74
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
96
75
  yield options.vueCompilerOptions.optionsWrapper[0];
97
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
76
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, codeFeatures_1.codeFeatures.all);
98
77
  yield options.vueCompilerOptions.optionsWrapper[1];
99
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
78
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
100
79
  }
101
80
  else if (classBlockEnd !== undefined) {
102
81
  if (options.vueCompilerOptions.skipTemplateCodegen) {
103
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
82
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
104
83
  }
105
84
  else {
106
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
85
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
107
86
  yield `__VLS_template = () => {${utils_1.newLine}`;
108
87
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
109
88
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
110
89
  yield `}${utils_1.endOfLine}`;
111
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
90
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
112
91
  }
113
92
  }
114
93
  else {
115
- yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
94
+ yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
116
95
  }
117
96
  }
118
97
  else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
119
- yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
120
98
  yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
121
99
  }
122
100
  if (options.sfc.script) {
@@ -126,28 +104,24 @@ function* generateScript(options) {
126
104
  yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
127
105
  }
128
106
  if (!ctx.generatedTemplate) {
129
- yield `function __VLS_template() {${utils_1.newLine}`;
130
107
  const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
131
- yield `}${utils_1.endOfLine}`;
132
108
  yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
133
109
  }
134
- // #4788
135
- yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
136
110
  if (options.edited) {
137
111
  yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
138
112
  }
139
113
  yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
140
114
  if (options.appendGlobalTypes) {
141
- yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
115
+ yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
142
116
  }
143
117
  if (options.sfc.scriptSetup) {
144
- yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
118
+ yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
145
119
  }
146
120
  return ctx;
147
121
  }
148
122
  function* generateScriptSectionPartiallyEnding(source, end, mark) {
149
123
  yield `;`;
150
- yield ['', source, end, exports.codeFeatures.verification];
124
+ yield ['', source, end, codeFeatures_1.codeFeatures.verification];
151
125
  yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
152
126
  }
153
127
  //# sourceMappingURL=index.js.map