Skip to content

Commit ee5e6fb

Browse files
committed
fix(language-core): avoid loss of scoped class references
1 parent eadfcdd commit ee5e6fb

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

packages/language-core/lib/codegen/style/classProperty.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ export function* generateClassProperty(
88
offset: number,
99
propertyType: string
1010
): Generator<Code> {
11-
yield `${newLine} & { '`;
11+
yield `${newLine} & { `;
1212
yield [
1313
'',
1414
'style_' + styleIndex,
1515
offset,
1616
codeFeatures.navigation,
1717
];
18+
yield `'`;
1819
yield [
1920
classNameWithDot.slice(1),
2021
'style_' + styleIndex,
2122
offset + 1,
2223
codeFeatures.navigation,
2324
];
24-
yield `': ${propertyType}`;
25+
yield `'`;
26+
yield [
27+
'',
28+
'style_' + styleIndex,
29+
offset + classNameWithDot.length,
30+
codeFeatures.navigation,
31+
];
32+
yield `: ${propertyType}`;
2533
yield ` }`;
2634
}

packages/language-core/lib/codegen/template/styleScopedClasses.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ export function* generateStyleScopedClassReferences(
2121
yield `']} */${endOfLine}`;
2222
}
2323
for (const { source, className, offset } of ctx.scopedClasses) {
24-
yield `/** @type {__VLS_StyleScopedClasses['`;
25-
if (withDot) {
26-
yield [
27-
'',
28-
source,
29-
offset - 1,
30-
ctx.codeFeatures.navigation,
31-
];
32-
}
24+
yield `/** @type {__VLS_StyleScopedClasses[`;
25+
yield [
26+
'',
27+
source,
28+
offset - (withDot ? 1 : 0),
29+
ctx.codeFeatures.navigation,
30+
];
31+
yield `'`;
32+
3333
// fix https://github.com/vuejs/language-tools/issues/4537
3434
yield* escapeString(source, className, offset, ['\\', '\'']);
35-
yield `']} */${endOfLine}`;
35+
yield `'`;
36+
yield [
37+
'',
38+
source,
39+
offset + className.length,
40+
ctx.codeFeatures.navigation,
41+
];
42+
yield `]} */${endOfLine}`;
3643
}
3744

3845
function* escapeString(source: string, className: string, offset: number, escapeTargets: string[]): Generator<Code> {

0 commit comments

Comments
 (0)