Skip to content

Commit

Permalink
fix: can't assign expression to no args event
Browse files Browse the repository at this point in the history
close #270
johnsoncodehk committed Jun 30, 2021
1 parent 768cb8c commit 8628f3f
Showing 2 changed files with 44 additions and 51 deletions.
94 changes: 43 additions & 51 deletions packages/vscode-vue-languageservice/src/generators/template.ts
Original file line number Diff line number Diff line change
@@ -1003,7 +1003,7 @@ export function generate(

tsCodeGen.addText(`let ${var_on}!: { `);
tsCodeGen.addText(validTsVar.test(key_1) ? key_1 : `'${key_1}'`);
tsCodeGen.addText(`: __VLS_FirstFunction<\n`);
tsCodeGen.addText(`: __VLS_FillingEventArg<__VLS_FirstFunction<\n`);
if (key_1 !== key_3) {
tsCodeGen.addText(`__VLS_FirstFunction<\n`);
tsCodeGen.addText(`__VLS_EmitEvent<typeof __VLS_components['${getComponentName(node.tag)}'], '${key_1}'>,\n`);
@@ -1025,7 +1025,7 @@ export function generate(
capabilities: capabilitiesSet.attr,
},
);
tsCodeGen.addText(`]> };\n`);
tsCodeGen.addText(`]>>\n};\n`);

const transformResult = transformOn(prop, node, transformContext);
for (const prop_2 of transformResult.props) {
@@ -1043,63 +1043,55 @@ export function generate(
},
);
tsCodeGen.addText(`: `);
appendExpressionNode(prop);
tsCodeGen.addText(`\n};\n`);

if (prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
if (value.type === NodeTypes.SIMPLE_EXPRESSION) {
if (value.content === prop.exp.content) {
writeCode(
value.content,
{
start: prop.exp.loc.start.offset,
end: prop.exp.loc.end.offset,
},
SourceMaps.Mode.Offset,
{
vueTag: 'template',
capabilities: capabilitiesSet.all,
},
formatBrackets.empty,
);
function appendExpressionNode(prop: vueDom.DirectiveNode) {
if (prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
if (value.type === NodeTypes.SIMPLE_EXPRESSION) {
appendSimpleExpressionNode(value, prop.exp);
}
else {
tsCodeGen.addText(value.content);
else if (value.type === NodeTypes.COMPOUND_EXPRESSION) {
appendCompoundExpressionNode(value, prop.exp);
}
}
else if (value.type === NodeTypes.COMPOUND_EXPRESSION) {
for (const child of value.children) {
if (typeof child === 'string') {
tsCodeGen.addText(child);
}
else if (typeof child === 'symbol') {
// ignore
}
else if (child.type === NodeTypes.SIMPLE_EXPRESSION) {
if (child.content === prop.exp.content) {
writeCode(
child.content,
{
start: prop.exp.loc.start.offset,
end: prop.exp.loc.end.offset,
},
SourceMaps.Mode.Offset,
{
vueTag: 'template',
capabilities: capabilitiesSet.all,
},
formatBrackets.empty,
);
}
else {
tsCodeGen.addText(child.content);
}
}
else {
tsCodeGen.addText(`undefined`);
}
}
function appendCompoundExpressionNode(node: vueDom.CompoundExpressionNode, exp: vueDom.SimpleExpressionNode) {
for (const child of node.children) {
if (typeof child === 'string') {
tsCodeGen.addText(child);
}
else if (typeof child === 'symbol') {
// ignore
}
else if (child.type === NodeTypes.SIMPLE_EXPRESSION) {
appendSimpleExpressionNode(child, exp);
}
}
}
else {
tsCodeGen.addText(`undefined`);
function appendSimpleExpressionNode(node: vueDom.SimpleExpressionNode, exp: vueDom.SimpleExpressionNode) {
if (node.content === exp.content) {
writeCode(
node.content,
{
start: exp.loc.start.offset,
end: exp.loc.end.offset,
},
SourceMaps.Mode.Offset,
{
vueTag: 'template',
capabilities: capabilitiesSet.all,
},
formatBrackets.empty,
);
}
else {
tsCodeGen.addText(node.content);
}
}
tsCodeGen.addText(`\n};\n`);
}
}
}
1 change: 1 addition & 0 deletions packages/vscode-vue-languageservice/src/virtuals/global.ts
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ declare global {
function __VLS_getVforIndexType<T>(source: T): T extends AnyArray ? undefined : number;
function __VLS_getNameOption<T>(t?: T): T extends { name: infer N } ? N : undefined;
function __VLS_pickForItem<S, T1, T2>(source: S, forOfItem: T1, forInItem: T2): S extends { [Symbol.iterator](): infer _ } ? T1 : T2;
type __VLS_FillingEventArg<E> = E extends () => infer R ? ($event?: undefined) => R : E;
type __VLS_PickNotAny<A, B> = PickNotAny<A, B>;
type __VLS_ExtractComponentProps<C> = C extends new (...args: any) => { $props: infer P1 } ? P1 : C extends FunctionalComponent<infer P2> ? P2 : C extends { props: infer P3 } ? P3 : C;
type __VLS_ExtractRawComponents<T> = { [K in keyof T]: __VLS_ExtractRawComponent<T[K]> };

0 comments on commit 8628f3f

Please sign in to comment.