@vue/language-core 2.1.4 → 2.1.6

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 (36) hide show
  1. package/lib/codegen/globalTypes.d.ts +1 -1
  2. package/lib/codegen/globalTypes.js +123 -125
  3. package/lib/codegen/script/component.js +35 -32
  4. package/lib/codegen/script/{internalComponent.d.ts → componentSelf.d.ts} +1 -1
  5. package/lib/codegen/script/{internalComponent.js → componentSelf.js} +6 -6
  6. package/lib/codegen/script/index.d.ts +1 -0
  7. package/lib/codegen/script/index.js +14 -6
  8. package/lib/codegen/script/scriptSetup.js +10 -37
  9. package/lib/codegen/script/styleModulesType.d.ts +4 -0
  10. package/lib/codegen/script/styleModulesType.js +36 -0
  11. package/lib/codegen/script/template.d.ts +3 -3
  12. package/lib/codegen/script/template.js +53 -66
  13. package/lib/codegen/template/context.d.ts +1 -0
  14. package/lib/codegen/template/context.js +2 -0
  15. package/lib/codegen/template/element.js +4 -4
  16. package/lib/codegen/template/elementDirectives.js +1 -1
  17. package/lib/codegen/template/elementEvents.js +4 -1
  18. package/lib/codegen/template/elementProps.js +27 -18
  19. package/lib/codegen/template/index.d.ts +2 -2
  20. package/lib/codegen/template/index.js +2 -2
  21. package/lib/codegen/template/interpolation.d.ts +1 -1
  22. package/lib/codegen/template/interpolation.js +26 -12
  23. package/lib/parsers/scriptRanges.d.ts +1 -0
  24. package/lib/parsers/scriptRanges.js +7 -2
  25. package/lib/parsers/scriptSetupRanges.js +1 -1
  26. package/lib/plugins/vue-sfc-template.js +2 -2
  27. package/lib/plugins/vue-tsx.d.ts +2 -0
  28. package/lib/plugins/vue-tsx.js +25 -10
  29. package/lib/types.d.ts +2 -2
  30. package/lib/utils/ts.d.ts +8 -2
  31. package/lib/utils/ts.js +45 -8
  32. package/package.json +2 -2
  33. package/lib/codegen/script/globalTypes.d.ts +0 -2
  34. package/lib/codegen/script/globalTypes.js +0 -147
  35. package/lib/codegen/template/vBindShorthand.d.ts +0 -3
  36. package/lib/codegen/template/vBindShorthand.js +0 -18
@@ -1 +1 @@
1
- export declare function generateGlobalTypes(mode: 'global' | 'local', lib: string, target: number, strictTemplates: boolean): string;
1
+ export declare function generateGlobalTypes(lib: string, target: number, strictTemplates: boolean): string;
@@ -2,140 +2,138 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateGlobalTypes = generateGlobalTypes;
4
4
  const shared_1 = require("../utils/shared");
5
- const common_1 = require("./common");
6
- function generateGlobalTypes(mode, lib, target, strictTemplates) {
5
+ function generateGlobalTypes(lib, target, strictTemplates) {
7
6
  const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${strictTemplates ? '' : ' & Record<string, unknown>'}`;
8
- let str = '';
9
- let globalComponentsType;
10
- if (mode === 'global') {
11
- str += `// @ts-nocheck${common_1.newLine}`;
12
- str += `export {}${common_1.endOfLine}`;
13
- str += `declare module '${lib}' {${common_1.newLine}`;
14
- str += ` export interface GlobalComponents { }${common_1.newLine}`;
15
- str += `}${common_1.newLine}`;
16
- str += `declare global {${common_1.newLine}`;
17
- globalComponentsType = `import('${lib}').GlobalComponents`;
7
+ let text = ``;
8
+ if (target < 3.5) {
9
+ text += `
10
+ ; declare module '${lib}' {
11
+ export interface GlobalComponents { }
12
+ export interface GlobalDirectives { }
13
+ }`;
18
14
  }
19
- else {
20
- str += `const __VLS_globalComponents = { ...{} as import('${lib}').GlobalComponents }${common_1.endOfLine}`;
21
- globalComponentsType = `void extends typeof __VLS_globalComponents ? {} : typeof __VLS_globalComponents`;
22
- }
23
- str += `
24
- const __VLS_intrinsicElements: __VLS_IntrinsicElements;
25
- const __VLS_directiveBindingRestFields = { instance: null, oldValue: null, modifiers: null as any, dir: null as any };
15
+ text += `
16
+ ; declare global {
17
+ const __VLS_intrinsicElements: __VLS_IntrinsicElements;
18
+ const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
19
+ const __VLS_unref: typeof import('${lib}').unref;
20
+
21
+ const __VLS_nativeElements = {
22
+ ...{} as SVGElementTagNameMap,
23
+ ...{} as HTMLElementTagNameMap,
24
+ };
26
25
 
27
- type __VLS_IntrinsicElements = ${(target >= 3.3
26
+ type __VLS_IntrinsicElements = ${(target >= 3.3
28
27
  ? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
29
28
  : `globalThis.JSX.IntrinsicElements;`)}
30
- type __VLS_Element = ${(target >= 3.3
29
+ type __VLS_Element = ${(target >= 3.3
31
30
  ? `import('${lib}/jsx-runtime').JSX.Element;`
32
31
  : `globalThis.JSX.Element;`)}
33
- type __VLS_GlobalComponents = ${(target >= 3.5
34
- ? globalComponentsType
35
- : `(${globalComponentsType}) & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`)}
36
- type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
37
- type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
38
- type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
39
- type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
40
- N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
41
- N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
42
- N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
43
- N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
44
- N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
45
- N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
46
- ${strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
47
- type __VLS_FunctionalComponentProps<T, K> =
48
- '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
49
- : T extends (props: infer P, ...args: any) => any ? P :
50
- {};
51
- type __VLS_IsFunction<T, K> = K extends keyof T
52
- ? __VLS_IsAny<T[K]> extends false
53
- ? unknown extends T[K]
54
- ? false
55
- : true
56
- : false
57
- : false;
58
- // fix https://github.com/vuejs/language-tools/issues/926
59
- type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
60
- type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
61
- ? U extends T
62
- ? never
63
- : __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
64
- : never;
65
- type __VLS_OverloadUnion<T> = Exclude<
66
- __VLS_OverloadUnionInner<(() => never) & T>,
67
- T extends () => never ? never : () => never
68
- >;
69
- type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
70
- ? F extends (event: infer E, ...args: infer A) => any
71
- ? { [K in E & string]: (...args: A) => void; }
72
- : never
73
- : never;
74
- type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
75
- __VLS_UnionToIntersection<
76
- __VLS_ConstructorOverloads<T> & {
77
- [K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
78
- }
79
- >
80
- >;
81
- type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
32
+ type __VLS_GlobalComponents = ${(target >= 3.5
33
+ ? `import('${lib}').GlobalComponents;`
34
+ : `import('${lib}').GlobalComponents & Pick<typeof import('${lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`)}
35
+ type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
36
+ type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
37
+ type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
38
+ type __VLS_unknownDirective = (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
39
+ type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
40
+ N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
41
+ N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
42
+ N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
43
+ N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
44
+ N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
45
+ N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
46
+ ${strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
47
+ type __VLS_FunctionalComponentProps<T, K> =
48
+ '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
49
+ : T extends (props: infer P, ...args: any) => any ? P :
50
+ {};
51
+ type __VLS_IsFunction<T, K> = K extends keyof T
52
+ ? __VLS_IsAny<T[K]> extends false
53
+ ? unknown extends T[K]
54
+ ? false
55
+ : true
56
+ : false
57
+ : false;
58
+ // fix https://github.com/vuejs/language-tools/issues/926
59
+ type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
60
+ type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
61
+ ? U extends T
62
+ ? never
63
+ : __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
64
+ : never;
65
+ type __VLS_OverloadUnion<T> = Exclude<
66
+ __VLS_OverloadUnionInner<(() => never) & T>,
67
+ T extends () => never ? never : () => never
68
+ >;
69
+ type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
70
+ ? F extends (event: infer E, ...args: infer A) => any
71
+ ? { [K in E & string]: (...args: A) => void; }
72
+ : never
73
+ : never;
74
+ type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
75
+ __VLS_UnionToIntersection<
76
+ __VLS_ConstructorOverloads<T> & {
77
+ [K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
78
+ }
79
+ >
80
+ >;
81
+ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
82
82
 
83
- function __VLS_getVForSourceType(source: number): [number, number, number][];
84
- function __VLS_getVForSourceType(source: string): [string, number, number][];
85
- function __VLS_getVForSourceType<T extends any[]>(source: T): [
86
- item: T[number],
87
- key: number,
88
- index: number,
89
- ][];
90
- function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
91
- item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
92
- key: number,
93
- index: undefined,
94
- ][];
95
- // #3845
96
- function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
97
- item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
98
- key: number,
99
- index: undefined,
100
- ][];
101
- function __VLS_getVForSourceType<T>(source: T): [
102
- item: T[keyof T],
103
- key: keyof T,
104
- index: number,
105
- ][];
106
- // @ts-ignore
107
- function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
108
- // @ts-ignore
109
- function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
110
- function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
111
- ? T | __VLS_unknownDirective
112
- : NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
113
- function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
114
- function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
115
- function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
116
- function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
117
- T extends new (...args: any) => any
118
- ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
119
- attrs?: any,
120
- slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
121
- emit?: K extends { $emit: infer Emit } ? Emit : any
122
- } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
123
- : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
124
- : T extends (...args: any) => any ? T
125
- : (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
126
- function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
127
- function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
128
- function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
129
- '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
130
- , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
131
- >>;
132
- function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
133
- function __VLS_tryAsConstant<const T>(t: T): T;
83
+ function __VLS_getVForSourceType(source: number): [number, number, number][];
84
+ function __VLS_getVForSourceType(source: string): [string, number, number][];
85
+ function __VLS_getVForSourceType<T extends any[]>(source: T): [
86
+ item: T[number],
87
+ key: number,
88
+ index: number,
89
+ ][];
90
+ function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
91
+ item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
92
+ key: number,
93
+ index: undefined,
94
+ ][];
95
+ // #3845
96
+ function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
97
+ item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
98
+ key: number,
99
+ index: undefined,
100
+ ][];
101
+ function __VLS_getVForSourceType<T>(source: T): [
102
+ item: T[keyof T],
103
+ key: keyof T,
104
+ index: number,
105
+ ][];
106
+ // @ts-ignore
107
+ function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
108
+ // @ts-ignore
109
+ function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
110
+ function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
111
+ ? T | __VLS_unknownDirective
112
+ : NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
113
+ function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
114
+ function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
115
+ function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
116
+ function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
117
+ T extends new (...args: any) => any
118
+ ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
119
+ attrs?: any,
120
+ slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
121
+ emit?: K extends { $emit: infer Emit } ? Emit : any
122
+ } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
123
+ : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
124
+ : T extends (...args: any) => any ? T
125
+ : (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
126
+ function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
127
+ function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
128
+ function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): NonNullable<__VLS_PickNotAny<
129
+ '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
130
+ , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
131
+ >>;
132
+ function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
133
+ function __VLS_tryAsConstant<const T>(t: T): T;
134
+ }
134
135
  `;
135
- if (mode === 'global') {
136
- str += `}${common_1.newLine}`;
137
- }
138
- return str;
136
+ return text;
139
137
  }
140
138
  ;
141
139
  //# sourceMappingURL=globalTypes.js.map
@@ -37,7 +37,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
37
37
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
38
38
  }
39
39
  if (options.vueCompilerOptions.target >= 3.5 && scriptSetupRanges.templateRefs.length) {
40
- yield `__typeRefs: {} as __VLS_Refs,${common_1.newLine}`;
40
+ yield `__typeRefs: {} as __VLS_TemplateResult['refs'],${common_1.newLine}`;
41
41
  }
42
42
  yield `})`;
43
43
  }
@@ -104,66 +104,69 @@ function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
104
104
  }
105
105
  }
106
106
  function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
107
- const optionExpCodes = [];
108
- const typeOptionExpCodes = [];
107
+ const codes = [];
109
108
  if (ctx.generatedPropsType) {
110
- optionExpCodes.push([
111
- `{} as `,
112
- scriptSetupRanges.props.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
113
- `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
114
- scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
115
- ].join(''));
116
- typeOptionExpCodes.push(`{} as __VLS_PublicProps`);
109
+ codes.push({
110
+ optionExp: [
111
+ `{} as `,
112
+ scriptSetupRanges.props.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
113
+ `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
114
+ scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
115
+ ].join(''),
116
+ typeOptionExp: `{} as __VLS_PublicProps`,
117
+ });
117
118
  }
118
119
  if (scriptSetupRanges.props.define?.arg) {
119
120
  const { arg } = scriptSetupRanges.props.define;
120
- optionExpCodes.push((0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation));
121
+ codes.push({
122
+ optionExp: (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
123
+ typeOptionExp: undefined,
124
+ });
121
125
  }
122
126
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
123
- let attrsType = `typeof __VLS_templateResult['attrs']`;
127
+ let attrsType = `__VLS_TemplateResult['attrs']`;
124
128
  if (hasEmitsOption) {
125
129
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
126
130
  }
127
131
  const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
128
132
  const optionType = `${ctx.localTypes.TypePropsToOption}<${propsType}>`;
129
- if (optionExpCodes.length) {
130
- optionExpCodes.unshift(`{} as ${optionType}`);
131
- }
132
- else {
133
- // workaround for https://github.com/vuejs/core/pull/7419
134
- optionExpCodes.unshift(`{} as keyof ${propsType} extends never ? never: ${optionType}`);
135
- }
136
- typeOptionExpCodes.unshift(`{} as ${attrsType}`);
133
+ codes.unshift({
134
+ optionExp: codes.length
135
+ ? `{} as ${optionType}`
136
+ // workaround for https://github.com/vuejs/core/pull/7419
137
+ : `{} as keyof ${propsType} extends never ? never: ${optionType}`,
138
+ typeOptionExp: `{} as ${attrsType}`,
139
+ });
137
140
  }
138
- const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionExpCodes.length;
139
- const useOption = (!useTypeOption || scriptSetupRanges.props.withDefaults) && optionExpCodes.length;
141
+ const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
142
+ const useOption = !useTypeOption || scriptSetupRanges.props.withDefaults;
140
143
  if (useTypeOption) {
141
- if (typeOptionExpCodes.length === 1) {
144
+ if (codes.length === 1) {
142
145
  yield `__typeProps: `;
143
- yield typeOptionExpCodes[0];
146
+ yield codes[0].typeOptionExp;
144
147
  yield `,${common_1.newLine}`;
145
148
  }
146
- else if (typeOptionExpCodes.length >= 2) {
149
+ else if (codes.length >= 2) {
147
150
  yield `__typeProps: {${common_1.newLine}`;
148
- for (const code of typeOptionExpCodes) {
151
+ for (const { typeOptionExp } of codes) {
149
152
  yield `...`;
150
- yield code;
153
+ yield typeOptionExp;
151
154
  yield `,${common_1.newLine}`;
152
155
  }
153
156
  yield `},${common_1.newLine}`;
154
157
  }
155
158
  }
156
159
  if (useOption) {
157
- if (optionExpCodes.length === 1) {
160
+ if (codes.length === 1) {
158
161
  yield `props: `;
159
- yield optionExpCodes[0];
162
+ yield codes[0].optionExp;
160
163
  yield `,${common_1.newLine}`;
161
164
  }
162
- else if (optionExpCodes.length >= 2) {
165
+ else if (codes.length >= 2) {
163
166
  yield `props: {${common_1.newLine}`;
164
- for (const code of optionExpCodes) {
167
+ for (const { optionExp } of codes) {
165
168
  yield `...`;
166
- yield code;
169
+ yield optionExp;
167
170
  yield `,${common_1.newLine}`;
168
171
  }
169
172
  yield `},${common_1.newLine}`;
@@ -2,4 +2,4 @@ import type { Code } from '../../types';
2
2
  import type { TemplateCodegenContext } from '../template/context';
3
3
  import type { ScriptCodegenContext } from './context';
4
4
  import { type ScriptCodegenOptions } from './index';
5
- export declare function generateInternalComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
5
+ export declare function generateComponentSelf(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateInternalComponent = generateInternalComponent;
3
+ exports.generateComponentSelf = generateComponentSelf;
4
4
  const common_1 = require("../common");
5
5
  const component_1 = require("./component");
6
6
  const index_1 = require("./index");
7
7
  const template_1 = require("./template");
8
- function* generateInternalComponent(options, ctx, templateCodegenCtx) {
8
+ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
9
9
  if (options.sfc.scriptSetup && options.scriptSetupRanges) {
10
- yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
10
+ yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
11
11
  yield `setup() {${common_1.newLine}`;
12
12
  yield `return {${common_1.newLine}`;
13
13
  if (ctx.bypassDefineComponent) {
@@ -54,10 +54,10 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
54
54
  yield `})${common_1.endOfLine}`; // defineComponent {
55
55
  }
56
56
  else if (options.sfc.script) {
57
- yield `let __VLS_internalComponent!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
57
+ yield `let __VLS_self!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
58
58
  }
59
59
  else {
60
- yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
60
+ yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
61
61
  }
62
62
  }
63
- //# sourceMappingURL=internalComponent.js.map
63
+ //# sourceMappingURL=componentSelf.js.map
@@ -25,6 +25,7 @@ export interface ScriptCodegenOptions {
25
25
  codes: Code[];
26
26
  } | undefined;
27
27
  edited: boolean;
28
+ appendGlobalTypes: boolean;
28
29
  getGeneratedLength: () => number;
29
30
  linkedCodeMappings: Mapping[];
30
31
  }
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.codeFeatures = void 0;
4
4
  exports.generateScript = generateScript;
5
5
  const common_1 = require("../common");
6
+ const globalTypes_1 = require("../globalTypes");
6
7
  const context_1 = require("./context");
8
+ const componentSelf_1 = require("./componentSelf");
7
9
  const scriptSetup_1 = require("./scriptSetup");
8
10
  const src_1 = require("./src");
11
+ const styleModulesType_1 = require("./styleModulesType");
9
12
  const template_1 = require("./template");
10
- const globalTypes_1 = require("../globalTypes");
11
13
  exports.codeFeatures = {
12
14
  all: {
13
15
  verification: true,
@@ -32,7 +34,7 @@ exports.codeFeatures = {
32
34
  };
33
35
  function* generateScript(options) {
34
36
  const ctx = (0, context_1.createScriptCodegenContext)(options);
35
- if (options.vueCompilerOptions.__setupedGlobalTypes?.()) {
37
+ if (options.vueCompilerOptions.__setupedGlobalTypes) {
36
38
  yield `/// <reference types=".vue-global-types/${options.vueCompilerOptions.lib}_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}.d.ts" />${common_1.newLine}`;
37
39
  }
38
40
  else {
@@ -91,7 +93,8 @@ function* generateScript(options) {
91
93
  else {
92
94
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
93
95
  yield `__VLS_template = () => {`;
94
- yield* (0, template_1.generateTemplate)(options, ctx, true);
96
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, true);
97
+ yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
95
98
  yield `},${common_1.newLine}`;
96
99
  yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
97
100
  }
@@ -112,14 +115,19 @@ function* generateScript(options) {
112
115
  }
113
116
  yield common_1.newLine;
114
117
  if (!ctx.generatedTemplate) {
115
- yield* (0, template_1.generateTemplate)(options, ctx, false);
118
+ yield `function __VLS_template() {${common_1.newLine}`;
119
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, false);
120
+ yield `}${common_1.endOfLine}`;
121
+ yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
116
122
  }
123
+ // #4788
124
+ yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
117
125
  if (options.edited) {
118
126
  yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
119
127
  }
120
128
  yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
121
- if (!options.vueCompilerOptions.__setupedGlobalTypes?.()) {
122
- yield (0, globalTypes_1.generateGlobalTypes)('local', options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
129
+ if (options.appendGlobalTypes) {
130
+ yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions.lib, options.vueCompilerOptions.target, options.vueCompilerOptions.strictTemplates);
123
131
  }
124
132
  if (options.sfc.scriptSetup) {
125
133
  yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
@@ -5,6 +5,7 @@ exports.generateScriptSetup = generateScriptSetup;
5
5
  const common_1 = require("../common");
6
6
  const component_1 = require("./component");
7
7
  const index_1 = require("./index");
8
+ const componentSelf_1 = require("./componentSelf");
8
9
  const template_1 = require("./template");
9
10
  function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
10
11
  yield [
@@ -57,7 +58,7 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
57
58
  + ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
58
59
  + ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
59
60
  + ` attrs: any,${common_1.newLine}`
60
- + ` slots: __VLS_Slots,${common_1.newLine}`
61
+ + ` slots: __VLS_TemplateResult['slots'],${common_1.newLine}`
61
62
  + ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${common_1.newLine}`
62
63
  + ` }${common_1.endOfLine}`;
63
64
  yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
@@ -223,9 +224,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
223
224
  if (define?.arg) {
224
225
  setupCodeModifies.push([
225
226
  [
226
- `<__VLS_Refs[`,
227
+ `<__VLS_TemplateResult['refs'][`,
227
228
  (0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
228
- `], keyof __VLS_Refs>`
229
+ `], keyof __VLS_TemplateResult['refs']>`
229
230
  ],
230
231
  define.arg.start - 1,
231
232
  define.arg.start - 1
@@ -260,17 +261,18 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
260
261
  }
261
262
  yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
262
263
  yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
263
- yield* generateStyleModules(options, ctx);
264
- yield* (0, template_1.generateTemplate)(options, ctx, false);
265
- yield `type __VLS_Refs = typeof __VLS_templateResult['refs']${common_1.endOfLine}`;
266
- yield `type __VLS_Slots = typeof __VLS_templateResult['slots']${common_1.endOfLine}`;
264
+ yield `function __VLS_template() {${common_1.newLine}`;
265
+ const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx, false);
266
+ yield `}${common_1.endOfLine}`;
267
+ yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
268
+ yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${common_1.endOfLine}`;
267
269
  if (syntax) {
268
270
  if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
269
271
  yield `const __VLS_component = `;
270
272
  yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
271
273
  yield common_1.endOfLine;
272
274
  yield `${syntax} `;
273
- yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_Slots>${common_1.endOfLine}`;
275
+ yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_TemplateResult['slots']>${common_1.endOfLine}`;
274
276
  }
275
277
  else {
276
278
  yield `${syntax} `;
@@ -403,35 +405,6 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
403
405
  }
404
406
  }
405
407
  }
406
- function* generateStyleModules(options, ctx) {
407
- const styles = options.sfc.styles.filter(style => style.module);
408
- if (!styles.length) {
409
- return;
410
- }
411
- yield `type __VLS_StyleModules = {${common_1.newLine}`;
412
- for (let i = 0; i < styles.length; i++) {
413
- const style = styles[i];
414
- const { name, offset } = style.module;
415
- if (offset) {
416
- yield [
417
- name,
418
- 'main',
419
- offset + 1,
420
- index_1.codeFeatures.all
421
- ];
422
- }
423
- else {
424
- yield name;
425
- }
426
- yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
427
- for (const className of style.classNames) {
428
- yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
429
- }
430
- yield `>${common_1.endOfLine}`;
431
- }
432
- yield `}`;
433
- yield common_1.endOfLine;
434
- }
435
408
  function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
436
409
  if (defineProp.type) {
437
410
  // Infer from defineProp<T>
@@ -0,0 +1,4 @@
1
+ import type { Code } from '../../types';
2
+ import type { ScriptCodegenContext } from './context';
3
+ import { ScriptCodegenOptions } from './index';
4
+ export declare function generateStyleModulesType(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStyleModulesType = generateStyleModulesType;
4
+ const index_1 = require("./index");
5
+ const template_1 = require("./template");
6
+ const common_1 = require("../common");
7
+ function* generateStyleModulesType(options, ctx) {
8
+ const styles = options.sfc.styles.filter(style => style.module);
9
+ if (!styles.length) {
10
+ return;
11
+ }
12
+ yield `type __VLS_StyleModules = {${common_1.newLine}`;
13
+ for (let i = 0; i < styles.length; i++) {
14
+ const style = styles[i];
15
+ const { name, offset } = style.module;
16
+ if (offset) {
17
+ yield [
18
+ name,
19
+ 'main',
20
+ offset + 1,
21
+ index_1.codeFeatures.all
22
+ ];
23
+ }
24
+ else {
25
+ yield name;
26
+ }
27
+ yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
28
+ for (const className of style.classNames) {
29
+ yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
30
+ }
31
+ yield `>${common_1.endOfLine}`;
32
+ }
33
+ yield `}`;
34
+ yield common_1.endOfLine;
35
+ }
36
+ //# sourceMappingURL=styleModulesType.js.map