Skip to content
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

fix(language-core): inject generics of useTemplateRef into correct location #4829

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 11 additions & 11 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ function* generateSetupFunction(
}
}
if (scriptSetupRanges.cssModules.length) {
for (const { exp, arg } of scriptSetupRanges.cssModules) {
if (arg) {
for (const { define } of scriptSetupRanges.cssModules) {
if (define.arg) {
setupCodeModifies.push([
[
` as Omit<__VLS_StyleModules, '$style'>[`,
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.all),
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.all),
`]`
],
exp.end,
exp.end
define.exp.end,
define.exp.end
]);
}
else {
setupCodeModifies.push([
[
` as __VLS_StyleModules[`,
['', scriptSetup.name, exp.start, codeFeatures.verification],
['', scriptSetup.name, define.exp.start, codeFeatures.verification],
`'$style'`,
['', scriptSetup.name, exp.end, codeFeatures.verification],
['', scriptSetup.name, define.exp.end, codeFeatures.verification],
`]`
],
exp.end,
exp.end
define.exp.end,
define.exp.end
]);
}
}
Expand All @@ -251,8 +251,8 @@ function* generateSetupFunction(
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.navigation),
`], keyof __VLS_TemplateResult['refs']>`
],
define.arg.start - 1,
define.arg.start - 1
define.exp.end,
define.exp.end
]);
}
}
Expand Down
19 changes: 8 additions & 11 deletions packages/language-core/lib/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ export function parseScriptSetupRanges(
inheritAttrs?: string;
} = {};
const cssModules: {
exp: TextRange;
arg?: TextRange;
define: ReturnType<typeof parseDefineFunction>;
}[] = [];
const templateRefs: {
name?: string;
define?: ReturnType<typeof parseDefineFunction>;
define: ReturnType<typeof parseDefineFunction>;
}[] = [];
const definePropProposalA = vueCompilerOptions.experimentalDefinePropProposal === 'kevinEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=kevinEdition');
const definePropProposalB = vueCompilerOptions.experimentalDefinePropProposal === 'johnsonEdition' || ast.text.trimStart().startsWith('// @experimentalDefinePropProposal=johnsonEdition');
Expand Down Expand Up @@ -129,11 +128,13 @@ export function parseScriptSetupRanges(
}

function parseDefineFunction(node: ts.CallExpression): TextRange & {
exp: TextRange;
arg?: TextRange;
typeArg?: TextRange;
} {
return {
..._getStartEnd(node),
exp: _getStartEnd(node.expression),
arg: node.arguments.length ? _getStartEnd(node.arguments[0]) : undefined,
typeArg: node.typeArguments?.length ? _getStartEnd(node.typeArguments[0]) : undefined,
};
Expand Down Expand Up @@ -383,7 +384,6 @@ export function parseScriptSetupRanges(
}
} else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
const define = parseDefineFunction(node);
define.arg = _getStartEnd(node.arguments[0]);
let name;
if (ts.isVariableDeclaration(parent)) {
name = getNodeText(ts, parent.name, ast);
Expand All @@ -394,13 +394,10 @@ export function parseScriptSetupRanges(
});
}
else if (vueCompilerOptions.composibles.useCssModule.includes(callText)) {
const module: (typeof cssModules)[number] = {
exp: _getStartEnd(node)
};
if (node.arguments.length) {
module.arg = _getStartEnd(node.arguments[0]);
}
cssModules.push(module);
const define = parseDefineFunction(node);
cssModules.push({
define
});
}
}
ts.forEachChild(node, child => {
Expand Down