@vue/language-core 3.0.7-alpha.1 → 3.1.0-alpha.0
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.js +19 -13
- package/lib/codegen/localTypes.d.ts +2 -4
- package/lib/codegen/localTypes.js +10 -33
- package/lib/codegen/script/component.d.ts +0 -3
- package/lib/codegen/script/component.js +15 -22
- package/lib/codegen/script/componentSelf.js +1 -1
- package/lib/codegen/script/context.d.ts +2 -4
- package/lib/codegen/script/index.d.ts +4 -6
- package/lib/codegen/script/index.js +70 -63
- package/lib/codegen/script/scriptSetup.js +142 -143
- package/lib/codegen/script/template.d.ts +1 -3
- package/lib/codegen/script/template.js +90 -16
- package/lib/codegen/template/context.js +1 -1
- package/lib/codegen/template/element.js +4 -6
- package/lib/codegen/template/elementProps.js +6 -11
- package/lib/codegen/template/index.d.ts +1 -1
- package/lib/codegen/template/index.js +12 -13
- package/lib/codegen/template/slotOutlet.js +2 -3
- package/lib/codegen/template/styleScopedClasses.js +1 -2
- package/lib/codegen/template/vFor.js +1 -1
- package/lib/codegen/template/vSlot.js +1 -1
- package/lib/codegen/tenp.d.ts +1 -0
- package/lib/codegen/tenp.js +3 -0
- package/lib/codegen/utils/index.d.ts +1 -0
- package/lib/codegen/utils/index.js +7 -0
- package/lib/compilerOptions.js +3 -8
- package/lib/languagePlugin.js +8 -19
- package/lib/parsers/scriptRanges.d.ts +0 -1
- package/lib/parsers/scriptRanges.js +6 -9
- package/lib/parsers/scriptSetupRanges.d.ts +0 -6
- package/lib/parsers/scriptSetupRanges.js +9 -95
- package/lib/parsers/utils.d.ts +12 -0
- package/lib/parsers/utils.js +95 -0
- package/lib/plugins/file-css.d.ts +3 -0
- package/lib/plugins/file-css.js +57 -0
- package/lib/plugins/vue-template-inline-ts.js +2 -3
- package/lib/plugins/vue-tsx.d.ts +2 -5
- package/lib/plugins/vue-tsx.js +16 -13
- package/lib/types.d.ts +1 -1
- package/lib/utils/parseCssClassNames.d.ts +4 -0
- package/lib/utils/parseCssClassNames.js +17 -0
- package/lib/utils/parseCssImports.d.ts +4 -0
- package/lib/utils/parseCssImports.js +19 -0
- package/lib/utils/parseCssVars.d.ts +6 -0
- package/lib/utils/parseCssVars.js +26 -0
- package/lib/utils/shared.d.ts +1 -2
- package/lib/utils/shared.js +0 -4
- package/lib/virtualFile/computedSfc.js +4 -4
- package/lib/virtualFile/vueFile.d.ts +5 -10
- package/lib/virtualFile/vueFile.js +3 -10
- package/package.json +2 -3
- package/lib/utils/ts.js +0 -296
- package/lib/utils/vue2TemplateCompiler.d.ts +0 -2
- package/lib/utils/vue2TemplateCompiler.js +0 -90
|
@@ -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(options) {
|
|
7
6
|
return [
|
|
8
7
|
options.lib,
|
|
@@ -42,13 +41,13 @@ function generateGlobalTypes(options) {
|
|
|
42
41
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
43
42
|
type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
|
|
44
43
|
type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
|
|
45
|
-
N1 extends keyof LocalComponents ?
|
|
46
|
-
N2 extends keyof LocalComponents ?
|
|
47
|
-
N3 extends keyof LocalComponents ?
|
|
44
|
+
N1 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N1] } :
|
|
45
|
+
N2 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N2] } :
|
|
46
|
+
N3 extends keyof LocalComponents ? { [K in N0]: LocalComponents[N3] } :
|
|
48
47
|
Self extends object ? { [K in N0]: Self } :
|
|
49
|
-
N1 extends keyof __VLS_GlobalComponents ?
|
|
50
|
-
N2 extends keyof __VLS_GlobalComponents ?
|
|
51
|
-
N3 extends keyof __VLS_GlobalComponents ?
|
|
48
|
+
N1 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N1] } :
|
|
49
|
+
N2 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N2] } :
|
|
50
|
+
N3 extends keyof __VLS_GlobalComponents ? { [K in N0]: __VLS_GlobalComponents[N3] } :
|
|
52
51
|
{};
|
|
53
52
|
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<'__ctx' extends keyof __VLS_PickNotAny<K, {}>
|
|
54
53
|
? K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never : any
|
|
@@ -61,7 +60,7 @@ function generateGlobalTypes(options) {
|
|
|
61
60
|
type __VLS_FunctionalComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
62
61
|
__ctx?: {
|
|
63
62
|
attrs?: any;
|
|
64
|
-
slots?: T extends { $
|
|
63
|
+
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
|
|
65
64
|
emit?: T extends { $emit: infer Emit } ? Emit : {};
|
|
66
65
|
props?: ${fnPropsType};
|
|
67
66
|
expose?: (exposed: T) => void;
|
|
@@ -110,6 +109,10 @@ function generateGlobalTypes(options) {
|
|
|
110
109
|
}
|
|
111
110
|
>
|
|
112
111
|
>;
|
|
112
|
+
type __VLS_EmitsToProps<T> = __VLS_PrettifyGlobal<{
|
|
113
|
+
[K in string & keyof T as \`on\${Capitalize<K>}\`]?:
|
|
114
|
+
(...args: T[K] extends (...args: infer P) => any ? P : T[K] extends null ? any[] : never) => any;
|
|
115
|
+
}>;
|
|
113
116
|
type __VLS_ResolveEmits<
|
|
114
117
|
Comp,
|
|
115
118
|
Emits,
|
|
@@ -119,10 +122,16 @@ function generateGlobalTypes(options) {
|
|
|
119
122
|
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
|
|
120
123
|
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
|
|
121
124
|
type __VLS_ResolveDirectives<T> = {
|
|
122
|
-
[K in
|
|
125
|
+
[K in keyof T & string as \`v\${Capitalize<K>}\`]: T[K];
|
|
123
126
|
};
|
|
124
127
|
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K]; } & {};
|
|
128
|
+
type __VLS_WithDefaultsGlobal<P, D> = {
|
|
129
|
+
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
|
|
130
|
+
} & {
|
|
131
|
+
[K in keyof P as K extends keyof D ? never : K]: P[K];
|
|
132
|
+
};
|
|
125
133
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
134
|
+
type __VLS_ProxyRefs<T> = import('${lib}').ShallowUnwrapRef<T>;
|
|
126
135
|
|
|
127
136
|
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
128
137
|
item: T extends number ? number
|
|
@@ -144,12 +153,9 @@ function generateGlobalTypes(options) {
|
|
|
144
153
|
: T extends (...args: any) => any
|
|
145
154
|
? T
|
|
146
155
|
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
|
147
|
-
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
148
156
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
149
157
|
T extends new (...args: any) => any ? __VLS_FunctionalComponent<K>
|
|
150
|
-
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T
|
|
151
|
-
? `: T extends import('${lib}').AsyncComponent ? (props: {}, ctx?: any) => any`
|
|
152
|
-
: ``}
|
|
158
|
+
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
153
159
|
: T extends (...args: any) => any ? T
|
|
154
160
|
: __VLS_FunctionalComponent<{}>;
|
|
155
161
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { VueCompilerOptions } from '../types';
|
|
2
2
|
export declare function getLocalTypesGenerator(vueCompilerOptions: VueCompilerOptions): {
|
|
3
|
-
generate: (
|
|
4
|
-
getUsedNames(): Set<string>;
|
|
3
|
+
generate: () => Generator<string, void, unknown>;
|
|
5
4
|
readonly PrettifyLocal: string;
|
|
6
|
-
readonly
|
|
7
|
-
readonly WithDefaults: string;
|
|
5
|
+
readonly WithDefaultsLocal: string;
|
|
8
6
|
readonly WithSlots: string;
|
|
9
7
|
readonly PropsChildren: string;
|
|
10
8
|
readonly TypePropsToOption: string;
|
|
@@ -1,17 +1,11 @@
|
|
|
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
5
|
function getLocalTypesGenerator(vueCompilerOptions) {
|
|
7
6
|
const used = new Set();
|
|
8
|
-
const
|
|
9
|
-
type
|
|
10
|
-
? Pick<T, Exclude<keyof T, K>>
|
|
11
|
-
: never;
|
|
12
|
-
`.trimStart());
|
|
13
|
-
const WithDefaults = defineHelper(`__VLS_WithDefaults`, () => `
|
|
14
|
-
type __VLS_WithDefaults<P, D> = {
|
|
7
|
+
const WithDefaultsLocal = defineHelper(`__VLS_WithDefaultsLocal`, () => `
|
|
8
|
+
type __VLS_WithDefaultsLocal<P, D> = {
|
|
15
9
|
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
16
10
|
? ${PrettifyLocal.name}<P[K] & { default: D[K] }>
|
|
17
11
|
: P[K]
|
|
@@ -21,8 +15,7 @@ type __VLS_WithDefaults<P, D> = {
|
|
|
21
15
|
const WithSlots = defineHelper(`__VLS_WithSlots`, () => `
|
|
22
16
|
type __VLS_WithSlots<T, S> = T & {
|
|
23
17
|
new(): {
|
|
24
|
-
$
|
|
25
|
-
${vueCompilerOptions.jsxSlots ? `$props: ${PropsChildren.name}<S>;` : ''}
|
|
18
|
+
$slots: S;
|
|
26
19
|
}
|
|
27
20
|
};
|
|
28
21
|
`.trimStart());
|
|
@@ -51,8 +44,7 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
51
44
|
const OmitIndexSignature = defineHelper(`__VLS_OmitIndexSignature`, () => `type __VLS_OmitIndexSignature<T> = { [K in keyof T as {} extends Record<K, unknown> ? never : K]: T[K]; }${utils_1.endOfLine}`);
|
|
52
45
|
const helpers = {
|
|
53
46
|
[PrettifyLocal.name]: PrettifyLocal,
|
|
54
|
-
[
|
|
55
|
-
[WithDefaults.name]: WithDefaults,
|
|
47
|
+
[WithDefaultsLocal.name]: WithDefaultsLocal,
|
|
56
48
|
[WithSlots.name]: WithSlots,
|
|
57
49
|
[PropsChildren.name]: PropsChildren,
|
|
58
50
|
[TypePropsToOption.name]: TypePropsToOption,
|
|
@@ -61,17 +53,11 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
61
53
|
used.clear();
|
|
62
54
|
return {
|
|
63
55
|
generate,
|
|
64
|
-
getUsedNames() {
|
|
65
|
-
return used;
|
|
66
|
-
},
|
|
67
56
|
get PrettifyLocal() {
|
|
68
57
|
return PrettifyLocal.name;
|
|
69
58
|
},
|
|
70
|
-
get
|
|
71
|
-
return
|
|
72
|
-
},
|
|
73
|
-
get WithDefaults() {
|
|
74
|
-
return WithDefaults.name;
|
|
59
|
+
get WithDefaultsLocal() {
|
|
60
|
+
return WithDefaultsLocal.name;
|
|
75
61
|
},
|
|
76
62
|
get WithSlots() {
|
|
77
63
|
return WithSlots.name;
|
|
@@ -86,20 +72,11 @@ type __VLS_TypePropsToOption<T> = {
|
|
|
86
72
|
return OmitIndexSignature.name;
|
|
87
73
|
},
|
|
88
74
|
};
|
|
89
|
-
function* generate(
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
used.clear();
|
|
93
|
-
for (const name of names) {
|
|
94
|
-
if (generated.has(name)) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
const helper = helpers[name];
|
|
98
|
-
yield helper.generate();
|
|
99
|
-
generated.add(name);
|
|
100
|
-
}
|
|
101
|
-
names = [...used].filter(name => !generated.has(name));
|
|
75
|
+
function* generate() {
|
|
76
|
+
for (const name of used) {
|
|
77
|
+
yield helpers[name].generate();
|
|
102
78
|
}
|
|
79
|
+
used.clear();
|
|
103
80
|
}
|
|
104
81
|
function defineHelper(name, generate) {
|
|
105
82
|
return {
|
|
@@ -3,6 +3,3 @@ import type { Code, Sfc } from '../../types';
|
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
4
|
import type { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
|
-
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<string>;
|
|
7
|
-
export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
8
|
-
export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges, hasEmitsOption: boolean, inheritAttrs: boolean): Generator<Code>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateComponent = generateComponent;
|
|
4
|
-
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
|
5
|
-
exports.generateEmitsOption = generateEmitsOption;
|
|
6
|
-
exports.generatePropsOption = generatePropsOption;
|
|
7
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
5
|
const utils_1 = require("../utils");
|
|
9
6
|
const merge_1 = require("../utils/merge");
|
|
@@ -19,7 +16,16 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
19
16
|
}
|
|
20
17
|
const returns = [];
|
|
21
18
|
if (ctx.bypassDefineComponent) {
|
|
22
|
-
|
|
19
|
+
// fill $props
|
|
20
|
+
if (scriptSetupRanges.defineProps) {
|
|
21
|
+
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
|
|
22
|
+
// NOTE: defineProps is inaccurate for $props
|
|
23
|
+
returns.push(name, `{} as { $props: Partial<typeof ${name}> }`);
|
|
24
|
+
}
|
|
25
|
+
// fill $emit
|
|
26
|
+
if (scriptSetupRanges.defineEmits) {
|
|
27
|
+
returns.push(`{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`);
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
if (scriptSetupRanges.defineExpose) {
|
|
25
31
|
returns.push(`__VLS_exposed`);
|
|
@@ -32,7 +38,7 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
32
38
|
if (!ctx.bypassDefineComponent) {
|
|
33
39
|
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
34
40
|
yield* emitOptionCodes;
|
|
35
|
-
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length
|
|
41
|
+
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length);
|
|
36
42
|
}
|
|
37
43
|
if (options.vueCompilerOptions.target >= 3.5
|
|
38
44
|
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
@@ -50,19 +56,6 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
50
56
|
}
|
|
51
57
|
yield `})`;
|
|
52
58
|
}
|
|
53
|
-
function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
54
|
-
// fill $props
|
|
55
|
-
if (scriptSetupRanges.defineProps) {
|
|
56
|
-
const name = scriptSetupRanges.defineProps.name ?? `__VLS_props`;
|
|
57
|
-
// NOTE: defineProps is inaccurate for $props
|
|
58
|
-
yield name;
|
|
59
|
-
yield `{} as { $props: Partial<typeof ${name}> }`;
|
|
60
|
-
}
|
|
61
|
-
// fill $emit
|
|
62
|
-
if (scriptSetupRanges.defineEmits) {
|
|
63
|
-
yield `{} as { $emit: typeof ${scriptSetupRanges.defineEmits.name ?? `__VLS_emit`} }`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
59
|
function* generateEmitsOption(options, scriptSetupRanges) {
|
|
67
60
|
const optionCodes = [];
|
|
68
61
|
const typeOptionCodes = [];
|
|
@@ -91,10 +84,10 @@ function* generateEmitsOption(options, scriptSetupRanges) {
|
|
|
91
84
|
yield `,${utils_1.newLine}`;
|
|
92
85
|
}
|
|
93
86
|
}
|
|
94
|
-
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption
|
|
87
|
+
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasEmitsOption) {
|
|
95
88
|
const getOptionCodes = [];
|
|
96
89
|
const typeOptionCodes = [];
|
|
97
|
-
if (
|
|
90
|
+
if (options.templateCodegen?.inheritedAttrVars.size) {
|
|
98
91
|
let attrsType = `__VLS_InheritedAttrs`;
|
|
99
92
|
if (hasEmitsOption) {
|
|
100
93
|
attrsType = `Omit<${attrsType}, \`on\${string}\`>`;
|
|
@@ -111,7 +104,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
111
104
|
getOptionCodes.push(() => {
|
|
112
105
|
const propsType = `${ctx.localTypes.TypePropsToOption}<__VLS_PublicProps>`;
|
|
113
106
|
return `{} as ` + (scriptSetupRanges.withDefaults?.arg
|
|
114
|
-
? `${ctx.localTypes.
|
|
107
|
+
? `${ctx.localTypes.WithDefaultsLocal}<${propsType}, typeof __VLS_defaults>`
|
|
115
108
|
: propsType);
|
|
116
109
|
});
|
|
117
110
|
}
|
|
@@ -127,7 +120,7 @@ function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, hasE
|
|
|
127
120
|
if (useTypeOption) {
|
|
128
121
|
if (options.vueCompilerOptions.target >= 3.6
|
|
129
122
|
&& scriptSetupRanges.withDefaults?.arg) {
|
|
130
|
-
yield `__defaults:
|
|
123
|
+
yield `__defaults: __VLS_defaults,${utils_1.newLine}`;
|
|
131
124
|
}
|
|
132
125
|
yield `__typeProps: `;
|
|
133
126
|
yield* (0, merge_1.generateSpreadMerge)(typeOptionCodes);
|
|
@@ -32,7 +32,7 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
32
32
|
yield `${varName},${utils_1.newLine}`;
|
|
33
33
|
}
|
|
34
34
|
yield `}),${utils_1.newLine}`;
|
|
35
|
-
if (
|
|
35
|
+
if (!ctx.bypassDefineComponent) {
|
|
36
36
|
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
37
37
|
yield* emitOptionCodes;
|
|
38
38
|
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
|
@@ -7,11 +7,9 @@ export declare function createScriptCodegenContext(options: ScriptCodegenOptions
|
|
|
7
7
|
bypassDefineComponent: boolean;
|
|
8
8
|
bindingNames: Set<string>;
|
|
9
9
|
localTypes: {
|
|
10
|
-
generate: (
|
|
11
|
-
getUsedNames(): Set<string>;
|
|
10
|
+
generate: () => Generator<string, void, unknown>;
|
|
12
11
|
readonly PrettifyLocal: string;
|
|
13
|
-
readonly
|
|
14
|
-
readonly WithDefaults: string;
|
|
12
|
+
readonly WithDefaultsLocal: string;
|
|
15
13
|
readonly WithSlots: string;
|
|
16
14
|
readonly PropsChildren: string;
|
|
17
15
|
readonly TypePropsToOption: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
2
|
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
3
3
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
4
|
-
import type { Code, Sfc, VueCompilerOptions } from '../../types';
|
|
4
|
+
import type { Code, Sfc, SfcBlock, VueCompilerOptions } from '../../types';
|
|
5
5
|
import type { TemplateCodegenContext } from '../template/context';
|
|
6
6
|
export interface ScriptCodegenOptions {
|
|
7
7
|
ts: typeof ts;
|
|
@@ -26,11 +26,9 @@ declare function generate(options: ScriptCodegenOptions): {
|
|
|
26
26
|
bypassDefineComponent: boolean;
|
|
27
27
|
bindingNames: Set<string>;
|
|
28
28
|
localTypes: {
|
|
29
|
-
generate: (
|
|
30
|
-
getUsedNames(): Set<string>;
|
|
29
|
+
generate: () => Generator<string, void, unknown>;
|
|
31
30
|
readonly PrettifyLocal: string;
|
|
32
|
-
readonly
|
|
33
|
-
readonly WithDefaults: string;
|
|
31
|
+
readonly WithDefaultsLocal: string;
|
|
34
32
|
readonly WithSlots: string;
|
|
35
33
|
readonly PropsChildren: string;
|
|
36
34
|
readonly TypePropsToOption: string;
|
|
@@ -38,4 +36,4 @@ declare function generate(options: ScriptCodegenOptions): {
|
|
|
38
36
|
};
|
|
39
37
|
inlayHints: import("../inlayHints").InlayHintInfo[];
|
|
40
38
|
};
|
|
41
|
-
export declare function
|
|
39
|
+
export declare function generateConstExport(options: ScriptCodegenOptions, block: SfcBlock): Generator<Code>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateScript = generate;
|
|
4
|
-
exports.
|
|
4
|
+
exports.generateConstExport = generateConstExport;
|
|
5
5
|
const path = require("path-browserify");
|
|
6
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
-
const
|
|
8
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
9
9
|
const context_1 = require("./context");
|
|
10
10
|
const scriptSetup_1 = require("./scriptSetup");
|
|
11
11
|
const src_1 = require("./src");
|
|
@@ -19,89 +19,71 @@ function generate(options) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
function* generateScript(options, ctx) {
|
|
22
|
-
yield*
|
|
23
|
-
if (options.sfc.script?.src) {
|
|
24
|
-
yield* (0, src_1.generateSrc)(options.sfc.script.src);
|
|
25
|
-
}
|
|
22
|
+
yield* generateGlobalTypesReference(options);
|
|
26
23
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
27
24
|
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
28
25
|
}
|
|
29
26
|
if (options.sfc.script && options.scriptRanges) {
|
|
30
|
-
const { exportDefault
|
|
31
|
-
const isExportRawObject = exportDefault
|
|
32
|
-
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
27
|
+
const { exportDefault } = options.scriptRanges;
|
|
33
28
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
34
29
|
if (exportDefault) {
|
|
35
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.
|
|
30
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
|
|
36
31
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
37
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
38
32
|
}
|
|
39
33
|
else {
|
|
40
34
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
41
|
-
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/both.vue');
|
|
42
35
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
|
-
else if (exportDefault
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
:
|
|
53
|
-
|
|
54
|
-
'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
: '
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
yield options.vueCompilerOptions.optionsWrapper[0];
|
|
67
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, codeFeatures_1.codeFeatures.all);
|
|
68
|
-
yield options.vueCompilerOptions.optionsWrapper[1];
|
|
69
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
70
|
-
}
|
|
71
|
-
else if (classBlockEnd !== undefined) {
|
|
72
|
-
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
|
73
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
38
|
+
else if (exportDefault) {
|
|
39
|
+
let wrapLeft;
|
|
40
|
+
let wrapRight;
|
|
41
|
+
if (options.sfc.script.content[exportDefault.expression.start] === '{'
|
|
42
|
+
&& options.vueCompilerOptions.optionsWrapper.length) {
|
|
43
|
+
[wrapLeft, wrapRight] = options.vueCompilerOptions.optionsWrapper;
|
|
44
|
+
ctx.inlayHints.push({
|
|
45
|
+
blockName: options.sfc.script.name,
|
|
46
|
+
offset: exportDefault.expression.start,
|
|
47
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
48
|
+
label: wrapLeft || '[Missing optionsWrapper[0]]',
|
|
49
|
+
tooltip: [
|
|
50
|
+
'This is virtual code that is automatically wrapped for type support, it does not affect your runtime behavior, you can customize it via `vueCompilerOptions.optionsWrapper` option in tsconfig / jsconfig.',
|
|
51
|
+
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
52
|
+
].join('\n\n'),
|
|
53
|
+
}, {
|
|
54
|
+
blockName: options.sfc.script.name,
|
|
55
|
+
offset: exportDefault.expression.end,
|
|
56
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
57
|
+
label: wrapRight || '[Missing optionsWrapper[1]]',
|
|
58
|
+
});
|
|
74
59
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
80
|
-
yield `}${utils_1.endOfLine}`;
|
|
81
|
-
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
60
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.start, codeFeatures_1.codeFeatures.all);
|
|
61
|
+
yield* generateConstExport(options, options.sfc.script);
|
|
62
|
+
if (wrapLeft) {
|
|
63
|
+
yield wrapLeft;
|
|
82
64
|
}
|
|
65
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, codeFeatures_1.codeFeatures.all);
|
|
66
|
+
if (wrapRight) {
|
|
67
|
+
yield wrapRight;
|
|
68
|
+
}
|
|
69
|
+
yield utils_1.endOfLine;
|
|
83
70
|
}
|
|
84
71
|
else {
|
|
85
72
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
86
|
-
yield*
|
|
73
|
+
yield* generateConstExport(options, options.sfc.script);
|
|
74
|
+
yield `(await import('${options.vueCompilerOptions.lib}')).defineComponent({})${utils_1.endOfLine}`;
|
|
87
75
|
}
|
|
88
76
|
}
|
|
89
77
|
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
90
78
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
91
79
|
}
|
|
92
|
-
if (options.sfc.scriptSetup) {
|
|
93
|
-
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue', ';');
|
|
94
|
-
}
|
|
95
80
|
if (!ctx.generatedTemplate) {
|
|
96
|
-
|
|
97
|
-
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
98
|
-
}
|
|
99
|
-
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
100
|
-
if (options.sfc.scriptSetup) {
|
|
101
|
-
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, codeFeatures_1.codeFeatures.verification];
|
|
81
|
+
yield* (0, template_1.generateTemplate)(options, ctx);
|
|
102
82
|
}
|
|
83
|
+
yield* generateExportDefault(options);
|
|
84
|
+
yield* ctx.localTypes.generate();
|
|
103
85
|
}
|
|
104
|
-
function*
|
|
86
|
+
function* generateGlobalTypesReference(options) {
|
|
105
87
|
const globalTypesPath = options.vueCompilerOptions.globalTypesPath(options.fileName);
|
|
106
88
|
if (!globalTypesPath) {
|
|
107
89
|
yield `/* placeholder */${utils_1.newLine}`;
|
|
@@ -119,9 +101,34 @@ function* generateGlobalTypesPath(options) {
|
|
|
119
101
|
yield `/// <reference types="${globalTypesPath}" />${utils_1.newLine}`;
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
|
-
function*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
104
|
+
function* generateConstExport(options, block) {
|
|
105
|
+
if (options.sfc.script) {
|
|
106
|
+
yield* (0, utils_1.generatePartiallyEnding)(options.sfc.script.name, options.scriptRanges?.exportDefault
|
|
107
|
+
? options.scriptRanges.exportDefault.start
|
|
108
|
+
: options.sfc.script.content.length, '#3632/script.vue');
|
|
109
|
+
}
|
|
110
|
+
yield `const `;
|
|
111
|
+
yield* (0, wrapWith_1.wrapWith)(0, block.content.length, block.name, codeFeatures_1.codeFeatures.verification, `__VLS_export`);
|
|
112
|
+
yield ` = `;
|
|
113
|
+
}
|
|
114
|
+
function* generateExportDefault(options) {
|
|
115
|
+
if (options.sfc.script?.src) {
|
|
116
|
+
yield* (0, src_1.generateSrc)(options.sfc.script.src);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let prefix;
|
|
120
|
+
let suffix;
|
|
121
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault) {
|
|
122
|
+
const { exportDefault } = options.scriptRanges;
|
|
123
|
+
prefix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.start, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
|
|
124
|
+
suffix = (0, utils_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
prefix = `export default `;
|
|
128
|
+
suffix = utils_1.endOfLine;
|
|
129
|
+
}
|
|
130
|
+
yield prefix;
|
|
131
|
+
yield `{} as typeof __VLS_export`;
|
|
132
|
+
yield suffix;
|
|
126
133
|
}
|
|
127
134
|
//# sourceMappingURL=index.js.map
|