Skip to content

Commit dacbfdf

Browse files
committed
chore(language-core): code adjust
1 parent cc42b9b commit dacbfdf

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

packages/language-core/lib/codegen/script/globalTypes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ declare global {
6666
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
6767
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
6868
69-
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
70-
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
7169
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
7270
T extends new (...args: any) => any
7371
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {

packages/language-core/lib/codegen/template/elementEvents.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ export function* generateElementEvents(
4141
if (!options.vueCompilerOptions.strictTemplates) {
4242
yield `Record<string, unknown> & `;
4343
}
44-
yield `Partial<`;
44+
yield `(`;
4545
yield `__VLS_IsAny<__VLS_AsFunctionOrAny<typeof ${propsVar}['${originalPropName}']>> extends false${newLine}`;
4646
yield `? typeof ${propsVar}${newLine}`;
4747
yield `: __VLS_IsAny<typeof ${eventsVar}['${prop.arg.loc.source}']> extends false${newLine}`;
4848
yield `? {${newLine}`;
4949
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${newLine}`;
50-
yield `${originalPropNameObjectKey}: typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
50+
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
5151
yield `}${newLine}`;
5252
if (prop.arg.loc.source !== camelize(prop.arg.loc.source)) {
5353
yield `: __VLS_IsAny<typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']> extends false${newLine}`;
5454
yield `? {${newLine}`;
5555
yield `/**__VLS_emit,${emitVar},${camelize(prop.arg.loc.source)}*/${newLine}`;
56-
yield `${originalPropNameObjectKey}: typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
56+
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
5757
yield `}${newLine}`;
5858
}
5959
yield `: typeof ${propsVar}${newLine}`;
60-
yield `> = {${newLine}`;
61-
yield* generateEventArg(options, ctx, prop.arg, true);
60+
yield `) = {${newLine}`;
61+
yield* generateEventArg(ctx, prop.arg, true);
6262
yield `: `;
6363
yield* generateEventExpression(options, ctx, prop);
6464
yield `}${endOfLine}`;
@@ -104,7 +104,6 @@ const eventArgFeatures: VueCodeInformation = {
104104
};
105105

106106
export function* generateEventArg(
107-
options: TemplateCodegenOptions,
108107
ctx: TemplateCodegenContext,
109108
arg: CompilerDOM.SimpleExpressionNode,
110109
enableHover: boolean,
@@ -115,21 +114,7 @@ export function* generateEventArg(
115114
...eventArgFeatures,
116115
}
117116
: eventArgFeatures;
118-
if (arg.loc.source.startsWith('[') && arg.loc.source.endsWith(']')) {
119-
yield `[`;
120-
yield* generateInterpolation(
121-
options,
122-
ctx,
123-
arg.loc.source.slice(1, -1),
124-
arg.loc,
125-
arg.loc.start.offset + 1,
126-
ctx.codeFeatures.all,
127-
'',
128-
'',
129-
);
130-
yield `]`;
131-
}
132-
else if (variableNameRegex.test(camelize(arg.loc.source))) {
117+
if (variableNameRegex.test(camelize(arg.loc.source))) {
133118
yield ['', 'template', arg.loc.start.offset, features];
134119
yield `on`;
135120
yield* generateCamelized(

packages/language-core/lib/codegen/template/elementProps.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,27 @@ export function* generateElementProps(
4242
if (
4343
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
4444
&& prop.name === 'on'
45+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
46+
&& !prop.arg.loc.source.startsWith('[')
47+
&& !prop.arg.loc.source.endsWith(']')
48+
) {
49+
yield* generateEventArg(ctx, prop.arg, true);
50+
yield `: `;
51+
yield* generateEventExpression(options, ctx, prop);
52+
yield `,${newLine}`;
53+
}
54+
else if (
55+
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
56+
&& prop.name === 'on'
4557
) {
46-
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
47-
yield* generateEventArg(options, ctx, prop.arg, true);
48-
yield `: `;
49-
yield* generateEventExpression(options, ctx, prop);
50-
yield `,${newLine}`;
58+
if (
59+
prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
60+
&& prop.arg.loc.source.startsWith('[')
61+
&& prop.arg.loc.source.endsWith(']')
62+
) {
63+
propsFailedExps?.push(prop.arg);
5164
}
52-
else if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
65+
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
5366
propsFailedExps?.push(prop.exp);
5467
}
5568
}

0 commit comments

Comments
 (0)