Skip to content

Commit

Permalink
fix: generate ref as identifier instead of interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Aug 13, 2024
1 parent 0f14cde commit 28ed0d8
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,20 @@ function* generateReferencesForElements(
&& prop.name === 'ref'
&& prop.value
) {
let [content, startOffset] = normalizeAttributeValue(prop.value);

yield `// @ts-ignore${newLine}`;
yield* generateInterpolation(
yield `__VLS_ctx`;
yield* generatePropertyAccess(
options,
ctx,
prop.value.content,
prop.value.loc,
prop.value.loc.start.offset + 1,
content,
startOffset,
ctx.codeFeatures.navigation,
'(',
')'
prop.value.loc
);
yield endOfLine;
ctx.accessExternalVariable(content, startOffset);
}
}
}
Expand All @@ -568,15 +570,7 @@ function* generateReferencesForScopedCssClasses(
&& prop.name === 'class'
&& prop.value
) {
let startOffset = prop.value.loc.start.offset;
let content = prop.value.loc.source;
if (
(content.startsWith(`'`) && content.endsWith(`'`))
|| (content.startsWith(`"`) && content.endsWith(`"`))
) {
startOffset++;
content = content.slice(1, -1);
}
let [content, startOffset] = normalizeAttributeValue(prop.value);
if (content) {
let currentClassName = '';
for (const char of (content + ' ')) {
Expand Down Expand Up @@ -622,3 +616,16 @@ function camelizeComponentName(newName: string) {
function getTagRenameApply(oldName: string) {
return oldName === hyphenateTag(oldName) ? hyphenateTag : undefined;
}

function normalizeAttributeValue(node: CompilerDOM.TextNode): [string, number] {
let offset = node.loc.start.offset;
let content = node.loc.source;
if (
(content.startsWith(`'`) && content.endsWith(`'`))
|| (content.startsWith(`"`) && content.endsWith(`"`))
) {
offset++;
content = content.slice(1, -1);
}
return [content, offset];
}

0 comments on commit 28ed0d8

Please sign in to comment.