Skip to content

Commit

Permalink
fix(language-core): semantic highlight of the end tag of namespaced e…
Browse files Browse the repository at this point in the history
…lements (#4623)
  • Loading branch information
KermanX authored and johnsoncodehk committed Aug 2, 2024
1 parent f242e85 commit 892e4de
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function* generateComponent(
let props = node.props;
let dynamicTagInfo: {
exp: string;
offset: number;
offsets: [number, number | undefined];
astHolder: any;
} | undefined;

Expand All @@ -56,7 +56,7 @@ export function* generateComponent(
if (prop.type === CompilerDOM.NodeTypes.DIRECTIVE && prop.name === 'bind' && prop.arg?.loc.source === 'is' && prop.exp) {
dynamicTagInfo = {
exp: prop.exp.loc.source,
offset: prop.exp.loc.start.offset,
offsets: [prop.exp.loc.start.offset, undefined],
astHolder: prop.exp.loc,
};
props = props.filter(p => p !== prop);
Expand All @@ -69,7 +69,7 @@ export function* generateComponent(
dynamicTagInfo = {
exp: node.tag,
astHolder: node.loc,
offset: startTagOffset,
offsets: [startTagOffset, endTagOffset],
};
}

Expand Down Expand Up @@ -104,18 +104,34 @@ export function* generateComponent(
yield `]${endOfLine}`;
}
else if (dynamicTagInfo) {
yield `const ${var_originalComponent} = `;
yield `const ${var_originalComponent} = (`;
yield* generateInterpolation(
options,
ctx,
dynamicTagInfo.exp,
dynamicTagInfo.astHolder,
dynamicTagInfo.offset,
dynamicTagInfo.offsets[0],
ctx.codeFeatures.all,
'(',
')'
);
yield endOfLine;
if (dynamicTagInfo.offsets[1] !== undefined) {
yield `,`;
yield* generateInterpolation(
options,
ctx,
dynamicTagInfo.exp,
dynamicTagInfo.astHolder,
dynamicTagInfo.offsets[1],
{
...ctx.codeFeatures.all,
completion: false,
},
'(',
')'
);
}
yield `)${endOfLine}`;
}
else if (!isComponentTag) {
yield `// @ts-ignore${newLine}`;
Expand Down
25 changes: 25 additions & 0 deletions test-workspace/language-service/syntax/namespaced.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { Component } from "vue";
import { defineComponent } from "vue";
const A = {
B: {
C: defineComponent({
setup() {
return () => "";
},
}),
},
};
const C: Component & {
D: Component;
} = null!;
</script>

<template>
<A.B.C> {{ A.B.C }} </A.B.C>
<A.B.C />
<C>
<C.D> 222 </C.D>
<C.D />
</C>
</template>

0 comments on commit 892e4de

Please sign in to comment.