@vue/language-core 3.2.6 → 3.2.8
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 +1 -1
- package/index.js +3 -24
- package/lib/codegen/codeFeatures.d.ts +84 -18
- package/lib/codegen/names.d.ts +73 -26
- package/lib/codegen/names.js +75 -27
- package/lib/codegen/script/component.js +19 -58
- package/lib/codegen/script/index.js +12 -12
- package/lib/codegen/script/scriptSetup.js +48 -81
- package/lib/codegen/script/template.js +29 -63
- package/lib/codegen/style/index.d.ts +7 -7
- package/lib/codegen/style/modules.js +4 -37
- package/lib/codegen/style/scopedClasses.js +2 -1
- package/lib/codegen/template/context.d.ts +7 -7
- package/lib/codegen/template/element.js +28 -25
- package/lib/codegen/template/elementDirectives.js +4 -4
- package/lib/codegen/template/elementEvents.js +3 -2
- package/lib/codegen/template/elementProps.js +3 -3
- package/lib/codegen/template/index.d.ts +7 -7
- package/lib/codegen/template/index.js +16 -49
- package/lib/codegen/template/interpolation.js +3 -36
- package/lib/codegen/template/objectProperty.js +2 -1
- package/lib/codegen/template/slotOutlet.js +5 -5
- package/lib/codegen/template/styleScopedClasses.js +3 -2
- package/lib/codegen/template/vFor.js +2 -1
- package/lib/codegen/template/vSlot.js +2 -1
- package/lib/compilerOptions.js +2 -6
- package/lib/parsers/scriptRanges.d.ts +3 -3
- package/lib/plugins/file-md.js +2 -2
- package/lib/plugins/vue-tsx.d.ts +10 -10
- package/lib/plugins/vue-tsx.js +5 -22
- package/lib/types.d.ts +1 -1
- package/lib/utils/shared.js +1 -1
- package/lib/virtualCode/embeddedCodes.js +2 -6
- package/lib/virtualCode/index.js +1 -10
- package/package.json +9 -6
- package/scripts/generate-names.js +41 -0
|
@@ -1,44 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateScriptSetupImports = generateScriptSetupImports;
|
|
37
4
|
exports.generateGeneric = generateGeneric;
|
|
38
5
|
exports.generateSetupFunction = generateSetupFunction;
|
|
39
6
|
const shared_1 = require("@vue/shared");
|
|
40
7
|
const codeFeatures_1 = require("../codeFeatures");
|
|
41
|
-
const
|
|
8
|
+
const names_1 = require("../names");
|
|
42
9
|
const utils_1 = require("../utils");
|
|
43
10
|
const boundary_1 = require("../utils/boundary");
|
|
44
11
|
const camelized_1 = require("../utils/camelized");
|
|
@@ -63,34 +30,34 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
|
|
|
63
30
|
yield `>`;
|
|
64
31
|
}
|
|
65
32
|
yield `(${utils_1.newLine}`
|
|
66
|
-
+ ` ${names.props}: NonNullable<Awaited<typeof ${names.setup}>>['props'],${utils_1.newLine}`
|
|
67
|
-
+ ` ${names.ctx}?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof ${names.setup}>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}`
|
|
68
|
-
+ ` ${names.exposed}?: NonNullable<Awaited<typeof ${names.setup}>>['expose'],${utils_1.newLine}`
|
|
69
|
-
+ ` ${names.setup} = (async () => {${utils_1.newLine}`;
|
|
33
|
+
+ ` ${names_1.names.props}: NonNullable<Awaited<typeof ${names_1.names.setup}>>['props'],${utils_1.newLine}`
|
|
34
|
+
+ ` ${names_1.names.ctx}?: ${ctx.localTypes.PrettifyLocal}<Pick<NonNullable<Awaited<typeof ${names_1.names.setup}>>, 'attrs' | 'emit' | 'slots'>>,${utils_1.newLine}`
|
|
35
|
+
+ ` ${names_1.names.exposed}?: NonNullable<Awaited<typeof ${names_1.names.setup}>>['expose'],${utils_1.newLine}`
|
|
36
|
+
+ ` ${names_1.names.setup} = (async () => {${utils_1.newLine}`;
|
|
70
37
|
yield* body;
|
|
71
38
|
const propTypes = [];
|
|
72
39
|
const emitTypes = [];
|
|
73
40
|
const { vueCompilerOptions } = options;
|
|
74
|
-
if (ctx.generatedTypes.has(names.PublicProps)) {
|
|
75
|
-
propTypes.push(names.PublicProps);
|
|
41
|
+
if (ctx.generatedTypes.has(names_1.names.PublicProps)) {
|
|
42
|
+
propTypes.push(names_1.names.PublicProps);
|
|
76
43
|
}
|
|
77
44
|
if (scriptSetupRanges.defineProps?.arg) {
|
|
78
|
-
yield `const
|
|
45
|
+
yield `const ${names_1.names.propsOption} = `;
|
|
79
46
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.defineProps.arg.start, scriptSetupRanges.defineProps.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
80
47
|
yield utils_1.endOfLine;
|
|
81
|
-
propTypes.push(`import('${vueCompilerOptions.lib}').${vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof
|
|
48
|
+
propTypes.push(`import('${vueCompilerOptions.lib}').${vueCompilerOptions.target >= 3.3 ? `ExtractPublicPropTypes` : `ExtractPropTypes`}<typeof ${names_1.names.propsOption}>`);
|
|
82
49
|
}
|
|
83
50
|
if (scriptSetupRanges.defineEmits || scriptSetupRanges.defineModel.length) {
|
|
84
|
-
propTypes.push(names.EmitProps);
|
|
51
|
+
propTypes.push(names_1.names.EmitProps);
|
|
85
52
|
}
|
|
86
|
-
if (options.templateAndStyleTypes.has(names.InheritedAttrs)) {
|
|
87
|
-
propTypes.push(names.InheritedAttrs);
|
|
53
|
+
if (options.templateAndStyleTypes.has(names_1.names.InheritedAttrs)) {
|
|
54
|
+
propTypes.push(names_1.names.InheritedAttrs);
|
|
88
55
|
}
|
|
89
56
|
if (scriptSetupRanges.defineEmits) {
|
|
90
|
-
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names.emit}`);
|
|
57
|
+
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names_1.names.emit}`);
|
|
91
58
|
}
|
|
92
59
|
if (scriptSetupRanges.defineModel.length) {
|
|
93
|
-
emitTypes.push(`typeof ${names.modelEmit}`);
|
|
60
|
+
emitTypes.push(`typeof ${names_1.names.modelEmit}`);
|
|
94
61
|
}
|
|
95
62
|
yield `return {} as {${utils_1.newLine}`;
|
|
96
63
|
yield ` props: `;
|
|
@@ -107,62 +74,62 @@ function* generateGeneric(options, ctx, scriptSetup, scriptSetupRanges, generic,
|
|
|
107
74
|
yield ` & (typeof globalThis extends { __VLS_PROPS_FALLBACK: infer P } ? P : {})${utils_1.endOfLine}`;
|
|
108
75
|
yield ` expose: (exposed: `;
|
|
109
76
|
yield scriptSetupRanges.defineExpose
|
|
110
|
-
? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names.exposed}>`
|
|
77
|
+
? `import('${vueCompilerOptions.lib}').ShallowUnwrapRef<typeof ${names_1.names.exposed}>`
|
|
111
78
|
: `{}`;
|
|
112
79
|
if (options.vueCompilerOptions.inferComponentDollarRefs
|
|
113
|
-
&& options.templateAndStyleTypes.has(names.TemplateRefs)) {
|
|
114
|
-
yield ` & { $refs: ${names.TemplateRefs}; }`;
|
|
80
|
+
&& options.templateAndStyleTypes.has(names_1.names.TemplateRefs)) {
|
|
81
|
+
yield ` & { $refs: ${names_1.names.TemplateRefs}; }`;
|
|
115
82
|
}
|
|
116
83
|
if (options.vueCompilerOptions.inferComponentDollarEl
|
|
117
|
-
&& options.templateAndStyleTypes.has(names.RootEl)) {
|
|
118
|
-
yield ` & { $el: ${names.RootEl}; }`;
|
|
84
|
+
&& options.templateAndStyleTypes.has(names_1.names.RootEl)) {
|
|
85
|
+
yield ` & { $el: ${names_1.names.RootEl}; }`;
|
|
119
86
|
}
|
|
120
87
|
yield `) => void${utils_1.endOfLine}`;
|
|
121
88
|
yield ` attrs: any${utils_1.endOfLine}`;
|
|
122
|
-
yield ` slots: ${hasSlotsType(options) ? names.Slots : `{}`}${utils_1.endOfLine}`;
|
|
89
|
+
yield ` slots: ${hasSlotsType(options) ? names_1.names.Slots : `{}`}${utils_1.endOfLine}`;
|
|
123
90
|
yield ` emit: ${emitTypes.length ? emitTypes.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
|
124
91
|
yield `}${utils_1.endOfLine}`;
|
|
125
92
|
yield `})(),${utils_1.newLine}`; // __VLS_setup = (async () => {
|
|
126
|
-
yield `) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof ${names.setup}> }))${utils_1.endOfLine}`;
|
|
93
|
+
yield `) => ({} as import('${vueCompilerOptions.lib}').VNode & { __ctx?: Awaited<typeof ${names_1.names.setup}> }))${utils_1.endOfLine}`;
|
|
127
94
|
}
|
|
128
95
|
function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, body, output) {
|
|
129
96
|
const transforms = [];
|
|
130
97
|
if (scriptSetupRanges.defineProps) {
|
|
131
98
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineProps;
|
|
132
99
|
const _callExp = scriptSetupRanges.withDefaults?.callExp ?? callExp;
|
|
133
|
-
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, _callExp, typeArg, name, names.props, names.Props));
|
|
100
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, _callExp, typeArg, name, names_1.names.props, names_1.names.Props));
|
|
134
101
|
}
|
|
135
102
|
if (scriptSetupRanges.defineEmits) {
|
|
136
103
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineEmits;
|
|
137
|
-
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.emit, names.Emit));
|
|
104
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names_1.names.emit, names_1.names.Emit));
|
|
138
105
|
}
|
|
139
106
|
if (scriptSetupRanges.defineSlots) {
|
|
140
107
|
const { name, statement, callExp, typeArg } = scriptSetupRanges.defineSlots;
|
|
141
|
-
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names.slots, names.Slots));
|
|
108
|
+
transforms.push(...generateDefineWithTypeTransforms(scriptSetup, statement, callExp, typeArg, name, names_1.names.slots, names_1.names.Slots));
|
|
142
109
|
}
|
|
143
110
|
if (scriptSetupRanges.defineExpose) {
|
|
144
111
|
const { callExp, arg, typeArg } = scriptSetupRanges.defineExpose;
|
|
145
112
|
if (typeArg) {
|
|
146
113
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
147
|
-
yield `let ${names.exposed}!: `;
|
|
114
|
+
yield `let ${names_1.names.exposed}!: `;
|
|
148
115
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, typeArg.start, typeArg.end, codeFeatures_1.codeFeatures.all);
|
|
149
116
|
yield utils_1.endOfLine;
|
|
150
117
|
}), (0, transform_1.replace)(typeArg.start, typeArg.end, function* () {
|
|
151
|
-
yield `typeof ${names.exposed}`;
|
|
118
|
+
yield `typeof ${names_1.names.exposed}`;
|
|
152
119
|
}));
|
|
153
120
|
}
|
|
154
121
|
else if (arg) {
|
|
155
122
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
156
|
-
yield `const ${names.exposed} = `;
|
|
123
|
+
yield `const ${names_1.names.exposed} = `;
|
|
157
124
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.all);
|
|
158
125
|
yield utils_1.endOfLine;
|
|
159
126
|
}), (0, transform_1.replace)(arg.start, arg.end, function* () {
|
|
160
|
-
yield
|
|
127
|
+
yield names_1.names.exposed;
|
|
161
128
|
}));
|
|
162
129
|
}
|
|
163
130
|
else {
|
|
164
131
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
165
|
-
yield `const ${names.exposed} = {}${utils_1.endOfLine}`;
|
|
132
|
+
yield `const ${names_1.names.exposed} = {}${utils_1.endOfLine}`;
|
|
166
133
|
}));
|
|
167
134
|
}
|
|
168
135
|
}
|
|
@@ -171,7 +138,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
171
138
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
172
139
|
yield `(`;
|
|
173
140
|
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
174
|
-
yield ` as typeof ${names.dollars}.$attrs)`;
|
|
141
|
+
yield ` as typeof ${names_1.names.dollars}.$attrs)`;
|
|
175
142
|
}));
|
|
176
143
|
}
|
|
177
144
|
}
|
|
@@ -179,8 +146,8 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
179
146
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
180
147
|
yield `(`;
|
|
181
148
|
}));
|
|
182
|
-
const type = options.templateAndStyleTypes.has(names.StyleModules)
|
|
183
|
-
? names.StyleModules
|
|
149
|
+
const type = options.templateAndStyleTypes.has(names_1.names.StyleModules)
|
|
150
|
+
? names_1.names.StyleModules
|
|
184
151
|
: `{}`;
|
|
185
152
|
if (arg) {
|
|
186
153
|
transforms.push((0, transform_1.insert)(callExp.end, function* () {
|
|
@@ -206,7 +173,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
206
173
|
transforms.push((0, transform_1.insert)(callExp.start, function* () {
|
|
207
174
|
yield `(`;
|
|
208
175
|
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
209
|
-
yield ` as typeof ${names.dollars}.$slots)`;
|
|
176
|
+
yield ` as typeof ${names_1.names.dollars}.$slots)`;
|
|
210
177
|
}));
|
|
211
178
|
}
|
|
212
179
|
}
|
|
@@ -216,7 +183,7 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
216
183
|
}), (0, transform_1.insert)(callExp.end, function* () {
|
|
217
184
|
yield ` as Readonly<import('${options.vueCompilerOptions.lib}').ShallowRef<`;
|
|
218
185
|
if (arg) {
|
|
219
|
-
yield names.TemplateRefs;
|
|
186
|
+
yield names_1.names.TemplateRefs;
|
|
220
187
|
yield `[`;
|
|
221
188
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, codeFeatures_1.codeFeatures.withoutSemantic);
|
|
222
189
|
yield `]`;
|
|
@@ -239,11 +206,11 @@ function* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, bo
|
|
|
239
206
|
yield* body;
|
|
240
207
|
if (output) {
|
|
241
208
|
if (hasSlotsType(options)) {
|
|
242
|
-
yield `const
|
|
209
|
+
yield `const ${names_1.names.base} = `;
|
|
243
210
|
yield* (0, component_1.generateComponent)(options, ctx, scriptSetup, scriptSetupRanges);
|
|
244
211
|
yield utils_1.endOfLine;
|
|
245
212
|
yield* output;
|
|
246
|
-
yield `{} as ${ctx.localTypes.WithSlots}<typeof
|
|
213
|
+
yield `{} as ${ctx.localTypes.WithSlots}<typeof ${names_1.names.base}, ${names_1.names.Slots}>${utils_1.endOfLine}`;
|
|
247
214
|
}
|
|
248
215
|
else {
|
|
249
216
|
yield* output;
|
|
@@ -316,28 +283,28 @@ function* generateDefineWithTypeTransforms(scriptSetup, statement, callExp, type
|
|
|
316
283
|
}
|
|
317
284
|
function* generatePublicProps(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
318
285
|
if (scriptSetupRanges.defineProps?.typeArg && scriptSetupRanges.withDefaults?.arg) {
|
|
319
|
-
yield `const ${names.defaults} = `;
|
|
286
|
+
yield `const ${names_1.names.defaults} = `;
|
|
320
287
|
yield* (0, utils_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.withDefaults.arg.start, scriptSetupRanges.withDefaults.arg.end, codeFeatures_1.codeFeatures.navigation);
|
|
321
288
|
yield utils_1.endOfLine;
|
|
322
289
|
}
|
|
323
290
|
const propTypes = [];
|
|
324
291
|
if (options.vueCompilerOptions.jsxSlots && hasSlotsType(options)) {
|
|
325
|
-
propTypes.push(`${ctx.localTypes.PropsChildren}<${names.Slots}>`);
|
|
292
|
+
propTypes.push(`${ctx.localTypes.PropsChildren}<${names_1.names.Slots}>`);
|
|
326
293
|
}
|
|
327
294
|
if (scriptSetupRanges.defineProps?.typeArg) {
|
|
328
|
-
propTypes.push(names.Props);
|
|
295
|
+
propTypes.push(names_1.names.Props);
|
|
329
296
|
}
|
|
330
297
|
if (scriptSetupRanges.defineModel.length) {
|
|
331
|
-
propTypes.push(names.ModelProps);
|
|
298
|
+
propTypes.push(names_1.names.ModelProps);
|
|
332
299
|
}
|
|
333
300
|
if (propTypes.length) {
|
|
334
|
-
yield `type ${names.PublicProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
|
|
335
|
-
ctx.generatedTypes.add(names.PublicProps);
|
|
301
|
+
yield `type ${names_1.names.PublicProps} = ${propTypes.join(` & `)}${utils_1.endOfLine}`;
|
|
302
|
+
ctx.generatedTypes.add(names_1.names.PublicProps);
|
|
336
303
|
}
|
|
337
304
|
}
|
|
338
305
|
function hasSlotsType(options) {
|
|
339
306
|
return !!(options.scriptSetupRanges?.defineSlots
|
|
340
|
-
|| options.templateAndStyleTypes.has(names.Slots));
|
|
307
|
+
|| options.templateAndStyleTypes.has(names_1.names.Slots));
|
|
341
308
|
}
|
|
342
309
|
function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
343
310
|
if (!scriptSetupRanges.defineModel.length) {
|
|
@@ -361,7 +328,7 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
|
361
328
|
}
|
|
362
329
|
else if (defineModel.defaultValue && propName) {
|
|
363
330
|
// Infer from defineModel({ default: T })
|
|
364
|
-
modelType = `typeof ${names.defaultModels}['${propName}']`;
|
|
331
|
+
modelType = `typeof ${names_1.names.defaultModels}['${propName}']`;
|
|
365
332
|
}
|
|
366
333
|
else {
|
|
367
334
|
modelType = `any`;
|
|
@@ -373,22 +340,22 @@ function* generateModels(scriptSetup, scriptSetupRanges) {
|
|
|
373
340
|
emitCodes.push(generateModelEmit(defineModel, propName, modelType));
|
|
374
341
|
}
|
|
375
342
|
if (defaultCodes.length) {
|
|
376
|
-
yield `const ${names.defaultModels} = {${utils_1.newLine}`;
|
|
343
|
+
yield `const ${names_1.names.defaultModels} = {${utils_1.newLine}`;
|
|
377
344
|
yield* defaultCodes;
|
|
378
345
|
yield `}${utils_1.endOfLine}`;
|
|
379
346
|
}
|
|
380
|
-
yield `type ${names.ModelProps} = {${utils_1.newLine}`;
|
|
347
|
+
yield `type ${names_1.names.ModelProps} = {${utils_1.newLine}`;
|
|
381
348
|
for (const codes of propCodes) {
|
|
382
349
|
yield* codes;
|
|
383
350
|
}
|
|
384
351
|
yield `}${utils_1.endOfLine}`;
|
|
385
|
-
yield `type ${names.ModelEmit} = {${utils_1.newLine}`;
|
|
352
|
+
yield `type ${names_1.names.ModelEmit} = {${utils_1.newLine}`;
|
|
386
353
|
for (const codes of emitCodes) {
|
|
387
354
|
yield* codes;
|
|
388
355
|
}
|
|
389
356
|
yield `}${utils_1.endOfLine}`;
|
|
390
357
|
// avoid `defineModel<...>()` to prevent JS AST issues
|
|
391
|
-
yield `let ${names.modelEmit}!:
|
|
358
|
+
yield `let ${names_1.names.modelEmit}!: ${names_1.names.ShortEmits}<${names_1.names.ModelEmit}>${utils_1.endOfLine}`;
|
|
392
359
|
}
|
|
393
360
|
function* generateModelProp(scriptSetup, defineModel, propName, modelType) {
|
|
394
361
|
if (defineModel.comments) {
|
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateTemplate = generateTemplate;
|
|
37
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
38
|
-
const
|
|
5
|
+
const names_1 = require("../names");
|
|
39
6
|
const utils_1 = require("../utils");
|
|
40
7
|
const merge_1 = require("../utils/merge");
|
|
41
8
|
function* generateTemplate(options, ctx, selfType) {
|
|
@@ -55,87 +22,86 @@ function* generateTemplateCtx({ vueCompilerOptions, templateAndStyleTypes, scrip
|
|
|
55
22
|
exps.push([`globalThis`]);
|
|
56
23
|
}
|
|
57
24
|
if (selfType) {
|
|
58
|
-
exps.push([`{} as InstanceType<
|
|
25
|
+
exps.push([`{} as InstanceType<${names_1.names.PickNotAny}<typeof ${selfType}, new () => {}>>`]);
|
|
59
26
|
}
|
|
60
27
|
else {
|
|
61
28
|
exps.push([`{} as import('${vueCompilerOptions.lib}').ComponentPublicInstance`]);
|
|
62
29
|
}
|
|
63
|
-
if (templateAndStyleTypes.has(names.StyleModules)) {
|
|
64
|
-
exps.push([`{} as ${names.StyleModules}`]);
|
|
30
|
+
if (templateAndStyleTypes.has(names_1.names.StyleModules)) {
|
|
31
|
+
exps.push([`{} as ${names_1.names.StyleModules}`]);
|
|
65
32
|
}
|
|
66
33
|
if (scriptSetupRanges?.defineEmits) {
|
|
67
|
-
|
|
68
|
-
emitTypes.push(`typeof ${defineEmits.name ?? names.emit}`);
|
|
34
|
+
emitTypes.push(`typeof ${scriptSetupRanges.defineEmits.name ?? names_1.names.emit}`);
|
|
69
35
|
}
|
|
70
36
|
if (scriptSetupRanges?.defineModel.length) {
|
|
71
|
-
emitTypes.push(`typeof ${names.modelEmit}`);
|
|
37
|
+
emitTypes.push(`typeof ${names_1.names.modelEmit}`);
|
|
72
38
|
}
|
|
73
39
|
if (emitTypes.length) {
|
|
74
|
-
yield `type ${names.EmitProps} =
|
|
40
|
+
yield `type ${names_1.names.EmitProps} = ${names_1.names.EmitsToProps}<${names_1.names.NormalizeEmits}<${emitTypes.join(` & `)}>>${utils_1.endOfLine}`;
|
|
75
41
|
exps.push([`{} as { $emit: ${emitTypes.join(` & `)} }`]);
|
|
76
42
|
}
|
|
77
43
|
if (scriptSetupRanges?.defineProps) {
|
|
78
|
-
propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names.props}`);
|
|
44
|
+
propTypes.push(`typeof ${scriptSetupRanges.defineProps.name ?? names_1.names.props}`);
|
|
79
45
|
}
|
|
80
46
|
if (scriptSetupRanges?.defineModel.length) {
|
|
81
|
-
propTypes.push(names.ModelProps);
|
|
47
|
+
propTypes.push(names_1.names.ModelProps);
|
|
82
48
|
}
|
|
83
49
|
if (emitTypes.length) {
|
|
84
|
-
propTypes.push(names.EmitProps);
|
|
50
|
+
propTypes.push(names_1.names.EmitProps);
|
|
85
51
|
}
|
|
86
52
|
if (propTypes.length) {
|
|
87
53
|
exps.push([`{} as { $props: ${propTypes.join(` & `)} }`]);
|
|
88
54
|
exps.push([`{} as ${propTypes.join(` & `)}`]);
|
|
89
55
|
}
|
|
90
|
-
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
|
91
|
-
exps.push([`{} as ${names.SetupExposed}`]);
|
|
56
|
+
if (ctx.generatedTypes.has(names_1.names.SetupExposed)) {
|
|
57
|
+
exps.push([`{} as ${names_1.names.SetupExposed}`]);
|
|
92
58
|
}
|
|
93
|
-
yield `const ${names.ctx} = `;
|
|
59
|
+
yield `const ${names_1.names.ctx} = `;
|
|
94
60
|
yield* (0, merge_1.generateSpreadMerge)(exps);
|
|
95
61
|
yield utils_1.endOfLine;
|
|
96
62
|
}
|
|
97
63
|
function* generateTemplateComponents({ vueCompilerOptions, script, scriptRanges }, ctx) {
|
|
98
64
|
const types = [];
|
|
99
|
-
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
|
100
|
-
types.push(names.SetupExposed);
|
|
65
|
+
if (ctx.generatedTypes.has(names_1.names.SetupExposed)) {
|
|
66
|
+
types.push(names_1.names.SetupExposed);
|
|
101
67
|
}
|
|
102
68
|
if (script && scriptRanges?.exportDefault?.options?.components) {
|
|
103
69
|
const { components } = scriptRanges.exportDefault.options;
|
|
104
|
-
yield `const
|
|
70
|
+
yield `const ${names_1.names.componentsOption} = `;
|
|
105
71
|
yield* (0, utils_1.generateSfcBlockSection)(script, components.start, components.end, codeFeatures_1.codeFeatures.navigation);
|
|
106
72
|
yield utils_1.endOfLine;
|
|
107
|
-
types.push(`typeof
|
|
73
|
+
types.push(`typeof ${names_1.names.componentsOption}`);
|
|
108
74
|
}
|
|
109
|
-
yield `type
|
|
110
|
-
yield `type
|
|
75
|
+
yield `type ${names_1.names.LocalComponents} = ${types.length ? types.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
|
76
|
+
yield `type ${names_1.names.GlobalComponents} = ${vueCompilerOptions.target >= 3.5
|
|
111
77
|
? `import('${vueCompilerOptions.lib}').GlobalComponents`
|
|
112
78
|
: `import('${vueCompilerOptions.lib}').GlobalComponents & Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>`}${utils_1.endOfLine}`;
|
|
113
|
-
yield `let ${names.components}!:
|
|
114
|
-
yield `let ${names.intrinsics}!: ${vueCompilerOptions.target >= 3.3
|
|
79
|
+
yield `let ${names_1.names.components}!: ${names_1.names.LocalComponents} & ${names_1.names.GlobalComponents}${utils_1.endOfLine}`;
|
|
80
|
+
yield `let ${names_1.names.intrinsics}!: ${vueCompilerOptions.target >= 3.3
|
|
115
81
|
? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.IntrinsicElements`
|
|
116
82
|
: `globalThis.JSX.IntrinsicElements`}${utils_1.endOfLine}`;
|
|
117
83
|
}
|
|
118
84
|
function* generateTemplateDirectives({ vueCompilerOptions, script, scriptRanges }, ctx) {
|
|
119
85
|
const types = [];
|
|
120
|
-
if (ctx.generatedTypes.has(names.SetupExposed)) {
|
|
121
|
-
types.push(names.SetupExposed);
|
|
86
|
+
if (ctx.generatedTypes.has(names_1.names.SetupExposed)) {
|
|
87
|
+
types.push(names_1.names.SetupExposed);
|
|
122
88
|
}
|
|
123
89
|
if (script && scriptRanges?.exportDefault?.options?.directives) {
|
|
124
90
|
const { directives } = scriptRanges.exportDefault.options;
|
|
125
|
-
yield `const
|
|
91
|
+
yield `const ${names_1.names.directivesOption} = `;
|
|
126
92
|
yield* (0, utils_1.generateSfcBlockSection)(script, directives.start, directives.end, codeFeatures_1.codeFeatures.navigation);
|
|
127
93
|
yield utils_1.endOfLine;
|
|
128
|
-
types.push(
|
|
94
|
+
types.push(`${names_1.names.ResolveDirectives}<typeof ${names_1.names.directivesOption}>`);
|
|
129
95
|
}
|
|
130
|
-
yield `type
|
|
131
|
-
yield `let ${names.directives}!:
|
|
96
|
+
yield `type ${names_1.names.LocalDirectives} = ${types.length ? types.join(` & `) : `{}`}${utils_1.endOfLine}`;
|
|
97
|
+
yield `let ${names_1.names.directives}!: ${names_1.names.LocalDirectives} & import('${vueCompilerOptions.lib}').GlobalDirectives${utils_1.endOfLine}`;
|
|
132
98
|
}
|
|
133
99
|
function* generateSetupExposed({ vueCompilerOptions, exposed }, ctx) {
|
|
134
100
|
if (!exposed.size) {
|
|
135
101
|
return;
|
|
136
102
|
}
|
|
137
|
-
ctx.generatedTypes.add(names.SetupExposed);
|
|
138
|
-
yield `type ${names.SetupExposed} = import('${vueCompilerOptions.lib}').ShallowUnwrapRef<{${utils_1.newLine}`;
|
|
103
|
+
ctx.generatedTypes.add(names_1.names.SetupExposed);
|
|
104
|
+
yield `type ${names_1.names.SetupExposed} = import('${vueCompilerOptions.lib}').ShallowUnwrapRef<{${utils_1.newLine}`;
|
|
139
105
|
for (const bindingName of exposed) {
|
|
140
106
|
const token = Symbol(bindingName.length);
|
|
141
107
|
yield ['', undefined, 0, { __linkedToken: token }];
|
|
@@ -10,21 +10,21 @@ export { generate as generateStyle };
|
|
|
10
10
|
declare function generate(options: StyleCodegenOptions): {
|
|
11
11
|
generatedTypes: Set<string>;
|
|
12
12
|
currentInfo: {
|
|
13
|
-
ignoreError?: boolean
|
|
13
|
+
ignoreError?: boolean;
|
|
14
14
|
expectError?: {
|
|
15
15
|
token: number;
|
|
16
16
|
node: import("@vue/compiler-dom").CommentNode;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
generic?: {
|
|
19
19
|
content: string;
|
|
20
20
|
offset: number;
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
};
|
|
23
23
|
resolveCodeFeatures: (features: import("../../types").VueCodeInformation) => import("../../types").VueCodeInformation;
|
|
24
24
|
inVFor: boolean;
|
|
25
25
|
slots: {
|
|
26
26
|
name: string;
|
|
27
|
-
offset?: number
|
|
27
|
+
offset?: number;
|
|
28
28
|
tagRange: [number, number];
|
|
29
29
|
nodeLoc: any;
|
|
30
30
|
propsVar: string;
|
|
@@ -45,7 +45,7 @@ declare function generate(options: StyleCodegenOptions): {
|
|
|
45
45
|
singleRootElTypes: Set<string>;
|
|
46
46
|
singleRootNodes: Set<import("@vue/compiler-dom").ElementNode | null>;
|
|
47
47
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
48
|
-
recordComponentAccess(source: string, name: string, offset?: number
|
|
48
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
49
49
|
scopes: Set<string>[];
|
|
50
50
|
components: (() => string)[];
|
|
51
51
|
declare(...varNames: string[]): void;
|
|
@@ -54,7 +54,7 @@ declare function generate(options: StyleCodegenOptions): {
|
|
|
54
54
|
getHoistVariable(originalVar: string): string;
|
|
55
55
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
56
56
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
57
|
-
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").
|
|
58
|
-
exit(): Generator<Code
|
|
57
|
+
enter(node: import("@vue/compiler-dom").RootNode | import("@vue/compiler-dom").TemplateChildNode | import("@vue/compiler-dom").SimpleExpressionNode): boolean;
|
|
58
|
+
exit(): Generator<Code>;
|
|
59
59
|
codes: Code[];
|
|
60
60
|
};
|
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.generateStyleModules = generateStyleModules;
|
|
37
4
|
const codeFeatures_1 = require("../codeFeatures");
|
|
38
|
-
const
|
|
5
|
+
const names_1 = require("../names");
|
|
39
6
|
const utils_1 = require("../utils");
|
|
40
7
|
const common_1 = require("./common");
|
|
41
8
|
function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
|
|
@@ -43,8 +10,8 @@ function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
|
|
|
43
10
|
if (!styleModules.length) {
|
|
44
11
|
return;
|
|
45
12
|
}
|
|
46
|
-
ctx.generatedTypes.add(names.StyleModules);
|
|
47
|
-
yield `type ${names.StyleModules} = {${utils_1.newLine}`;
|
|
13
|
+
ctx.generatedTypes.add(names_1.names.StyleModules);
|
|
14
|
+
yield `type ${names_1.names.StyleModules} = {${utils_1.newLine}`;
|
|
48
15
|
for (const style of styleModules) {
|
|
49
16
|
if (style.module === true) {
|
|
50
17
|
yield `$style`;
|
|
@@ -62,7 +29,7 @@ function* generateStyleModules({ styles, vueCompilerOptions }, ctx) {
|
|
|
62
29
|
if (!vueCompilerOptions.strictCssModules) {
|
|
63
30
|
yield `Record<string, string> & `;
|
|
64
31
|
}
|
|
65
|
-
yield
|
|
32
|
+
yield `${names_1.names.PrettifyGlobal}<{}`;
|
|
66
33
|
if (vueCompilerOptions.resolveStyleImports) {
|
|
67
34
|
yield* (0, common_1.generateStyleImports)(style);
|
|
68
35
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateStyleScopedClasses = generateStyleScopedClasses;
|
|
4
|
+
const names_1 = require("../names");
|
|
4
5
|
const styleScopedClasses_1 = require("../template/styleScopedClasses");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
7
|
const common_1 = require("./common");
|
|
@@ -15,7 +16,7 @@ function* generateStyleScopedClasses({ vueCompilerOptions, styles }) {
|
|
|
15
16
|
}
|
|
16
17
|
const visited = new Set();
|
|
17
18
|
const deferredGenerations = [];
|
|
18
|
-
yield `type
|
|
19
|
+
yield `type ${names_1.names.StyleScopedClasses} = {}`;
|
|
19
20
|
for (const style of scopedStyles) {
|
|
20
21
|
if (resolveStyleImports) {
|
|
21
22
|
yield* (0, common_1.generateStyleImports)(style);
|
|
@@ -102,21 +102,21 @@ export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenCont
|
|
|
102
102
|
export declare function createTemplateCodegenContext(): {
|
|
103
103
|
generatedTypes: Set<string>;
|
|
104
104
|
readonly currentInfo: {
|
|
105
|
-
ignoreError?: boolean
|
|
105
|
+
ignoreError?: boolean;
|
|
106
106
|
expectError?: {
|
|
107
107
|
token: number;
|
|
108
108
|
node: CompilerDOM.CommentNode;
|
|
109
|
-
}
|
|
109
|
+
};
|
|
110
110
|
generic?: {
|
|
111
111
|
content: string;
|
|
112
112
|
offset: number;
|
|
113
|
-
}
|
|
113
|
+
};
|
|
114
114
|
};
|
|
115
115
|
resolveCodeFeatures: (features: VueCodeInformation) => VueCodeInformation;
|
|
116
116
|
inVFor: boolean;
|
|
117
117
|
slots: {
|
|
118
118
|
name: string;
|
|
119
|
-
offset?: number
|
|
119
|
+
offset?: number;
|
|
120
120
|
tagRange: [number, number];
|
|
121
121
|
nodeLoc: any;
|
|
122
122
|
propsVar: string;
|
|
@@ -137,7 +137,7 @@ export declare function createTemplateCodegenContext(): {
|
|
|
137
137
|
singleRootElTypes: Set<string>;
|
|
138
138
|
singleRootNodes: Set<CompilerDOM.ElementNode | null>;
|
|
139
139
|
addTemplateRef(name: string, typeExp: string, offset: number): void;
|
|
140
|
-
recordComponentAccess(source: string, name: string, offset?: number
|
|
140
|
+
recordComponentAccess(source: string, name: string, offset?: number): void;
|
|
141
141
|
scopes: Set<string>[];
|
|
142
142
|
components: (() => string)[];
|
|
143
143
|
declare(...varNames: string[]): void;
|
|
@@ -146,6 +146,6 @@ export declare function createTemplateCodegenContext(): {
|
|
|
146
146
|
getHoistVariable(originalVar: string): string;
|
|
147
147
|
generateHoistVariables(): Generator<string, void, unknown>;
|
|
148
148
|
generateConditionGuards(): Generator<string, void, unknown>;
|
|
149
|
-
enter(node: CompilerDOM.RootNode | CompilerDOM.
|
|
150
|
-
exit(): Generator<Code
|
|
149
|
+
enter(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.SimpleExpressionNode): boolean;
|
|
150
|
+
exit(): Generator<Code>;
|
|
151
151
|
};
|