@vue/language-core 2.2.0 → 2.2.4
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 +0 -1
- package/index.js +1 -2
- package/lib/codegen/codeFeatures.d.ts +83 -0
- package/lib/codegen/codeFeatures.js +71 -0
- package/lib/codegen/globalTypes.d.ts +3 -1
- package/lib/codegen/globalTypes.js +45 -37
- package/lib/codegen/localTypes.d.ts +1 -1
- package/lib/codegen/localTypes.js +4 -4
- package/lib/codegen/script/component.d.ts +1 -1
- package/lib/codegen/script/component.js +15 -11
- package/lib/codegen/script/componentSelf.d.ts +1 -1
- package/lib/codegen/script/componentSelf.js +2 -2
- package/lib/codegen/script/context.d.ts +1 -1
- package/lib/codegen/script/index.d.ts +1 -8
- package/lib/codegen/script/index.js +19 -45
- package/lib/codegen/script/scriptSetup.d.ts +1 -1
- package/lib/codegen/script/scriptSetup.js +78 -79
- package/lib/codegen/script/src.d.ts +2 -2
- package/lib/codegen/script/src.js +37 -38
- package/lib/codegen/script/template.d.ts +2 -3
- package/lib/codegen/script/template.js +12 -79
- package/lib/codegen/style/classProperty.d.ts +2 -0
- package/lib/codegen/style/classProperty.js +31 -0
- package/lib/codegen/style/modules.d.ts +3 -0
- package/lib/codegen/{script/styleModulesType.js → style/modules.js} +15 -15
- package/lib/codegen/style/scopedClasses.d.ts +4 -0
- package/lib/codegen/style/scopedClasses.js +32 -0
- package/lib/codegen/template/context.d.ts +122 -17
- package/lib/codegen/template/context.js +162 -92
- package/lib/codegen/template/element.d.ts +1 -1
- package/lib/codegen/template/element.js +86 -330
- package/lib/codegen/template/elementChildren.js +0 -13
- package/lib/codegen/template/elementDirectives.js +20 -12
- package/lib/codegen/template/elementEvents.d.ts +1 -1
- package/lib/codegen/template/elementEvents.js +15 -11
- package/lib/codegen/template/elementProps.d.ts +2 -1
- package/lib/codegen/template/elementProps.js +31 -33
- package/lib/codegen/template/index.d.ts +1 -0
- package/lib/codegen/template/index.js +53 -33
- package/lib/codegen/template/interpolation.js +13 -9
- package/lib/codegen/template/slotOutlet.js +44 -21
- package/lib/codegen/template/styleScopedClasses.d.ts +3 -0
- package/lib/codegen/template/styleScopedClasses.js +146 -9
- package/lib/codegen/template/templateChild.js +69 -30
- package/lib/codegen/template/vFor.js +2 -2
- package/lib/codegen/template/vIf.js +3 -3
- package/lib/codegen/template/vSlot.d.ts +6 -0
- package/lib/codegen/template/vSlot.js +92 -0
- package/lib/codegen/utils/index.d.ts +13 -2
- package/lib/codegen/utils/index.js +33 -6
- package/lib/parsers/scriptSetupRanges.d.ts +5 -3
- package/lib/parsers/scriptSetupRanges.js +24 -35
- package/lib/parsers/vueCompilerOptions.d.ts +2 -2
- package/lib/plugins/file-md.js +3 -0
- package/lib/plugins/vue-template-inline-ts.js +56 -15
- package/lib/plugins/vue-tsx.d.ts +43 -32
- package/lib/plugins/vue-tsx.js +88 -68
- package/lib/types.d.ts +29 -16
- package/lib/utils/parseSfc.js +41 -16
- package/lib/utils/signals.d.ts +2 -0
- package/lib/utils/signals.js +54 -0
- package/lib/utils/ts.d.ts +14 -2
- package/lib/utils/ts.js +134 -88
- package/lib/virtualFile/computedEmbeddedCodes.d.ts +1 -1
- package/lib/virtualFile/computedEmbeddedCodes.js +14 -24
- package/lib/virtualFile/computedSfc.d.ts +1 -2
- package/lib/virtualFile/computedSfc.js +86 -96
- package/lib/virtualFile/computedVueSfc.d.ts +1 -2
- package/lib/virtualFile/computedVueSfc.js +7 -7
- package/lib/virtualFile/vueFile.d.ts +8 -11
- package/lib/virtualFile/vueFile.js +15 -9
- package/package.json +4 -4
- package/lib/codegen/script/styleModulesType.d.ts +0 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
|
|
2
2
|
import type { Code, Sfc } from '../../types';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
|
-
import { ScriptCodegenOptions } from './index';
|
|
4
|
+
import { type ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateScriptSetupImports(scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
6
6
|
export declare function generateScriptSetup(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
4
4
|
exports.generateScriptSetup = generateScriptSetup;
|
|
5
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const component_1 = require("./component");
|
|
7
8
|
const componentSelf_1 = require("./componentSelf");
|
|
@@ -12,7 +13,7 @@ function* generateScriptSetupImports(scriptSetup, scriptSetupRanges) {
|
|
|
12
13
|
scriptSetup.content.slice(0, Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset)),
|
|
13
14
|
'scriptSetup',
|
|
14
15
|
0,
|
|
15
|
-
|
|
16
|
+
codeFeatures_1.codeFeatures.all,
|
|
16
17
|
];
|
|
17
18
|
}
|
|
18
19
|
function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
@@ -24,22 +25,26 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
24
25
|
'',
|
|
25
26
|
'scriptSetup',
|
|
26
27
|
options.sfc.scriptSetup.content.length,
|
|
27
|
-
|
|
28
|
+
codeFeatures_1.codeFeatures.verification,
|
|
28
29
|
];
|
|
29
30
|
}
|
|
30
31
|
yield `export default `;
|
|
31
32
|
}
|
|
32
|
-
yield `(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
yield `(`;
|
|
34
|
+
if (typeof scriptSetup.generic === 'object') {
|
|
35
|
+
yield `<`;
|
|
36
|
+
yield [
|
|
37
|
+
scriptSetup.generic.text,
|
|
38
|
+
'main',
|
|
39
|
+
scriptSetup.generic.offset,
|
|
40
|
+
codeFeatures_1.codeFeatures.all,
|
|
41
|
+
];
|
|
42
|
+
if (!scriptSetup.generic.text.endsWith(`,`)) {
|
|
43
|
+
yield `,`;
|
|
44
|
+
}
|
|
45
|
+
yield `>`;
|
|
41
46
|
}
|
|
42
|
-
yield
|
|
47
|
+
yield `(${utils_1.newLine}`
|
|
43
48
|
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${utils_1.newLine}`
|
|
44
49
|
+ ` __VLS_ctx?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}` // use __VLS_Prettify for less dts code
|
|
45
50
|
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${utils_1.newLine}`
|
|
@@ -53,10 +58,10 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
53
58
|
emitTypes.push(`typeof __VLS_modelEmit`);
|
|
54
59
|
}
|
|
55
60
|
yield `return {} as {${utils_1.newLine}`
|
|
56
|
-
+ ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps &
|
|
61
|
+
+ ` props: ${ctx.localTypes.PrettifyLocal}<__VLS_OwnProps & __VLS_PublicProps & Partial<__VLS_InheritedAttrs>> & __VLS_BuiltInPublicProps,${utils_1.newLine}`
|
|
57
62
|
+ ` expose(exposed: import('${options.vueCompilerOptions.lib}').ShallowUnwrapRef<${scriptSetupRanges.defineExpose ? 'typeof __VLS_exposed' : '{}'}>): void,${utils_1.newLine}`
|
|
58
63
|
+ ` attrs: any,${utils_1.newLine}`
|
|
59
|
-
+ ` slots:
|
|
64
|
+
+ ` slots: __VLS_Slots,${utils_1.newLine}`
|
|
60
65
|
+ ` emit: ${emitTypes.length ? emitTypes.join(' & ') : `{}`},${utils_1.newLine}`
|
|
61
66
|
+ `}${utils_1.endOfLine}`;
|
|
62
67
|
yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
|
|
@@ -80,28 +85,15 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
80
85
|
let setupCodeModifies = [];
|
|
81
86
|
if (scriptSetupRanges.defineProps) {
|
|
82
87
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
83
|
-
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name,
|
|
88
|
+
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, scriptSetupRanges.withDefaults?.callExp ?? callExp, typeArg, name, `__VLS_props`, `__VLS_Props`));
|
|
84
89
|
}
|
|
85
90
|
if (scriptSetupRanges.defineEmits) {
|
|
86
91
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
|
|
87
|
-
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
92
|
+
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_emit`, `__VLS_Emit`));
|
|
88
93
|
}
|
|
89
94
|
if (scriptSetupRanges.defineSlots) {
|
|
90
|
-
const { name, callExp,
|
|
91
|
-
|
|
92
|
-
setupCodeModifies.push([
|
|
93
|
-
[`__VLS_slots;\nconst __VLS_slots = `],
|
|
94
|
-
callExp.start,
|
|
95
|
-
callExp.start,
|
|
96
|
-
]);
|
|
97
|
-
}
|
|
98
|
-
else if (!name) {
|
|
99
|
-
setupCodeModifies.push([
|
|
100
|
-
[`const __VLS_slots = `],
|
|
101
|
-
callExp.start,
|
|
102
|
-
callExp.start
|
|
103
|
-
]);
|
|
104
|
-
}
|
|
95
|
+
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
|
|
96
|
+
setupCodeModifies.push(...generateDefineWithType(scriptSetup, statement, callExp, typeArg, name, `__VLS_slots`, `__VLS_Slots`));
|
|
105
97
|
}
|
|
106
98
|
if (scriptSetupRanges.defineExpose) {
|
|
107
99
|
const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
|
|
@@ -109,7 +101,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
109
101
|
setupCodeModifies.push([
|
|
110
102
|
[
|
|
111
103
|
`let __VLS_exposed!: `,
|
|
112
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end,
|
|
104
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.navigation),
|
|
113
105
|
`${utils_1.endOfLine}`,
|
|
114
106
|
],
|
|
115
107
|
callExp.start,
|
|
@@ -120,7 +112,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
120
112
|
setupCodeModifies.push([
|
|
121
113
|
[
|
|
122
114
|
`const __VLS_exposed = `,
|
|
123
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end,
|
|
115
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.navigation),
|
|
124
116
|
`${utils_1.endOfLine}`,
|
|
125
117
|
],
|
|
126
118
|
callExp.start,
|
|
@@ -135,18 +127,19 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
135
127
|
]);
|
|
136
128
|
}
|
|
137
129
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
130
|
+
if (options.vueCompilerOptions.inferTemplateDollarAttrs) {
|
|
131
|
+
for (const { callExp } of scriptSetupRanges.useAttrs) {
|
|
132
|
+
setupCodeModifies.push([
|
|
133
|
+
[`(`],
|
|
134
|
+
callExp.start,
|
|
135
|
+
callExp.start
|
|
136
|
+
], [
|
|
137
|
+
[` as typeof __VLS_dollars.$attrs)`],
|
|
138
|
+
callExp.end,
|
|
139
|
+
callExp.end
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
150
143
|
for (const { callExp, exp, arg } of scriptSetupRanges.useCssModule) {
|
|
151
144
|
setupCodeModifies.push([
|
|
152
145
|
[`(`],
|
|
@@ -155,11 +148,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
155
148
|
], [
|
|
156
149
|
arg ? [
|
|
157
150
|
` as Omit<__VLS_StyleModules, '$style'>[`,
|
|
158
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end,
|
|
151
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
159
152
|
`])`
|
|
160
153
|
] : [
|
|
161
154
|
` as __VLS_StyleModules[`,
|
|
162
|
-
['', scriptSetup.name, exp.start,
|
|
155
|
+
['', scriptSetup.name, exp.start, codeFeatures_1.codeFeatures.verification],
|
|
163
156
|
`'$style'`,
|
|
164
157
|
['', scriptSetup.name, exp.end, utils_1.combineLastMapping],
|
|
165
158
|
`])`
|
|
@@ -169,29 +162,31 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
169
162
|
]);
|
|
170
163
|
if (arg) {
|
|
171
164
|
setupCodeModifies.push([
|
|
172
|
-
[`
|
|
165
|
+
[`__VLS_placeholder`],
|
|
173
166
|
arg.start,
|
|
174
167
|
arg.end
|
|
175
168
|
]);
|
|
176
169
|
}
|
|
177
170
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
[
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
171
|
+
if (options.vueCompilerOptions.inferTemplateDollarSlots) {
|
|
172
|
+
for (const { callExp } of scriptSetupRanges.useSlots) {
|
|
173
|
+
setupCodeModifies.push([
|
|
174
|
+
[`(`],
|
|
175
|
+
callExp.start,
|
|
176
|
+
callExp.start
|
|
177
|
+
], [
|
|
178
|
+
[` as typeof __VLS_dollars.$slots)`],
|
|
179
|
+
callExp.end,
|
|
180
|
+
callExp.end
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
188
183
|
}
|
|
189
184
|
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
|
|
190
185
|
for (const { callExp, exp, arg } of scriptSetupRanges.useTemplateRef) {
|
|
191
186
|
const templateRefType = arg
|
|
192
187
|
? [
|
|
193
|
-
`
|
|
194
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end,
|
|
188
|
+
`__VLS_TemplateRefs[`,
|
|
189
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all),
|
|
195
190
|
`]`
|
|
196
191
|
]
|
|
197
192
|
: [`unknown`];
|
|
@@ -223,7 +218,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
223
218
|
}
|
|
224
219
|
if (arg) {
|
|
225
220
|
setupCodeModifies.push([
|
|
226
|
-
[`
|
|
221
|
+
[`__VLS_placeholder`],
|
|
227
222
|
arg.start,
|
|
228
223
|
arg.end
|
|
229
224
|
]);
|
|
@@ -232,36 +227,36 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
232
227
|
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
|
|
233
228
|
let nextStart = Math.max(scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.leadingCommentEndOffset);
|
|
234
229
|
for (const [codes, start, end] of setupCodeModifies) {
|
|
235
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start,
|
|
230
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, start, codeFeatures_1.codeFeatures.all);
|
|
236
231
|
for (const code of codes) {
|
|
237
232
|
yield code;
|
|
238
233
|
}
|
|
239
234
|
nextStart = end;
|
|
240
235
|
}
|
|
241
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length,
|
|
236
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, nextStart, scriptSetup.content.length, codeFeatures_1.codeFeatures.all);
|
|
242
237
|
yield* (0, index_1.generateScriptSectionPartiallyEnding)(scriptSetup.name, scriptSetup.content.length, '#3632/scriptSetup.vue');
|
|
243
238
|
yield* generateMacros(options, ctx);
|
|
244
239
|
yield* generateDefineProp(options);
|
|
245
240
|
if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
|
|
246
241
|
// fix https://github.com/vuejs/language-tools/issues/1187
|
|
247
242
|
yield `const __VLS_withDefaultsArg = (function <T>(t: T) { return t })(`;
|
|
248
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end,
|
|
243
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
249
244
|
yield `)${utils_1.endOfLine}`;
|
|
250
245
|
}
|
|
251
246
|
yield* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges);
|
|
252
247
|
yield* generateModelEmit(scriptSetup, scriptSetupRanges);
|
|
253
|
-
yield `function __VLS_template() {${utils_1.newLine}`;
|
|
254
248
|
const templateCodegenCtx = yield* (0, template_1.generateTemplate)(options, ctx);
|
|
255
|
-
yield `}${utils_1.endOfLine}`;
|
|
256
249
|
yield* (0, componentSelf_1.generateComponentSelf)(options, ctx, templateCodegenCtx);
|
|
257
|
-
yield `type __VLS_TemplateResult = ReturnType<typeof __VLS_template>${utils_1.endOfLine}`;
|
|
258
250
|
if (syntax) {
|
|
259
|
-
if (!options.vueCompilerOptions.skipTemplateCodegen
|
|
251
|
+
if (!options.vueCompilerOptions.skipTemplateCodegen
|
|
252
|
+
&& (scriptSetupRanges.defineSlots
|
|
253
|
+
|| options.templateCodegen?.slots.length
|
|
254
|
+
|| options.templateCodegen?.dynamicSlots.length)) {
|
|
260
255
|
yield `const __VLS_component = `;
|
|
261
256
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
262
257
|
yield utils_1.endOfLine;
|
|
263
258
|
yield `${syntax} `;
|
|
264
|
-
yield `{} as ${ctx.localTypes.
|
|
259
|
+
yield `{} as ${ctx.localTypes.WithSlots}<typeof __VLS_component, __VLS_Slots>${utils_1.endOfLine}`;
|
|
265
260
|
}
|
|
266
261
|
else {
|
|
267
262
|
yield `${syntax} `;
|
|
@@ -272,6 +267,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, sy
|
|
|
272
267
|
}
|
|
273
268
|
function* generateMacros(options, ctx) {
|
|
274
269
|
if (options.vueCompilerOptions.target >= 3.3) {
|
|
270
|
+
yield `// @ts-ignore${utils_1.newLine}`;
|
|
275
271
|
yield `declare const { `;
|
|
276
272
|
for (const macro of Object.keys(options.vueCompilerOptions.macros)) {
|
|
277
273
|
if (!ctx.bindingNames.has(macro)) {
|
|
@@ -301,7 +297,7 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
|
301
297
|
if (typeArg) {
|
|
302
298
|
yield [[
|
|
303
299
|
`type ${typeName} = `,
|
|
304
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end,
|
|
300
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all),
|
|
305
301
|
utils_1.endOfLine,
|
|
306
302
|
], statement.start, statement.start];
|
|
307
303
|
yield [[typeName], typeArg.start, typeArg.end];
|
|
@@ -313,21 +309,21 @@ function* generateDefineWithType(scriptSetup, statement, callExp, typeArg, name,
|
|
|
313
309
|
else if (typeArg) {
|
|
314
310
|
yield [[
|
|
315
311
|
`const ${defaultName} = `,
|
|
316
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start,
|
|
312
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, typeArg.start, codeFeatures_1.codeFeatures.all)
|
|
317
313
|
], statement.start, typeArg.start];
|
|
318
314
|
yield [[
|
|
319
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end,
|
|
315
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.end, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
320
316
|
utils_1.endOfLine,
|
|
321
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start,
|
|
317
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
322
318
|
defaultName
|
|
323
319
|
], typeArg.end, callExp.end];
|
|
324
320
|
}
|
|
325
321
|
else {
|
|
326
322
|
yield [[
|
|
327
323
|
`const ${defaultName} = `,
|
|
328
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end,
|
|
324
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, callExp.start, callExp.end, codeFeatures_1.codeFeatures.all),
|
|
329
325
|
utils_1.endOfLine,
|
|
330
|
-
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start,
|
|
326
|
+
(0, utils_1.generateSfcBlockSection)(scriptSetup, statement.start, callExp.start, codeFeatures_1.codeFeatures.all),
|
|
331
327
|
defaultName
|
|
332
328
|
], statement.start, callExp.end];
|
|
333
329
|
}
|
|
@@ -338,7 +334,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
338
334
|
yield `const __VLS_fnComponent = (await import('${options.vueCompilerOptions.lib}')).defineComponent({${utils_1.newLine}`;
|
|
339
335
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
340
336
|
yield `props: `;
|
|
341
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end,
|
|
337
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
342
338
|
yield `,${utils_1.newLine}`;
|
|
343
339
|
}
|
|
344
340
|
yield* (0, component_1.generateEmitsOption)(options, scriptSetupRanges);
|
|
@@ -383,7 +379,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
383
379
|
yield ` & `;
|
|
384
380
|
}
|
|
385
381
|
ctx.generatedPropsType = true;
|
|
386
|
-
yield `${ctx.localTypes.PropsChildren}<
|
|
382
|
+
yield `${ctx.localTypes.PropsChildren}<__VLS_Slots>`;
|
|
387
383
|
}
|
|
388
384
|
if (scriptSetupRanges.defineProp.length) {
|
|
389
385
|
if (ctx.generatedPropsType) {
|
|
@@ -397,10 +393,10 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
397
393
|
yield propName;
|
|
398
394
|
}
|
|
399
395
|
else if (defineProp.name) {
|
|
400
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end,
|
|
396
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, codeFeatures_1.codeFeatures.navigation);
|
|
401
397
|
}
|
|
402
398
|
else if (defineProp.localName) {
|
|
403
|
-
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end,
|
|
399
|
+
yield (0, utils_1.generateSfcBlockSection)(scriptSetup, defineProp.localName.start, defineProp.localName.end, codeFeatures_1.codeFeatures.navigation);
|
|
404
400
|
}
|
|
405
401
|
else {
|
|
406
402
|
continue;
|
|
@@ -438,6 +434,9 @@ function* generateModelEmit(scriptSetup, scriptSetupRanges) {
|
|
|
438
434
|
const [propName, localName] = getPropAndLocalName(scriptSetup, defineModel);
|
|
439
435
|
yield `'update:${propName}': [value: `;
|
|
440
436
|
yield* generateDefinePropType(scriptSetup, propName, localName, defineModel);
|
|
437
|
+
if (!defineModel.required && defineModel.defaultValue === undefined) {
|
|
438
|
+
yield ` | undefined`;
|
|
439
|
+
}
|
|
441
440
|
yield `]${utils_1.endOfLine}`;
|
|
442
441
|
}
|
|
443
442
|
yield `}${utils_1.endOfLine}`;
|
|
@@ -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>;
|
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateSrc = generateSrc;
|
|
4
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
src = src.slice(0, -'.d.ts'.length);
|
|
6
|
+
function* generateSrc(src) {
|
|
7
|
+
if (src === true) {
|
|
8
|
+
return;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let { text } = src;
|
|
11
|
+
if (text.endsWith('.d.ts')) {
|
|
12
|
+
text = text.slice(0, -'.d.ts'.length);
|
|
12
13
|
}
|
|
13
|
-
else if (
|
|
14
|
-
|
|
14
|
+
else if (text.endsWith('.ts')) {
|
|
15
|
+
text = text.slice(0, -'.ts'.length);
|
|
15
16
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
17
|
+
else if (text.endsWith('.tsx')) {
|
|
18
|
+
text = text.slice(0, -'.tsx'.length) + '.jsx';
|
|
19
|
+
}
|
|
20
|
+
if (!text.endsWith('.js') && !text.endsWith('.jsx')) {
|
|
21
|
+
text = text + '.js';
|
|
18
22
|
}
|
|
19
23
|
yield `export * from `;
|
|
20
|
-
yield
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else if (script?.src?.endsWith('.tsx')) {
|
|
41
|
-
newName = newName + '.tsx';
|
|
42
|
-
}
|
|
43
|
-
return newName;
|
|
44
|
-
},
|
|
24
|
+
yield* (0, utils_1.generateSfcBlockAttrValue)(src, text, {
|
|
25
|
+
...codeFeatures_1.codeFeatures.all,
|
|
26
|
+
navigation: text === src.text
|
|
27
|
+
? true
|
|
28
|
+
: {
|
|
29
|
+
shouldRename: () => false,
|
|
30
|
+
resolveRenameEditText(newName) {
|
|
31
|
+
if (newName.endsWith('.jsx') || newName.endsWith('.js')) {
|
|
32
|
+
newName = newName.split('.').slice(0, -1).join('.');
|
|
33
|
+
}
|
|
34
|
+
if (src?.text.endsWith('.d.ts')) {
|
|
35
|
+
newName = newName + '.d.ts';
|
|
36
|
+
}
|
|
37
|
+
else if (src?.text.endsWith('.ts')) {
|
|
38
|
+
newName = newName + '.ts';
|
|
39
|
+
}
|
|
40
|
+
else if (src?.text.endsWith('.tsx')) {
|
|
41
|
+
newName = newName + '.tsx';
|
|
42
|
+
}
|
|
43
|
+
return newName;
|
|
45
44
|
},
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
},
|
|
46
|
+
});
|
|
48
47
|
yield utils_1.endOfLine;
|
|
49
|
-
yield `export { default } from '${
|
|
48
|
+
yield `export { default } from '${text}'${utils_1.endOfLine}`;
|
|
50
49
|
}
|
|
51
50
|
//# sourceMappingURL=src.js.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Code } from '../../types';
|
|
2
|
-
import { TemplateCodegenContext } from '../template/context';
|
|
2
|
+
import { type TemplateCodegenContext } from '../template/context';
|
|
3
3
|
import type { ScriptCodegenContext } from './context';
|
|
4
|
-
import {
|
|
4
|
+
import type { ScriptCodegenOptions } from './index';
|
|
5
5
|
export declare function generateTemplate(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Generator<Code, TemplateCodegenContext>;
|
|
6
6
|
export declare function generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code>;
|
|
7
|
-
export declare function generateCssClassProperty(styleIndex: number, classNameWithDot: string, offset: number, propertyType: string, optional: boolean): Generator<Code>;
|
|
8
7
|
export declare function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptCodegenContext): Set<string>;
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateTemplate = generateTemplate;
|
|
4
4
|
exports.generateTemplateDirectives = generateTemplateDirectives;
|
|
5
|
-
exports.generateCssClassProperty = generateCssClassProperty;
|
|
6
5
|
exports.getTemplateUsageVars = getTemplateUsageVars;
|
|
7
|
-
const path = require("path-browserify");
|
|
8
6
|
const shared_1 = require("../../utils/shared");
|
|
7
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
8
|
+
const modules_1 = require("../style/modules");
|
|
9
|
+
const scopedClasses_1 = require("../style/scopedClasses");
|
|
9
10
|
const context_1 = require("../template/context");
|
|
10
11
|
const interpolation_1 = require("../template/interpolation");
|
|
11
12
|
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
|
12
13
|
const utils_1 = require("../utils");
|
|
13
|
-
const index_1 = require("./index");
|
|
14
14
|
function* generateTemplate(options, ctx) {
|
|
15
15
|
ctx.generatedTemplate = true;
|
|
16
16
|
const templateCodegenCtx = (0, context_1.createTemplateCodegenContext)({
|
|
@@ -56,25 +56,11 @@ function* generateTemplateComponents(options) {
|
|
|
56
56
|
options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
|
|
57
57
|
'script',
|
|
58
58
|
componentsOption.start,
|
|
59
|
-
|
|
59
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
60
60
|
];
|
|
61
61
|
yield utils_1.endOfLine;
|
|
62
62
|
types.push(`typeof __VLS_componentsOption`);
|
|
63
63
|
}
|
|
64
|
-
let nameType;
|
|
65
|
-
if (options.sfc.script && options.scriptRanges?.exportDefault?.nameOption) {
|
|
66
|
-
const { nameOption } = options.scriptRanges.exportDefault;
|
|
67
|
-
nameType = options.sfc.script.content.slice(nameOption.start, nameOption.end);
|
|
68
|
-
}
|
|
69
|
-
else if (options.sfc.scriptSetup) {
|
|
70
|
-
const baseName = path.basename(options.fileName);
|
|
71
|
-
nameType = `'${options.scriptSetupRanges?.defineOptions?.name ?? baseName.slice(0, baseName.lastIndexOf('.'))}'`;
|
|
72
|
-
}
|
|
73
|
-
if (nameType) {
|
|
74
|
-
types.push(`{ [K in ${nameType}]: typeof __VLS_self & (new () => { `
|
|
75
|
-
+ (0, shared_1.getSlotsPropertyName)(options.vueCompilerOptions.target)
|
|
76
|
-
+ `: typeof ${options.scriptSetupRanges?.defineSlots?.name ?? `__VLS_slots`} }) }`);
|
|
77
|
-
}
|
|
78
64
|
types.push(`typeof __VLS_ctx`);
|
|
79
65
|
yield `type __VLS_LocalComponents =`;
|
|
80
66
|
for (const type of types) {
|
|
@@ -93,7 +79,7 @@ function* generateTemplateDirectives(options) {
|
|
|
93
79
|
options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
|
|
94
80
|
'script',
|
|
95
81
|
directivesOption.start,
|
|
96
|
-
|
|
82
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
97
83
|
];
|
|
98
84
|
yield utils_1.endOfLine;
|
|
99
85
|
types.push(`typeof __VLS_directivesOption`);
|
|
@@ -108,8 +94,9 @@ function* generateTemplateDirectives(options) {
|
|
|
108
94
|
yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${utils_1.endOfLine}`;
|
|
109
95
|
}
|
|
110
96
|
function* generateTemplateBody(options, templateCodegenCtx) {
|
|
111
|
-
yield* generateStyleScopedClasses(options, templateCodegenCtx);
|
|
97
|
+
yield* (0, scopedClasses_1.generateStyleScopedClasses)(options, templateCodegenCtx);
|
|
112
98
|
yield* (0, styleScopedClasses_1.generateStyleScopedClassReferences)(templateCodegenCtx, true);
|
|
99
|
+
yield* (0, modules_1.generateStyleModules)(options);
|
|
113
100
|
yield* generateCssVars(options, templateCodegenCtx);
|
|
114
101
|
if (options.templateCodegen) {
|
|
115
102
|
for (const code of options.templateCodegen.codes) {
|
|
@@ -119,66 +106,12 @@ function* generateTemplateBody(options, templateCodegenCtx) {
|
|
|
119
106
|
else {
|
|
120
107
|
yield `// no template${utils_1.newLine}`;
|
|
121
108
|
if (!options.scriptSetupRanges?.defineSlots) {
|
|
122
|
-
yield `
|
|
109
|
+
yield `type __VLS_Slots = {}${utils_1.endOfLine}`;
|
|
123
110
|
}
|
|
124
|
-
yield `
|
|
125
|
-
yield `
|
|
126
|
-
yield `
|
|
111
|
+
yield `type __VLS_InheritedAttrs = {}${utils_1.endOfLine}`;
|
|
112
|
+
yield `type __VLS_TemplateRefs = {}${utils_1.endOfLine}`;
|
|
113
|
+
yield `type __VLS_RootEl = any${utils_1.endOfLine}`;
|
|
127
114
|
}
|
|
128
|
-
yield `return {${utils_1.newLine}`;
|
|
129
|
-
yield ` attrs: {} as Partial<typeof __VLS_inheritedAttrs>,${utils_1.newLine}`;
|
|
130
|
-
yield ` slots: ${options.scriptSetupRanges?.defineSlots?.name ?? '__VLS_slots'},${utils_1.newLine}`;
|
|
131
|
-
yield ` refs: $refs,${utils_1.newLine}`;
|
|
132
|
-
yield ` rootEl: $el,${utils_1.newLine}`;
|
|
133
|
-
yield `}${utils_1.endOfLine}`;
|
|
134
|
-
}
|
|
135
|
-
function* generateStyleScopedClasses(options, ctx) {
|
|
136
|
-
const firstClasses = new Set();
|
|
137
|
-
yield `type __VLS_StyleScopedClasses = {}`;
|
|
138
|
-
for (let i = 0; i < options.sfc.styles.length; i++) {
|
|
139
|
-
const style = options.sfc.styles[i];
|
|
140
|
-
const option = options.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
141
|
-
if (option === 'always' || (option === 'scoped' && style.scoped)) {
|
|
142
|
-
for (const className of style.classNames) {
|
|
143
|
-
if (firstClasses.has(className.text)) {
|
|
144
|
-
ctx.scopedClasses.push({
|
|
145
|
-
source: 'style_' + i,
|
|
146
|
-
className: className.text.slice(1),
|
|
147
|
-
offset: className.offset + 1
|
|
148
|
-
});
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
firstClasses.add(className.text);
|
|
152
|
-
yield* generateCssClassProperty(i, className.text, className.offset, 'boolean', true);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
yield utils_1.endOfLine;
|
|
157
|
-
}
|
|
158
|
-
function* generateCssClassProperty(styleIndex, classNameWithDot, offset, propertyType, optional) {
|
|
159
|
-
yield `${utils_1.newLine} & { `;
|
|
160
|
-
yield [
|
|
161
|
-
'',
|
|
162
|
-
'style_' + styleIndex,
|
|
163
|
-
offset,
|
|
164
|
-
index_1.codeFeatures.navigation,
|
|
165
|
-
];
|
|
166
|
-
yield `'`;
|
|
167
|
-
yield [
|
|
168
|
-
classNameWithDot.slice(1),
|
|
169
|
-
'style_' + styleIndex,
|
|
170
|
-
offset + 1,
|
|
171
|
-
index_1.codeFeatures.navigation,
|
|
172
|
-
];
|
|
173
|
-
yield `'`;
|
|
174
|
-
yield [
|
|
175
|
-
'',
|
|
176
|
-
'style_' + styleIndex,
|
|
177
|
-
offset + classNameWithDot.length,
|
|
178
|
-
index_1.codeFeatures.navigationWithoutRename,
|
|
179
|
-
];
|
|
180
|
-
yield `${optional ? '?' : ''}: ${propertyType}`;
|
|
181
|
-
yield ` }`;
|
|
182
115
|
}
|
|
183
116
|
function* generateCssVars(options, ctx) {
|
|
184
117
|
if (!options.sfc.styles.length) {
|
|
@@ -187,7 +120,7 @@ function* generateCssVars(options, ctx) {
|
|
|
187
120
|
yield `// CSS variable injection ${utils_1.newLine}`;
|
|
188
121
|
for (const style of options.sfc.styles) {
|
|
189
122
|
for (const cssBind of style.cssVars) {
|
|
190
|
-
yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name,
|
|
123
|
+
yield* (0, interpolation_1.generateInterpolation)(options, ctx, style.name, codeFeatures_1.codeFeatures.all, cssBind.text, cssBind.offset);
|
|
191
124
|
yield utils_1.endOfLine;
|
|
192
125
|
}
|
|
193
126
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateClassProperty = generateClassProperty;
|
|
4
|
+
const codeFeatures_1 = require("../codeFeatures");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
function* generateClassProperty(styleIndex, classNameWithDot, offset, propertyType) {
|
|
7
|
+
yield `${utils_1.newLine} & { `;
|
|
8
|
+
yield [
|
|
9
|
+
'',
|
|
10
|
+
'style_' + styleIndex,
|
|
11
|
+
offset,
|
|
12
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
13
|
+
];
|
|
14
|
+
yield `'`;
|
|
15
|
+
yield [
|
|
16
|
+
classNameWithDot.slice(1),
|
|
17
|
+
'style_' + styleIndex,
|
|
18
|
+
offset + 1,
|
|
19
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
20
|
+
];
|
|
21
|
+
yield `'`;
|
|
22
|
+
yield [
|
|
23
|
+
'',
|
|
24
|
+
'style_' + styleIndex,
|
|
25
|
+
offset + classNameWithDot.length,
|
|
26
|
+
codeFeatures_1.codeFeatures.navigation,
|
|
27
|
+
];
|
|
28
|
+
yield `: ${propertyType}`;
|
|
29
|
+
yield ` }`;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=classProperty.js.map
|