8000 fix(language-core): remove calculation logic of element inner loc by KazariEX · Pull Request #5460 · vuejs/language-tools · GitHub
[go: up one dir, main page]

Skip to content

fix(language-core): remove calculation logic of element inner loc #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(language-core): remove calculation logic of element inner loc
  • Loading branch information
KazariEX committed Jul 1, 2025
commit ef0356c9b12c2ce143411a46ed8fdf4ebf6f8fa4
35 changes: 4 additions & 31 deletions packages/language-core/lib/codegen/template/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export function* generateVSlot(
}
} else {
// #932: reference for implicit default slot
const { start, end } = getElementInnerLoc(options, node);
yield* wrapWith(
start,
end,
node.loc.start.offset,
node.loc.end.offset,
ctx.codeFeatures.navigation,
`default`,
);
Expand All @@ -78,11 +77,10 @@ export function* generateVSlot(
}

if (options.vueCompilerOptions.strictSlotChildren && node.children.length) {
const { start, end } = getElementInnerLoc(options, node);
yield `(): __VLS_NormalizeSlotReturns<typeof ${slotVar}> => (`;
yield* wrapWith(
start,
end,
node.loc.start.offset,
node.loc.end.offset,
ctx.codeFeatures.verification,
`{} as [`,
...ctx.currentComponent.childTypes.map(name => `${name}, `),
Expand Down Expand Up @@ -180,28 +178,3 @@ function* generateSlotParameters(
];
}
}

function getElementInnerLoc(
options: TemplateCodegenOptions,
node: CompilerDOM.ElementNode,
) {
if (node.children.length) {
let start = node.children[0].loc.start.offset;
let end = node.children.at(-1)!.loc.end.offset;
while (options.template.content[start - 1] !== '>') {
start--;
}
while (options.template.content[end] !== '<' && end < node.loc.end.offset) {
end++;
}
return {
start,
end,
};
} else {
return {
start: node.loc.start.offset,
end: node.loc.end.offset,
};
}
}
4 changes: 2 additions & 2 deletions packages/language-server/tests/references.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ test('Default slot', async () => {
{
"end": {
"line": 9,
"offset": 4,
"offset": 14,
},
"file": "\${testWorkspacePath}/tsconfigProject/foo.vue",
"isDefinition": false,
"isWriteAccess": false,
"lineText": " <Fixture>",
"start": {
"line": 7,
"offset": 13,
"offset": 4,
},
},
],
Expand Down
0