@vue/language-core 3.1.5 → 3.1.7
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 +2 -1
- package/index.js +3 -2
- package/lib/codegen/codeFeatures.d.ts +5 -9
- package/lib/codegen/codeFeatures.js +5 -5
- package/lib/codegen/globalTypes.js +12 -18
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +6 -6
- package/lib/codegen/names.d.ts +30 -0
- package/lib/codegen/names.js +34 -0
- package/lib/codegen/script/component.js +45 -54
- package/lib/codegen/script/context.d.ts +2 -5
- package/lib/codegen/script/context.js +1 -7
- package/lib/codegen/script/index.d.ts +10 -12
- package/lib/codegen/script/index.js +74 -73
- package/lib/codegen/script/scriptSetup.d.ts +3 -2
- package/lib/codegen/script/scriptSetup.js +209 -283
- package/lib/codegen/script/src.js +9 -3
- package/lib/codegen/script/template.js +64 -108
- package/lib/codegen/style/common.d.ts +3 -0
- package/lib/codegen/style/common.js +43 -0
- package/lib/codegen/style/index.d.ts +63 -0
- package/lib/codegen/style/index.js +38 -0
- package/lib/codegen/style/modules.d.ts +3 -2
- package/lib/codegen/style/modules.js +12 -11
- package/lib/codegen/style/scopedClasses.d.ts +2 -3
- package/lib/codegen/style/scopedClasses.js +23 -21
- package/lib/codegen/template/context.d.ts +7 -16
- package/lib/codegen/template/context.js +81 -93
- package/lib/codegen/template/element.js +153 -55
- package/lib/codegen/template/elementDirectives.js +32 -12
- package/lib/codegen/template/elementEvents.js +27 -28
- package/lib/codegen/template/elementProps.d.ts +2 -2
- package/lib/codegen/template/elementProps.js +49 -23
- package/lib/codegen/template/index.d.ts +8 -19
- package/lib/codegen/template/index.js +85 -80
- package/lib/codegen/template/interpolation.d.ts +3 -3
- package/lib/codegen/template/interpolation.js +90 -136
- package/lib/codegen/template/objectProperty.js +8 -4
- package/lib/codegen/template/propertyAccess.d.ts +1 -1
- package/lib/codegen/template/propertyAccess.js +5 -7
- package/lib/codegen/template/slotOutlet.js +25 -8
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -6
- package/lib/codegen/template/styleScopedClasses.js +23 -149
- package/lib/codegen/template/templateChild.d.ts +0 -1
- package/lib/codegen/template/templateChild.js +11 -68
- package/lib/codegen/template/vFor.js +10 -13
- package/lib/codegen/template/vIf.js +5 -3
- package/lib/codegen/template/vSlot.js +20 -15
- package/lib/codegen/utils/boundary.d.ts +3 -0
- package/lib/codegen/utils/boundary.js +13 -0
- package/lib/codegen/utils/camelized.js +3 -3
- package/lib/codegen/utils/escaped.js +4 -2
- package/lib/codegen/utils/index.d.ts +4 -5
- package/lib/codegen/utils/index.js +49 -21
- package/lib/codegen/utils/merge.d.ts +2 -2
- package/lib/codegen/utils/merge.js +9 -9
- package/lib/codegen/utils/stringLiteralKey.js +6 -3
- package/lib/codegen/utils/transform.d.ts +8 -0
- package/lib/codegen/utils/transform.js +27 -0
- package/lib/codegen/utils/unicode.js +4 -2
- package/lib/compilerOptions.d.ts +5 -2
- package/lib/compilerOptions.js +67 -44
- package/lib/languagePlugin.d.ts +1 -1
- package/lib/languagePlugin.js +5 -6
- package/lib/parsers/scriptRanges.d.ts +4 -8
- package/lib/parsers/scriptRanges.js +3 -2
- package/lib/parsers/scriptSetupRanges.d.ts +2 -6
- package/lib/parsers/scriptSetupRanges.js +3 -2
- package/lib/parsers/utils.d.ts +4 -6
- package/lib/parsers/utils.js +22 -27
- package/lib/plugins/vue-template-inline-css.js +2 -6
- package/lib/plugins/vue-template-inline-ts.js +12 -14
- package/lib/plugins/vue-tsx.d.ts +14 -32
- package/lib/plugins/vue-tsx.js +114 -72
- package/lib/plugins.js +1 -1
- package/lib/types.d.ts +5 -4
- package/lib/utils/parseSfc.js +7 -3
- package/lib/utils/shared.d.ts +1 -1
- package/lib/utils/shared.js +7 -6
- package/lib/utils/signals.d.ts +2 -2
- package/lib/utils/signals.js +8 -6
- package/lib/virtualCode/embeddedCodes.d.ts +12 -0
- package/lib/virtualCode/embeddedCodes.js +249 -0
- package/lib/{virtualFile/vueFile.d.ts → virtualCode/index.d.ts} +9 -9
- package/lib/virtualCode/index.js +81 -0
- package/lib/virtualCode/ir.d.ts +4 -0
- package/lib/{virtualFile/computedSfc.js → virtualCode/ir.js} +59 -94
- package/lib/virtualCode/normalize.d.ts +2 -0
- package/lib/virtualCode/normalize.js +170 -0
- package/package.json +4 -4
- package/lib/codegen/style/classProperty.d.ts +0 -2
- package/lib/codegen/style/classProperty.js +0 -18
- package/lib/codegen/style/imports.d.ts +0 -2
- package/lib/codegen/style/imports.js +0 -27
- package/lib/codegen/template/elementChildren.d.ts +0 -5
- package/lib/codegen/template/elementChildren.js +0 -12
- package/lib/codegen/utils/wrapWith.d.ts +0 -2
- package/lib/codegen/utils/wrapWith.js +0 -15
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +0 -4
- package/lib/virtualFile/computedEmbeddedCodes.js +0 -262
- package/lib/virtualFile/computedSfc.d.ts +0 -6
- package/lib/virtualFile/computedVueSfc.d.ts +0 -4
- package/lib/virtualFile/computedVueSfc.js +0 -41
- package/lib/virtualFile/embeddedFile.d.ts +0 -11
- package/lib/virtualFile/embeddedFile.js +0 -14
- package/lib/virtualFile/vueFile.js +0 -49
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
4
|
-
exports.
|
|
4
|
+
exports.generateGeneric = generateGeneric;
|
|
5
|
+
exports.generateSetupFunction = generateSetupFunction;
|
|
5
6
|
const shared_1 = require("@vue/shared");
|
|
6
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
+
const names = require("../names");
|
|
7
9
|
const utils_1 = require("../utils");
|
|
10
|
+
const boundary_1 = require("../utils/boundary");
|
|
8
11
|
const camelized_1 = require("../utils/camelized");
|
|
9
|
-
const
|
|
12
|
+
const transform_1 = require("../utils/transform");
|
|
10
13
|
const component_1 = require("./component");
|
|
11
|
-
const index_1 = require("./index");
|
|
12
|
-
const template_1 = require("./template");
|
|
13
14
|
function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
14
15
|
yield [
|
|
15
16
|
scriptSetup.content.slice(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
|
@@ -18,363 +19,288 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
|
18
19
|
codeFeatures_1.codeFeatures.all,
|
|
19
20
|
];
|
|
20
21
|
}
|
|
21
|
-
function*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
yield
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
yield
|
|
28
|
-
scriptSetup.generic.text,
|
|
29
|
-
'main',
|
|
30
|
-
scriptSetup.generic.offset,
|
|
31
|
-
codeFeatures_1.codeFeatures.all,
|
|
32
|
-
];
|
|
33
|
-
if (!scriptSetup.generic.text.endsWith(`,`)) {
|
|
34
|
-
yield `,`;
|
|
35
|
-
}
|
|
36
|
-
yield `>`;
|
|
37
|
-
}
|
|
38
|
-
yield `(${utils_1.newLine}`
|
|
39
|
-
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${utils_1.newLine}`
|
|
40
|
-
+ ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
|
|
41
|
-
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${utils_1.newLine}`
|
|
42
|
-
+ ` __VLS_setup = (async () => {${utils_1.newLine}`;
|
|
43
|
-
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined);
|
|
44
|
-
const propTypes = [];
|
|
45
|
-
if (ctx.generatedPropsType) {
|
|
46
|
-
propTypes.push(`__VLS_PublicProps`);
|
|
47
|
-
}
|
|
48
|
-
if (scriptSetupRanges.defineProps?.arg) {
|
|
49
|
-
yield `const __VLS_propsOption = `;
|
|
50
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
51
|
-
yield utils_1.endOfLine;
|
|
52
|
-
propTypes.push(`import('${options.vueCompilerOptions.lib}').${options.vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof __VLS_propsOption>`);
|
|
53
|
-
}
|
|
54
|
-
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
|
|
55
|
-
propTypes.push(`__VLS_EmitProps`);
|
|
56
|
-
}
|
|
57
|
-
if (options.templateCodegen?.inheritedAttrVars.size) {
|
|
58
|
-
propTypes.push(`__VLS_InheritedAttrs`);
|
|
59
|
-
}
|
|
60
|
-
const emitTypes = [];
|
|
61
|
-
if (scriptSetupRanges.defineEmits) {
|
|
62
|
-
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? '__VLS_emit'}`);
|
|
22
|
+
function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic, body) {
|
|
23
|
+
yield `(`;
|
|
24
|
+
if (typeof generic === 'object') {
|
|
25
|
+
yield `<`;
|
|
26
|
+
yield [generic.text, 'main', generic.offset, codeFeatures_1.codeFeatures.all];
|
|
27
|
+
if (!generic.text.endsWith(`,`)) {
|
|
28
|
+
yield `,`;
|
|
63
29
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
? `import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<typeof __VLS_exposed>`
|
|
77
|
-
: `{}`}) => void${utils_1.endOfLine}`
|
|
78
|
-
+ ` attrs: any${utils_1.endOfLine}`
|
|
79
|
-
+ ` slots: __VLS_Slots${utils_1.endOfLine}`
|
|
80
|
-
+ ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`
|
|
81
|
-
+ `}${utils_1.endOfLine}`;
|
|
82
|
-
yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
|
|
83
|
-
yield `) => ({} as import('${options.vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof __VLS_setup> }))${utils_1.endOfLine}`;
|
|
84
|
-
}
|
|
85
|
-
else if (!options.sfc.script) {
|
|
86
|
-
// no script block, generate script setup code at root
|
|
87
|
-
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, 'export default');
|
|
30
|
+
yield `>`;
|
|
31
|
+
}
|
|
32
|
+
yield `(${utils_1.newLine}`
|
|
33
|
+
+ ` ${names.props}: NonNullable<Awaited<typeof ${names.setup}>>['props'],${utils_1.newLine}`
|
|
34
|
+
+ ` ${names.ctx}?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof ${names.setup}>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
|
|
35
|
+
+ ` ${names.exposed}?: NonNullable<Awaited<typeof ${names.setup}>>['expose'],${utils_1.newLine}`
|
|
36
|
+
+ ` ${names.setup} = (async () => {${utils_1.newLine}`;
|
|
37
|
+
yield* body;
|
|
38
|
+
const propTypes = [];
|
|
39
|
+
const { vueCompilerOptions } = options;
|
|
40
|
+
if (ctx.generatedTypes.has(names.PublicProps)) {
|
|
41
|
+
propTypes.push(names.PublicProps);
|
|
88
42
|
}
|
|
89
|
-
|
|
90
|
-
yield
|
|
91
|
-
yield
|
|
92
|
-
yield
|
|
93
|
-
|
|
43
|
+
if (scriptSetupRanges.defineProps?.arg) {
|
|
44
|
+
yield `const __VLS_propsOption = `;
|
|
45
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
46
|
+
yield utils_1.endOfLine;
|
|
47
|
+
propTypes.push(`import('${vueCompilerOptions.lib}').${vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof __VLS_propsOption>`);
|
|
48
|
+
}
|
|
49
|
+
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
|
|
50
|
+
propTypes.push(names.EmitProps);
|
|
51
|
+
}
|
|
52
|
+
if (options.templateCodegen?.generatedTypes.has(names.InheritedAttrs)) {
|
|
53
|
+
propTypes.push(names.InheritedAttrs);
|
|
54
|
+
}
|
|
55
|
+
const emitTypes = [];
|
|
56
|
+
if (scriptSetupRanges.defineEmits) {
|
|
57
|
+
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
|
|
94
58
|
}
|
|
59
|
+
if (scriptSetupRanges.defineModel.length) {
|
|
60
|
+
emitTypes.push(`typeof ${names.modelEmit}`);
|
|
61
|
+
}
|
|
62
|
+
yield `return {} as {${utils_1.newLine}`;
|
|
63
|
+
yield ` props: ${propTypes.length ? `${ctx.localTypes.PrettifyLocal}<${propTypes.join(` & `)}> & ` : ``}${vueCompilerOptions.target >= 3.4
|
|
64
|
+
? `import('${vueCompilerOptions.lib}').PublicProps`
|
|
65
|
+
: vueCompilerOptions.target >= 3
|
|
66
|
+
? `import('${vueCompilerOptions.lib}').VNodeProps`
|
|
67
|
+
+ ` & import('${vueCompilerOptions.lib}').AllowedComponentProps`
|
|
68
|
+
+ ` & import('${vueCompilerOptions.lib}').ComponentCustomProps`
|
|
69
|
+
: `globalThis.JSX.IntrinsicAttributes`} & (typeof globalThis extends { ${names.PROPS_FALLBACK}: infer P } ? P : {})${utils_1.endOfLine}`;
|
|
70
|
+
yield ` expose: (exposed: `;
|
|
71
|
+
yield scriptSetupRanges.defineExpose
|
|
72
|
+
? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names.exposed}>`
|
|
73
|
+
: `{}`;
|
|
74
|
+
if (options.vueCompilerOptions.inferComponentDollarRefs
|
|
75
|
+
&& options.templateCodegen?.generatedTypes.has(names.TemplateRefs)) {
|
|
76
|
+
yield ` & { $refs: ${names.TemplateRefs}; }`;
|
|
77
|
+
}
|
|
78
|
+
if (options.vueCompilerOptions.inferComponentDollarEl
|
|
79
|
+
&& options.templateCodegen?.generatedTypes.has(names.RootEl)) {
|
|
80
|
+
yield ` & { $el: ${names.RootEl}; }`;
|
|
81
|
+
}
|
|
82
|
+
yield `) => void${utils_1.endOfLine}`;
|
|
83
|
+
yield ` attrs: any${utils_1.endOfLine}`;
|
|
84
|
+
yield ` slots: ${hasSlotsType(options) ? names.Slots : `{}`}${utils_1.endOfLine}`;
|
|
85
|
+
yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
|
86
|
+
yield `}${utils_1.endOfLine}`;
|
|
87
|
+
yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
|
|
88
|
+
yield `) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof ${names.setup}> }))${utils_1.endOfLine}`;
|
|
95
89
|
}
|
|
96
|
-
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges,
|
|
97
|
-
|
|
90
|
+
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, body, output) {
|
|
91
|
+
const transforms = [];
|
|
98
92
|
if (scriptSetupRanges.defineProps) {
|
|
99
93
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
100
|
-
|
|
94
|
+
const _callExp = scriptSetupRanges.withDefaults?.callExp ?? callExp;
|
|
95
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, _callExp, typeArg, name, names.props, names.Props));
|
|
101
96
|
}
|
|
102
97
|
if (scriptSetupRanges.defineEmits) {
|
|
103
98
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
|
|
104
|
-
|
|
99
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.emit, names.Emit));
|
|
105
100
|
}
|
|
106
101
|
if (scriptSetupRanges.defineSlots) {
|
|
107
102
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
|
|
108
|
-
|
|
103
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.slots, names.Slots));
|
|
109
104
|
}
|
|
110
105
|
if (scriptSetupRanges.defineExpose) {
|
|
111
106
|
const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
|
|
112
107
|
if (typeArg) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
callExp.start,
|
|
121
|
-
], [
|
|
122
|
-
[`typeof __VLS_exposed`],
|
|
123
|
-
typeArg.start,
|
|
124
|
-
typeArg.end,
|
|
125
|
-
]);
|
|
108
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
109
|
+
yield `let ${names.exposed}!: `;
|
|
110
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
|
|
111
|
+
yield utils_1.endOfLine;
|
|
112
|
+
}), (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
|
|
113
|
+
yield `typeof ${names.exposed}`;
|
|
114
|
+
}));
|
|
126
115
|
}
|
|
127
116
|
else if (arg) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
callExp.start,
|
|
136
|
-
], [
|
|
137
|
-
[`__VLS_exposed`],
|
|
138
|
-
arg.start,
|
|
139
|
-
arg.end,
|
|
140
|
-
]);
|
|
117
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
118
|
+
yield `const ${names.exposed} = `;
|
|
119
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all);
|
|
120
|
+
yield utils_1.endOfLine;
|
|
121
|
+
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
122
|
+
yield `${names.exposed}`;
|
|
123
|
+
}));
|
|
141
124
|
}
|
|
142
125
|
else {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
callExp.start,
|
|
147
|
-
]);
|
|
126
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
127
|
+
yield `const ${names.exposed} = {}${utils_1.endOfLine}`;
|
|
128
|
+
}));
|
|
148
129
|
}
|
|
149
130
|
}
|
|
150
131
|
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
151
132
|
for (const { callExp } of scriptSetupRanges.useAttrs) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
[` as typeof __VLS_dollars.$attrs)`],
|
|
158
|
-
callExp.end,
|
|
159
|
-
callExp.end,
|
|
160
|
-
]);
|
|
133
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
134
|
+
yield `(`;
|
|
135
|
+
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
136
|
+
yield ` as typeof ${names.dollars}.$attrs)`;
|
|
137
|
+
}));
|
|
161
138
|
}
|
|
162
139
|
}
|
|
163
140
|
for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
? [
|
|
171
|
-
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
172
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic),
|
|
173
|
-
`])`,
|
|
174
|
-
]
|
|
175
|
-
: [
|
|
176
|
-
` as __VLS_StyleModules[`,
|
|
177
|
-
...(0, wrapWith_1.wrapWith)(scriptSetup.name, exp.start, exp.end, codeFeatures_1.codeFeatures.verification, `'$style'`),
|
|
178
|
-
`])`,
|
|
179
|
-
],
|
|
180
|
-
callExp.end,
|
|
181
|
-
callExp.end,
|
|
182
|
-
]);
|
|
141
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
142
|
+
yield `(`;
|
|
143
|
+
}));
|
|
144
|
+
const type = options.styleCodegen?.generatedTypes.has(names.StyleModules)
|
|
145
|
+
? names.StyleModules
|
|
146
|
+
: `{}`;
|
|
183
147
|
if (arg) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
arg.start,
|
|
187
|
-
|
|
188
|
-
|
|
148
|
+
transforms.push((0, transform_1.insert)(callExp.end, function* () {
|
|
149
|
+
yield ` as Omit<${type}, '$style'>[`;
|
|
150
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
|
151
|
+
yield `])`;
|
|
152
|
+
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
153
|
+
yield names.placeholder;
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
transforms.push((0, transform_1.insert)(callExp.end, function* () {
|
|
158
|
+
yield ` as ${type}[`;
|
|
159
|
+
const token = yield* (0, boundary_1.startBoundary)(scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification);
|
|
160
|
+
yield `'$style'`;
|
|
161
|
+
yield (0, boundary_1.endBoundary)(token, exp.end);
|
|
162
|
+
yield `])`;
|
|
163
|
+
}));
|
|
189
164
|
}
|
|
190
165
|
}
|
|
191
166
|
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
192
167
|
for (const { callExp } of scriptSetupRanges.useSlots) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
[` as typeof __VLS_dollars.$slots)`],
|
|
199
|
-
callExp.end,
|
|
200
|
-
callExp.end,
|
|
201
|
-
]);
|
|
168
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
169
|
+
yield `(`;
|
|
170
|
+
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
171
|
+
yield ` as typeof ${names.dollars}.$slots)`;
|
|
172
|
+
}));
|
|
202
173
|
}
|
|
203
174
|
}
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
exp.end,
|
|
221
|
-
exp.end,
|
|
222
|
-
]);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
setupCodeModifies.push([
|
|
226
|
-
[`(`],
|
|
227
|
-
callExp.start,
|
|
228
|
-
callExp.start,
|
|
229
|
-
], [
|
|
230
|
-
[
|
|
231
|
-
` as __VLS_UseTemplateRef<`,
|
|
232
|
-
...templateRefType,
|
|
233
|
-
`>)`,
|
|
234
|
-
],
|
|
235
|
-
callExp.end,
|
|
236
|
-
callExp.end,
|
|
237
|
-
]);
|
|
238
|
-
}
|
|
175
|
+
for (const { callExp, arg } of scriptSetupRanges.useTemplateRef) {
|
|
176
|
+
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
177
|
+
yield `(`;
|
|
178
|
+
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
179
|
+
yield ` as __VLS_UseTemplateRef<`;
|
|
180
|
+
if (arg) {
|
|
181
|
+
yield names.TemplateRefs;
|
|
182
|
+
yield `[`;
|
|
183
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
|
184
|
+
yield `]`;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
yield `unknown`;
|
|
188
|
+
}
|
|
189
|
+
yield `>)`;
|
|
190
|
+
}));
|
|
239
191
|
if (arg) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
arg.end,
|
|
244
|
-
]);
|
|
192
|
+
transforms.push((0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
193
|
+
yield names.placeholder;
|
|
194
|
+
}));
|
|
245
195
|
}
|
|
246
196
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (const [codes, start, end] of setupCodeModifies) {
|
|
250
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
|
|
251
|
-
yield* codes;
|
|
252
|
-
nextStart = end;
|
|
253
|
-
}
|
|
254
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
|
|
255
|
-
yield* (0, utils_1.generatePartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
|
|
256
|
-
yield* generateMacros(options, ctx);
|
|
257
|
-
const hasSlots = !!(scriptSetupRanges.defineSlots
|
|
258
|
-
|| options.templateCodegen?.slots.length
|
|
259
|
-
|| options.templateCodegen?.dynamicSlots.length);
|
|
197
|
+
yield* (0, transform_1.generateCodeWithTransforms)(Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset), scriptSetup.content.length, transforms, (start, end) => (0, utils_1.generateSfcBlockSection)(scriptSetup, start, end, codeFeatures_1.codeFeatures.all));
|
|
198
|
+
yield* generateMacros(options);
|
|
260
199
|
yield* generateModels(scriptSetup, scriptSetupRanges);
|
|
261
|
-
yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges
|
|
262
|
-
yield*
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
? [`return `]
|
|
266
|
-
: (0, index_1.generateConstExport)(options, scriptSetup);
|
|
267
|
-
if (hasSlots) {
|
|
200
|
+
yield* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges);
|
|
201
|
+
yield* body;
|
|
202
|
+
if (output) {
|
|
203
|
+
if (hasSlotsType(options)) {
|
|
268
204
|
yield `const __VLS_base = `;
|
|
269
205
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
270
206
|
yield utils_1.endOfLine;
|
|
271
|
-
yield*
|
|
272
|
-
yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_base,
|
|
207
|
+
yield* output;
|
|
208
|
+
yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_base, ${names.Slots}>${utils_1.endOfLine}`;
|
|
273
209
|
}
|
|
274
210
|
else {
|
|
275
|
-
yield*
|
|
211
|
+
yield* output;
|
|
276
212
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
277
213
|
yield utils_1.endOfLine;
|
|
278
214
|
}
|
|
279
215
|
}
|
|
280
216
|
}
|
|
281
|
-
function* generateMacros(options
|
|
217
|
+
function* generateMacros(options) {
|
|
282
218
|
if (options.vueCompilerOptions.target >= 3.3) {
|
|
283
219
|
yield `// @ts-ignore${utils_1.newLine}`;
|
|
284
220
|
yield `declare const { `;
|
|
285
221
|
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
|
286
|
-
if (!
|
|
222
|
+
if (!options.setupExposed.has(macro)) {
|
|
287
223
|
yield `${macro}, `;
|
|
288
224
|
}
|
|
289
225
|
}
|
|
290
226
|
yield `}: typeof import('${options.vueCompilerOptions.lib}')${utils_1.endOfLine}`;
|
|
291
227
|
}
|
|
292
228
|
}
|
|
293
|
-
function*
|
|
229
|
+
function* generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, defaultName, typeName) {
|
|
294
230
|
if (typeArg) {
|
|
295
|
-
yield
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
];
|
|
304
|
-
yield [[typeName], typeArg.start, typeArg.end];
|
|
231
|
+
yield (0, transform_1.insert)(statement.start, function* () {
|
|
232
|
+
yield `type ${typeName} = `;
|
|
233
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
|
|
234
|
+
yield utils_1.endOfLine;
|
|
235
|
+
});
|
|
236
|
+
yield (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
|
|
237
|
+
yield typeName;
|
|
238
|
+
});
|
|
305
239
|
}
|
|
306
240
|
if (!name) {
|
|
307
241
|
if (statement.start === callExp.start && statement.end === callExp.end) {
|
|
308
|
-
yield
|
|
242
|
+
yield (0, transform_1.insert)(callExp.start, function* () {
|
|
243
|
+
yield `const ${defaultName} = `;
|
|
244
|
+
});
|
|
309
245
|
}
|
|
310
246
|
else if (typeArg) {
|
|
311
|
-
yield
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
322
|
-
utils_1.endOfLine,
|
|
323
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
324
|
-
defaultName,
|
|
325
|
-
],
|
|
326
|
-
typeArg.end,
|
|
327
|
-
callExp.end,
|
|
328
|
-
];
|
|
247
|
+
yield (0, transform_1.replace)(statement.start, typeArg.start, function* () {
|
|
248
|
+
yield `const ${defaultName} = `;
|
|
249
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all);
|
|
250
|
+
});
|
|
251
|
+
yield (0, transform_1.replace)(typeArg.end, callExp.end, function* () {
|
|
252
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all);
|
|
253
|
+
yield utils_1.endOfLine;
|
|
254
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
|
255
|
+
yield defaultName;
|
|
256
|
+
});
|
|
329
257
|
}
|
|
330
258
|
else {
|
|
331
|
-
yield
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
],
|
|
339
|
-
statement.start,
|
|
340
|
-
callExp.end,
|
|
341
|
-
];
|
|
259
|
+
yield (0, transform_1.replace)(statement.start, callExp.end, function* () {
|
|
260
|
+
yield `const ${defaultName} = `;
|
|
261
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all);
|
|
262
|
+
yield utils_1.endOfLine;
|
|
263
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
|
264
|
+
yield defaultName;
|
|
265
|
+
});
|
|
342
266
|
}
|
|
343
267
|
}
|
|
344
268
|
else if (!utils_1.identifierRegex.test(name)) {
|
|
345
|
-
yield
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
statement.end,
|
|
354
|
-
];
|
|
269
|
+
yield (0, transform_1.replace)(statement.start, callExp.start, function* () {
|
|
270
|
+
yield `const ${defaultName} = `;
|
|
271
|
+
});
|
|
272
|
+
yield (0, transform_1.insert)(statement.end, function* () {
|
|
273
|
+
yield utils_1.endOfLine;
|
|
274
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all);
|
|
275
|
+
yield defaultName;
|
|
276
|
+
});
|
|
355
277
|
}
|
|
356
278
|
}
|
|
357
|
-
function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges
|
|
279
|
+
function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
358
280
|
if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
|
|
359
|
-
yield `const
|
|
360
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
281
|
+
yield `const ${names.defaults} = `;
|
|
282
|
+
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
361
283
|
yield utils_1.endOfLine;
|
|
362
284
|
}
|
|
363
285
|
const propTypes = [];
|
|
364
|
-
if (options.vueCompilerOptions.jsxSlots &&
|
|
365
|
-
propTypes.push(`${ctx.localTypes.PropsChildren}
|
|
286
|
+
if (options.vueCompilerOptions.jsxSlots && hasSlotsType(options)) {
|
|
287
|
+
propTypes.push(`${ctx.localTypes.PropsChildren}<${names.Slots}>`);
|
|
366
288
|
}
|
|
367
289
|
if (scriptSetupRanges.defineProps?.typeArg) {
|
|
368
|
-
propTypes.push(
|
|
290
|
+
propTypes.push(names.Props);
|
|
369
291
|
}
|
|
370
292
|
if (scriptSetupRanges.defineModel.length) {
|
|
371
|
-
propTypes.push(
|
|
293
|
+
propTypes.push(names.ModelProps);
|
|
372
294
|
}
|
|
373
295
|
if (propTypes.length) {
|
|
374
|
-
|
|
375
|
-
|
|
296
|
+
yield `type ${names.PublicProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
|
|
297
|
+
ctx.generatedTypes.add(names.PublicProps);
|
|
376
298
|
}
|
|
377
299
|
}
|
|
300
|
+
function hasSlotsType(options) {
|
|
301
|
+
return !!(options.scriptSetupRanges?.defineSlots
|
|
302
|
+
|| options.templateCodegen?.generatedTypes.has(names.Slots));
|
|
303
|
+
}
|
|
378
304
|
function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
379
305
|
if (!scriptSetupRanges.defineModel.length) {
|
|
380
306
|
return;
|
|
@@ -397,7 +323,7 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
|
397
323
|
}
|
|
398
324
|
else if (defineModel.defaultValue && propName) {
|
|
399
325
|
// Infer from defineModel({ default: T })
|
|
400
|
-
modelType = `typeof
|
|
326
|
+
modelType = `typeof ${names.defaultModels}['${propName}']`;
|
|
401
327
|
}
|
|
402
328
|
else {
|
|
403
329
|
modelType = `any`;
|
|
@@ -409,21 +335,21 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
|
409
335
|
emitCodes.push(generateModelEmit(defineModel, propName, modelType));
|
|
410
336
|
}
|
|
411
337
|
if (defaultCodes.length) {
|
|
412
|
-
yield `const
|
|
338
|
+
yield `const ${names.defaultModels} = {${utils_1.newLine}`;
|
|
413
339
|
yield* defaultCodes;
|
|
414
340
|
yield `}${utils_1.endOfLine}`;
|
|
415
341
|
}
|
|
416
|
-
yield `type
|
|
342
|
+
yield `type ${names.ModelProps} = {${utils_1.newLine}`;
|
|
417
343
|
for (const codes of propCodes) {
|
|
418
344
|
yield* codes;
|
|
419
345
|
}
|
|
420
346
|
yield `}${utils_1.endOfLine}`;
|
|
421
|
-
yield `type
|
|
347
|
+
yield `type ${names.ModelEmit} = {${utils_1.newLine}`;
|
|
422
348
|
for (const codes of emitCodes) {
|
|
423
349
|
yield* codes;
|
|
424
350
|
}
|
|
425
351
|
yield `}${utils_1.endOfLine}`;
|
|
426
|
-
yield `const
|
|
352
|
+
yield `const ${names.modelEmit} = defineEmits<${names.ModelEmit}>()${utils_1.endOfLine}`;
|
|
427
353
|
}
|
|
428
354
|
function* generateModelProp(scriptSetup, defineModel, propName, modelType) {
|
|
429
355
|
if (defineModel.comments) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateSrc = generateSrc;
|
|
4
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const
|
|
6
|
+
const boundary_1 = require("../utils/boundary");
|
|
7
7
|
function* generateSrc(src) {
|
|
8
8
|
if (src === true) {
|
|
9
9
|
return;
|
|
@@ -22,10 +22,16 @@ function* generateSrc(src) {
|
|
|
22
22
|
text = text + '.js';
|
|
23
23
|
}
|
|
24
24
|
yield `export * from `;
|
|
25
|
-
|
|
25
|
+
const wrapCodeFeatures = {
|
|
26
26
|
...codeFeatures_1.codeFeatures.all,
|
|
27
27
|
...text !== src.text ? codeFeatures_1.codeFeatures.navigationWithoutRename : {},
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
|
+
const token = yield* (0, boundary_1.startBoundary)('main', src.offset, wrapCodeFeatures);
|
|
30
|
+
yield `'`;
|
|
31
|
+
yield [text.slice(0, src.text.length), 'main', src.offset, { __combineToken: token }];
|
|
32
|
+
yield text.slice(src.text.length);
|
|
33
|
+
yield `'`;
|
|
34
|
+
yield (0, boundary_1.endBoundary)(token, src.offset + src.text.length);
|
|
29
35
|
yield utils_1.endOfLine;
|
|
30
36
|
yield `export { default } from '${text}'${utils_1.endOfLine}`;
|
|
31
37
|
}
|