@@ -99,12 +99,9 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
99
99
ctx . codeFeatures . navigationWithoutRename ,
100
100
] ;
101
101
yield `'` ;
102
- yield [
103
- className ,
104
- 'template' ,
105
- offset ,
106
- ctx . codeFeatures . navigationAndAdditionalCompletion ,
107
- ] ;
102
+
103
+ // fix https://github.com/vuejs/language-tools/issues/4537
104
+ yield * escapeString ( className , offset , [ '\\' , '\'' ] ) ;
108
105
yield `'` ;
109
106
yield [
110
107
'' ,
@@ -136,6 +133,45 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
136
133
}
137
134
yield endOfLine ;
138
135
}
136
+
137
+ function * escapeString ( className : string , offset : number , escapeTargets : string [ ] ) : Generator < Code > {
138
+ let count = 0 ;
139
+
140
+ const currentEscapeTargets = [ ...escapeTargets ] ;
141
+ const firstEscapeTarget = currentEscapeTargets . shift ( ) ! ;
142
+ const splitted = className . split ( firstEscapeTarget ) ;
143
+
144
+ for ( let i = 0 ; i < splitted . length ; i ++ ) {
145
+ const part = splitted [ i ] ;
146
+ const partLength = part . length ;
147
+
148
+ if ( escapeTargets . length > 0 ) {
149
+ yield * escapeString ( part , offset + count , [ ...currentEscapeTargets ] ) ;
150
+ } else {
151
+ yield [
152
+ part ,
153
+ 'template' ,
154
+ offset + count ,
155
+ ctx . codeFeatures . navigationAndAdditionalCompletion ,
156
+ ] ;
157
+ }
158
+
159
+ if ( i !== splitted . length - 1 ) {
160
+ yield '\\' ;
161
+
162
+ yield [
163
+ firstEscapeTarget ,
164
+ 'template' ,
165
+ offset + count + partLength ,
166
+ ctx . codeFeatures . navigationAndAdditionalCompletion ,
167
+ ] ;
168
+
169
+ count += partLength + 1 ;
170
+ } else {
171
+ count += partLength ;
172
+ }
173
+ }
174
+ }
139
175
}
140
176
141
177
export function * forEachElementNode ( node : CompilerDOM . RootNode | CompilerDOM . TemplateChildNode ) : Generator < CompilerDOM . ElementNode > {
0 commit comments