@vue/language-core 2.0.6 → 2.0.10
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/generators/globalTypes.d.ts +2 -0
- package/lib/generators/globalTypes.js +135 -0
- package/lib/generators/inlineCss.d.ts +3 -0
- package/lib/generators/inlineCss.js +37 -0
- package/lib/generators/script.js +65 -144
- package/lib/generators/template.d.ts +13 -3
- package/lib/generators/template.js +130 -166
- package/lib/generators/utils.d.ts +1 -2
- package/lib/generators/utils.js +1 -5
- package/lib/languageModule.d.ts +7 -2
- package/lib/languageModule.js +40 -23
- package/lib/parsers/scriptSetupRanges.d.ts +1 -0
- package/lib/parsers/scriptSetupRanges.js +1 -0
- package/lib/plugins/file-vue.js +1 -1
- package/lib/plugins/vue-sfc-styles.js +37 -11
- package/lib/plugins/vue-template-inline-css.d.ts +3 -0
- package/lib/plugins/vue-template-inline-css.js +23 -0
- package/lib/plugins/vue-template-inline-ts.d.ts +3 -0
- package/lib/plugins/vue-template-inline-ts.js +151 -0
- package/lib/plugins/vue-tsx.d.ts +1 -4
- package/lib/plugins/vue-tsx.js +6 -75
- package/lib/plugins.js +9 -3
- package/lib/utils/transform.js +6 -3
- package/lib/utils/ts.d.ts +1 -1
- package/lib/utils/ts.js +9 -5
- package/lib/utils/vue2TemplateCompiler.js +2 -2
- package/lib/virtualFile/computedFiles.js +1 -10
- package/lib/virtualFile/computedMappings.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGlobalTypes = void 0;
|
|
4
|
+
const shared_1 = require("../utils/shared");
|
|
5
|
+
function generateGlobalTypes(vueCompilerOptions) {
|
|
6
|
+
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}`;
|
|
7
|
+
return `
|
|
8
|
+
; export const __VLS_globalTypesStart = {};
|
|
9
|
+
declare global {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<globalThis.JSX.IntrinsicElements, Record<string, any>>>;
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, globalThis.JSX.Element>;
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
type __VLS_GlobalComponents = ${[
|
|
16
|
+
`__VLS_PickNotAny<import('vue').GlobalComponents, {}>`,
|
|
17
|
+
`__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
|
|
18
|
+
`__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
|
|
19
|
+
`Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
|
|
20
|
+
].join(' & ')};
|
|
21
|
+
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
22
|
+
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
23
|
+
|
|
24
|
+
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
25
|
+
|
|
26
|
+
// v-for
|
|
27
|
+
function __VLS_getVForSourceType(source: number): [number, number, number][];
|
|
28
|
+
function __VLS_getVForSourceType(source: string): [string, number, number][];
|
|
29
|
+
function __VLS_getVForSourceType<T extends any[]>(source: T): [
|
|
30
|
+
item: T[number],
|
|
31
|
+
key: number,
|
|
32
|
+
index: number,
|
|
33
|
+
][];
|
|
34
|
+
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
35
|
+
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
|
|
36
|
+
key: number,
|
|
37
|
+
index: undefined,
|
|
38
|
+
][];
|
|
39
|
+
// #3845
|
|
40
|
+
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
41
|
+
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
|
|
42
|
+
key: number,
|
|
43
|
+
index: undefined,
|
|
44
|
+
][];
|
|
45
|
+
function __VLS_getVForSourceType<T>(source: T): [
|
|
46
|
+
item: T[keyof T],
|
|
47
|
+
key: keyof T,
|
|
48
|
+
index: number,
|
|
49
|
+
][];
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
55
|
+
function __VLS_directiveFunction<T>(dir: T):
|
|
56
|
+
T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (value: V) => void
|
|
57
|
+
: T;
|
|
58
|
+
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
59
|
+
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
60
|
+
|
|
61
|
+
type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
|
|
62
|
+
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
|
63
|
+
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
|
64
|
+
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
|
65
|
+
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
|
|
66
|
+
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
67
|
+
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
68
|
+
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
69
|
+
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
|
70
|
+
|
|
71
|
+
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
|
|
72
|
+
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
|
|
73
|
+
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
74
|
+
T extends new (...args: any) => any
|
|
75
|
+
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
|
76
|
+
attrs?: any,
|
|
77
|
+
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: infer Slots } ? Slots : any,
|
|
78
|
+
emit?: K extends { $emit: infer Emit } ? Emit : any
|
|
79
|
+
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
|
|
80
|
+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
81
|
+
: T extends (...args: any) => any ? T
|
|
82
|
+
: (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
83
|
+
function __VLS_elementAsFunctionalComponent<T>(t: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
84
|
+
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
|
|
85
|
+
function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
|
|
86
|
+
__VLS_PickNotAny<
|
|
87
|
+
__VLS_AsFunctionOrAny<E2>,
|
|
88
|
+
__VLS_AsFunctionOrAny<E1>
|
|
89
|
+
>
|
|
90
|
+
> | undefined;
|
|
91
|
+
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
|
|
92
|
+
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
93
|
+
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
94
|
+
>;
|
|
95
|
+
type __VLS_FunctionalComponentProps<T, K> =
|
|
96
|
+
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
97
|
+
: T extends (props: infer P, ...args: any) => any ? P :
|
|
98
|
+
{};
|
|
99
|
+
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
|
|
100
|
+
|
|
101
|
+
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* emit
|
|
105
|
+
*/
|
|
106
|
+
// fix https://github.com/vuejs/language-tools/issues/926
|
|
107
|
+
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
|
108
|
+
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
|
109
|
+
? U extends T
|
|
110
|
+
? never
|
|
111
|
+
: __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
|
|
112
|
+
: never;
|
|
113
|
+
type __VLS_OverloadUnion<T> = Exclude<
|
|
114
|
+
__VLS_OverloadUnionInner<(() => never) & T>,
|
|
115
|
+
T extends () => never ? never : () => never
|
|
116
|
+
>;
|
|
117
|
+
type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
|
|
118
|
+
? F extends (event: infer E, ...args: infer A) => any
|
|
119
|
+
? { [K in E & string]: (...args: A) => void; }
|
|
120
|
+
: never
|
|
121
|
+
: never;
|
|
122
|
+
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
|
|
123
|
+
__VLS_UnionToIntersection<
|
|
124
|
+
__VLS_ConstructorOverloads<T> & {
|
|
125
|
+
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
>;
|
|
129
|
+
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
130
|
+
}
|
|
131
|
+
export const __VLS_globalTypesEnd = {};`;
|
|
132
|
+
}
|
|
133
|
+
exports.generateGlobalTypes = generateGlobalTypes;
|
|
134
|
+
;
|
|
135
|
+
//# sourceMappingURL=globalTypes.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const CompilerDOM = require("@vue/compiler-dom");
|
|
5
|
+
const template_1 = require("./template");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const codeFeatures = (0, utils_1.enableAllFeatures)({
|
|
8
|
+
format: false,
|
|
9
|
+
structure: false,
|
|
10
|
+
});
|
|
11
|
+
function* generate(templateAst) {
|
|
12
|
+
for (const node of (0, template_1.forEachElementNode)(templateAst)) {
|
|
13
|
+
for (const prop of node.props) {
|
|
14
|
+
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE
|
|
15
|
+
&& prop.name === 'bind'
|
|
16
|
+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
17
|
+
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
|
|
18
|
+
&& prop.arg.content === 'style'
|
|
19
|
+
&& prop.exp.constType === CompilerDOM.ConstantTypes.CAN_STRINGIFY) {
|
|
20
|
+
const endCrt = prop.arg.loc.source[prop.arg.loc.source.length - 1]; // " | '
|
|
21
|
+
const start = prop.arg.loc.source.indexOf(endCrt) + 1;
|
|
22
|
+
const end = prop.arg.loc.source.lastIndexOf(endCrt);
|
|
23
|
+
const content = prop.arg.loc.source.substring(start, end);
|
|
24
|
+
yield `x { `;
|
|
25
|
+
yield [
|
|
26
|
+
content,
|
|
27
|
+
'template',
|
|
28
|
+
prop.arg.loc.start.offset + start,
|
|
29
|
+
codeFeatures,
|
|
30
|
+
];
|
|
31
|
+
yield ` }\n`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.generate = generate;
|
|
37
|
+
//# sourceMappingURL=inlineCss.js.map
|
package/lib/generators/script.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require("path-browserify");
|
|
|
5
5
|
const shared_1 = require("../utils/shared");
|
|
6
6
|
const transform_1 = require("../utils/transform");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
|
+
const globalTypes_1 = require("./globalTypes");
|
|
8
9
|
function* generate(ts, fileName, script, scriptSetup, styles, // TODO: computed it
|
|
9
10
|
lang, scriptRanges, scriptSetupRanges, templateCodegen, compilerOptions, vueCompilerOptions, globalTypesHolder, getGeneratedLength, linkedCodeMappings = [], codegenStack) {
|
|
10
11
|
//#region monkey fix: https://github.com/vuejs/language-tools/pull/2113
|
|
@@ -39,7 +40,18 @@ lang, scriptRanges, scriptSetupRanges, templateCodegen, compilerOptions, vueComp
|
|
|
39
40
|
...scriptSetupRanges?.bindings.map(range => scriptSetup.content.substring(range.start, range.end)) ?? [],
|
|
40
41
|
]);
|
|
41
42
|
const bypassDefineComponent = lang === 'js' || lang === 'jsx';
|
|
42
|
-
const _ =
|
|
43
|
+
const _ = (code) => {
|
|
44
|
+
if (typeof code !== 'string') {
|
|
45
|
+
code[3].structure = false;
|
|
46
|
+
code[3].format = false;
|
|
47
|
+
}
|
|
48
|
+
if (!codegenStack) {
|
|
49
|
+
return [code, ''];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return [code, (0, utils_1.getStack)()];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
43
55
|
const helperTypes = {
|
|
44
56
|
OmitKeepDiscriminatedUnion: {
|
|
45
57
|
get name() {
|
|
@@ -139,7 +151,7 @@ lang, scriptRanges, scriptSetupRanges, templateCodegen, compilerOptions, vueComp
|
|
|
139
151
|
yield* generateScriptSetupAndTemplate();
|
|
140
152
|
yield* generateScriptContentAfterExportDefault();
|
|
141
153
|
if (globalTypesHolder === fileName) {
|
|
142
|
-
yield
|
|
154
|
+
yield _((0, globalTypes_1.generateGlobalTypes)(vueCompilerOptions));
|
|
143
155
|
}
|
|
144
156
|
yield* generateLocalHelperTypes();
|
|
145
157
|
yield _(`\ntype __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements;\n`);
|
|
@@ -149,127 +161,6 @@ lang, scriptRanges, scriptSetupRanges, templateCodegen, compilerOptions, vueComp
|
|
|
149
161
|
if (scriptSetup) {
|
|
150
162
|
yield _(['', 'scriptSetup', scriptSetup.content.length, (0, utils_1.disableAllFeatures)({ verification: true })]);
|
|
151
163
|
}
|
|
152
|
-
function* generateGlobalHelperTypes() {
|
|
153
|
-
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}`;
|
|
154
|
-
yield _(`
|
|
155
|
-
; declare global {
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
type __VLS_IntrinsicElements = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.IntrinsicElements, __VLS_PickNotAny<JSX.IntrinsicElements, Record<string, any>>>;
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
type __VLS_Element = __VLS_PickNotAny<import('vue/jsx-runtime').JSX.Element, JSX.Element>;
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
type __VLS_GlobalComponents = ${[
|
|
162
|
-
`__VLS_PickNotAny<import('vue').GlobalComponents, {}>`,
|
|
163
|
-
`__VLS_PickNotAny<import('@vue/runtime-core').GlobalComponents, {}>`,
|
|
164
|
-
`__VLS_PickNotAny<import('@vue/runtime-dom').GlobalComponents, {}>`,
|
|
165
|
-
`Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`
|
|
166
|
-
].join(' & ')};
|
|
167
|
-
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
168
|
-
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
169
|
-
|
|
170
|
-
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
171
|
-
|
|
172
|
-
// v-for
|
|
173
|
-
function __VLS_getVForSourceType(source: number): [number, number, number][];
|
|
174
|
-
function __VLS_getVForSourceType(source: string): [string, number, number][];
|
|
175
|
-
function __VLS_getVForSourceType<T extends any[]>(source: T): [
|
|
176
|
-
T[number], // item
|
|
177
|
-
number, // key
|
|
178
|
-
number, // index
|
|
179
|
-
][];
|
|
180
|
-
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
181
|
-
T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never, // item
|
|
182
|
-
number, // key
|
|
183
|
-
undefined, // index
|
|
184
|
-
][];
|
|
185
|
-
function __VLS_getVForSourceType<T>(source: T): [
|
|
186
|
-
T[keyof T], // item
|
|
187
|
-
keyof T, // key
|
|
188
|
-
number, // index
|
|
189
|
-
][];
|
|
190
|
-
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
function __VLS_getSlotParams<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>;
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
195
|
-
function __VLS_directiveFunction<T>(dir: T):
|
|
196
|
-
T extends import('${vueCompilerOptions.lib}').ObjectDirective<infer E, infer V> | import('${vueCompilerOptions.lib}').FunctionDirective<infer E, infer V> ? (value: V) => void
|
|
197
|
-
: T;
|
|
198
|
-
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
199
|
-
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
200
|
-
|
|
201
|
-
type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
|
|
202
|
-
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
|
203
|
-
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
|
204
|
-
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
|
205
|
-
N3 extends keyof LocalComponents ? N3 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N3] } :
|
|
206
|
-
N1 extends keyof __VLS_GlobalComponents ? N1 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
207
|
-
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
208
|
-
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
209
|
-
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
|
|
210
|
-
|
|
211
|
-
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
|
|
212
|
-
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
|
|
213
|
-
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
214
|
-
T extends new (...args: any) => any
|
|
215
|
-
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
|
|
216
|
-
attrs?: any,
|
|
217
|
-
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(vueCompilerOptions.target)}: infer Slots } ? Slots : any,
|
|
218
|
-
emit?: K extends { $emit: infer Emit } ? Emit : any
|
|
219
|
-
} & { props?: ${fnPropsType}; expose?(exposed: K): void; } }
|
|
220
|
-
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
221
|
-
: T extends (...args: any) => any ? T
|
|
222
|
-
: (_: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
223
|
-
function __VLS_elementAsFunctionalComponent<T>(t: T): (_: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: T${vueCompilerOptions.strictTemplates ? '' : ' & Record<string, unknown>'} } };
|
|
224
|
-
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): Parameters<T>['length'] extends 2 ? [any] : [];
|
|
225
|
-
function __VLS_pickEvent<E1, E2>(emitEvent: E1, propEvent: E2): __VLS_FillingEventArg<
|
|
226
|
-
__VLS_PickNotAny<
|
|
227
|
-
__VLS_AsFunctionOrAny<E2>,
|
|
228
|
-
__VLS_AsFunctionOrAny<E1>
|
|
229
|
-
>
|
|
230
|
-
> | undefined;
|
|
231
|
-
function __VLS_pickFunctionalComponentCtx<T, K>(comp: T, compInstance: K): __VLS_PickNotAny<
|
|
232
|
-
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
233
|
-
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
234
|
-
>;
|
|
235
|
-
type __VLS_FunctionalComponentProps<T, K> =
|
|
236
|
-
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
237
|
-
: T extends (props: infer P, ...args: any) => any ? P :
|
|
238
|
-
{};
|
|
239
|
-
type __VLS_AsFunctionOrAny<F> = unknown extends F ? any : ((...args: any) => any) extends F ? F : any;
|
|
240
|
-
|
|
241
|
-
function __VLS_normalizeSlot<S>(s: S): S extends () => infer R ? (props: {}) => R : S;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* emit
|
|
245
|
-
*/
|
|
246
|
-
// fix https://github.com/vuejs/language-tools/issues/926
|
|
247
|
-
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends ((arg: infer P) => unknown) ? P : never;
|
|
248
|
-
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
|
|
249
|
-
? U extends T
|
|
250
|
-
? never
|
|
251
|
-
: __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
|
|
252
|
-
: never;
|
|
253
|
-
type __VLS_OverloadUnion<T> = Exclude<
|
|
254
|
-
__VLS_OverloadUnionInner<(() => never) & T>,
|
|
255
|
-
T extends () => never ? never : () => never
|
|
256
|
-
>;
|
|
257
|
-
type __VLS_ConstructorOverloads<T> = __VLS_OverloadUnion<T> extends infer F
|
|
258
|
-
? F extends (event: infer E, ...args: infer A) => any
|
|
259
|
-
? { [K in E & string]: (...args: A) => void; }
|
|
260
|
-
: never
|
|
261
|
-
: never;
|
|
262
|
-
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
|
|
263
|
-
__VLS_UnionToIntersection<
|
|
264
|
-
__VLS_ConstructorOverloads<T> & {
|
|
265
|
-
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never
|
|
266
|
-
}
|
|
267
|
-
>
|
|
268
|
-
>;
|
|
269
|
-
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
270
|
-
}
|
|
271
|
-
`);
|
|
272
|
-
}
|
|
273
164
|
function* generateLocalHelperTypes() {
|
|
274
165
|
let shouldCheck = true;
|
|
275
166
|
while (shouldCheck) {
|
|
@@ -284,17 +175,22 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
284
175
|
}
|
|
285
176
|
}
|
|
286
177
|
function* generateSrc() {
|
|
287
|
-
if (!script?.src)
|
|
178
|
+
if (!script?.src) {
|
|
288
179
|
return;
|
|
180
|
+
}
|
|
289
181
|
let src = script.src;
|
|
290
|
-
if (src.endsWith('.d.ts'))
|
|
182
|
+
if (src.endsWith('.d.ts')) {
|
|
291
183
|
src = src.substring(0, src.length - '.d.ts'.length);
|
|
292
|
-
|
|
184
|
+
}
|
|
185
|
+
else if (src.endsWith('.ts')) {
|
|
293
186
|
src = src.substring(0, src.length - '.ts'.length);
|
|
294
|
-
|
|
187
|
+
}
|
|
188
|
+
else if (src.endsWith('.tsx')) {
|
|
295
189
|
src = src.substring(0, src.length - '.tsx'.length) + '.jsx';
|
|
296
|
-
|
|
190
|
+
}
|
|
191
|
+
if (!src.endsWith('.js') && !src.endsWith('.jsx')) {
|
|
297
192
|
src = src + '.js';
|
|
193
|
+
}
|
|
298
194
|
yield _(`export * from `);
|
|
299
195
|
yield _([
|
|
300
196
|
`'${src}'`,
|
|
@@ -325,15 +221,19 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
325
221
|
yield _(`export { default } from '${src}';\n`);
|
|
326
222
|
}
|
|
327
223
|
function* generateScriptContentBeforeExportDefault() {
|
|
328
|
-
if (!script)
|
|
224
|
+
if (!script) {
|
|
329
225
|
return;
|
|
330
|
-
|
|
226
|
+
}
|
|
227
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
331
228
|
return yield _(generateSourceCode(script, 0, scriptRanges.exportDefault.expression.start));
|
|
229
|
+
}
|
|
332
230
|
let isExportRawObject = false;
|
|
333
|
-
if (scriptRanges?.exportDefault)
|
|
231
|
+
if (scriptRanges?.exportDefault) {
|
|
334
232
|
isExportRawObject = script.content.substring(scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.expression.end).startsWith('{');
|
|
335
|
-
|
|
233
|
+
}
|
|
234
|
+
if (!isExportRawObject || !vueCompilerOptions.optionsWrapper.length || !scriptRanges?.exportDefault) {
|
|
336
235
|
return yield _(generateSourceCode(script, 0, script.content.length));
|
|
236
|
+
}
|
|
337
237
|
yield _(generateSourceCode(script, 0, scriptRanges.exportDefault.expression.start));
|
|
338
238
|
yield _(vueCompilerOptions.optionsWrapper[0]);
|
|
339
239
|
yield _(['', 'script', scriptRanges.exportDefault.expression.start, (0, utils_1.disableAllFeatures)({
|
|
@@ -358,14 +258,17 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
358
258
|
yield _(generateSourceCode(script, scriptRanges.exportDefault.expression.end, script.content.length));
|
|
359
259
|
}
|
|
360
260
|
function* generateScriptContentAfterExportDefault() {
|
|
361
|
-
if (!script)
|
|
261
|
+
if (!script) {
|
|
362
262
|
return;
|
|
363
|
-
|
|
263
|
+
}
|
|
264
|
+
if (!!scriptSetup && scriptRanges?.exportDefault) {
|
|
364
265
|
yield _(generateSourceCode(script, scriptRanges.exportDefault.expression.end, script.content.length));
|
|
266
|
+
}
|
|
365
267
|
}
|
|
366
268
|
function* generateScriptSetupImports() {
|
|
367
|
-
if (!scriptSetup || !scriptSetupRanges)
|
|
269
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
368
270
|
return;
|
|
271
|
+
}
|
|
369
272
|
yield _([
|
|
370
273
|
scriptSetup.content.substring(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)) + '\n',
|
|
371
274
|
'scriptSetup',
|
|
@@ -381,8 +284,9 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
381
284
|
if (scriptSetupRanges.defineProp.length) {
|
|
382
285
|
yield _(` & ReturnType<typeof import('${vueCompilerOptions.lib}').defineEmits<{\n`);
|
|
383
286
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
384
|
-
if (!defineProp.isModel)
|
|
287
|
+
if (!defineProp.isModel) {
|
|
385
288
|
continue;
|
|
289
|
+
}
|
|
386
290
|
let propName = 'modelValue';
|
|
387
291
|
if (defineProp.name) {
|
|
388
292
|
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
@@ -402,8 +306,9 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
402
306
|
yield _(`;\n`);
|
|
403
307
|
}
|
|
404
308
|
function* generateScriptSetupAndTemplate() {
|
|
405
|
-
if (!scriptSetup || !scriptSetupRanges)
|
|
309
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
406
310
|
return;
|
|
311
|
+
}
|
|
407
312
|
const definePropMirrors = new Map();
|
|
408
313
|
if (scriptSetup.generic) {
|
|
409
314
|
if (!scriptRanges?.exportDefault) {
|
|
@@ -543,8 +448,9 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
543
448
|
}
|
|
544
449
|
}
|
|
545
450
|
function* generateSetupFunction(functional, mode, definePropMirrors) {
|
|
546
|
-
if (!scriptSetupRanges || !scriptSetup)
|
|
451
|
+
if (!scriptSetupRanges || !scriptSetup) {
|
|
547
452
|
return;
|
|
453
|
+
}
|
|
548
454
|
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
549
455
|
const definePropProposalB = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition') || vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition';
|
|
550
456
|
if (vueCompilerOptions.target >= 3.3) {
|
|
@@ -678,6 +584,18 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
678
584
|
else {
|
|
679
585
|
yield _(`import('${vueCompilerOptions.lib}').PropType<${type}>,\n`);
|
|
680
586
|
}
|
|
587
|
+
if (defineProp.modifierType) {
|
|
588
|
+
let propModifierName = 'modelModifiers';
|
|
589
|
+
if (defineProp.name) {
|
|
590
|
+
propModifierName = `${scriptSetup.content.substring(defineProp.name.start + 1, defineProp.name.end - 1)}Modifiers`;
|
|
591
|
+
}
|
|
592
|
+
const modifierType = scriptSetup.content.substring(defineProp.modifierType.start, defineProp.modifierType.end);
|
|
593
|
+
const start = getGeneratedLength();
|
|
594
|
+
definePropMirrors.set(propModifierName, start);
|
|
595
|
+
yield _(propModifierName);
|
|
596
|
+
yield _(`: `);
|
|
597
|
+
yield _(`import('${vueCompilerOptions.lib}').PropType<Record<${modifierType}, true>>,\n`);
|
|
598
|
+
}
|
|
681
599
|
}
|
|
682
600
|
yield _(`};\n`);
|
|
683
601
|
}
|
|
@@ -699,8 +617,9 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
699
617
|
}
|
|
700
618
|
}
|
|
701
619
|
function* generateComponent(functional) {
|
|
702
|
-
if (!scriptSetupRanges)
|
|
620
|
+
if (!scriptSetupRanges) {
|
|
703
621
|
return;
|
|
622
|
+
}
|
|
704
623
|
if (script && scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) {
|
|
705
624
|
// use defineComponent() from user space code if it exist
|
|
706
625
|
yield _(generateSourceCode(script, scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.args.start));
|
|
@@ -772,12 +691,14 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
|
772
691
|
}
|
|
773
692
|
yield _(`},\n`);
|
|
774
693
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
694
|
+
if (ranges.defineProp.filter(p => p.isModel).length || ranges.emits.define) {
|
|
695
|
+
yield _(`emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`);
|
|
696
|
+
if (ranges.emits.define) {
|
|
697
|
+
yield _(` & typeof `);
|
|
698
|
+
yield _(ranges.emits.name ?? '__VLS_emit');
|
|
699
|
+
}
|
|
700
|
+
yield _(`>),\n`);
|
|
779
701
|
}
|
|
780
|
-
yield _(`>),\n`);
|
|
781
702
|
}
|
|
782
703
|
if (script && scriptRanges?.exportDefault?.args) {
|
|
783
704
|
yield _(generateSourceCode(script, scriptRanges.exportDefault.args.start + 1, scriptRanges.exportDefault.args.end - 1));
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function generate(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, template: NonNullable<Sfc['template']>, shouldGenerateScopedClasses: boolean, stylesScopedClasses: Set<string>, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): Generator<
|
|
3
|
+
import type { CodeAndStack, Sfc, VueCompilerOptions } from '../types';
|
|
4
|
+
export declare function generate(ts: typeof import('typescript'), compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions, template: NonNullable<Sfc['template']>, shouldGenerateScopedClasses: boolean, stylesScopedClasses: Set<string>, hasScriptSetupSlots: boolean, slotsAssignName: string | undefined, propsAssignName: string | undefined, codegenStack: boolean): Generator<CodeAndStack, {
|
|
5
5
|
tagOffsetsMap: Map<string, number[]>;
|
|
6
6
|
accessedGlobalVariables: Set<string>;
|
|
7
7
|
hasSlot: boolean;
|
|
8
8
|
}, unknown>;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string): ts.SourceFile;
|
|
10
|
+
export declare function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile): boolean;
|
|
11
|
+
export declare function parseInterpolationNode(node: CompilerDOM.InterpolationNode, template: string): readonly [string, number];
|
|
12
|
+
export declare function parseVForNode(node: CompilerDOM.ForNode): {
|
|
13
|
+
leftExpressionRange: {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
leftExpressionText: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
export declare function forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator<CompilerDOM.ElementNode>;
|