@vue/language-core 2.2.2 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codegen/globalTypes.js +21 -34
- package/lib/codegen/script/component.js +11 -9
- package/lib/codegen/script/componentSelf.js +4 -11
- package/lib/codegen/script/context.d.ts +0 -1
- package/lib/codegen/script/context.js +0 -1
- package/lib/codegen/script/index.d.ts +1 -4
- package/lib/codegen/script/index.js +8 -12
- package/lib/codegen/script/scriptSetup.js +90 -70
- package/lib/codegen/script/src.d.ts +2 -2
- package/lib/codegen/script/src.js +36 -37
- package/lib/codegen/script/styleModulesType.d.ts +1 -1
- package/lib/codegen/script/styleModulesType.js +2 -2
- package/lib/codegen/script/template.d.ts +1 -2
- package/lib/codegen/script/template.js +5 -53
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +18 -0
- package/lib/codegen/style/modules.d.ts +3 -0
- package/lib/codegen/style/modules.js +34 -0
- package/lib/codegen/style/scopedClasses.d.ts +4 -0
- package/lib/codegen/style/scopedClasses.js +32 -0
- package/lib/codegen/template/context.d.ts +106 -5
- package/lib/codegen/template/context.js +131 -6
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +74 -97
- package/lib/codegen/template/elementChildren.d.ts +1 -1
- package/lib/codegen/template/elementChildren.js +1 -13
- package/lib/codegen/template/elementDirectives.js +8 -6
- package/lib/codegen/template/elementEvents.d.ts +2 -1
- package/lib/codegen/template/elementEvents.js +52 -28
- package/lib/codegen/template/elementProps.d.ts +1 -1
- package/lib/codegen/template/elementProps.js +23 -20
- package/lib/codegen/template/index.js +29 -14
- package/lib/codegen/template/interpolation.js +5 -5
- package/lib/codegen/template/objectProperty.js +5 -4
- package/lib/codegen/template/propertyAccess.js +1 -1
- package/lib/codegen/template/slotOutlet.js +13 -11
- package/lib/codegen/template/styleScopedClasses.js +8 -58
- package/lib/codegen/template/templateChild.js +60 -28
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.js +4 -8
- package/lib/codegen/template/vSlot.d.ts +1 -0
- package/lib/codegen/template/vSlot.js +14 -1
- package/lib/codegen/utils/camelized.d.ts +1 -1
- package/lib/codegen/utils/camelized.js +6 -6
- package/lib/codegen/utils/escaped.d.ts +2 -0
- package/lib/codegen/utils/escaped.js +23 -0
- package/lib/codegen/utils/index.d.ts +3 -3
- package/lib/codegen/utils/index.js +19 -15
- package/lib/codegen/utils/objectProperty.d.ts +3 -0
- package/lib/codegen/utils/objectProperty.js +41 -0
- package/lib/codegen/utils/stringLiteralKey.js +2 -1
- package/lib/codegen/utils/unicode.js +2 -2
- package/lib/codegen/utils/wrapWith.d.ts +3 -0
- package/lib/codegen/utils/wrapWith.js +24 -0
- package/lib/parsers/scriptSetupRanges.d.ts +2 -0
- package/lib/parsers/scriptSetupRanges.js +84 -106
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-template-inline-ts.js +3 -3
- package/lib/plugins/vue-tsx.d.ts +11 -8
- package/lib/plugins/vue-tsx.js +19 -28
- package/lib/types.d.ts +24 -14
- package/lib/utils/parseSfc.js +40 -16
- package/lib/utils/ts.js +17 -0
- package/lib/virtualFile/computedEmbeddedCodes.js +18 -11
- package/lib/virtualFile/computedSfc.js +21 -28
- package/lib/virtualFile/vueFile.d.ts +7 -10
- package/lib/virtualFile/vueFile.js +10 -4
- package/package.json +2 -2
- package/lib/codeFeatures.d.ts +0 -1
- package/lib/codeFeatures.js +0 -3
- package/lib/codegen/common.d.ts +0 -12
- package/lib/codegen/common.js +0 -79
- package/lib/codegen/script/binding.d.ts +0 -4
- package/lib/codegen/script/binding.js +0 -41
- package/lib/codegen/template/camelized.d.ts +0 -2
- package/lib/codegen/template/camelized.js +0 -31
- package/lib/codegen/utils/src.d.ts +0 -2
- package/lib/codegen/utils/src.js +0 -19
- package/lib/plugins/vue-style-class-names.d.ts +0 -5
- package/lib/plugins/vue-style-class-names.js +0 -32
- package/lib/plugins/vue-style-reference-link.d.ts +0 -1
- package/lib/plugins/vue-style-reference-link.js +0 -3
- package/lib/plugins/vue-style-reference-links.d.ts +0 -3
- package/lib/plugins/vue-style-reference-links.js +0 -26
- package/lib/plugins/vue-vine.d.ts +0 -3
- package/lib/plugins/vue-vine.js +0 -35
- package/lib/utils/findDestructuredProps.d.ts +0 -1
- package/lib/utils/findDestructuredProps.js +0 -3
- package/lib/utils/parseCssImports.d.ts +0 -4
- package/lib/utils/parseCssImports.js +0 -19
|
@@ -10,12 +10,7 @@ function getGlobalTypesFileName({ lib, target, checkUnknownProps, checkUnknownEv
|
|
|
10
10
|
checkUnknownProps,
|
|
11
11
|
checkUnknownEvents,
|
|
12
12
|
checkUnknownComponents,
|
|
13
|
-
].map(v =>
|
|
14
|
-
if (typeof v === 'boolean') {
|
|
15
|
-
return v ? 1 : 0;
|
|
16
|
-
}
|
|
17
|
-
return v;
|
|
18
|
-
}).join('_') + '.d.ts';
|
|
13
|
+
].map(v => (typeof v === 'boolean' ? Number(v) : v)).join('_') + '.d.ts';
|
|
19
14
|
}
|
|
20
15
|
function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvents, checkUnknownComponents, }) {
|
|
21
16
|
const fnPropsType = `(K extends { $props: infer Props } ? Props : any)${checkUnknownProps ? '' : ' & Record<string, unknown>'}`;
|
|
@@ -34,11 +29,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
34
29
|
const __VLS_unref: typeof import('${lib}').unref;
|
|
35
30
|
const __VLS_placeholder: any;
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
...{} as SVGElementTagNameMap,
|
|
39
|
-
...{} as HTMLElementTagNameMap,
|
|
40
|
-
};
|
|
41
|
-
|
|
32
|
+
type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
|
|
42
33
|
type __VLS_IntrinsicElements = ${(target >= 3.3
|
|
43
34
|
? `import('${lib}/jsx-runtime').JSX.IntrinsicElements;`
|
|
44
35
|
: `globalThis.JSX.IntrinsicElements;`)}
|
|
@@ -51,7 +42,7 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
51
42
|
type __VLS_GlobalDirectives = import('${lib}').GlobalDirectives;
|
|
52
43
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
53
44
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
54
|
-
type
|
|
45
|
+
type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
|
|
55
46
|
type __VLS_WithComponent<N0 extends string, LocalComponents, Self, N1 extends string, N2 extends string, N3 extends string> =
|
|
56
47
|
N1 extends keyof LocalComponents ? N1 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N1] } :
|
|
57
48
|
N2 extends keyof LocalComponents ? N2 extends N0 ? Pick<LocalComponents, N0 extends keyof LocalComponents ? N0 : never> : { [K in N0]: LocalComponents[N2] } :
|
|
@@ -114,19 +105,12 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
114
105
|
};
|
|
115
106
|
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
|
|
116
107
|
|
|
117
|
-
function __VLS_getVForSourceType(source:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
function __VLS_getVForSourceType<T extends { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
124
|
-
item: T extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never,
|
|
125
|
-
index: number,
|
|
126
|
-
][];
|
|
127
|
-
// #3845
|
|
128
|
-
function __VLS_getVForSourceType<T extends number | { [Symbol.iterator](): Iterator<any> }>(source: T): [
|
|
129
|
-
item: number | (Exclude<T, number> extends { [Symbol.iterator](): Iterator<infer T1> } ? T1 : never),
|
|
108
|
+
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(source: T): [
|
|
109
|
+
item: T extends number ? number
|
|
110
|
+
: T extends string ? string
|
|
111
|
+
: T extends any[] ? T[number]
|
|
112
|
+
: T extends Iterable<infer T1> ? T1
|
|
113
|
+
: any,
|
|
130
114
|
index: number,
|
|
131
115
|
][];
|
|
132
116
|
function __VLS_getVForSourceType<T>(source: T): [
|
|
@@ -142,22 +126,25 @@ function generateGlobalTypes({ lib, target, checkUnknownProps, checkUnknownEvent
|
|
|
142
126
|
? NonNullable<T['created' | 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted']>
|
|
143
127
|
: T extends (...args: any) => any
|
|
144
128
|
? T
|
|
145
|
-
:
|
|
146
|
-
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
129
|
+
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
|
|
147
130
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
148
131
|
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
|
|
149
132
|
T extends new (...args: any) => any
|
|
150
|
-
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
133
|
+
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
|
|
134
|
+
__ctx?: {
|
|
135
|
+
attrs?: any;
|
|
136
|
+
slots?: K extends { ${(0, shared_1.getSlotsPropertyName)(target)}: infer Slots } ? Slots : any;
|
|
137
|
+
emit?: K extends { $emit: infer Emit } ? Emit : any;
|
|
138
|
+
expose?(exposed: K): void;
|
|
139
|
+
props?: ${fnPropsType};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
155
142
|
: T extends () => any ? (props: {}, ctx?: any) => ReturnType<T>
|
|
156
143
|
: T extends (...args: any) => any ? T
|
|
157
144
|
: (_: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'}, ctx?: any) => { __ctx?: { attrs?: any, expose?: any, slots?: any, emit?: any, props?: {}${checkUnknownProps ? '' : ' & Record<string, unknown>'} } };
|
|
158
|
-
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (_: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
159
145
|
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(t: T): 2 extends Parameters<T>['length'] ? [any] : [];
|
|
160
|
-
function
|
|
146
|
+
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T${checkUnknownComponents ? '' : ' & Record<string, unknown>'}) => void;
|
|
147
|
+
function __VLS_asFunctionalSlot<S>(slot: S): (props: NonNullable<S> extends (props: infer P) => any ? P : {}) => void;
|
|
161
148
|
function __VLS_tryAsConstant<const T>(t: T): T;
|
|
162
149
|
}
|
|
163
150
|
`;
|
|
@@ -27,21 +27,23 @@ function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
27
27
|
yield `},${utils_1.newLine}`;
|
|
28
28
|
if (!ctx.bypassDefineComponent) {
|
|
29
29
|
const emitOptionCodes = [...generateEmitsOption(options, scriptSetupRanges)];
|
|
30
|
-
|
|
31
|
-
yield code;
|
|
32
|
-
}
|
|
30
|
+
yield* emitOptionCodes;
|
|
33
31
|
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges, !!emitOptionCodes.length, true);
|
|
34
32
|
}
|
|
35
|
-
if (options.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
if (options.vueCompilerOptions.target >= 3.5 && options.templateCodegen?.templateRefs.size) {
|
|
33
|
+
if (options.vueCompilerOptions.target >= 3.5
|
|
34
|
+
&& options.vueCompilerOptions.inferComponentDollarRefs
|
|
35
|
+
&& options.templateCodegen?.templateRefs.size) {
|
|
40
36
|
yield `__typeRefs: {} as __VLS_TemplateRefs,${utils_1.newLine}`;
|
|
41
37
|
}
|
|
42
|
-
if (options.vueCompilerOptions.target >= 3.5
|
|
38
|
+
if (options.vueCompilerOptions.target >= 3.5
|
|
39
|
+
&& options.vueCompilerOptions.inferComponentDollarEl
|
|
40
|
+
&& options.templateCodegen?.singleRootElTypes.length) {
|
|
43
41
|
yield `__typeEl: {} as __VLS_RootEl,${utils_1.newLine}`;
|
|
44
42
|
}
|
|
43
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
44
|
+
const { args } = options.scriptRanges.exportDefault;
|
|
45
|
+
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, codeFeatures_1.codeFeatures.all);
|
|
46
|
+
}
|
|
45
47
|
yield `})`;
|
|
46
48
|
}
|
|
47
49
|
function* generateComponentSetupReturns(scriptSetupRanges) {
|
|
@@ -27,25 +27,18 @@ function* generateComponentSelf(options, ctx, templateCodegenCtx) {
|
|
|
27
27
|
if (!templateUsageVars.has(varName) && !templateCodegenCtx.accessExternalVariables.has(varName)) {
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const token = Symbol(varName.length);
|
|
31
|
+
yield ['', undefined, 0, { __linkedToken: token }];
|
|
31
32
|
yield `${varName}: ${varName} as typeof `;
|
|
32
|
-
|
|
33
|
+
yield ['', undefined, 0, { __linkedToken: token }];
|
|
33
34
|
yield `${varName},${utils_1.newLine}`;
|
|
34
|
-
options.linkedCodeMappings.push({
|
|
35
|
-
sourceOffsets: [scriptOffset],
|
|
36
|
-
generatedOffsets: [templateOffset],
|
|
37
|
-
lengths: [varName.length],
|
|
38
|
-
data: undefined,
|
|
39
|
-
});
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
37
|
yield `}${utils_1.endOfLine}`; // return {
|
|
43
38
|
yield `},${utils_1.newLine}`; // setup() {
|
|
44
39
|
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
|
|
45
40
|
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.scriptSetupRanges)];
|
|
46
|
-
|
|
47
|
-
yield code;
|
|
48
|
-
}
|
|
41
|
+
yield* emitOptionCodes;
|
|
49
42
|
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
|
50
43
|
}
|
|
51
44
|
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
@@ -10,7 +10,6 @@ export type ScriptCodegenContext = ReturnType<typeof createScriptCodegenContext>
|
|
|
10
10
|
export declare function createScriptCodegenContext(options: ScriptCodegenOptions): {
|
|
11
11
|
generatedTemplate: boolean;
|
|
12
12
|
generatedPropsType: boolean;
|
|
13
|
-
scriptSetupGeneratedOffset: number | undefined;
|
|
14
13
|
bypassDefineComponent: boolean;
|
|
15
14
|
bindingNames: Set<string>;
|
|
16
15
|
localTypes: {
|
|
@@ -8,7 +8,6 @@ function createScriptCodegenContext(options) {
|
|
|
8
8
|
return {
|
|
9
9
|
generatedTemplate: false,
|
|
10
10
|
generatedPropsType: false,
|
|
11
|
-
scriptSetupGeneratedOffset: undefined,
|
|
12
11
|
bypassDefineComponent: options.lang === 'js' || options.lang === 'jsx',
|
|
13
12
|
bindingNames: new Set([
|
|
14
13
|
...options.scriptRanges?.bindings.map(({ range }) => options.sfc.script.content.slice(range.start, range.end)) ?? [],
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Mapping } from '@volar/language-core';
|
|
2
1
|
import type * as ts from 'typescript';
|
|
3
2
|
import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
4
3
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
@@ -20,9 +19,7 @@ export interface ScriptCodegenOptions {
|
|
|
20
19
|
} | undefined;
|
|
21
20
|
destructuredPropNames: Set<string>;
|
|
22
21
|
templateRefNames: Set<string>;
|
|
23
|
-
getGeneratedLength: () => number;
|
|
24
|
-
linkedCodeMappings: Mapping[];
|
|
25
22
|
appendGlobalTypes: boolean;
|
|
26
23
|
}
|
|
27
24
|
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
|
28
|
-
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string): Generator<Code>;
|
|
25
|
+
export declare function generateScriptSectionPartiallyEnding(source: string, end: number, mark: string, delimiter?: string): Generator<Code>;
|
|
@@ -10,7 +10,6 @@ const componentSelf_1 = require("./componentSelf");
|
|
|
10
10
|
const context_1 = require("./context");
|
|
11
11
|
const scriptSetup_1 = require("./scriptSetup");
|
|
12
12
|
const src_1 = require("./src");
|
|
13
|
-
const styleModulesType_1 = require("./styleModulesType");
|
|
14
13
|
const template_1 = require("./template");
|
|
15
14
|
function* generateScript(options) {
|
|
16
15
|
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
|
@@ -31,14 +30,16 @@ function* generateScript(options) {
|
|
|
31
30
|
yield `/* placeholder */`;
|
|
32
31
|
}
|
|
33
32
|
if (options.sfc.script?.src) {
|
|
34
|
-
yield* (0, src_1.generateSrc)(options.sfc.script
|
|
33
|
+
yield* (0, src_1.generateSrc)(options.sfc.script.src);
|
|
34
|
+
}
|
|
35
|
+
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
36
|
+
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
35
37
|
}
|
|
36
38
|
if (options.sfc.script && options.scriptRanges) {
|
|
37
39
|
const { exportDefault, classBlockEnd } = options.scriptRanges;
|
|
38
40
|
const isExportRawObject = exportDefault
|
|
39
41
|
&& options.sfc.script.content[exportDefault.expression.start] === '{';
|
|
40
42
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
41
|
-
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
42
43
|
if (exportDefault) {
|
|
43
44
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, codeFeatures_1.codeFeatures.all);
|
|
44
45
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
@@ -91,24 +92,19 @@ function* generateScript(options) {
|
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
94
|
yield (0, utils_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, codeFeatures_1.codeFeatures.all);
|
|
95
|
+
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
else if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
97
|
-
yield* (0, scriptSetup_1.generateScriptSetupImports)(options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
98
99
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
99
100
|
}
|
|
100
|
-
if (options.sfc.script) {
|
|
101
|
-
yield* generateScriptSectionPartiallyEnding(options.sfc.script.name, options.sfc.script.content.length, '#3632/script.vue');
|
|
102
|
-
}
|
|
103
101
|
if (options.sfc.scriptSetup) {
|
|
104
|
-
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue');
|
|
102
|
+
yield* generateScriptSectionPartiallyEnding(options.sfc.scriptSetup.name, options.sfc.scriptSetup.content.length, '#4569/main.vue', ';');
|
|
105
103
|
}
|
|
106
104
|
if (!ctx.generatedTemplate) {
|
|
107
105
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
108
106
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
109
107
|
}
|
|
110
|
-
// #4788
|
|
111
|
-
yield* (0, styleModulesType_1.generateStyleModulesType)(options, ctx);
|
|
112
108
|
if (options.edited) {
|
|
113
109
|
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${utils_1.endOfLine}`;
|
|
114
110
|
}
|
|
@@ -121,8 +117,8 @@ function* generateScript(options) {
|
|
|
121
117
|
}
|
|
122
118
|
return ctx;
|
|
123
119
|
}
|
|
124
|
-
function* generateScriptSectionPartiallyEnding(source, end, mark) {
|
|
125
|
-
yield
|
|
120
|
+
function* generateScriptSectionPartiallyEnding(source, end, mark, delimiter = 'debugger') {
|
|
121
|
+
yield delimiter;
|
|
126
122
|
yield ['', source, end, codeFeatures_1.codeFeatures.verification];
|
|
127
123
|
yield `/* PartiallyEnd: ${mark} */${utils_1.newLine}`;
|
|
128
124
|
}
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
4
4
|
exports.generateScriptSetup = generateScriptSetup;
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
5
6
|
const codeFeatures_1 = require("../codeFeatures");
|
|
6
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const camelized_1 = require("../utils/camelized");
|
|
9
|
+
const wrapWith_1 = require("../utils/wrapWith");
|
|
7
10
|
const component_1 = require("./component");
|
|
8
11
|
const componentSelf_1 = require("./componentSelf");
|
|
9
12
|
const index_1 = require("./index");
|
|
@@ -19,28 +22,25 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
|
19
22
|
function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
20
23
|
if (scriptSetup.generic) {
|
|
21
24
|
if (!options.scriptRanges?.exportDefault) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
yield [
|
|
25
|
-
'',
|
|
26
|
-
'scriptSetup',
|
|
27
|
-
options.sfc.scriptSetup.content.length,
|
|
28
|
-
codeFeatures_1.codeFeatures.verification,
|
|
29
|
-
];
|
|
30
|
-
}
|
|
25
|
+
// #4569
|
|
26
|
+
yield ['', 'scriptSetup', 0, codeFeatures_1.codeFeatures.verification];
|
|
31
27
|
yield `export default `;
|
|
32
28
|
}
|
|
33
|
-
yield `(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
yield `(`;
|
|
30
|
+
if (typeof scriptSetup.generic === 'object') {
|
|
31
|
+
yield `<`;
|
|
32
|
+
yield [
|
|
33
|
+
scriptSetup.generic.text,
|
|
34
|
+
'main',
|
|
35
|
+
scriptSetup.generic.offset,
|
|
36
|
+
codeFeatures_1.codeFeatures.all,
|
|
37
|
+
];
|
|
38
|
+
if (!scriptSetup.generic.text.endsWith(`,`)) {
|
|
39
|
+
yield `,`;
|
|
40
|
+
}
|
|
41
|
+
yield `>`;
|
|
42
42
|
}
|
|
43
|
-
yield
|
|
43
|
+
yield `(${utils_1.newLine}`
|
|
44
44
|
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${utils_1.newLine}`
|
|
45
45
|
+ ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
|
|
46
46
|
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${utils_1.newLine}`
|
|
@@ -77,8 +77,16 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, syntax) {
|
|
80
|
-
ctx.scriptSetupGeneratedOffset = options.getGeneratedLength() - scriptSetupRanges.importSectionEndOffset;
|
|
81
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
|
+
}
|
|
82
90
|
if (scriptSetupRanges.defineProps) {
|
|
83
91
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
84
92
|
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
|
|
@@ -97,22 +105,30 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
97
105
|
setupCodeModifies.push([
|
|
98
106
|
[
|
|
99
107
|
`let __VLS_exposed!: `,
|
|
100
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.
|
|
108
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
|
|
101
109
|
`${utils_1.endOfLine}`,
|
|
102
110
|
],
|
|
103
111
|
callExp.start,
|
|
104
112
|
callExp.start,
|
|
113
|
+
], [
|
|
114
|
+
[`typeof __VLS_exposed`],
|
|
115
|
+
typeArg.start,
|
|
116
|
+
typeArg.end,
|
|
105
117
|
]);
|
|
106
118
|
}
|
|
107
119
|
else if (arg) {
|
|
108
120
|
setupCodeModifies.push([
|
|
109
121
|
[
|
|
110
122
|
`const __VLS_exposed = `,
|
|
111
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.
|
|
123
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
112
124
|
`${utils_1.endOfLine}`,
|
|
113
125
|
],
|
|
114
126
|
callExp.start,
|
|
115
127
|
callExp.start,
|
|
128
|
+
], [
|
|
129
|
+
[`__VLS_exposed`],
|
|
130
|
+
arg.start,
|
|
131
|
+
arg.end,
|
|
116
132
|
]);
|
|
117
133
|
}
|
|
118
134
|
else {
|
|
@@ -123,16 +139,18 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
123
139
|
]);
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
[
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
143
|
+
for (const { callExp } of scriptSetupRanges.useAttrs) {
|
|
144
|
+
setupCodeModifies.push([
|
|
145
|
+
[`(`],
|
|
146
|
+
callExp.start,
|
|
147
|
+
callExp.start
|
|
148
|
+
], [
|
|
149
|
+
[` as typeof __VLS_dollars.$attrs)`],
|
|
150
|
+
callExp.end,
|
|
151
|
+
callExp.end
|
|
152
|
+
]);
|
|
153
|
+
}
|
|
136
154
|
}
|
|
137
155
|
for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
|
|
138
156
|
setupCodeModifies.push([
|
|
@@ -146,9 +164,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
146
164
|
`])`
|
|
147
165
|
] : [
|
|
148
166
|
` as __VLS_StyleModules[`,
|
|
149
|
-
|
|
150
|
-
`'$style'`,
|
|
151
|
-
['', scriptSetup.name, exp.end, utils_1.combineLastMapping],
|
|
167
|
+
...(0, wrapWith_1.wrapWith)(exp.start, exp.end, scriptSetup.name, codeFeatures_1.codeFeatures.verification, `'$style'`),
|
|
152
168
|
`])`
|
|
153
169
|
],
|
|
154
170
|
callExp.end,
|
|
@@ -156,22 +172,24 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
156
172
|
]);
|
|
157
173
|
if (arg) {
|
|
158
174
|
setupCodeModifies.push([
|
|
159
|
-
[`
|
|
175
|
+
[`__VLS_placeholder`],
|
|
160
176
|
arg.start,
|
|
161
177
|
arg.end
|
|
162
178
|
]);
|
|
163
179
|
}
|
|
164
180
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
[
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
181
|
+
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
182
|
+
for (const { callExp } of scriptSetupRanges.useSlots) {
|
|
183
|
+
setupCodeModifies.push([
|
|
184
|
+
[`(`],
|
|
185
|
+
callExp.start,
|
|
186
|
+
callExp.start
|
|
187
|
+
], [
|
|
188
|
+
[` as typeof __VLS_dollars.$slots)`],
|
|
189
|
+
callExp.end,
|
|
190
|
+
callExp.end
|
|
191
|
+
]);
|
|
192
|
+
}
|
|
175
193
|
}
|
|
176
194
|
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
|
|
177
195
|
for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
|
|
@@ -210,7 +228,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
210
228
|
}
|
|
211
229
|
if (arg) {
|
|
212
230
|
setupCodeModifies.push([
|
|
213
|
-
[`
|
|
231
|
+
[`__VLS_placeholder`],
|
|
214
232
|
arg.start,
|
|
215
233
|
arg.end
|
|
216
234
|
]);
|
|
@@ -220,9 +238,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
220
238
|
let nextStart = Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset);
|
|
221
239
|
for (const [codes, start, end] of setupCodeModifies) {
|
|
222
240
|
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
|
|
223
|
-
|
|
224
|
-
yield code;
|
|
225
|
-
}
|
|
241
|
+
yield* codes;
|
|
226
242
|
nextStart = end;
|
|
227
243
|
}
|
|
228
244
|
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
|
|
@@ -240,7 +256,10 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
240
256
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
241
257
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
242
258
|
if (syntax) {
|
|
243
|
-
if (!options.vueCompilerOptions.skipTemplateCodegen
|
|
259
|
+
if (!options.vueCompilerOptions.skipTemplateCodegen
|
|
260
|
+
&& (scriptSetupRanges.defineSlots
|
|
261
|
+
|| options.templateCodegen?.slots.length
|
|
262
|
+
|| options.templateCodegen?.dynamicSlots.length)) {
|
|
244
263
|
yield `const __VLS_component = `;
|
|
245
264
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
246
265
|
yield utils_1.endOfLine;
|
|
@@ -357,7 +376,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
357
376
|
continue;
|
|
358
377
|
}
|
|
359
378
|
yield `: `;
|
|
360
|
-
yield
|
|
379
|
+
yield getRangeText(scriptSetup, defineProp.defaultValue);
|
|
361
380
|
yield `,${utils_1.newLine}`;
|
|
362
381
|
}
|
|
363
382
|
yield `}${utils_1.endOfLine}`;
|
|
@@ -370,6 +389,13 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
370
389
|
ctx.generatedPropsType = true;
|
|
371
390
|
yield `${ctx.localTypes.PropsChildren}<__VLS_Slots>`;
|
|
372
391
|
}
|
|
392
|
+
if (scriptSetupRanges.defineProps?.typeArg) {
|
|
393
|
+
if (ctx.generatedPropsType) {
|
|
394
|
+
yield ` & `;
|
|
395
|
+
}
|
|
396
|
+
ctx.generatedPropsType = true;
|
|
397
|
+
yield `__VLS_Props`;
|
|
398
|
+
}
|
|
373
399
|
if (scriptSetupRanges.defineProp.length) {
|
|
374
400
|
if (ctx.generatedPropsType) {
|
|
375
401
|
yield ` & `;
|
|
@@ -378,11 +404,15 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
378
404
|
yield `{${utils_1.newLine}`;
|
|
379
405
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
380
406
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
407
|
+
if (defineProp.comments) {
|
|
408
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.comments.start, defineProp.comments.end, codeFeatures_1.codeFeatures.all);
|
|
409
|
+
yield utils_1.newLine;
|
|
410
|
+
}
|
|
381
411
|
if (defineProp.isModel && !defineProp.name) {
|
|
382
412
|
yield propName;
|
|
383
413
|
}
|
|
384
414
|
else if (defineProp.name) {
|
|
385
|
-
yield (0,
|
|
415
|
+
yield* (0, camelized_1.generateCamelized)(getRangeText(scriptSetup, defineProp.name), scriptSetup.name, defineProp.name.start, codeFeatures_1.codeFeatures.navigation);
|
|
386
416
|
}
|
|
387
417
|
else if (defineProp.localName) {
|
|
388
418
|
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
|
|
@@ -397,19 +427,12 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
397
427
|
yield `,${utils_1.newLine}`;
|
|
398
428
|
if (defineProp.modifierType) {
|
|
399
429
|
const modifierName = `${defineProp.name ? propName : 'model'}Modifiers`;
|
|
400
|
-
const modifierType =
|
|
430
|
+
const modifierType = getRangeText(scriptSetup, defineProp.modifierType);
|
|
401
431
|
yield `'${modifierName}'?: Partial<Record<${modifierType}, true>>,${utils_1.newLine}`;
|
|
402
432
|
}
|
|
403
433
|
}
|
|
404
434
|
yield `}`;
|
|
405
435
|
}
|
|
406
|
-
if (scriptSetupRanges.defineProps?.typeArg) {
|
|
407
|
-
if (ctx.generatedPropsType) {
|
|
408
|
-
yield ` & `;
|
|
409
|
-
}
|
|
410
|
-
ctx.generatedPropsType = true;
|
|
411
|
-
yield `__VLS_Props`;
|
|
412
|
-
}
|
|
413
436
|
if (!ctx.generatedPropsType) {
|
|
414
437
|
yield `{}`;
|
|
415
438
|
}
|
|
@@ -423,7 +446,7 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
|
423
446
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
424
447
|
yield `'update:${propName}': [value: `;
|
|
425
448
|
yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
|
|
426
|
-
if (!defineModel.required) {
|
|
449
|
+
if (!defineModel.required && !defineModel.defaultValue) {
|
|
427
450
|
yield ` | undefined`;
|
|
428
451
|
}
|
|
429
452
|
yield `]${utils_1.endOfLine}`;
|
|
@@ -435,7 +458,7 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
|
435
458
|
function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
|
436
459
|
if (defineProp.type) {
|
|
437
460
|
// Infer from defineProp<T>
|
|
438
|
-
yield
|
|
461
|
+
yield getRangeText(scriptSetup, defineProp.type);
|
|
439
462
|
}
|
|
440
463
|
else if (defineProp.runtimeType && localName) {
|
|
441
464
|
// Infer from actual prop declaration code
|
|
@@ -451,19 +474,16 @@ function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
|
|
451
474
|
}
|
|
452
475
|
function getPropAndLocalName(scriptSetup, defineProp) {
|
|
453
476
|
const localName = defineProp.localName
|
|
454
|
-
?
|
|
477
|
+
? getRangeText(scriptSetup, defineProp.localName)
|
|
455
478
|
: undefined;
|
|
456
|
-
|
|
457
|
-
?
|
|
479
|
+
const propName = defineProp.name
|
|
480
|
+
? (0, shared_1.camelize)(getRangeText(scriptSetup, defineProp.name).slice(1, -1))
|
|
458
481
|
: defineProp.isModel
|
|
459
482
|
? 'modelValue'
|
|
460
483
|
: localName;
|
|
461
|
-
if (defineProp.name) {
|
|
462
|
-
propName = propName.replace(/['"]+/g, '');
|
|
463
|
-
}
|
|
464
484
|
return [propName, localName];
|
|
465
485
|
}
|
|
466
|
-
function
|
|
486
|
+
function getRangeText(scriptSetup, range) {
|
|
467
487
|
return scriptSetup.content.slice(range.start, range.end);
|
|
468
488
|
}
|
|
469
489
|
//# sourceMappingURL=scriptSetup.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Code,
|
|
2
|
-
export declare function generateSrc(
|
|
1
|
+
import type { Code, SfcBlockAttr } from '../../types';
|
|
2
|
+
export declare function generateSrc(src: SfcBlockAttr): Generator<Code>;
|