Skip to content

Commit 29b13cf

Browse files
authored
test: add scoped classes renaming case (#4727)
1 parent 0e2db19 commit 29b13cf

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ function* generateReferencesForScopedCssClasses(
713713
if (ts.isIdentifier(name)) {
714714
walkIdentifier(name);
715715
}
716+
else if (ts.isStringLiteral(name)) {
717+
literals.push(name);
718+
}
716719
else if (ts.isComputedPropertyName(name)) {
717720
const { expression } = name;
718721
if (ts.isStringLiteralLike(expression)) {

packages/language-server/tests/renaming.spec.ts

+87
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,93 @@ describe('Renaming', async () => {
790790
`);
791791
});
792792

793+
it('Scoped Classes', async () => {
794+
expect(
795+
await requestRename('fixture.vue', 'vue', `
796+
<template>
797+
<div :class="'foo|'"></div>
798+
<div :class="['foo', { 'foo': true }]"></div>
799+
<div :class="{ foo }"></div>
800+
</template>
801+
<style scoped>
802+
.foo { }
803+
</style>
804+
`, 'bar')
805+
).toMatchInlineSnapshot(`
806+
{
807+
"changes": {
808+
"file://\${testWorkspacePath}/fixture.vue": [
809+
{
810+
"newText": "bar",
811+
"range": {
812+
"end": {
813+
"character": 23,
814+
"line": 4,
815+
},
816+
"start": {
817+
"character": 20,
818+
"line": 4,
819+
},
820+
},
821+
},
822+
{
823+
"newText": "bar",
824+
"range": {
825+
"end": {
826+
"character": 32,
827+
"line": 3,
828+
},
829+
"start": {
830+
"character": 29,
831+
"line": 3,
832+
},
833+
},
834+
},
835+
{
836+
"newText": "bar",
837+
"range": {
838+
"end": {
839+
"character": 23,
840+
"line": 3,
841+
},
842+
"start": {
843+
"character": 20,
844+
"line": 3,
845+
},
846+
},
847+
},
848+
{
849+
"newText": "bar",
850+
"range": {
851+
"end": {
852+
"character": 22,
853+
"line": 2,
854+
},
855+
"start": {
856+
"character": 19,
857+
"line": 2,
858+
},
859+
},
860+
},
861+
{
862+
"newText": "bar",
863+
"range": {
864+
"end": {
865+
"character": 8,
866+
"line": 7,
867+
},
868+
"start": {
869+
"character": 5,
870+
"line": 7,
871+
},
872+
},
873+
},
874+
],
875+
},
876+
}
877+
`);
878+
});
879+
793880
const openedDocuments: TextDocument[] = [];
794881

795882
afterEach(async () => {

0 commit comments

Comments
 (0)