@vue/language-core 2.0.29 → 2.1.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/index.d.ts +4 -3
- package/index.js +4 -3
- package/lib/codegen/common.d.ts +2 -1
- package/lib/codegen/common.js +16 -5
- package/lib/codegen/globalTypes.d.ts +1 -0
- package/lib/codegen/globalTypes.js +123 -0
- package/lib/codegen/localTypes.d.ts +14 -0
- package/lib/codegen/localTypes.js +120 -0
- package/lib/codegen/script/component.d.ts +1 -4
- package/lib/codegen/script/component.js +112 -63
- package/lib/codegen/script/context.d.ts +14 -10
- package/lib/codegen/script/context.js +5 -107
- package/lib/codegen/script/index.d.ts +3 -2
- package/lib/codegen/script/index.js +37 -53
- package/lib/codegen/script/internalComponent.d.ts +1 -1
- package/lib/codegen/script/internalComponent.js +13 -5
- package/lib/codegen/script/scriptSetup.js +144 -62
- package/lib/codegen/script/template.d.ts +3 -0
- package/lib/codegen/script/template.js +80 -79
- package/lib/codegen/template/context.d.ts +6 -1
- package/lib/codegen/template/context.js +9 -2
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +214 -92
- package/lib/codegen/template/elementChildren.js +1 -0
- package/lib/codegen/template/elementDirectives.js +8 -4
- package/lib/codegen/template/elementEvents.js +13 -14
- package/lib/codegen/template/elementProps.js +43 -22
- package/lib/codegen/template/index.d.ts +3 -0
- package/lib/codegen/template/index.js +29 -41
- package/lib/codegen/template/interpolation.d.ts +1 -1
- package/lib/codegen/template/interpolation.js +24 -15
- package/lib/codegen/template/objectProperty.d.ts +1 -1
- package/lib/codegen/template/objectProperty.js +7 -2
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +72 -0
- package/lib/codegen/template/templateChild.js +5 -1
- package/lib/codegen/types.d.ts +9 -0
- package/lib/codegen/types.js +3 -0
- package/lib/languagePlugin.d.ts +2 -4
- package/lib/languagePlugin.js +4 -57
- package/lib/parsers/scriptRanges.d.ts +1 -0
- package/lib/parsers/scriptRanges.js +5 -0
- package/lib/parsers/scriptSetupRanges.d.ts +17 -3
- package/lib/parsers/scriptSetupRanges.js +127 -44
- package/lib/plugins/file-md.js +9 -6
- package/lib/plugins/vue-root-tags.js +51 -0
- package/lib/plugins/vue-tsx.d.ts +40 -3
- package/lib/plugins/vue-tsx.js +17 -4
- package/lib/plugins.js +2 -0
- package/lib/types.d.ts +14 -10
- package/lib/utils/findDestructuredProps.js +3 -0
- package/lib/utils/parseCssClassNames.js +4 -6
- package/lib/utils/parseCssVars.js +5 -7
- package/lib/utils/parseSfc.js +4 -1
- package/lib/utils/ts.js +8 -2
- package/lib/virtualFile/{computedFiles.d.ts → computedEmbeddedCodes.d.ts} +1 -1
- package/lib/virtualFile/{computedFiles.js → computedEmbeddedCodes.js} +3 -3
- package/lib/virtualFile/computedSfc.d.ts +1 -1
- package/lib/virtualFile/computedSfc.js +14 -3
- package/lib/virtualFile/vueFile.d.ts +13 -3
- package/lib/virtualFile/vueFile.js +17 -9
- package/package.json +4 -4
- package/lib/codegen/script/globalTypes.d.ts +0 -2
- package/lib/codegen/script/globalTypes.js +0 -134
- package/lib/codegen/template/objectKey.js +0 -34
- package/lib/languageModule.d.ts +0 -5
- package/lib/languageModule.js +0 -159
- package/lib/plugins/file-dot-setup.js +0 -34
- package/lib/virtualFile/computedMappings.d.ts +0 -4
- package/lib/virtualFile/computedMappings.js +0 -65
- /package/lib/plugins/{file-dot-setup.d.ts → vue-root-tags.d.ts} +0 -0
- /package/lib/{codegen/template/objectKey.d.ts → utils/findDestructuredProps.d.ts} +0 -0
|
@@ -1,99 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createScriptCodegenContext = createScriptCodegenContext;
|
|
4
|
-
const
|
|
5
|
-
const common_1 = require("../common");
|
|
4
|
+
const localTypes_1 = require("../localTypes");
|
|
6
5
|
function createScriptCodegenContext(options) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
get name() {
|
|
10
|
-
this.used = true;
|
|
11
|
-
return `__VLS_OmitKeepDiscriminatedUnion`;
|
|
12
|
-
},
|
|
13
|
-
get code() {
|
|
14
|
-
return `type __VLS_OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any
|
|
15
|
-
? Pick<T, Exclude<keyof T, K>>
|
|
16
|
-
: never;`;
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
WithDefaults: {
|
|
20
|
-
get name() {
|
|
21
|
-
this.used = true;
|
|
22
|
-
return `__VLS_WithDefaults`;
|
|
23
|
-
},
|
|
24
|
-
get code() {
|
|
25
|
-
return `type __VLS_WithDefaults<P, D> = {
|
|
26
|
-
[K in keyof Pick<P, keyof P>]: K extends keyof D
|
|
27
|
-
? ${helperTypes.Prettify.name}<P[K] & { default: D[K]}>
|
|
28
|
-
: P[K]
|
|
29
|
-
};`;
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
Prettify: {
|
|
33
|
-
get name() {
|
|
34
|
-
this.used = true;
|
|
35
|
-
return `__VLS_Prettify`;
|
|
36
|
-
},
|
|
37
|
-
get code() {
|
|
38
|
-
return `type __VLS_Prettify<T> = { [K in keyof T]: T[K]; } & {};`;
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
WithTemplateSlots: {
|
|
42
|
-
get name() {
|
|
43
|
-
this.used = true;
|
|
44
|
-
return `__VLS_WithTemplateSlots`;
|
|
45
|
-
},
|
|
46
|
-
get code() {
|
|
47
|
-
return `type __VLS_WithTemplateSlots<T, S> = T & {
|
|
48
|
-
new(): {
|
|
49
|
-
${(0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)}: S;
|
|
50
|
-
${options.vueCompilerOptions.jsxSlots ? `$props: ${helperTypes.PropsChildren.name}<S>;` : ''}
|
|
51
|
-
}
|
|
52
|
-
};`;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
PropsChildren: {
|
|
56
|
-
get name() {
|
|
57
|
-
this.used = true;
|
|
58
|
-
return `__VLS_PropsChildren`;
|
|
59
|
-
},
|
|
60
|
-
get code() {
|
|
61
|
-
return `type __VLS_PropsChildren<S> = {
|
|
62
|
-
[K in keyof (
|
|
63
|
-
boolean extends (
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
JSX.ElementChildrenAttribute extends never
|
|
66
|
-
? true
|
|
67
|
-
: false
|
|
68
|
-
)
|
|
69
|
-
? never
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
: JSX.ElementChildrenAttribute
|
|
72
|
-
)]?: S;
|
|
73
|
-
};`;
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
TypePropsToOption: {
|
|
77
|
-
get name() {
|
|
78
|
-
this.used = true;
|
|
79
|
-
return `__VLS_TypePropsToOption`;
|
|
80
|
-
},
|
|
81
|
-
get code() {
|
|
82
|
-
return options.compilerOptions.exactOptionalPropertyTypes ?
|
|
83
|
-
`type __VLS_TypePropsToOption<T> = {
|
|
84
|
-
[K in keyof T]-?: {} extends Pick<T, K>
|
|
85
|
-
? { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]> }
|
|
86
|
-
: { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
87
|
-
};` :
|
|
88
|
-
`type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
89
|
-
type __VLS_TypePropsToOption<T> = {
|
|
90
|
-
[K in keyof T]-?: {} extends Pick<T, K>
|
|
91
|
-
? { type: import('${options.vueCompilerOptions.lib}').PropType<__VLS_NonUndefinedable<T[K]>> }
|
|
92
|
-
: { type: import('${options.vueCompilerOptions.lib}').PropType<T[K]>, required: true }
|
|
93
|
-
};`;
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
6
|
+
const localTypes = (0, localTypes_1.getLocalTypesGenerator)(options.compilerOptions, options.vueCompilerOptions);
|
|
7
|
+
const inlayHints = [];
|
|
97
8
|
return {
|
|
98
9
|
generatedTemplate: false,
|
|
99
10
|
generatedPropsType: false,
|
|
@@ -103,21 +14,8 @@ function createScriptCodegenContext(options) {
|
|
|
103
14
|
...options.scriptRanges?.bindings.map(range => options.sfc.script.content.substring(range.start, range.end)) ?? [],
|
|
104
15
|
...options.scriptSetupRanges?.bindings.map(range => options.sfc.scriptSetup.content.substring(range.start, range.end)) ?? [],
|
|
105
16
|
]),
|
|
106
|
-
|
|
107
|
-
|
|
17
|
+
localTypes,
|
|
18
|
+
inlayHints,
|
|
108
19
|
};
|
|
109
|
-
function* generateHelperTypes() {
|
|
110
|
-
let shouldCheck = true;
|
|
111
|
-
while (shouldCheck) {
|
|
112
|
-
shouldCheck = false;
|
|
113
|
-
for (const helperType of Object.values(helperTypes)) {
|
|
114
|
-
if (helperType.used && !helperType.generated) {
|
|
115
|
-
shouldCheck = true;
|
|
116
|
-
helperType.generated = true;
|
|
117
|
-
yield common_1.newLine + helperType.code + common_1.newLine;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
20
|
}
|
|
123
21
|
//# sourceMappingURL=context.js.map
|
|
@@ -4,6 +4,7 @@ import type { ScriptRanges } from '../../parsers/scriptRanges';
|
|
|
4
4
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
5
5
|
import type { Code, Sfc, VueCodeInformation, VueCompilerOptions } from '../../types';
|
|
6
6
|
import type { TemplateCodegenContext } from '../template/context';
|
|
7
|
+
import { ScriptCodegenContext } from './context';
|
|
7
8
|
export declare const codeFeatures: {
|
|
8
9
|
all: VueCodeInformation;
|
|
9
10
|
none: VueCodeInformation;
|
|
@@ -23,8 +24,8 @@ export interface ScriptCodegenOptions {
|
|
|
23
24
|
templateCodegen: TemplateCodegenContext & {
|
|
24
25
|
codes: Code[];
|
|
25
26
|
} | undefined;
|
|
26
|
-
|
|
27
|
+
edited: boolean;
|
|
27
28
|
getGeneratedLength: () => number;
|
|
28
29
|
linkedCodeMappings: Mapping[];
|
|
29
30
|
}
|
|
30
|
-
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code>;
|
|
31
|
+
export declare function generateScript(options: ScriptCodegenOptions): Generator<Code, ScriptCodegenContext>;
|
|
@@ -4,7 +4,6 @@ exports.codeFeatures = void 0;
|
|
|
4
4
|
exports.generateScript = generateScript;
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const context_1 = require("./context");
|
|
7
|
-
const globalTypes_1 = require("./globalTypes");
|
|
8
7
|
const scriptSetup_1 = require("./scriptSetup");
|
|
9
8
|
const src_1 = require("./src");
|
|
10
9
|
const template_1 = require("./template");
|
|
@@ -32,7 +31,7 @@ exports.codeFeatures = {
|
|
|
32
31
|
};
|
|
33
32
|
function* generateScript(options) {
|
|
34
33
|
const ctx = (0, context_1.createScriptCodegenContext)(options);
|
|
35
|
-
yield
|
|
34
|
+
yield `/// <reference types="${options.vueCompilerOptions.lib}/__globalTypes_${options.vueCompilerOptions.target}_${options.vueCompilerOptions.strictTemplates}" />${common_1.newLine}`;
|
|
36
35
|
if (options.sfc.script?.src) {
|
|
37
36
|
yield* (0, src_1.generateSrc)(options.sfc.script, options.sfc.script.src);
|
|
38
37
|
}
|
|
@@ -54,47 +53,42 @@ function* generateScript(options) {
|
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
else if (exportDefault && isExportRawObject && options.vueCompilerOptions.optionsWrapper.length) {
|
|
56
|
+
ctx.inlayHints.push({
|
|
57
|
+
blockName: options.sfc.script.name,
|
|
58
|
+
offset: exportDefault.expression.start,
|
|
59
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
60
|
+
label: options.vueCompilerOptions.optionsWrapper.length
|
|
61
|
+
? options.vueCompilerOptions.optionsWrapper[0]
|
|
62
|
+
: '[Missing optionsWrapper[0]]',
|
|
63
|
+
tooltip: [
|
|
64
|
+
'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.',
|
|
65
|
+
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
66
|
+
].join('\n\n'),
|
|
67
|
+
}, {
|
|
68
|
+
blockName: options.sfc.script.name,
|
|
69
|
+
offset: exportDefault.expression.end,
|
|
70
|
+
setting: 'vue.inlayHints.optionsWrapper',
|
|
71
|
+
label: options.vueCompilerOptions.optionsWrapper.length >= 2
|
|
72
|
+
? options.vueCompilerOptions.optionsWrapper[1]
|
|
73
|
+
: '[Missing optionsWrapper[1]]',
|
|
74
|
+
});
|
|
57
75
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, exportDefault.expression.start, exports.codeFeatures.all);
|
|
58
76
|
yield options.vueCompilerOptions.optionsWrapper[0];
|
|
59
|
-
yield [
|
|
60
|
-
'',
|
|
61
|
-
'script',
|
|
62
|
-
exportDefault.expression.start,
|
|
63
|
-
{
|
|
64
|
-
__hint: {
|
|
65
|
-
setting: 'vue.inlayHints.optionsWrapper',
|
|
66
|
-
label: options.vueCompilerOptions.optionsWrapper.length
|
|
67
|
-
? options.vueCompilerOptions.optionsWrapper[0]
|
|
68
|
-
: '[Missing optionsWrapper]',
|
|
69
|
-
tooltip: [
|
|
70
|
-
'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.',
|
|
71
|
-
'To hide it, you can set `"vue.inlayHints.optionsWrapper": false` in IDE settings.',
|
|
72
|
-
].join('\n\n'),
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
77
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.start, exportDefault.expression.end, exports.codeFeatures.all);
|
|
77
|
-
yield [
|
|
78
|
-
'',
|
|
79
|
-
'script',
|
|
80
|
-
exportDefault.expression.end,
|
|
81
|
-
{
|
|
82
|
-
__hint: {
|
|
83
|
-
setting: 'vue.inlayHints.optionsWrapper',
|
|
84
|
-
label: options.vueCompilerOptions.optionsWrapper.length === 2
|
|
85
|
-
? options.vueCompilerOptions.optionsWrapper[1]
|
|
86
|
-
: '[Missing optionsWrapper]',
|
|
87
|
-
tooltip: '',
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
78
|
yield options.vueCompilerOptions.optionsWrapper[1];
|
|
92
79
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, exportDefault.expression.end, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
93
80
|
}
|
|
94
81
|
else if (classBlockEnd !== undefined) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
82
|
+
if (options.vueCompilerOptions.skipTemplateCodegen) {
|
|
83
|
+
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, classBlockEnd, exports.codeFeatures.all);
|
|
87
|
+
yield `__VLS_template = () => {`;
|
|
88
|
+
yield* (0, template_1.generateTemplate)(options, ctx, true);
|
|
89
|
+
yield `},${common_1.newLine}`;
|
|
90
|
+
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, classBlockEnd, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
91
|
+
}
|
|
98
92
|
}
|
|
99
93
|
else {
|
|
100
94
|
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, 0, options.sfc.script.content.length, exports.codeFeatures.all);
|
|
@@ -108,30 +102,20 @@ function* generateScript(options) {
|
|
|
108
102
|
yield `;`;
|
|
109
103
|
if (options.sfc.scriptSetup) {
|
|
110
104
|
// #4569
|
|
111
|
-
yield [
|
|
112
|
-
'',
|
|
113
|
-
'scriptSetup',
|
|
114
|
-
options.sfc.scriptSetup.content.length,
|
|
115
|
-
exports.codeFeatures.verification,
|
|
116
|
-
];
|
|
105
|
+
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
|
|
117
106
|
}
|
|
118
107
|
yield common_1.newLine;
|
|
119
|
-
if (options.globalTypes) {
|
|
120
|
-
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
|
|
121
|
-
}
|
|
122
|
-
yield* ctx.generateHelperTypes();
|
|
123
|
-
yield `\ntype __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
|
|
124
108
|
if (!ctx.generatedTemplate) {
|
|
125
109
|
yield* (0, template_1.generateTemplate)(options, ctx, false);
|
|
126
110
|
}
|
|
111
|
+
if (options.edited) {
|
|
112
|
+
yield `type __VLS_IntrinsicElementsCompletion = __VLS_IntrinsicElements${common_1.endOfLine}`;
|
|
113
|
+
}
|
|
114
|
+
yield* ctx.localTypes.generate([...ctx.localTypes.getUsedNames()]);
|
|
127
115
|
if (options.sfc.scriptSetup) {
|
|
128
|
-
yield [
|
|
129
|
-
'',
|
|
130
|
-
'scriptSetup',
|
|
131
|
-
options.sfc.scriptSetup.content.length,
|
|
132
|
-
exports.codeFeatures.verification,
|
|
133
|
-
];
|
|
116
|
+
yield ['', 'scriptSetup', options.sfc.scriptSetup.content.length, exports.codeFeatures.verification];
|
|
134
117
|
}
|
|
118
|
+
return ctx;
|
|
135
119
|
}
|
|
136
120
|
function* generateDefineProp(options, scriptSetup) {
|
|
137
121
|
const definePropProposalA = scriptSetup.content.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition') || options.vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
2
|
import type { TemplateCodegenContext } from '../template/context';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
|
-
import type
|
|
4
|
+
import { type ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateInternalComponent(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, templateCodegenCtx: TemplateCodegenContext): Generator<Code>;
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateInternalComponent = generateInternalComponent;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
5
|
const component_1 = require("./component");
|
|
6
|
+
const index_1 = require("./index");
|
|
6
7
|
const template_1 = require("./template");
|
|
7
8
|
function* generateInternalComponent(options, ctx, templateCodegenCtx) {
|
|
8
9
|
if (options.sfc.scriptSetup && options.scriptSetupRanges) {
|
|
9
|
-
yield `
|
|
10
|
-
yield `const __VLS_internalComponent = __VLS_defineComponent({${common_1.newLine}`;
|
|
10
|
+
yield `const __VLS_internalComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
|
11
11
|
yield `setup() {${common_1.newLine}`;
|
|
12
12
|
yield `return {${common_1.newLine}`;
|
|
13
13
|
if (ctx.bypassDefineComponent) {
|
|
@@ -40,11 +40,19 @@ function* generateInternalComponent(options, ctx, templateCodegenCtx) {
|
|
|
40
40
|
}
|
|
41
41
|
yield `}${common_1.endOfLine}`; // return {
|
|
42
42
|
yield `},${common_1.newLine}`; // setup() {
|
|
43
|
+
if (options.vueCompilerOptions.target >= 3.5) {
|
|
44
|
+
yield `__typeRefs: {} as __VLS_Refs,${common_1.newLine}`;
|
|
45
|
+
}
|
|
43
46
|
if (options.sfc.scriptSetup && options.scriptSetupRanges && !ctx.bypassDefineComponent) {
|
|
44
|
-
|
|
47
|
+
const emitOptionCodes = [...(0, component_1.generateEmitsOption)(options, options.sfc.scriptSetup, options.scriptSetupRanges)];
|
|
48
|
+
for (const code of emitOptionCodes) {
|
|
49
|
+
yield code;
|
|
50
|
+
}
|
|
51
|
+
yield* (0, component_1.generatePropsOption)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges, !!emitOptionCodes.length, false);
|
|
45
52
|
}
|
|
46
|
-
if (options.sfc.script && options.scriptRanges) {
|
|
47
|
-
|
|
53
|
+
if (options.sfc.script && options.scriptRanges?.exportDefault?.args) {
|
|
54
|
+
const { args } = options.scriptRanges.exportDefault;
|
|
55
|
+
yield (0, common_1.generateSfcBlockSection)(options.sfc.script, args.start + 1, args.end - 1, index_1.codeFeatures.all);
|
|
48
56
|
}
|
|
49
57
|
yield `})${common_1.endOfLine}`; // defineComponent {
|
|
50
58
|
}
|
|
@@ -42,20 +42,23 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
42
42
|
}
|
|
43
43
|
yield `>(${common_1.newLine}`
|
|
44
44
|
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${common_1.newLine}`
|
|
45
|
-
+ ` __VLS_ctx?: ${ctx.
|
|
45
|
+
+ ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
|
|
46
46
|
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
|
|
47
47
|
+ ` __VLS_setup = (async () => {${common_1.newLine}`;
|
|
48
48
|
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
|
|
49
|
-
const emitTypes = [
|
|
49
|
+
const emitTypes = [];
|
|
50
50
|
if (scriptSetupRanges.emits.define) {
|
|
51
|
-
emitTypes.
|
|
51
|
+
emitTypes.push(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
|
|
52
|
+
}
|
|
53
|
+
if (scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
|
54
|
+
emitTypes.push(`__VLS_ModelEmitsType`);
|
|
52
55
|
}
|
|
53
56
|
yield ` return {} as {${common_1.newLine}`
|
|
54
|
-
+ ` props: ${ctx.
|
|
57
|
+
+ ` props: ${ctx.localTypes.PrettifyLocal}<typeof __VLS_functionalComponentProps & __VLS_PublicProps> & __VLS_BuiltInPublicProps,${common_1.newLine}`
|
|
55
58
|
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.expose.define ? 'typeof __VLS_exposed' : '{}'}>): void,${common_1.newLine}`
|
|
56
59
|
+ ` attrs: any,${common_1.newLine}`
|
|
57
|
-
+ ` slots:
|
|
58
|
-
+ ` emit: ${emitTypes.join(' & ')},${common_1.newLine}`
|
|
60
|
+
+ ` slots: __VLS_Slots,${common_1.newLine}`
|
|
61
|
+
+ ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${common_1.newLine}`
|
|
59
62
|
+ ` }${common_1.endOfLine}`;
|
|
60
63
|
yield ` })(),${common_1.newLine}`; // __VLS_setup = (async () => {
|
|
61
64
|
yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))`;
|
|
@@ -74,16 +77,16 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
74
77
|
}
|
|
75
78
|
if (ctx.scriptSetupGeneratedOffset !== undefined) {
|
|
76
79
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
77
|
-
if (!defineProp.
|
|
80
|
+
if (!defineProp.localName) {
|
|
78
81
|
continue;
|
|
79
82
|
}
|
|
80
|
-
const
|
|
81
|
-
const propMirror = definePropMirrors.get(
|
|
83
|
+
const [_, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
84
|
+
const propMirror = definePropMirrors.get(localName);
|
|
82
85
|
if (propMirror !== undefined) {
|
|
83
86
|
options.linkedCodeMappings.push({
|
|
84
|
-
sourceOffsets: [defineProp.
|
|
87
|
+
sourceOffsets: [defineProp.localName.start + ctx.scriptSetupGeneratedOffset],
|
|
85
88
|
generatedOffsets: [propMirror],
|
|
86
|
-
lengths: [defineProp.
|
|
89
|
+
lengths: [defineProp.localName.end - defineProp.localName.start],
|
|
87
90
|
data: undefined,
|
|
88
91
|
});
|
|
89
92
|
}
|
|
@@ -94,7 +97,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
94
97
|
if (options.vueCompilerOptions.target >= 3.3) {
|
|
95
98
|
yield `const { `;
|
|
96
99
|
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
|
97
|
-
if (!ctx.bindingNames.has(macro)) {
|
|
100
|
+
if (!ctx.bindingNames.has(macro) && macro !== 'templateRef') {
|
|
98
101
|
yield macro + `, `;
|
|
99
102
|
}
|
|
100
103
|
}
|
|
@@ -188,6 +191,39 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
188
191
|
]);
|
|
189
192
|
}
|
|
190
193
|
}
|
|
194
|
+
if (scriptSetupRanges.cssModules.length) {
|
|
195
|
+
for (const { exp, arg } of scriptSetupRanges.cssModules) {
|
|
196
|
+
if (arg) {
|
|
197
|
+
setupCodeModifies.push([
|
|
198
|
+
[
|
|
199
|
+
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
200
|
+
(0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.all),
|
|
201
|
+
`]`
|
|
202
|
+
],
|
|
203
|
+
exp.end,
|
|
204
|
+
exp.end
|
|
205
|
+
]);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
setupCodeModifies.push([
|
|
209
|
+
[
|
|
210
|
+
` as __VLS_StyleModules[`,
|
|
211
|
+
['', scriptSetup.name, exp.start, index_1.codeFeatures.verification],
|
|
212
|
+
`'$style'`,
|
|
213
|
+
['', scriptSetup.name, exp.end, index_1.codeFeatures.verification],
|
|
214
|
+
`]`
|
|
215
|
+
],
|
|
216
|
+
exp.end,
|
|
217
|
+
exp.end
|
|
218
|
+
]);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const { define } of scriptSetupRanges.templateRefs) {
|
|
223
|
+
if (define?.arg) {
|
|
224
|
+
setupCodeModifies.push([[`<__VLS_Refs[${scriptSetup.content.slice(define.arg.start, define.arg.end)}], keyof __VLS_Refs>`], define.arg.start - 1, define.arg.start - 1]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
191
227
|
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
|
192
228
|
if (setupCodeModifies.length) {
|
|
193
229
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.importSectionEndOffset, setupCodeModifies[0][1], index_1.codeFeatures.all);
|
|
@@ -216,14 +252,17 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
216
252
|
}
|
|
217
253
|
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors);
|
|
218
254
|
yield* generateModelEmits(options, scriptSetup, scriptSetupRanges);
|
|
255
|
+
yield* generateStyleModules(options, ctx);
|
|
219
256
|
yield* (0, template_1.generateTemplate)(options, ctx, false);
|
|
257
|
+
yield `type __VLS_Refs = typeof __VLS_templateResult['refs']${common_1.endOfLine}`;
|
|
258
|
+
yield `type __VLS_Slots = typeof __VLS_templateResult['slots']${common_1.endOfLine}`;
|
|
220
259
|
if (syntax) {
|
|
221
260
|
if (!options.vueCompilerOptions.skipTemplateCodegen && (options.templateCodegen?.hasSlot || scriptSetupRanges?.slots.define)) {
|
|
222
261
|
yield `const __VLS_component = `;
|
|
223
262
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
224
263
|
yield common_1.endOfLine;
|
|
225
264
|
yield `${syntax} `;
|
|
226
|
-
yield `{} as ${ctx.
|
|
265
|
+
yield `{} as ${ctx.localTypes.WithTemplateSlots}<typeof __VLS_component, __VLS_Slots>${common_1.endOfLine}`;
|
|
227
266
|
}
|
|
228
267
|
else {
|
|
229
268
|
yield `${syntax} `;
|
|
@@ -233,10 +272,9 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
233
272
|
}
|
|
234
273
|
}
|
|
235
274
|
function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, definePropMirrors) {
|
|
236
|
-
yield `const __VLS_fnComponent =
|
|
237
|
-
+ `(await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
|
275
|
+
yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${common_1.newLine}`;
|
|
238
276
|
if (scriptSetupRanges.props.define?.arg) {
|
|
239
|
-
yield `
|
|
277
|
+
yield `props: `;
|
|
240
278
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
|
|
241
279
|
yield `,${common_1.newLine}`;
|
|
242
280
|
}
|
|
@@ -251,20 +289,24 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
251
289
|
: `globalThis.JSX.IntrinsicAttributes;`}`;
|
|
252
290
|
yield common_1.endOfLine;
|
|
253
291
|
yield `let __VLS_functionalComponentProps!: `;
|
|
254
|
-
yield `${ctx.
|
|
292
|
+
yield `${ctx.localTypes.OmitKeepDiscriminatedUnion}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
255
293
|
yield common_1.endOfLine;
|
|
256
294
|
if (scriptSetupRanges.defineProp.length) {
|
|
257
295
|
yield `const __VLS_defaults = {${common_1.newLine}`;
|
|
258
296
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
259
297
|
if (defineProp.defaultValue) {
|
|
260
|
-
|
|
261
|
-
|
|
298
|
+
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
299
|
+
if (defineProp.name || defineProp.isModel) {
|
|
300
|
+
yield propName;
|
|
301
|
+
}
|
|
302
|
+
else if (defineProp.localName) {
|
|
303
|
+
yield localName;
|
|
262
304
|
}
|
|
263
305
|
else {
|
|
264
|
-
|
|
306
|
+
continue;
|
|
265
307
|
}
|
|
266
308
|
yield `: `;
|
|
267
|
-
yield scriptSetup
|
|
309
|
+
yield getRangeName(scriptSetup, defineProp.defaultValue);
|
|
268
310
|
yield `,${common_1.newLine}`;
|
|
269
311
|
}
|
|
270
312
|
}
|
|
@@ -276,7 +318,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
276
318
|
yield ` & `;
|
|
277
319
|
}
|
|
278
320
|
ctx.generatedPropsType = true;
|
|
279
|
-
yield `${ctx.
|
|
321
|
+
yield `${ctx.localTypes.PropsChildren}<typeof __VLS_slots>`;
|
|
280
322
|
}
|
|
281
323
|
if (scriptSetupRanges.defineProp.length) {
|
|
282
324
|
if (ctx.generatedPropsType) {
|
|
@@ -285,32 +327,32 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
285
327
|
ctx.generatedPropsType = true;
|
|
286
328
|
yield `{${common_1.newLine}`;
|
|
287
329
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
288
|
-
|
|
289
|
-
if (defineProp.
|
|
330
|
+
const [propName, localName] = getPropAndLocalName(scriptSetup, defineProp);
|
|
331
|
+
if (defineProp.isModel && !defineProp.name) {
|
|
332
|
+
yield propName;
|
|
333
|
+
}
|
|
334
|
+
else if (defineProp.name) {
|
|
290
335
|
// renaming support
|
|
291
336
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
|
|
292
|
-
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
293
|
-
propName = propName.replace(/['"]+/g, '');
|
|
294
337
|
}
|
|
295
|
-
else if (defineProp.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
yield propName;
|
|
338
|
+
else if (defineProp.localName) {
|
|
339
|
+
definePropMirrors.set(localName, options.getGeneratedLength());
|
|
340
|
+
yield localName;
|
|
299
341
|
}
|
|
300
342
|
else {
|
|
301
|
-
|
|
343
|
+
continue;
|
|
302
344
|
}
|
|
303
345
|
yield defineProp.required
|
|
304
346
|
? `: `
|
|
305
347
|
: `?: `;
|
|
306
|
-
yield* generateDefinePropType(scriptSetup, propName, defineProp);
|
|
348
|
+
yield* generateDefinePropType(scriptSetup, propName, localName, defineProp);
|
|
307
349
|
yield `,${common_1.newLine}`;
|
|
308
350
|
if (defineProp.modifierType) {
|
|
309
351
|
let propModifierName = 'modelModifiers';
|
|
310
352
|
if (defineProp.name) {
|
|
311
|
-
propModifierName = `${scriptSetup
|
|
353
|
+
propModifierName = `${getRangeName(scriptSetup, defineProp.name, true)}Modifiers`;
|
|
312
354
|
}
|
|
313
|
-
const modifierType = scriptSetup
|
|
355
|
+
const modifierType = getRangeName(scriptSetup, defineProp.modifierType);
|
|
314
356
|
definePropMirrors.set(propModifierName, options.getGeneratedLength());
|
|
315
357
|
yield `${propModifierName}?: Record<${modifierType}, true>,${common_1.endOfLine}`;
|
|
316
358
|
}
|
|
@@ -330,46 +372,68 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
330
372
|
yield common_1.endOfLine;
|
|
331
373
|
}
|
|
332
374
|
function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (!defineProp.isModel) {
|
|
342
|
-
continue;
|
|
375
|
+
const defineModels = scriptSetupRanges.defineProp.filter(p => p.isModel);
|
|
376
|
+
if (defineModels.length) {
|
|
377
|
+
const generateDefineModels = function* () {
|
|
378
|
+
for (const defineModel of defineModels) {
|
|
379
|
+
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
380
|
+
yield `'update:${propName}': [${propName}:`;
|
|
381
|
+
yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
|
|
382
|
+
yield `]${common_1.endOfLine}`;
|
|
343
383
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
yield `'update:${propName}': [${propName}:`;
|
|
350
|
-
yield* generateDefinePropType(scriptSetup, propName, defineProp);
|
|
351
|
-
yield `]${common_1.endOfLine}`;
|
|
384
|
+
};
|
|
385
|
+
if (options.vueCompilerOptions.target >= 3.5) {
|
|
386
|
+
yield `type __VLS_ModelEmitsType = {${common_1.newLine}`;
|
|
387
|
+
yield* generateDefineModels();
|
|
388
|
+
yield `}${common_1.endOfLine}`;
|
|
352
389
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
yield
|
|
390
|
+
else {
|
|
391
|
+
yield `const __VLS_modelEmitsType = (await import('${options.vueCompilerOptions.lib}')).defineEmits<{${common_1.newLine}`;
|
|
392
|
+
yield* generateDefineModels();
|
|
393
|
+
yield `}>()${common_1.endOfLine}`;
|
|
394
|
+
yield `type __VLS_ModelEmitsType = typeof __VLS_modelEmitsType${common_1.endOfLine}`;
|
|
356
395
|
}
|
|
357
396
|
}
|
|
358
|
-
|
|
359
|
-
|
|
397
|
+
}
|
|
398
|
+
function* generateStyleModules(options, ctx) {
|
|
399
|
+
const styles = options.sfc.styles.filter(style => style.module);
|
|
400
|
+
if (!styles.length) {
|
|
401
|
+
return;
|
|
360
402
|
}
|
|
403
|
+
yield `type __VLS_StyleModules = {${common_1.newLine}`;
|
|
404
|
+
for (let i = 0; i < styles.length; i++) {
|
|
405
|
+
const style = styles[i];
|
|
406
|
+
const { name, offset } = style.module;
|
|
407
|
+
if (offset) {
|
|
408
|
+
yield [
|
|
409
|
+
name,
|
|
410
|
+
'main',
|
|
411
|
+
offset + 1,
|
|
412
|
+
index_1.codeFeatures.all
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
yield name;
|
|
417
|
+
}
|
|
418
|
+
yield `: Record<string, string> & ${ctx.localTypes.PrettifyLocal}<{}`;
|
|
419
|
+
for (const className of style.classNames) {
|
|
420
|
+
yield* (0, template_1.generateCssClassProperty)(i, className.text, className.offset, 'string', false);
|
|
421
|
+
}
|
|
422
|
+
yield `>${common_1.endOfLine}`;
|
|
423
|
+
}
|
|
424
|
+
yield `}`;
|
|
361
425
|
yield common_1.endOfLine;
|
|
362
426
|
}
|
|
363
|
-
function* generateDefinePropType(scriptSetup, propName, defineProp) {
|
|
427
|
+
function* generateDefinePropType(scriptSetup, propName, localName, defineProp) {
|
|
364
428
|
if (defineProp.type) {
|
|
365
429
|
// Infer from defineProp<T>
|
|
366
|
-
yield scriptSetup
|
|
430
|
+
yield getRangeName(scriptSetup, defineProp.type);
|
|
367
431
|
}
|
|
368
|
-
else if (
|
|
432
|
+
else if (defineProp.runtimeType && localName) {
|
|
369
433
|
// Infer from actual prop declaration code
|
|
370
|
-
yield `
|
|
434
|
+
yield `typeof ${localName}['value']`;
|
|
371
435
|
}
|
|
372
|
-
else if (defineProp.defaultValue) {
|
|
436
|
+
else if (defineProp.defaultValue && propName) {
|
|
373
437
|
// Infer from defineProp({default: T})
|
|
374
438
|
yield `typeof __VLS_defaults['${propName}']`;
|
|
375
439
|
}
|
|
@@ -377,4 +441,22 @@ function* generateDefinePropType(scriptSetup, propName, defineProp) {
|
|
|
377
441
|
yield `any`;
|
|
378
442
|
}
|
|
379
443
|
}
|
|
444
|
+
function getPropAndLocalName(scriptSetup, defineProp) {
|
|
445
|
+
const localName = defineProp.localName
|
|
446
|
+
? getRangeName(scriptSetup, defineProp.localName)
|
|
447
|
+
: undefined;
|
|
448
|
+
let propName = defineProp.name
|
|
449
|
+
? getRangeName(scriptSetup, defineProp.name)
|
|
450
|
+
: defineProp.isModel
|
|
451
|
+
? 'modelValue'
|
|
452
|
+
: localName;
|
|
453
|
+
if (defineProp.name) {
|
|
454
|
+
propName = propName.replace(/['"]+/g, '');
|
|
455
|
+
}
|
|
456
|
+
return [propName, localName];
|
|
457
|
+
}
|
|
458
|
+
function getRangeName(scriptSetup, range, unwrap = false) {
|
|
459
|
+
const offset = unwrap ? 1 : 0;
|
|
460
|
+
return scriptSetup.content.substring(range.start + offset, range.end - offset);
|
|
461
|
+
}
|
|
380
462
|
//# sourceMappingURL=scriptSetup.js.map
|