Skip to content

Commit

Permalink
chore(language-core): code adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 13, 2024
1 parent cc42b9b commit dacbfdf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
2 changes: 0 additions & 2 deletions packages/language-core/lib/codegen/script/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ declare global {
N3 extends keyof __VLS_GlobalComponents ? N3 extends N0 ? Pick<__VLS_GlobalComponents, N0 extends keyof __VLS_GlobalComponents ? N0 : never> : { [K in N0]: __VLS_GlobalComponents[N3] } :
${vueCompilerOptions.strictTemplates ? '{}' : '{ [K in N0]: unknown }'}
type __VLS_FillingEventArg_ParametersLength<E extends (...args: any) => any> = __VLS_IsAny<Parameters<E>> extends true ? -1 : Parameters<E>['length'];
type __VLS_FillingEventArg<E> = E extends (...args: any) => any ? __VLS_FillingEventArg_ParametersLength<E> extends 0 ? ($event?: undefined) => ReturnType<E> : E : E;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends new (...args: any) => any
? (props: ${fnPropsType}, ctx?: any) => __VLS_Element & { __ctx?: {
Expand Down
27 changes: 6 additions & 21 deletions packages/language-core/lib/codegen/template/elementEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ export function* generateElementEvents(
if (!options.vueCompilerOptions.strictTemplates) {
yield `Record<string, unknown> & `;
}
yield `Partial<`;
yield `(`;
yield `__VLS_IsAny<__VLS_AsFunctionOrAny<typeof ${propsVar}['${originalPropName}']>> extends false${newLine}`;
yield `? typeof ${propsVar}${newLine}`;
yield `: __VLS_IsAny<typeof ${eventsVar}['${prop.arg.loc.source}']> extends false${newLine}`;
yield `? {${newLine}`;
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${newLine}`;
yield `${originalPropNameObjectKey}: typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
yield `}${newLine}`;
if (prop.arg.loc.source !== camelize(prop.arg.loc.source)) {
yield `: __VLS_IsAny<typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']> extends false${newLine}`;
yield `? {${newLine}`;
yield `/**__VLS_emit,${emitVar},${camelize(prop.arg.loc.source)}*/${newLine}`;
yield `${originalPropNameObjectKey}: typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
yield `${originalPropNameObjectKey}?: typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
yield `}${newLine}`;
}
yield `: typeof ${propsVar}${newLine}`;
yield `> = {${newLine}`;
yield* generateEventArg(options, ctx, prop.arg, true);
yield `) = {${newLine}`;
yield* generateEventArg(ctx, prop.arg, true);
yield `: `;
yield* generateEventExpression(options, ctx, prop);
yield `}${endOfLine}`;
Expand Down Expand Up @@ -104,7 +104,6 @@ const eventArgFeatures: VueCodeInformation = {
};

export function* generateEventArg(
options: TemplateCodegenOptions,
ctx: TemplateCodegenContext,
arg: CompilerDOM.SimpleExpressionNode,
enableHover: boolean,
Expand All @@ -115,21 +114,7 @@ export function* generateEventArg(
...eventArgFeatures,
}
: eventArgFeatures;
if (arg.loc.source.startsWith('[') && arg.loc.source.endsWith(']')) {
yield `[`;
yield* generateInterpolation(
options,
ctx,
arg.loc.source.slice(1, -1),
arg.loc,
arg.loc.start.offset + 1,
ctx.codeFeatures.all,
'',
'',
);
yield `]`;
}
else if (variableNameRegex.test(camelize(arg.loc.source))) {
if (variableNameRegex.test(camelize(arg.loc.source))) {
yield ['', 'template', arg.loc.start.offset, features];
yield `on`;
yield* generateCamelized(
Expand Down
25 changes: 19 additions & 6 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,27 @@ export function* generateElementProps(
if (
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
&& prop.name === 'on'
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
&& !prop.arg.loc.source.startsWith('[')
&& !prop.arg.loc.source.endsWith(']')
) {
yield* generateEventArg(ctx, prop.arg, true);
yield `: `;
yield* generateEventExpression(options, ctx, prop);
yield `,${newLine}`;
}
else if (
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
&& prop.name === 'on'
) {
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
yield* generateEventArg(options, ctx, prop.arg, true);
yield `: `;
yield* generateEventExpression(options, ctx, prop);
yield `,${newLine}`;
if (
prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
&& prop.arg.loc.source.startsWith('[')
&& prop.arg.loc.source.endsWith(']')
) {
propsFailedExps?.push(prop.arg);
}
else if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
propsFailedExps?.push(prop.exp);
}
}
Expand Down

0 comments on commit dacbfdf

Please sign in to comment.