@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.
- package/lib/codegen/globalTypes.d.ts +1 -1
- package/lib/codegen/globalTypes.js +123 -125
- package/lib/codegen/script/component.js +35 -32
- package/lib/codegen/script/{internalComponent.d.ts → componentSelf.d.ts} +1 -1
- package/lib/codegen/script/{internalComponent.js → componentSelf.js} +6 -6
- package/lib/codegen/script/index.d.ts +1 -0
- package/lib/codegen/script/index.js +14 -6
- package/lib/codegen/script/scriptSetup.js +10 -37
- package/lib/codegen/script/styleModulesType.d.ts +4 -0
- package/lib/codegen/script/styleModulesType.js +36 -0
- package/lib/codegen/script/template.d.ts +3 -3
- package/lib/codegen/script/template.js +53 -66
- package/lib/codegen/template/context.d.ts +1 -0
- package/lib/codegen/template/context.js +2 -0
- package/lib/codegen/template/element.js +4 -4
- package/lib/codegen/template/elementDirectives.js +1 -1
- package/lib/codegen/template/elementEvents.js +4 -1
- package/lib/codegen/template/elementProps.js +27 -18
- package/lib/codegen/template/index.d.ts +2 -2
- package/lib/codegen/template/index.js +2 -2
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +26 -12
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +7 -2
- package/lib/parsers/scriptSetupRanges.js +1 -1
- package/lib/plugins/vue-sfc-template.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +2 -0
- package/lib/plugins/vue-tsx.js +25 -10
- package/lib/types.d.ts +2 -2
- package/lib/utils/ts.d.ts +8 -2
- package/lib/utils/ts.js +45 -8
- package/package.json +2 -2
- package/lib/codegen/script/globalTypes.d.ts +0 -2
- package/lib/codegen/script/globalTypes.js +0 -147
- package/lib/codegen/template/vBindShorthand.d.ts +0 -3
- package/lib/codegen/template/vBindShorthand.js +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function generateGlobalTypes(
|
|
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
|
-
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
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
|
-
?
|
|
35
|
-
: `(${
|
|
36
|
-
type
|
|
37
|
-
type
|
|
38
|
-
type
|
|
39
|
-
type
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
type
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
][];
|
|
90
|
-
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
][];
|
|
95
|
-
// #3845
|
|
96
|
-
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
][];
|
|
101
|
-
function __VLS_getVForSourceType<T>(source: T): [
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
112
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
108
|
-
const typeOptionExpCodes = [];
|
|
107
|
+
const codes = [];
|
|
109
108
|
if (ctx.generatedPropsType) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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 = `
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 &&
|
|
139
|
-
const useOption =
|
|
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 (
|
|
144
|
+
if (codes.length === 1) {
|
|
142
145
|
yield `__typeProps: `;
|
|
143
|
-
yield
|
|
146
|
+
yield codes[0].typeOptionExp;
|
|
144
147
|
yield `,${common_1.newLine}`;
|
|
145
148
|
}
|
|
146
|
-
else if (
|
|
149
|
+
else if (codes.length >= 2) {
|
|
147
150
|
yield `__typeProps: {${common_1.newLine}`;
|
|
148
|
-
for (const
|
|
151
|
+
for (const { typeOptionExp } of codes) {
|
|
149
152
|
yield `...`;
|
|
150
|
-
yield
|
|
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 (
|
|
160
|
+
if (codes.length === 1) {
|
|
158
161
|
yield `props: `;
|
|
159
|
-
yield
|
|
162
|
+
yield codes[0].optionExp;
|
|
160
163
|
yield `,${common_1.newLine}`;
|
|
161
164
|
}
|
|
162
|
-
else if (
|
|
165
|
+
else if (codes.length >= 2) {
|
|
163
166
|
yield `props: {${common_1.newLine}`;
|
|
164
|
-
for (const
|
|
167
|
+
for (const { optionExp } of codes) {
|
|
165
168
|
yield `...`;
|
|
166
|
-
yield
|
|
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
|
|
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.
|
|
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*
|
|
8
|
+
function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
9
9
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
10
|
-
yield `const
|
|
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
|
|
57
|
+
yield `let __VLS_self!: typeof import('./${options.fileBaseName}').default${common_1.endOfLine}`;
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
yield `const
|
|
60
|
+
yield `const __VLS_self = (await import('${options.vueCompilerOptions.lib}')).defineComponent({})${common_1.endOfLine}`;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
//# sourceMappingURL=
|
|
63
|
+
//# sourceMappingURL=componentSelf.js.map
|
|
@@ -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
|
|
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 (
|
|
122
|
-
yield (0, globalTypes_1.generateGlobalTypes)(
|
|
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:
|
|
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
|
-
`<
|
|
227
|
+
`<__VLS_TemplateResult['refs'][`,
|
|
227
228
|
(0, common_1.generateSfcBlockSection)(scriptSetup, define.arg.start, define.arg.end, index_1.codeFeatures.navigation),
|
|
228
|
-
`], keyof
|
|
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
|
|
264
|
-
yield* (0, template_1.generateTemplate)(options, ctx, false);
|
|
265
|
-
yield `
|
|
266
|
-
yield
|
|
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,
|
|
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
|