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 18edfdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
21 changes: 3 additions & 18 deletions packages/language-core/lib/codegen/template/elementEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function* generateElementEvents(
if (!options.vueCompilerOptions.strictTemplates) {
yield `Record<string, unknown> & `;
}
yield `Partial<`;
yield `Partial<${newLine}`;
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}`;
Expand All @@ -58,7 +58,7 @@ export function* generateElementEvents(
}
yield `: typeof ${propsVar}${newLine}`;
yield `> = {${newLine}`;
yield* generateEventArg(options, ctx, prop.arg, true);
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 18edfdb

Please sign in to comment.