@vue/language-core 2.0.26-alpha.2 → 2.0.28
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 +1 -1
- package/lib/codegen/script/component.d.ts +2 -0
- package/lib/codegen/script/component.js +57 -41
- package/lib/codegen/script/globalTypes.js +4 -9
- package/lib/codegen/script/index.js +11 -1
- package/lib/codegen/script/scriptSetup.js +52 -32
- package/lib/codegen/template/element.js +25 -26
- package/lib/codegen/template/elementChildren.js +1 -1
- package/lib/codegen/template/elementEvents.js +10 -1
- package/lib/codegen/template/elementProps.js +1 -1
- package/lib/codegen/template/objectKey.d.ts +1 -0
- package/lib/codegen/template/objectKey.js +34 -0
- package/lib/languageModule.js +8 -7
- package/lib/languagePlugin.d.ts +8 -0
- package/lib/languagePlugin.js +175 -0
- package/lib/parsers/scriptSetupRanges.d.ts +3 -1
- package/lib/parsers/scriptSetupRanges.js +8 -0
- package/lib/plugins/file-dot-setup.d.ts +3 -0
- package/lib/plugins/file-dot-setup.js +34 -0
- package/lib/plugins/file-html.js +14 -3
- package/lib/plugins/file-md.js +14 -3
- package/lib/plugins/file-vue.js +14 -3
- package/lib/plugins/vue-script-js.js +1 -1
- package/lib/plugins/vue-sfc-customblocks.js +1 -1
- package/lib/plugins/vue-sfc-scripts.js +1 -1
- package/lib/plugins/vue-sfc-styles.js +1 -1
- package/lib/plugins/vue-sfc-template.js +1 -1
- package/lib/plugins/vue-template-html.js +1 -1
- package/lib/plugins/vue-template-inline-css.js +1 -1
- package/lib/plugins/vue-template-inline-ts.js +1 -1
- package/lib/plugins/vue-tsx.d.ts +3 -1
- package/lib/plugins/vue-tsx.js +1 -1
- package/lib/plugins.d.ts +2 -26
- package/lib/plugins.js +24 -10
- package/lib/types.d.ts +15 -11
- package/lib/types.js +2 -2
- package/lib/utils/ts.js +7 -20
- package/lib/virtualFile/computedFiles.d.ts +2 -2
- package/lib/virtualFile/computedSfc.d.ts +2 -2
- package/lib/virtualFile/computedVueSfc.d.ts +2 -2
- package/lib/virtualFile/computedVueSfc.js +3 -2
- package/lib/virtualFile/vueFile.d.ts +3 -3
- package/lib/virtualFile/vueFile.js +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.tsCodegen = exports.scriptRanges = void 0;
|
|
18
18
|
__exportStar(require("./lib/codegen/template"), exports);
|
|
19
|
-
__exportStar(require("./lib/
|
|
19
|
+
__exportStar(require("./lib/languagePlugin"), exports);
|
|
20
20
|
__exportStar(require("./lib/parsers/scriptSetupRanges"), exports);
|
|
21
21
|
__exportStar(require("./lib/plugins"), exports);
|
|
22
22
|
__exportStar(require("./lib/virtualFile/vueFile"), exports);
|
|
@@ -7,3 +7,5 @@ export declare function generateComponent(options: ScriptCodegenOptions, ctx: Sc
|
|
|
7
7
|
export declare function generateComponentSetupReturns(scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
8
8
|
export declare function generateScriptOptions(script: NonNullable<Sfc['script']>, scriptRanges: ScriptRanges): Generator<Code>;
|
|
9
9
|
export declare function generateScriptSetupOptions(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
10
|
+
export declare function generatePropsOption(options: ScriptCodegenOptions, ctx: ScriptCodegenContext, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code, void, unknown>;
|
|
11
|
+
export declare function generateEmitsOption(options: ScriptCodegenOptions, scriptSetup: NonNullable<Sfc['scriptSetup']>, scriptSetupRanges: ScriptSetupRanges): Generator<Code>;
|
|
@@ -4,6 +4,8 @@ exports.generateComponent = generateComponent;
|
|
|
4
4
|
exports.generateComponentSetupReturns = generateComponentSetupReturns;
|
|
5
5
|
exports.generateScriptOptions = generateScriptOptions;
|
|
6
6
|
exports.generateScriptSetupOptions = generateScriptSetupOptions;
|
|
7
|
+
exports.generatePropsOption = generatePropsOption;
|
|
8
|
+
exports.generateEmitsOption = generateEmitsOption;
|
|
7
9
|
const common_1 = require("../common");
|
|
8
10
|
const index_1 = require("./index");
|
|
9
11
|
function* generateComponent(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
@@ -51,58 +53,72 @@ function* generateScriptOptions(script, scriptRanges) {
|
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
function* generateScriptSetupOptions(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
yield `${ctx.helperTypes.TypePropsToOption.name}<`;
|
|
62
|
-
yield `__VLS_PublicProps>`;
|
|
63
|
-
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
64
|
-
yield `, typeof __VLS_withDefaultsArg>`;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (scriptSetupRanges.props.define?.arg) {
|
|
69
|
-
const { arg } = scriptSetupRanges.props.define;
|
|
70
|
-
propsCodegens.push(function* () {
|
|
71
|
-
yield (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation);
|
|
72
|
-
});
|
|
56
|
+
yield* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges);
|
|
57
|
+
yield* generateEmitsOption(options, scriptSetup, scriptSetupRanges);
|
|
58
|
+
}
|
|
59
|
+
function* generatePropsOption(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
60
|
+
if (options.vueCompilerOptions.target >= 3.5 && ctx.generatedPropsType) {
|
|
61
|
+
yield `__typeProps: {} as __VLS_PublicProps,${common_1.newLine}`;
|
|
73
62
|
}
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
if (options.vueCompilerOptions.target < 3.5 || !ctx.generatedPropsType || scriptSetupRanges.props.withDefaults) {
|
|
64
|
+
const codegens = [];
|
|
65
|
+
if (ctx.generatedPropsType) {
|
|
66
|
+
codegens.push(function* () {
|
|
67
|
+
yield `{} as `;
|
|
68
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
69
|
+
yield `${ctx.helperTypes.WithDefaults.name}<`;
|
|
70
|
+
}
|
|
71
|
+
yield `${ctx.helperTypes.TypePropsToOption.name}<`;
|
|
72
|
+
yield `__VLS_PublicProps>`;
|
|
73
|
+
if (scriptSetupRanges.props.withDefaults?.arg) {
|
|
74
|
+
yield `, typeof __VLS_withDefaultsArg>`;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
if (scriptSetupRanges.props.define?.arg) {
|
|
79
|
+
const { arg } = scriptSetupRanges.props.define;
|
|
80
|
+
codegens.push(function* () {
|
|
81
|
+
yield (0, common_1.generateSfcBlockSection)(scriptSetup, arg.start, arg.end, index_1.codeFeatures.navigation);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (codegens.length === 1) {
|
|
85
|
+
yield `props: `;
|
|
86
|
+
for (const generate of codegens) {
|
|
87
|
+
yield* generate();
|
|
88
|
+
}
|
|
86
89
|
yield `,${common_1.newLine}`;
|
|
87
90
|
}
|
|
88
|
-
|
|
91
|
+
else if (codegens.length >= 2) {
|
|
92
|
+
yield `props: {${common_1.newLine}`;
|
|
93
|
+
for (const generate of codegens) {
|
|
94
|
+
yield `...`;
|
|
95
|
+
yield* generate();
|
|
96
|
+
yield `,${common_1.newLine}`;
|
|
97
|
+
}
|
|
98
|
+
yield `},${common_1.newLine}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function* generateEmitsOption(options, scriptSetup, scriptSetupRanges) {
|
|
103
|
+
if (!scriptSetupRanges.emits.define && !scriptSetupRanges.defineProp.some(p => p.isModel)) {
|
|
104
|
+
return;
|
|
89
105
|
}
|
|
90
|
-
if (
|
|
91
|
-
yield `emits: ({} as __VLS_NormalizeEmits<
|
|
92
|
-
if (scriptSetupRanges
|
|
106
|
+
if (options.vueCompilerOptions.target < 3.5 || scriptSetupRanges.emits.define?.arg || scriptSetupRanges.emits.define?.hasUnionTypeArg) {
|
|
107
|
+
yield `emits: ({} as __VLS_NormalizeEmits<__VLS_ModelEmitsType`;
|
|
108
|
+
if (scriptSetupRanges?.emits.define) {
|
|
93
109
|
yield ` & typeof `;
|
|
94
110
|
yield scriptSetupRanges.emits.name ?? '__VLS_emit';
|
|
95
111
|
}
|
|
96
112
|
yield `>),${common_1.newLine}`;
|
|
97
113
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
yield `__typeEmits: ${scriptSetupRanges.emits.name ?? '__VLS_emit'},${common_1.newLine}`;
|
|
114
|
+
else {
|
|
115
|
+
yield `__typeEmits: {} as __VLS_ModelEmitsType`;
|
|
116
|
+
const typeArg = scriptSetupRanges.emits.define?.typeArg;
|
|
117
|
+
if (typeArg) {
|
|
118
|
+
yield ` & `;
|
|
119
|
+
yield scriptSetup.content.slice(typeArg.start, typeArg.end);
|
|
105
120
|
}
|
|
121
|
+
yield `,${common_1.newLine}`;
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
124
|
//# sourceMappingURL=component.js.map
|
|
@@ -15,15 +15,9 @@ declare global {
|
|
|
15
15
|
type __VLS_Element = ${vueCompilerOptions.target >= 3.3
|
|
16
16
|
? `import('${vueCompilerOptions.lib}/jsx-runtime').JSX.Element;`
|
|
17
17
|
: `globalThis.JSX.Element;`}
|
|
18
|
-
type __VLS_GlobalComponents =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
? `import('${vueCompilerOptions.lib}').PublicProps;`
|
|
22
|
-
: vueCompilerOptions.target >= 3.0
|
|
23
|
-
? `import('${vueCompilerOptions.lib}').VNodeProps
|
|
24
|
-
& import('${vueCompilerOptions.lib}').AllowedComponentProps
|
|
25
|
-
& import('${vueCompilerOptions.lib}').ComponentCustomProps;`
|
|
26
|
-
: `globalThis.JSX.IntrinsicAttributes;`}
|
|
18
|
+
type __VLS_GlobalComponents = ${vueCompilerOptions.target >= 3.5
|
|
19
|
+
? `import('${vueCompilerOptions.lib}').GlobalComponents;`
|
|
20
|
+
: `import('${vueCompilerOptions.lib}').GlobalComponents & Pick<typeof import('${vueCompilerOptions.lib}'), 'Transition' | 'TransitionGroup' | 'KeepAlive' | 'Suspense' | 'Teleport'>;`}
|
|
27
21
|
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
|
|
28
22
|
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
|
|
29
23
|
|
|
@@ -63,6 +57,7 @@ declare global {
|
|
|
63
57
|
: T;
|
|
64
58
|
function __VLS_withScope<T, K>(ctx: T, scope: K): ctx is T & K;
|
|
65
59
|
function __VLS_makeOptional<T>(t: T): { [K in keyof T]?: T[K] };
|
|
60
|
+
function __VLS_nonNullable<T>(t: T): T extends null | undefined ? never : T;
|
|
66
61
|
|
|
67
62
|
type __VLS_SelfComponent<N, C> = string extends N ? {} : N extends string ? { [P in N]: C } : {};
|
|
68
63
|
type __VLS_WithComponent<N0 extends string, LocalComponents, N1 extends string, N2 extends string, N3 extends string> =
|
|
@@ -105,7 +105,17 @@ function* generateScript(options) {
|
|
|
105
105
|
yield* generateDefineProp(options, options.sfc.scriptSetup);
|
|
106
106
|
yield* (0, scriptSetup_1.generateScriptSetup)(options, ctx, options.sfc.scriptSetup, options.scriptSetupRanges);
|
|
107
107
|
}
|
|
108
|
-
yield
|
|
108
|
+
yield `;`;
|
|
109
|
+
if (options.sfc.scriptSetup) {
|
|
110
|
+
// #4569
|
|
111
|
+
yield [
|
|
112
|
+
'',
|
|
113
|
+
'scriptSetup',
|
|
114
|
+
options.sfc.scriptSetup.content.length,
|
|
115
|
+
exports.codeFeatures.verification,
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
yield common_1.newLine;
|
|
109
119
|
if (options.globalTypes) {
|
|
110
120
|
yield (0, globalTypes_1.generateGlobalTypes)(options.vueCompilerOptions);
|
|
111
121
|
}
|
|
@@ -19,6 +19,15 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
19
19
|
const definePropMirrors = new Map();
|
|
20
20
|
if (scriptSetup.generic) {
|
|
21
21
|
if (!options.scriptRanges?.exportDefault) {
|
|
22
|
+
if (options.sfc.scriptSetup) {
|
|
23
|
+
// #4569
|
|
24
|
+
yield [
|
|
25
|
+
'',
|
|
26
|
+
'scriptSetup',
|
|
27
|
+
options.sfc.scriptSetup.content.length,
|
|
28
|
+
index_1.codeFeatures.verification,
|
|
29
|
+
];
|
|
30
|
+
}
|
|
22
31
|
yield `export default `;
|
|
23
32
|
}
|
|
24
33
|
yield `(<`;
|
|
@@ -32,12 +41,12 @@ function* generateScriptSetup(options, ctx, scriptSetup, scriptSetupRanges) {
|
|
|
32
41
|
yield `,`;
|
|
33
42
|
}
|
|
34
43
|
yield `>(${common_1.newLine}`
|
|
35
|
-
+ ` __VLS_props: Awaited<typeof __VLS_setup
|
|
36
|
-
+ ` __VLS_ctx?: ${ctx.helperTypes.Prettify.name}<Pick<Awaited<typeof __VLS_setup
|
|
44
|
+
+ ` __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>['props'],${common_1.newLine}`
|
|
45
|
+
+ ` __VLS_ctx?: ${ctx.helperTypes.Prettify.name}<Pick<NonNullable<Awaited<typeof __VLS_setup>>, 'attrs' | 'emit' | 'slots'>>,${common_1.newLine}` // use __VLS_Prettify for less dts code
|
|
37
46
|
+ ` __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>['expose'],${common_1.newLine}`
|
|
38
47
|
+ ` __VLS_setup = (async () => {${common_1.newLine}`;
|
|
39
48
|
yield* generateSetupFunction(options, ctx, scriptSetup, scriptSetupRanges, undefined, definePropMirrors);
|
|
40
|
-
const emitTypes = ['
|
|
49
|
+
const emitTypes = ['__VLS_ModelEmitsType'];
|
|
41
50
|
if (scriptSetupRanges.emits.define) {
|
|
42
51
|
emitTypes.unshift(`typeof ${scriptSetupRanges.emits.name ?? '__VLS_emit'}`);
|
|
43
52
|
}
|
|
@@ -231,15 +240,16 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
231
240
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, scriptSetupRanges.props.define.arg.start, scriptSetupRanges.props.define.arg.end, index_1.codeFeatures.navigation);
|
|
232
241
|
yield `,${common_1.newLine}`;
|
|
233
242
|
}
|
|
234
|
-
|
|
235
|
-
yield ` emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`;
|
|
236
|
-
if (scriptSetupRanges.emits.define) {
|
|
237
|
-
yield ` & typeof `;
|
|
238
|
-
yield scriptSetupRanges.emits.name ?? '__VLS_emit';
|
|
239
|
-
}
|
|
240
|
-
yield `>),${common_1.newLine}`;
|
|
241
|
-
}
|
|
243
|
+
yield* (0, component_1.generateEmitsOption)(options, scriptSetup, scriptSetupRanges);
|
|
242
244
|
yield `})${common_1.endOfLine}`;
|
|
245
|
+
yield `type __VLS_BuiltInPublicProps = ${options.vueCompilerOptions.target >= 3.4
|
|
246
|
+
? `import('${options.vueCompilerOptions.lib}').PublicProps;`
|
|
247
|
+
: options.vueCompilerOptions.target >= 3.0
|
|
248
|
+
? `import('${options.vueCompilerOptions.lib}').VNodeProps
|
|
249
|
+
& import('${options.vueCompilerOptions.lib}').AllowedComponentProps
|
|
250
|
+
& import('${options.vueCompilerOptions.lib}').ComponentCustomProps;`
|
|
251
|
+
: `globalThis.JSX.IntrinsicAttributes;`}`;
|
|
252
|
+
yield common_1.endOfLine;
|
|
243
253
|
yield `let __VLS_functionalComponentProps!: `;
|
|
244
254
|
yield `${ctx.helperTypes.OmitKeepDiscriminatedUnion.name}<InstanceType<typeof __VLS_fnComponent>['$props'], keyof __VLS_BuiltInPublicProps>`;
|
|
245
255
|
yield common_1.endOfLine;
|
|
@@ -279,6 +289,8 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
279
289
|
if (defineProp.name && defineProp.nameIsString) {
|
|
280
290
|
// renaming support
|
|
281
291
|
yield (0, common_1.generateSfcBlockSection)(scriptSetup, defineProp.name.start, defineProp.name.end, index_1.codeFeatures.navigation);
|
|
292
|
+
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
293
|
+
propName = propName.replace(/['"]+/g, '');
|
|
282
294
|
}
|
|
283
295
|
else if (defineProp.name) {
|
|
284
296
|
propName = scriptSetup.content.substring(defineProp.name.start, defineProp.name.end);
|
|
@@ -291,18 +303,7 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
291
303
|
yield defineProp.required
|
|
292
304
|
? `: `
|
|
293
305
|
: `?: `;
|
|
294
|
-
|
|
295
|
-
yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
|
|
296
|
-
}
|
|
297
|
-
else if (!defineProp.nameIsString) {
|
|
298
|
-
yield `NonNullable<typeof ${propName}['value']>`;
|
|
299
|
-
}
|
|
300
|
-
else if (defineProp.defaultValue) {
|
|
301
|
-
yield `typeof __VLS_defaults['${propName}']`;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
yield `any`;
|
|
305
|
-
}
|
|
306
|
+
yield* generateDefinePropType(scriptSetup, propName, defineProp);
|
|
306
307
|
yield `,${common_1.newLine}`;
|
|
307
308
|
if (defineProp.modifierType) {
|
|
308
309
|
let propModifierName = 'modelModifiers';
|
|
@@ -329,9 +330,13 @@ function* generateComponentProps(options, ctx, scriptSetup, scriptSetupRanges, d
|
|
|
329
330
|
yield common_1.endOfLine;
|
|
330
331
|
}
|
|
331
332
|
function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
332
|
-
yield `
|
|
333
|
+
yield `type __VLS_ModelEmitsType = `;
|
|
333
334
|
if (scriptSetupRanges.defineProp.filter(p => p.isModel).length) {
|
|
334
|
-
|
|
335
|
+
if (options.vueCompilerOptions.target < 3.5) {
|
|
336
|
+
yield `typeof __VLS_modelEmitsType${common_1.endOfLine}`;
|
|
337
|
+
yield `const __VLS_modelEmitsType = (await import('${options.vueCompilerOptions.lib}')).defineEmits<`;
|
|
338
|
+
}
|
|
339
|
+
yield `{${common_1.newLine}`;
|
|
335
340
|
for (const defineProp of scriptSetupRanges.defineProp) {
|
|
336
341
|
if (!defineProp.isModel) {
|
|
337
342
|
continue;
|
|
@@ -342,19 +347,34 @@ function* generateModelEmits(options, scriptSetup, scriptSetupRanges) {
|
|
|
342
347
|
propName = propName.replace(/['"]+/g, '');
|
|
343
348
|
}
|
|
344
349
|
yield `'update:${propName}': [${propName}:`;
|
|
345
|
-
|
|
346
|
-
yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
yield `any`;
|
|
350
|
-
}
|
|
350
|
+
yield* generateDefinePropType(scriptSetup, propName, defineProp);
|
|
351
351
|
yield `]${common_1.endOfLine}`;
|
|
352
352
|
}
|
|
353
|
-
yield `}
|
|
353
|
+
yield `}`;
|
|
354
|
+
if (options.vueCompilerOptions.target < 3.5) {
|
|
355
|
+
yield `>()`;
|
|
356
|
+
}
|
|
354
357
|
}
|
|
355
358
|
else {
|
|
356
359
|
yield `{}`;
|
|
357
360
|
}
|
|
358
361
|
yield common_1.endOfLine;
|
|
359
362
|
}
|
|
363
|
+
function* generateDefinePropType(scriptSetup, propName, defineProp) {
|
|
364
|
+
if (defineProp.type) {
|
|
365
|
+
// Infer from defineProp<T>
|
|
366
|
+
yield scriptSetup.content.substring(defineProp.type.start, defineProp.type.end);
|
|
367
|
+
}
|
|
368
|
+
else if ((defineProp.name && defineProp.nameIsString) || !defineProp.nameIsString) {
|
|
369
|
+
// Infer from actual prop declaration code
|
|
370
|
+
yield `NonNullable<typeof ${propName}['value']>`;
|
|
371
|
+
}
|
|
372
|
+
else if (defineProp.defaultValue) {
|
|
373
|
+
// Infer from defineProp({default: T})
|
|
374
|
+
yield `typeof __VLS_defaults['${propName}']`;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
yield `any`;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
360
380
|
//# sourceMappingURL=scriptSetup.js.map
|
|
@@ -16,6 +16,7 @@ const elementProps_1 = require("./elementProps");
|
|
|
16
16
|
const interpolation_1 = require("./interpolation");
|
|
17
17
|
const propertyAccess_1 = require("./propertyAccess");
|
|
18
18
|
const templateChild_1 = require("./templateChild");
|
|
19
|
+
const objectProperty_1 = require("./objectProperty");
|
|
19
20
|
const colonReg = /:/g;
|
|
20
21
|
function* generateComponent(options, ctx, node, currentComponent, componentCtxVar) {
|
|
21
22
|
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
@@ -168,6 +169,13 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
168
169
|
yield* generateVScope(options, ctx, node, props);
|
|
169
170
|
ctx.usedComponentCtxVars.add(componentCtxVar);
|
|
170
171
|
const usedComponentEventsVar = yield* (0, elementEvents_1.generateElementEvents)(options, ctx, node, var_functionalComponent, var_componentInstance, var_componentEmit, var_componentEvents);
|
|
172
|
+
if (var_defineComponentCtx && ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
|
|
173
|
+
yield `const ${componentCtxVar} = __VLS_nonNullable(__VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance}))${common_1.endOfLine}`;
|
|
174
|
+
}
|
|
175
|
+
if (usedComponentEventsVar) {
|
|
176
|
+
yield `let ${var_componentEmit}!: typeof ${componentCtxVar}.emit${common_1.endOfLine}`;
|
|
177
|
+
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${common_1.endOfLine}`;
|
|
178
|
+
}
|
|
171
179
|
const slotDir = node.props.find(p => p.type === CompilerDOM.NodeTypes.DIRECTIVE && p.name === 'slot');
|
|
172
180
|
if (slotDir) {
|
|
173
181
|
yield* generateComponentSlot(options, ctx, node, slotDir, currentComponent, componentCtxVar);
|
|
@@ -175,13 +183,6 @@ function* generateComponent(options, ctx, node, currentComponent, componentCtxVa
|
|
|
175
183
|
else {
|
|
176
184
|
yield* (0, elementChildren_1.generateElementChildren)(options, ctx, node, currentComponent, componentCtxVar);
|
|
177
185
|
}
|
|
178
|
-
if (var_defineComponentCtx && ctx.usedComponentCtxVars.has(var_defineComponentCtx)) {
|
|
179
|
-
yield `const ${componentCtxVar} = __VLS_pickFunctionalComponentCtx(${var_originalComponent}, ${var_componentInstance})!${common_1.endOfLine}`;
|
|
180
|
-
}
|
|
181
|
-
if (usedComponentEventsVar) {
|
|
182
|
-
yield `let ${var_componentEmit}!: typeof ${componentCtxVar}.emit${common_1.endOfLine}`;
|
|
183
|
-
yield `let ${var_componentEvents}!: __VLS_NormalizeEmits<typeof ${var_componentEmit}>${common_1.endOfLine}`;
|
|
184
|
-
}
|
|
185
186
|
}
|
|
186
187
|
function* generateElement(options, ctx, node, currentComponent, componentCtxVar) {
|
|
187
188
|
const startTagOffset = node.loc.start.offset + options.template.content.substring(node.loc.start.offset).indexOf(node.tag);
|
|
@@ -271,11 +272,23 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
|
|
|
271
272
|
ctx.hasSlotElements.add(currentComponent);
|
|
272
273
|
}
|
|
273
274
|
const slotBlockVars = [];
|
|
274
|
-
|
|
275
|
+
yield `const {`;
|
|
276
|
+
if (slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content) {
|
|
277
|
+
yield* (0, objectProperty_1.generateObjectProperty)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc);
|
|
278
|
+
yield ': __VLS_thisSlot';
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
yield `default: `;
|
|
282
|
+
yield* (0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
283
|
+
? '#'.length
|
|
284
|
+
: slotDir.loc.source.startsWith('v-slot:')
|
|
285
|
+
? 'v-slot:'.length
|
|
286
|
+
: 0), ctx.codeFeatures.withoutHighlightAndCompletion, `__VLS_thisSlot`);
|
|
287
|
+
}
|
|
288
|
+
yield `} = __VLS_nonNullable(${componentCtxVar}.slots)${common_1.endOfLine}`;
|
|
275
289
|
if (slotDir?.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
|
|
276
290
|
const slotAst = (0, common_1.createTsAst)(options.ts, slotDir, `(${slotDir.exp.content}) => {}`);
|
|
277
291
|
(0, common_1.collectVars)(options.ts, slotAst, slotAst, slotBlockVars);
|
|
278
|
-
hasProps = true;
|
|
279
292
|
if (!slotDir.exp.content.includes(':')) {
|
|
280
293
|
yield `const [`;
|
|
281
294
|
yield [
|
|
@@ -284,7 +297,7 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
|
|
|
284
297
|
slotDir.exp.loc.start.offset,
|
|
285
298
|
ctx.codeFeatures.all,
|
|
286
299
|
];
|
|
287
|
-
yield `] = __VLS_getSlotParams(`;
|
|
300
|
+
yield `] = __VLS_getSlotParams(__VLS_thisSlot)${common_1.endOfLine}`;
|
|
288
301
|
}
|
|
289
302
|
else {
|
|
290
303
|
yield `const `;
|
|
@@ -294,23 +307,9 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
|
|
|
294
307
|
slotDir.exp.loc.start.offset,
|
|
295
308
|
ctx.codeFeatures.all,
|
|
296
309
|
];
|
|
297
|
-
yield ` = __VLS_getSlotParam(`;
|
|
310
|
+
yield ` = __VLS_getSlotParam(__VLS_thisSlot)${common_1.endOfLine}`;
|
|
298
311
|
}
|
|
299
312
|
}
|
|
300
|
-
yield* (0, common_1.wrapWith)((slotDir.arg ?? slotDir).loc.start.offset, (slotDir.arg ?? slotDir).loc.end.offset, ctx.codeFeatures.verification, `(${componentCtxVar}.slots!)`, ...(slotDir?.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && slotDir.arg.content
|
|
301
|
-
? (0, propertyAccess_1.generatePropertyAccess)(options, ctx, slotDir.arg.loc.source, slotDir.arg.loc.start.offset, slotDir.arg.isStatic ? ctx.codeFeatures.withoutHighlight : ctx.codeFeatures.all, slotDir.arg.loc)
|
|
302
|
-
: [
|
|
303
|
-
`.`,
|
|
304
|
-
...(0, common_1.wrapWith)(slotDir.loc.start.offset, slotDir.loc.start.offset + (slotDir.loc.source.startsWith('#')
|
|
305
|
-
? '#'.length
|
|
306
|
-
: slotDir.loc.source.startsWith('v-slot:')
|
|
307
|
-
? 'v-slot:'.length
|
|
308
|
-
: 0), ctx.codeFeatures.withoutHighlightAndCompletion, `default`)
|
|
309
|
-
]));
|
|
310
|
-
if (hasProps) {
|
|
311
|
-
yield `)`;
|
|
312
|
-
}
|
|
313
|
-
yield common_1.endOfLine;
|
|
314
313
|
for (const varName of slotBlockVars) {
|
|
315
314
|
ctx.addLocalVariable(varName);
|
|
316
315
|
}
|
|
@@ -328,7 +327,7 @@ function* generateComponentSlot(options, ctx, node, slotDir, currentComponent, c
|
|
|
328
327
|
isStatic = slotDir.arg.isStatic;
|
|
329
328
|
}
|
|
330
329
|
if (isStatic && slotDir && !slotDir.arg) {
|
|
331
|
-
yield
|
|
330
|
+
yield `__VLS_nonNullable(${componentCtxVar}.slots)['`;
|
|
332
331
|
yield [
|
|
333
332
|
'',
|
|
334
333
|
'template',
|
|
@@ -18,7 +18,7 @@ function* generateElementChildren(options, ctx, node, currentComponent, componen
|
|
|
18
18
|
&& node.children.length
|
|
19
19
|
&& node.tagType !== CompilerDOM.ElementTypes.ELEMENT
|
|
20
20
|
&& node.tagType !== CompilerDOM.ElementTypes.TEMPLATE) {
|
|
21
|
-
yield `(${componentCtxVar}.slots
|
|
21
|
+
yield `__VLS_nonNullable(${componentCtxVar}.slots).`;
|
|
22
22
|
yield* (0, common_1.wrapWith)(node.children[0].loc.start.offset, node.children[node.children.length - 1].loc.end.offset, ctx.codeFeatures.navigation, `default`);
|
|
23
23
|
yield common_1.endOfLine;
|
|
24
24
|
}
|
|
@@ -144,7 +144,7 @@ function isCompoundExpression(ts, ast) {
|
|
|
144
144
|
if (ts.isArrowFunction(child_2)) {
|
|
145
145
|
result = false;
|
|
146
146
|
}
|
|
147
|
-
else if (ts
|
|
147
|
+
else if (isPropertyAccessOrId(ts, child_2)) {
|
|
148
148
|
result = false;
|
|
149
149
|
}
|
|
150
150
|
});
|
|
@@ -156,4 +156,13 @@ function isCompoundExpression(ts, ast) {
|
|
|
156
156
|
}
|
|
157
157
|
return result;
|
|
158
158
|
}
|
|
159
|
+
function isPropertyAccessOrId(ts, node) {
|
|
160
|
+
if (ts.isIdentifier(node)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
164
|
+
return isPropertyAccessOrId(ts, node.expression);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
159
168
|
//# sourceMappingURL=elementEvents.js.map
|
|
@@ -86,7 +86,7 @@ function* generateElementProps(options, ctx, node, props, enableCodeFeatures, pr
|
|
|
86
86
|
}
|
|
87
87
|
: false,
|
|
88
88
|
}, prop.loc.name_2 ?? (prop.loc.name_2 = {}), shouldCamelize)
|
|
89
|
-
:
|
|
89
|
+
: (0, common_1.wrapWith)(prop.loc.start.offset, prop.loc.start.offset + 'v-model'.length, ctx.codeFeatures.verification, propName)), `: (`, ...genereatePropExp(options, ctx, prop.exp, ctx.codeFeatures.all, prop.arg?.loc.start.offset === prop.exp?.loc.start.offset, enableCodeFeatures), `)`);
|
|
90
90
|
if (!enableCodeFeatures) {
|
|
91
91
|
yield (0, muggle_string_1.toString)([...codes]);
|
|
92
92
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import type { Code, VueCodeInformation } from '../../types';
|
|
3
|
+
// import type { TemplateCodegenContext } from './context';
|
|
4
|
+
// import type { TemplateCodegenOptions } from './index';
|
|
5
|
+
// import { generateInterpolation } from './interpolation';
|
|
6
|
+
// import { generateStringLiteralKey } from './stringLiteralKey';
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
// export function* generateObjectKey(
|
|
9
|
+
// options: TemplateCodegenOptions,
|
|
10
|
+
// ctx: TemplateCodegenContext,
|
|
11
|
+
// code: string,
|
|
12
|
+
// offset: number,
|
|
13
|
+
// features: VueCodeInformation,
|
|
14
|
+
// astHolder?: any
|
|
15
|
+
// ): Generator<Code> {
|
|
16
|
+
// yield `[`;
|
|
17
|
+
// if (code.startsWith('[') && code.endsWith(']')) {
|
|
18
|
+
// yield* generateInterpolation(
|
|
19
|
+
// options,
|
|
20
|
+
// ctx,
|
|
21
|
+
// code.slice(1, -1),
|
|
22
|
+
// astHolder,
|
|
23
|
+
// offset + 1,
|
|
24
|
+
// features,
|
|
25
|
+
// '',
|
|
26
|
+
// ''
|
|
27
|
+
// );
|
|
28
|
+
// }
|
|
29
|
+
// else {
|
|
30
|
+
// yield* generateStringLiteralKey(code, offset, features)
|
|
31
|
+
// }
|
|
32
|
+
// yield `]`;
|
|
33
|
+
// }
|
|
34
|
+
//# sourceMappingURL=objectKey.js.map
|
package/lib/languageModule.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/// <reference types="@volar/typescript" />
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.createVueLanguagePlugin = createVueLanguagePlugin;
|
|
4
5
|
const language_core_1 = require("@volar/language-core");
|
|
5
|
-
const plugins_1 = require("./plugins");
|
|
6
|
-
const vueFile_1 = require("./virtualFile/vueFile");
|
|
7
6
|
const CompilerDOM = require("@vue/compiler-dom");
|
|
8
|
-
const
|
|
7
|
+
const plugins_1 = require("./plugins");
|
|
9
8
|
const file_html_1 = require("./plugins/file-html");
|
|
10
9
|
const file_md_1 = require("./plugins/file-md");
|
|
11
10
|
const file_vue_1 = require("./plugins/file-vue");
|
|
11
|
+
const CompilerVue2 = require("./utils/vue2TemplateCompiler");
|
|
12
|
+
const vueFile_1 = require("./virtualFile/vueFile");
|
|
12
13
|
const normalFileRegistries = [];
|
|
13
14
|
const holderFileRegistries = [];
|
|
14
15
|
function getVueFileRegistry(isGlobalTypesHolder, key, plugins) {
|
|
@@ -73,11 +74,11 @@ function createVueLanguagePlugin(ts, asFileName, getProjectVersion, isRootFile,
|
|
|
73
74
|
createVirtualCode(scriptId, languageId, snapshot) {
|
|
74
75
|
if (languageId === 'vue' || languageId === 'markdown' || languageId === 'html') {
|
|
75
76
|
const fileName = asFileName(scriptId);
|
|
76
|
-
if (
|
|
77
|
+
if (getProjectVersion() !== canonicalRootFileNamesVersion) {
|
|
77
78
|
canonicalRootFileNamesVersion = getProjectVersion();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
}
|
|
80
|
+
if (!pluginContext.globalTypesHolder && isRootFile(fileName)) {
|
|
81
|
+
pluginContext.globalTypesHolder = fileName;
|
|
81
82
|
}
|
|
82
83
|
const fileRegistry = getFileRegistry(pluginContext.globalTypesHolder === fileName);
|
|
83
84
|
const code = fileRegistry.get(fileName);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type LanguagePlugin } from '@volar/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { VueCompilerOptions } from './types';
|
|
4
|
+
import { VueVirtualCode } from './virtualFile/vueFile';
|
|
5
|
+
export declare function createRootFileChecker(getProjectVersion: (() => string) | undefined, getRootFileNames: () => string[], caseSensitive: boolean): (fileName: string) => boolean;
|
|
6
|
+
export declare function createVueLanguagePlugin<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, _getProjectVersion: (() => string) | undefined, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
|
|
7
|
+
export declare function createVueLanguagePlugin2<T>(ts: typeof import('typescript'), asFileName: (scriptId: T) => string, isRootFile: (fileName: string) => boolean, compilerOptions: ts.CompilerOptions, vueCompilerOptions: VueCompilerOptions): LanguagePlugin<T, VueVirtualCode>;
|
|
8
|
+
export declare function getAllExtensions(options: VueCompilerOptions): string[];
|