@vue/language-core 2.2.10 → 3.0.0-alpha.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/index.d.ts +1 -2
- package/index.js +1 -1
- package/lib/codegen/codeFeatures.d.ts +5 -0
- package/lib/codegen/codeFeatures.js +5 -0
- package/lib/codegen/globalTypes.js +44 -31
- package/lib/codegen/localTypes.d.ts +2 -3
- package/lib/codegen/localTypes.js +5 -15
- package/lib/codegen/script/component.js +21 -9
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/context.js +1 -1
- package/lib/codegen/script/index.d.ts +1 -2
- package/lib/codegen/script/index.js +2 -18
- package/lib/codegen/script/scriptSetup.js +5 -16
- package/lib/codegen/script/src.js +4 -22
- package/lib/codegen/script/template.js +7 -6
- package/lib/codegen/template/context.d.ts +29 -19
- package/lib/codegen/template/context.js +87 -56
- package/lib/codegen/template/element.d.ts +2 -2
- package/lib/codegen/template/element.js +34 -63
- package/lib/codegen/template/elementChildren.d.ts +2 -2
- package/lib/codegen/template/elementChildren.js +4 -6
- package/lib/codegen/template/elementDirectives.js +3 -15
- package/lib/codegen/template/elementEvents.d.ts +4 -3
- package/lib/codegen/template/elementEvents.js +61 -29
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +11 -22
- package/lib/codegen/template/index.d.ts +1 -2
- package/lib/codegen/template/index.js +22 -11
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +53 -51
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +2 -2
- package/lib/codegen/template/templateChild.d.ts +1 -1
- package/lib/codegen/template/templateChild.js +12 -46
- package/lib/codegen/template/vFor.js +5 -10
- package/lib/codegen/template/vIf.js +2 -10
- package/lib/codegen/template/vSlot.d.ts +1 -2
- package/lib/codegen/template/vSlot.js +111 -59
- package/lib/codegen/utils/index.d.ts +2 -3
- package/lib/codegen/utils/index.js +2 -18
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +1 -7
- package/lib/parsers/scriptRanges.d.ts +2 -3
- package/lib/parsers/scriptRanges.js +10 -13
- package/lib/parsers/scriptSetupRanges.d.ts +0 -3
- package/lib/parsers/scriptSetupRanges.js +36 -43
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-style-css.d.ts +3 -0
- package/lib/plugins/vue-style-css.js +18 -0
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +5 -2
- package/lib/plugins/vue-tsx.d.ts +27 -18
- package/lib/plugins/vue-tsx.js +32 -24
- package/lib/plugins.d.ts +1 -1
- package/lib/types.d.ts +3 -2
- package/lib/utils/shared.d.ts +4 -1
- package/lib/utils/shared.js +12 -4
- package/lib/utils/signals.d.ts +1 -0
- package/lib/utils/signals.js +11 -0
- package/lib/utils/ts.d.ts +0 -4
- package/lib/utils/ts.js +4 -14
- package/lib/virtualFile/computedSfc.js +6 -6
- package/package.json +6 -8
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -89
package/index.d.ts
CHANGED
|
@@ -5,9 +5,8 @@ export * from './lib/parsers/scriptSetupRanges';
|
|
|
5
5
|
export * from './lib/plugins';
|
|
6
6
|
export * from './lib/types';
|
|
7
7
|
export * from './lib/utils/parseSfc';
|
|
8
|
+
export * from './lib/utils/shared';
|
|
8
9
|
export * from './lib/utils/ts';
|
|
9
10
|
export * from './lib/virtualFile/vueFile';
|
|
10
11
|
export { tsCodegen } from './lib/plugins/vue-tsx';
|
|
11
|
-
export * from './lib/utils/shared';
|
|
12
12
|
export * from '@volar/language-core';
|
|
13
|
-
export type * as CompilerDOM from '@vue/compiler-dom';
|
package/index.js
CHANGED
|
@@ -22,10 +22,10 @@ __exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
|
22
22
|
__exportStar(require("./lib/plugins"), exports);
|
|
23
23
|
__exportStar(require("./lib/types"), exports);
|
|
24
24
|
__exportStar(require("./lib/utils/parseSfc"), exports);
|
|
25
|
+
__exportStar(require("./lib/utils/shared"), exports);
|
|
25
26
|
__exportStar(require("./lib/utils/ts"), exports);
|
|
26
27
|
__exportStar(require("./lib/virtualFile/vueFile"), exports);
|
|
27
28
|
var vue_tsx_1 = require("./lib/plugins/vue-tsx");
|
|
28
29
|
Object.defineProperty(exports, "tsCodegen", { enumerable: true, get: function () { return vue_tsx_1.tsCodegen; } });
|
|
29
|
-
__exportStar(require("./lib/utils/shared"), exports);
|
|
30
30
|
__exportStar(require("@volar/language-core"), exports);
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -78,6 +78,11 @@ declare const raw: {
|
|
|
78
78
|
};
|
|
79
79
|
verification: true;
|
|
80
80
|
};
|
|
81
|
+
withoutSemantic: {
|
|
82
|
+
verification: true;
|
|
83
|
+
navigation: true;
|
|
84
|
+
completion: true;
|
|
85
|
+
};
|
|
81
86
|
};
|
|
82
87
|
export declare const codeFeatures: { [K in keyof typeof raw]: VueCodeInformation; };
|
|
83
88
|
export {};
|
|
@@ -66,6 +66,11 @@ const raw = {
|
|
|
66
66
|
semantic: { shouldHighlight: () => false },
|
|
67
67
|
verification: true,
|
|
68
68
|
},
|
|
69
|
+
withoutSemantic: {
|
|
70
|
+
verification: true,
|
|
71
|
+
navigation: true,
|
|
72
|
+
completion: true,
|
|
73
|
+
},
|
|
69
74
|
};
|
|
70
75
|
exports.codeFeatures = raw;
|
|
71
76
|
//# sourceMappingURL=codeFeatures.js.map
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGlobalTypesFileName = getGlobalTypesFileName;
|
|
4
4
|
exports.generateGlobalTypes = generateGlobalTypes;
|
|
5
|
-
const shared_1 = require("../utils/shared");
|
|
6
5
|
function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
7
6
|
return [
|
|
8
7
|
lib,
|
|
@@ -13,7 +12,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
|
|
|
13
12
|
].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
|
|
14
13
|
}
|
|
15
14
|
function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
16
|
-
const fnPropsType = `(
|
|
15
|
+
const fnPropsType = `(T extends { $props: infer Props } ? Props : {})${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
|
|
17
16
|
let text = ``;
|
|
18
17
|
if (target < 3.5) {
|
|
19
18
|
text += `
|
|
@@ -24,7 +23,6 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
24
23
|
}
|
|
25
24
|
text += `
|
|
26
25
|
; declare global {
|
|
27
|
-
const __VLS_intrinsicElements: __VLS_IntrinsicElements;
|
|
28
26
|
const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
|
|
29
27
|
const __VLS_unref: typeof import('${lib}').unref;
|
|
30
28
|
const __VLS_placeholder: any;
|
|
@@ -52,10 +50,31 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
52
50
|
N2 extends keyof __VLS_GlobalComponents ? N2 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
53
51
|
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
54
52
|
${checkUnknownComponents ? '{}' : '{ [K in N0]: unknown }'};
|
|
55
|
-
type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
|
|
54
|
+
? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
|
|
55
|
+
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
56
|
+
>;
|
|
57
|
+
type __VLS_FunctionalComponentProps<T, K> = '__ctx' extends keyof __VLS_PickNotAny<K, {}>
|
|
58
|
+
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
|
|
59
|
+
: T extends (props: infer P, ...args: any) => any ? P
|
|
60
|
+
: {};
|
|
61
|
+
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
62
|
+
__ctx?: {
|
|
63
|
+
attrs?: any,
|
|
64
|
+
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>,
|
|
65
|
+
emit?: T extends { $emit: infer Emit } ? Emit : {},
|
|
66
|
+
props?: ${fnPropsType},
|
|
67
|
+
expose?: (exposed: T) => void,
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
type __VLS_NormalizeSlotReturns<S, R = NonNullable<S> extends (...args: any) => infer K ? K : any> = R extends any[] ? {
|
|
71
|
+
[K in keyof R]: R[K] extends infer V
|
|
72
|
+
? V extends Element ? V
|
|
73
|
+
: V extends new (...args: any) => infer R ? ReturnType<__VLS_FunctionalComponent<R>>
|
|
74
|
+
: V extends (...args: any) => infer R ? R
|
|
75
|
+
: any
|
|
76
|
+
: never
|
|
77
|
+
} : R;
|
|
59
78
|
type __VLS_IsFunction<T, K> = K extends keyof T
|
|
60
79
|
? __VLS_IsAny<T[K]> extends false
|
|
61
80
|
? unknown extends T[K]
|
|
@@ -63,13 +82,13 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
63
82
|
: true
|
|
64
83
|
: false
|
|
65
84
|
: false;
|
|
66
|
-
type __VLS_NormalizeComponentEvent<Props,
|
|
85
|
+
type __VLS_NormalizeComponentEvent<Props, Emits, onEvent extends keyof Props, Event extends keyof Emits, CamelizedEvent extends keyof Emits> = (
|
|
67
86
|
__VLS_IsFunction<Props, onEvent> extends true
|
|
68
87
|
? Props
|
|
69
|
-
: __VLS_IsFunction<
|
|
70
|
-
? { [K in onEvent]?:
|
|
71
|
-
: __VLS_IsFunction<
|
|
72
|
-
? { [K in onEvent]?:
|
|
88
|
+
: __VLS_IsFunction<Emits, Event> extends true
|
|
89
|
+
? { [K in onEvent]?: Emits[Event] }
|
|
90
|
+
: __VLS_IsFunction<Emits, CamelizedEvent> extends true
|
|
91
|
+
? { [K in onEvent]?: Emits[CamelizedEvent] }
|
|
73
92
|
: Props
|
|
74
93
|
)${checkUnknownEvents ? '' : ' & Record<string, unknown>'};
|
|
75
94
|
// fix https://github.com/vuejs/language-tools/issues/926
|
|
@@ -95,11 +114,16 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
95
114
|
}
|
|
96
115
|
>
|
|
97
116
|
>;
|
|
117
|
+
type __VLS_ResolveEmits<
|
|
118
|
+
Comp,
|
|
119
|
+
Emits,
|
|
120
|
+
TypeEmits = ${target >= 3.6 ? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}` : `{}`},
|
|
121
|
+
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
|
|
122
|
+
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
|
|
123
|
+
type __VLS_ResolveDirectives<T> = {
|
|
124
|
+
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
|
|
125
|
+
};
|
|
98
126
|
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
|
|
99
|
-
type __VLS_PickFunctionalComponentCtx<T, K> = NonNullable<__VLS_PickNotAny<
|
|
100
|
-
'__ctx' extends keyof __VLS_PickNotAny<K, {}> ? K extends { __ctx?: infer Ctx } ? Ctx : never : any
|
|
101
|
-
, T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
|
|
102
|
-
>>;
|
|
103
127
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
104
128
|
|
|
105
129
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
@@ -115,10 +139,8 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
115
139
|
key: keyof T,
|
|
116
140
|
index: number,
|
|
117
141
|
][];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
function __VLS_getSlotParam<T>(slot: T): Parameters<__VLS_PickNotAny<NonNullable<T>, (...args: any[]) => any>>[0];
|
|
142
|
+
function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D):
|
|
143
|
+
__VLS_PickNotAny<NonNullable<D>, (...args: any) => any> extends (...args: infer P) => any ? P : any[];
|
|
122
144
|
function __VLS_asFunctionalDirective<T>(dir: T): T extends import('${lib}').ObjectDirective
|
|
123
145
|
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
|
124
146
|
: T extends (...args: any) => any
|
|
@@ -126,19 +148,10 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
126
148
|
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
|
127
149
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
128
150
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
129
|
-
T extends new (...args: any) => any
|
|
130
|
-
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
131
|
-
__ctx?: {
|
|
132
|
-
attrs?: any;
|
|
133
|
-
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any;
|
|
134
|
-
emit?: K extends { $emit: infer Emit } ? Emit : any;
|
|
135
|
-
expose?(exposed: K): void;
|
|
136
|
-
props?: ${fnPropsType};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
151
|
+
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
|
|
139
152
|
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
140
153
|
: T extends (...args: any) => any ? T
|
|
141
|
-
:
|
|
154
|
+
: __VLS_FunctionalComponent<{}>;
|
|
142
155
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
143
156
|
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
144
157
|
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
export declare function getLocalTypesGenerator(compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): {
|
|
1
|
+
import type { VueCompilerOptions } from '../types';
|
|
2
|
+
export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
|
|
4
3
|
generate: (names: string[]) => Generator<string, void, unknown>;
|
|
5
4
|
getUsedNames(): Set<string>;
|
|
6
5
|
readonly PrettifyLocal: string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLocalTypesGenerator = getLocalTypesGenerator;
|
|
4
|
-
const shared_1 = require("../utils/shared");
|
|
5
4
|
const utils_1 = require("./utils");
|
|
6
|
-
function getLocalTypesGenerator(
|
|
5
|
+
function getLocalTypesGenerator(vueCompilerOptions) {
|
|
7
6
|
const used = new Set();
|
|
8
7
|
const OmitKeepDiscriminatedUnion = defineHelper(`__VLS_OmitKeepDiscriminatedUnion`, () => `
|
|
9
8
|
type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
@@ -13,7 +12,7 @@ type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
|
13
12
|
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
|
14
13
|
type __VLS_WithDefaults<P, D> = {
|
|
15
14
|
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
16
|
-
? ${PrettifyLocal.name}<P[K] & { default: D[K]}>
|
|
15
|
+
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
|
|
17
16
|
: P[K]
|
|
18
17
|
};
|
|
19
18
|
`.trimStart());
|
|
@@ -21,7 +20,7 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
21
20
|
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
22
21
|
type __VLS_WithSlots<T, S> = T & {
|
|
23
22
|
new(): {
|
|
24
|
-
$
|
|
23
|
+
$slots: S;
|
|
25
24
|
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
|
|
26
25
|
}
|
|
27
26
|
};
|
|
@@ -41,19 +40,10 @@ type __VLS_PropsChildren<S> = {
|
|
|
41
40
|
)]?: S;
|
|
42
41
|
};
|
|
43
42
|
`.trimStart());
|
|
44
|
-
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () =>
|
|
45
|
-
`
|
|
43
|
+
const TypePropsToOption = defineHelper(`__VLS_TypePropsToOption`, () => `
|
|
46
44
|
type __VLS_TypePropsToOption<T> = {
|
|
47
45
|
[K in keyof T]-?: {} extends Pick<T, K>
|
|
48
|
-
? { type: import('${vueCompilerOptions.lib}').PropType<T[K]> }
|
|
49
|
-
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
50
|
-
};
|
|
51
|
-
`.trimStart() :
|
|
52
|
-
`
|
|
53
|
-
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
54
|
-
type __VLS_TypePropsToOption<T> = {
|
|
55
|
-
[K in keyof T]-?: {} extends Pick<T, K>
|
|
56
|
-
? { type: import('${vueCompilerOptions.lib}').PropType<__VLS_NonUndefinedable<T[K]>> }
|
|
46
|
+
? { type: import('${vueCompilerOptions.lib}').PropType<Required<T>[K]> }
|
|
57
47
|
: { type: import('${vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
58
48
|
};
|
|
59
49
|
`.trimStart());
|
|
@@ -111,15 +111,23 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
111
111
|
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption, inheritAttrs) {
|
|
112
112
|
const codes = [];
|
|
113
113
|
if (ctx.generatedPropsType) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
if (options.vueCompilerOptions.target >= 3.6) {
|
|
115
|
+
codes.push({
|
|
116
|
+
optionExp: '{}',
|
|
117
|
+
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
codes.push({
|
|
122
|
+
optionExp: [
|
|
123
|
+
`{} as `,
|
|
124
|
+
scriptSetupRanges.withDefaults?.arg ? `${ctx.localTypes.WithDefaults}<` : '',
|
|
125
|
+
`${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`,
|
|
126
|
+
scriptSetupRanges.withDefaults?.arg ? `, typeof __VLS_withDefaultsArg>` : '',
|
|
127
|
+
].join(''),
|
|
128
|
+
typeOptionExp: `{} as __VLS_PublicProps`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
123
131
|
}
|
|
124
132
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
125
133
|
const { arg } = scriptSetupRanges.defineProps;
|
|
@@ -146,6 +154,10 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
146
154
|
const useTypeOption = options.vueCompilerOptions.target >= 3.5 && codes.every(code => code.typeOptionExp);
|
|
147
155
|
const useOption = !useTypeOption || scriptSetupRanges.withDefaults;
|
|
148
156
|
if (useTypeOption) {
|
|
157
|
+
if (options.vueCompilerOptions.target >= 3.6
|
|
158
|
+
&& scriptSetupRanges.withDefaults?.arg) {
|
|
159
|
+
yield `__defaults: __VLS_withDefaultsArg,${utils_1.newLine}`;
|
|
160
|
+
}
|
|
149
161
|
if (codes.length === 1) {
|
|
150
162
|
yield `__typeProps: `;
|
|
151
163
|
yield codes[0].typeOptionExp;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createScriptCodegenContext = createScriptCodegenContext;
|
|
4
4
|
const localTypes_1 = require("../localTypes");
|
|
5
5
|
function createScriptCodegenContext(options) {
|
|
6
|
-
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.
|
|
6
|
+
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.vueCompilerOptions);
|
|
7
7
|
const inlayHints = [];
|
|
8
8
|
return {
|
|
9
9
|
generatedTemplate: false,
|
|
@@ -3,13 +3,12 @@ import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
|
3
3
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
4
4
|
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
5
5
|
import type { TemplateCodegenContext } from '../template/context';
|
|
6
|
-
import { ScriptCodegenContext } from './context';
|
|
6
|
+
import { type ScriptCodegenContext } from './context';
|
|
7
7
|
export interface ScriptCodegenOptions {
|
|
8
8
|
ts: typeof ts;
|
|
9
9
|
compilerOptions: ts.CompilerOptions;
|
|
10
10
|
vueCompilerOptions: VueCompilerOptions;
|
|
11
11
|
sfc: Sfc;
|
|
12
|
-
edited: boolean;
|
|
13
12
|
fileName: string;
|
|
14
13
|
lang: string;
|
|
15
14
|
scriptRanges: ScriptRanges | undefined;
|
|
@@ -27,7 +27,7 @@ function* generateScript(options) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
yield
|
|
30
|
+
yield `/// <reference path="./__VLS_fake.d.ts" />`;
|
|
31
31
|
}
|
|
32
32
|
if (options.sfc.script?.src) {
|
|
33
33
|
yield* (0, src_1.generateSrc)(options.sfc.script.src);
|
|
@@ -36,7 +36,7 @@ function* generateScript(options) {
|
|
|
36
36
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
37
37
|
}
|
|
38
38
|
if (options.sfc.script && options.scriptRanges) {
|
|
39
|
-
const { exportDefault
|
|
39
|
+
const { exportDefault } = options.scriptRanges;
|
|
40
40
|
const isExportRawObject = exportDefault
|
|
41
41
|
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
42
42
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
@@ -77,19 +77,6 @@ function* generateScript(options) {
|
|
|
77
77
|
yield options.vueCompilerOptions.optionsWrapper[1];
|
|
78
78
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
79
79
|
}
|
|
80
|
-
else if (classBlockEnd !== undefined) {
|
|
81
|
-
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
|
82
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, codeFeatures_1.codeFeatures.all);
|
|
86
|
-
yield `__VLS_template = () => {${utils_1.newLine}`;
|
|
87
|
-
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
88
|
-
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
89
|
-
yield `}${utils_1.endOfLine}`;
|
|
90
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
80
|
else {
|
|
94
81
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
95
82
|
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
|
@@ -105,9 +92,6 @@ function* generateScript(options) {
|
|
|
105
92
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
106
93
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
107
94
|
}
|
|
108
|
-
if (options.edited) {
|
|
109
|
-
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
110
|
-
}
|
|
111
95
|
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
112
96
|
if (options.appendGlobalTypes) {
|
|
113
97
|
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
|
|
@@ -78,15 +78,6 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
78
78
|
}
|
|
79
79
|
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax) {
|
|
80
80
|
let setupCodeModifies = [];
|
|
81
|
-
for (const { comments } of scriptSetupRanges.defineProp) {
|
|
82
|
-
if (comments) {
|
|
83
|
-
setupCodeModifies.push([
|
|
84
|
-
[``],
|
|
85
|
-
comments.start,
|
|
86
|
-
comments.end,
|
|
87
|
-
]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
81
|
if (scriptSetupRanges.defineProps) {
|
|
91
82
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
92
83
|
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
|
|
@@ -196,7 +187,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
196
187
|
const templateRefType = arg
|
|
197
188
|
? [
|
|
198
189
|
`__VLS_TemplateRefs[`,
|
|
199
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.
|
|
190
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
|
|
200
191
|
`]`
|
|
201
192
|
]
|
|
202
193
|
: [`unknown`];
|
|
@@ -349,11 +340,9 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
349
340
|
yield `})${utils_1.endOfLine}`;
|
|
350
341
|
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
|
|
351
342
|
? `import('${options.vueCompilerOptions.lib}').PublicProps`
|
|
352
|
-
: options.vueCompilerOptions.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`
|
|
356
|
-
: `globalThis.JSX.IntrinsicAttributes`}`;
|
|
343
|
+
: `import('${options.vueCompilerOptions.lib}').VNodeProps`
|
|
344
|
+
+ ` & import('${options.vueCompilerOptions.lib}').AllowedComponentProps`
|
|
345
|
+
+ ` & import('${options.vueCompilerOptions.lib}').ComponentCustomProps`}`;
|
|
357
346
|
yield utils_1.endOfLine;
|
|
358
347
|
yield `type __VLS_OwnProps = `;
|
|
359
348
|
yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
@@ -405,7 +394,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
405
394
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
406
395
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
407
396
|
if (defineProp.comments) {
|
|
408
|
-
yield
|
|
397
|
+
yield scriptSetup.content.slice(defineProp.comments.start, defineProp.comments.end);
|
|
409
398
|
yield utils_1.newLine;
|
|
410
399
|
}
|
|
411
400
|
if (defineProp.isModel && !defineProp.name) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateSrc = generateSrc;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
6
7
|
function* generateSrc(src) {
|
|
7
8
|
if (src === true) {
|
|
8
9
|
return;
|
|
@@ -21,29 +22,10 @@ function* generateSrc(src) {
|
|
|
21
22
|
text = text + '.js';
|
|
22
23
|
}
|
|
23
24
|
yield `export * from `;
|
|
24
|
-
yield* (0,
|
|
25
|
+
yield* (0, wrapWith_1.wrapWith)(src.offset, src.offset + src.text.length, 'main', {
|
|
25
26
|
...codeFeatures_1.codeFeatures.all,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
: {
|
|
29
|
-
shouldRename: () => false,
|
|
30
|
-
resolveRenameEditText(newName) {
|
|
31
|
-
if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
|
|
32
|
-
newName = newName.split('.').slice(0, -1).join('.');
|
|
33
|
-
}
|
|
34
|
-
if (src?.text.endsWith('.d.ts')) {
|
|
35
|
-
newName = newName + '.d.ts';
|
|
36
|
-
}
|
|
37
|
-
else if (src?.text.endsWith('.ts')) {
|
|
38
|
-
newName = newName + '.ts';
|
|
39
|
-
}
|
|
40
|
-
else if (src?.text.endsWith('.tsx')) {
|
|
41
|
-
newName = newName + '.tsx';
|
|
42
|
-
}
|
|
43
|
-
return newName;
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
27
|
+
...text !== src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
|
28
|
+
}, `'`, [text.slice(0, src.text.length), 'main', src.offset, utils_1.combineLastMapping], text.slice(src.text.length), `'`);
|
|
47
29
|
yield utils_1.endOfLine;
|
|
48
30
|
yield `export { default } from '${text}'${utils_1.endOfLine}`;
|
|
49
31
|
}
|
|
@@ -15,9 +15,9 @@ function* generateTemplate(options, ctx) {
|
|
|
15
15
|
ctx.generatedTemplate = true;
|
|
16
16
|
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
|
17
17
|
scriptSetupBindingNames: new Set(),
|
|
18
|
-
edited: options.edited,
|
|
19
18
|
});
|
|
20
19
|
yield* generateTemplateCtx(options);
|
|
20
|
+
yield* generateTemplateElements();
|
|
21
21
|
yield* generateTemplateComponents(options);
|
|
22
22
|
yield* generateTemplateDirectives(options);
|
|
23
23
|
yield* generateTemplateBody(options, templateCodegenCtx);
|
|
@@ -47,8 +47,11 @@ function* generateTemplateCtx(options) {
|
|
|
47
47
|
yield `}${utils_1.endOfLine}`;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
function* generateTemplateElements() {
|
|
51
|
+
yield `let __VLS_elements!: __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
52
|
+
}
|
|
50
53
|
function* generateTemplateComponents(options) {
|
|
51
|
-
const types = [];
|
|
54
|
+
const types = [`typeof __VLS_ctx`];
|
|
52
55
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
|
|
53
56
|
const { componentsOption } = options.scriptRanges.exportDefault;
|
|
54
57
|
yield `const __VLS_componentsOption = `;
|
|
@@ -61,7 +64,6 @@ function* generateTemplateComponents(options) {
|
|
|
61
64
|
yield utils_1.endOfLine;
|
|
62
65
|
types.push(`typeof __VLS_componentsOption`);
|
|
63
66
|
}
|
|
64
|
-
types.push(`typeof __VLS_ctx`);
|
|
65
67
|
yield `type __VLS_LocalComponents =`;
|
|
66
68
|
for (const type of types) {
|
|
67
69
|
yield ` & `;
|
|
@@ -71,7 +73,7 @@ function* generateTemplateComponents(options) {
|
|
|
71
73
|
yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${utils_1.endOfLine}`;
|
|
72
74
|
}
|
|
73
75
|
function* generateTemplateDirectives(options) {
|
|
74
|
-
const types = [];
|
|
76
|
+
const types = [`typeof __VLS_ctx`];
|
|
75
77
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
|
|
76
78
|
const { directivesOption } = options.scriptRanges.exportDefault;
|
|
77
79
|
yield `const __VLS_directivesOption = `;
|
|
@@ -82,9 +84,8 @@ function* generateTemplateDirectives(options) {
|
|
|
82
84
|
codeFeatures_1.codeFeatures.navigation,
|
|
83
85
|
];
|
|
84
86
|
yield utils_1.endOfLine;
|
|
85
|
-
types.push(`typeof __VLS_directivesOption
|
|
87
|
+
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
|
|
86
88
|
}
|
|
87
|
-
types.push(`typeof __VLS_ctx`);
|
|
88
89
|
yield `type __VLS_LocalDirectives =`;
|
|
89
90
|
for (const type of types) {
|
|
90
91
|
yield ` & `;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as CompilerDOM from '@vue/compiler-dom';
|
|
2
2
|
import type { Code, VueCodeInformation } from '../../types';
|
|
3
|
-
import { InlayHintInfo } from '../inlayHints';
|
|
3
|
+
import type { InlayHintInfo } from '../inlayHints';
|
|
4
4
|
import type { TemplateCodegenOptions } from './index';
|
|
5
5
|
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;
|
|
6
6
|
/**
|
|
@@ -100,7 +100,18 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
100
100
|
* an error/diagnostic was encountered for a region of code covered by a `@vue-expect-error` directive,
|
|
101
101
|
* and additionally how we use that to determine whether to propagate diagnostics back upward.
|
|
102
102
|
*/
|
|
103
|
-
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'
|
|
103
|
+
export declare function createTemplateCodegenContext(options: Pick<TemplateCodegenOptions, 'scriptSetupBindingNames'>): {
|
|
104
|
+
readonly currentInfo: {
|
|
105
|
+
ignoreError?: boolean;
|
|
106
|
+
expectError?: {
|
|
107
|
+
token: number;
|
|
108
|
+
node: CompilerDOM.CommentNode;
|
|
109
|
+
};
|
|
110
|
+
generic?: {
|
|
111
|
+
content: string;
|
|
112
|
+
offset: number;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
104
115
|
codeFeatures: {
|
|
105
116
|
all: VueCodeInformation;
|
|
106
117
|
none: VueCodeInformation;
|
|
@@ -118,8 +129,10 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
118
129
|
withoutHighlightAndNavigation: VueCodeInformation;
|
|
119
130
|
withoutHighlightAndCompletion: VueCodeInformation;
|
|
120
131
|
withoutHighlightAndCompletionAndNavigation: VueCodeInformation;
|
|
132
|
+
withoutSemantic: VueCodeInformation;
|
|
121
133
|
};
|
|
122
134
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
135
|
+
inVFor: boolean;
|
|
123
136
|
slots: {
|
|
124
137
|
name: string;
|
|
125
138
|
offset?: number;
|
|
@@ -133,10 +146,6 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
133
146
|
}[];
|
|
134
147
|
dollarVars: Set<string>;
|
|
135
148
|
accessExternalVariables: Map<string, Set<number>>;
|
|
136
|
-
lastGenericComment: {
|
|
137
|
-
content: string;
|
|
138
|
-
offset: number;
|
|
139
|
-
} | undefined;
|
|
140
149
|
blockConditions: string[];
|
|
141
150
|
scopedClasses: {
|
|
142
151
|
source: string;
|
|
@@ -150,23 +159,24 @@ export declare function createTemplateCodegenContext(options: Pick<TemplateCodeg
|
|
|
150
159
|
templateRefs: Map<string, {
|
|
151
160
|
typeExp: string;
|
|
152
161
|
offset: number;
|
|
153
|
-
}>;
|
|
162
|
+
}[]>;
|
|
154
163
|
currentComponent: {
|
|
155
164
|
ctxVar: string;
|
|
165
|
+
childTypes: string[];
|
|
156
166
|
used: boolean;
|
|
157
167
|
} | undefined;
|
|
158
168
|
singleRootElTypes: string[];
|
|
159
169
|
singleRootNodes: Set<CompilerDOM.ElementNode | null>;
|
|
170
|
+
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
160
171
|
accessExternalVariable(name: string, offset?: number): void;
|
|
161
|
-
hasLocalVariable
|
|
162
|
-
addLocalVariable
|
|
163
|
-
removeLocalVariable
|
|
164
|
-
getInternalVariable
|
|
165
|
-
getHoistVariable
|
|
166
|
-
generateHoistVariables
|
|
167
|
-
generateConditionGuards
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
generateAutoImportCompletion: () => Generator<Code>;
|
|
172
|
+
hasLocalVariable(name: string): boolean;
|
|
173
|
+
addLocalVariable(name: string): void;
|
|
174
|
+
removeLocalVariable(name: string): void;
|
|
175
|
+
getInternalVariable(): string;
|
|
176
|
+
getHoistVariable(originalVar: string): string;
|
|
177
|
+
generateHoistVariables(): Generator<string, void, unknown>;
|
|
178
|
+
generateConditionGuards(): Generator<string, void, unknown>;
|
|
179
|
+
generateAutoImportCompletion(): Generator<Code>;
|
|
180
|
+
enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
|
|
181
|
+
exit(): Generator<Code>;
|
|
172
182
|
};
|