@vue/language-core 2.1.4 → 2.1.6-patch.1

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 (40) hide show
  1. package/lib/codegen/common.d.ts +2 -2
  2. package/lib/codegen/common.js +8 -10
  3. package/lib/codegen/globalTypes.d.ts +1 -1
  4. package/lib/codegen/globalTypes.js +123 -125
  5. package/lib/codegen/script/component.js +38 -32
  6. package/lib/codegen/script/{internalComponent.d.ts → componentSelf.d.ts} +1 -1
  7. package/lib/codegen/script/{internalComponent.js → componentSelf.js} +6 -6
  8. package/lib/codegen/script/index.d.ts +1 -0
  9. package/lib/codegen/script/index.js +14 -6
  10. package/lib/codegen/script/scriptSetup.js +10 -37
  11. package/lib/codegen/script/styleModulesType.d.ts +4 -0
  12. package/lib/codegen/script/styleModulesType.js +36 -0
  13. package/lib/codegen/script/template.d.ts +3 -3
  14. package/lib/codegen/script/template.js +56 -67
  15. package/lib/codegen/template/context.d.ts +2 -0
  16. package/lib/codegen/template/context.js +3 -0
  17. package/lib/codegen/template/element.js +15 -6
  18. package/lib/codegen/template/elementDirectives.js +1 -1
  19. package/lib/codegen/template/elementEvents.js +4 -1
  20. package/lib/codegen/template/elementProps.js +28 -19
  21. package/lib/codegen/template/index.d.ts +3 -2
  22. package/lib/codegen/template/index.js +63 -53
  23. package/lib/codegen/template/interpolation.d.ts +1 -1
  24. package/lib/codegen/template/interpolation.js +52 -26
  25. package/lib/codegen/template/templateChild.js +4 -0
  26. package/lib/parsers/scriptRanges.d.ts +1 -0
  27. package/lib/parsers/scriptRanges.js +7 -2
  28. package/lib/parsers/scriptSetupRanges.d.ts +2 -1
  29. package/lib/parsers/scriptSetupRanges.js +12 -2
  30. package/lib/plugins/vue-sfc-template.js +2 -2
  31. package/lib/plugins/vue-tsx.d.ts +5 -1
  32. package/lib/plugins/vue-tsx.js +37 -10
  33. package/lib/types.d.ts +2 -2
  34. package/lib/utils/ts.d.ts +8 -2
  35. package/lib/utils/ts.js +45 -8
  36. package/package.json +5 -6
  37. package/lib/codegen/script/globalTypes.d.ts +0 -2
  38. package/lib/codegen/script/globalTypes.js +0 -147
  39. package/lib/codegen/template/vBindShorthand.d.ts +0 -3
  40. package/lib/codegen/template/vBindShorthand.js +0 -18
@@ -6,7 +6,7 @@ export declare const combineLastMapping: VueCodeInformation;
6
6
  export declare const variableNameRegex: RegExp;
7
7
  export declare function conditionWrapWith(condition: boolean, startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
8
8
  export declare function wrapWith(startOffset: number, endOffset: number, features: VueCodeInformation, ...wrapCodes: Code[]): Generator<Code>;
9
- export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[], includesRest?: boolean): string[];
10
- export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: ts.Identifier[], includesRest?: boolean): ts.Identifier[];
9
+ export declare function collectVars(ts: typeof import('typescript'), node: ts.Node, ast: ts.SourceFile, results?: string[]): string[];
10
+ export declare function collectIdentifiers(ts: typeof import('typescript'), node: ts.Node, results?: [id: ts.Identifier, isRest: boolean][], isRest?: boolean): [id: ts.Identifier, isRest: boolean][];
11
11
  export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
12
12
  export declare function generateSfcBlockSection(block: SfcBlock, start: number, end: number, features: VueCodeInformation): Code;
@@ -33,33 +33,31 @@ function* wrapWith(startOffset, endOffset, features, ...wrapCodes) {
33
33
  }
34
34
  yield ['', 'template', endOffset, { __combineOffsetMapping: offset }];
35
35
  }
36
- function collectVars(ts, node, ast, results = [], includesRest = true) {
37
- const identifiers = collectIdentifiers(ts, node, [], includesRest);
38
- for (const id of identifiers) {
36
+ function collectVars(ts, node, ast, results = []) {
37
+ const identifiers = collectIdentifiers(ts, node, []);
38
+ for (const [id] of identifiers) {
39
39
  results.push((0, scriptSetupRanges_1.getNodeText)(ts, id, ast));
40
40
  }
41
41
  return results;
42
42
  }
43
- function collectIdentifiers(ts, node, results = [], includesRest = true) {
43
+ function collectIdentifiers(ts, node, results = [], isRest = false) {
44
44
  if (ts.isIdentifier(node)) {
45
- results.push(node);
45
+ results.push([node, isRest]);
46
46
  }
47
47
  else if (ts.isObjectBindingPattern(node)) {
48
48
  for (const el of node.elements) {
49
- if (includesRest || !el.dotDotDotToken) {
50
- collectIdentifiers(ts, el.name, results, includesRest);
51
- }
49
+ collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
52
50
  }
53
51
  }
54
52
  else if (ts.isArrayBindingPattern(node)) {
55
53
  for (const el of node.elements) {
56
54
  if (ts.isBindingElement(el)) {
57
- collectIdentifiers(ts, el.name, results, includesRest);
55
+ collectIdentifiers(ts, el.name, results, !!el.dotDotDotToken);
58
56
  }
59
57
  }
60
58
  }
61
59
  else {
62
- ts.forEachChild(node, node => collectIdentifiers(ts, node, results, includesRest));
60
+ ts.forEachChild(node, node => collectIdentifiers(ts, node, results, false));
63
61
  }
64
62
  return results;
65
63
  }
@@ -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
+ type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<
83
+ '__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
84
+ , T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
85
+ >>;
82
86
 
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;
87
+ function __VLS_getVForSourceType(source: number): [number, number, number][];
88
+ function __VLS_getVForSourceType(source: string): [string, number, number][];
89
+ function __VLS_getVForSourceType<T extends any[]>(source: T): [
90
+ item: T[number],
91
+ key: number,
92
+ index: number,
93
+ ][];
94
+ function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
95
+ item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
96
+ key: number,
97
+ index: undefined,
98
+ ][];
99
+ // #3845
100
+ function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
101
+ item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
102
+ key: number,
103
+ index: undefined,
104
+ ][];
105
+ function __VLS_getVForSourceType<T>(source: T): [
106
+ item: T[keyof T],
107
+ key: keyof T,
108
+ index: number,
109
+ ][];
110
+ // @ts-ignore
111
+ function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
112
+ // @ts-ignore
113
+ function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
114
+ function __VLS_directiveAsFunction<T extends import('${lib}').Directive>(dir: T): T extends (...args: any) => any
115
+ ? T | __VLS_unknownDirective
116
+ : NonNullable<(T & Record<string, __VLS_unknownDirective>)['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>;
117
+ function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
118
+ function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
119
+ function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
120
+ function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
121
+ T extends new (...args: any) => any
122
+ ? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
123
+ attrs?: any,
124
+ slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any,
125
+ emit?: K extends { $emit: infer Emit } ? Emit : any
126
+ } & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
127
+ : T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
128
+ : T extends (...args: any) => any ? T
129
+ : (_: {}${strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${strictTemplates ? '' : ' & Record<string, unknown>'} } };
130
+ function __VLS_elementAsFunction<T>(tag: T, endTag?: T): (_: T${strictTemplates ? '' : ' & Record<string, unknown>'}) => void;
131
+ function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
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,10 @@ 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
+ }
42
+ if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.singleRootElType) {
43
+ yield `__typeEl: {} as __VLS_TemplateResult['rootEl'],${common_1.newLine}`;
41
44
  }
42
45
  yield `})`;
43
46
  }
@@ -104,66 +107,69 @@ function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
104
107
  }
105
108
  }
106
109
  function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
107
- const optionExpCodes = [];
108
- const typeOptionExpCodes = [];
110
+ const codes = [];
109
111
  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`);
112
+ codes.push({
113
+ optionExp: [
114
+ `{} as `,
115
+ scriptSetupRanges.props.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
116
+ `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
117
+ scriptSetupRanges.props.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
118
+ ].join(''),
119
+ typeOptionExp: `{} as __VLS_PublicProps`,
120
+ });
117
121
  }
118
122
  if (scriptSetupRanges.props.define?.arg) {
119
123
  const { arg } = scriptSetupRanges.props.define;
120
- optionExpCodes.push((0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation));
124
+ codes.push({
125
+ optionExp: (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation),
126
+ typeOptionExp: undefined,
127
+ });
121
128
  }
122
129
  if (inheritAttrs && options.templateCodegen?.inheritedAttrVars.size) {
123
- let attrsType = `typeof __VLS_templateResult['attrs']`;
130
+ let attrsType = `__VLS_TemplateResult['attrs']`;
124
131
  if (hasEmitsOption) {
125
132
  attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
126
133
  }
127
134
  const propsType = `__VLS_PickNotAny<${ctx.localTypes.OmitIndexSignature}<${attrsType}>, {}>`;
128
135
  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}`);
136
+ codes.unshift({
137
+ optionExp: codes.length
138
+ ? `{} as ${optionType}`
139
+ // workaround for https://github.com/vuejs/core/pull/7419
140
+ : `{} as keyof ${propsType} extends never ? never: ${optionType}`,
141
+ typeOptionExp: `{} as ${attrsType}`,
142
+ });
137
143
  }
138
- const useTypeOption = options.vueCompilerOptions.target >= 3.5 && typeOptionExpCodes.length;
139
- const useOption = (!useTypeOption || scriptSetupRanges.props.withDefaults) && optionExpCodes.length;
144
+ const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
145
+ const useOption = !useTypeOption || scriptSetupRanges.props.withDefaults;
140
146
  if (useTypeOption) {
141
- if (typeOptionExpCodes.length === 1) {
147
+ if (codes.length === 1) {
142
148
  yield `__typeProps: `;
143
- yield typeOptionExpCodes[0];
149
+ yield codes[0].typeOptionExp;
144
150
  yield `,${common_1.newLine}`;
145
151
  }
146
- else if (typeOptionExpCodes.length >= 2) {
152
+ else if (codes.length >= 2) {
147
153
  yield `__typeProps: {${common_1.newLine}`;
148
- for (const code of typeOptionExpCodes) {
154
+ for (const { typeOptionExp } of codes) {
149
155
  yield `...`;
150
- yield code;
156
+ yield typeOptionExp;
151
157
  yield `,${common_1.newLine}`;
152
158
  }
153
159
  yield `},${common_1.newLine}`;
154
160
  }
155
161
  }
156
162
  if (useOption) {
157
- if (optionExpCodes.length === 1) {
163
+ if (codes.length === 1) {
158
164
  yield `props: `;
159
- yield optionExpCodes[0];
165
+ yield codes[0].optionExp;
160
166
  yield `,${common_1.newLine}`;
161
167
  }
162
- else if (optionExpCodes.length >= 2) {
168
+ else if (codes.length >= 2) {
163
169
  yield `props: {${common_1.newLine}`;
164
- for (const code of optionExpCodes) {
170
+ for (const { optionExp } of codes) {
165
171
  yield `...`;
166
- yield code;
172
+ yield optionExp;
167
173
  yield `,${common_1.newLine}`;
168
174
  }
169
175
  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];