@@ -3,9 +3,12 @@ import type * as ts from 'typescript';
33import { getNodeText } from '../../parsers/scriptSetupRanges' ;
44import type { Code } from '../../types' ;
55import { endOfLine , normalizeAttributeValue } from '../utils' ;
6+ import { generateEscaped } from '../utils/escaped' ;
67import type { TemplateCodegenContext } from './context' ;
78import type { TemplateCodegenOptions } from './index' ;
89
10+ const classNameEscapeRegex = / ( [ \\ ' ] ) / ;
11+
912export function * generateStyleScopedClassReferences (
1013 ctx : TemplateCodegenContext ,
1114 withDot = false
@@ -31,7 +34,13 @@ export function* generateStyleScopedClassReferences(
3134 yield `'` ;
3235
3336 // fix https://github.com/vuejs/language-tools/issues/4537
34- yield * escapeString ( source , className , offset , [ '\\' , '\'' ] ) ;
37+ yield * generateEscaped (
38+ className ,
39+ source ,
40+ offset ,
41+ ctx . codeFeatures . navigationAndAdditionalCompletion ,
42+ classNameEscapeRegex
43+ ) ;
3544 yield `'` ;
3645 yield [
3746 '' ,
@@ -41,45 +50,6 @@ export function* generateStyleScopedClassReferences(
4150 ] ;
4251 yield `]} */${ endOfLine } ` ;
4352 }
44-
45- function * escapeString ( source : string , className : string , offset : number , escapeTargets : string [ ] ) : Generator < Code > {
46- let count = 0 ;
47-
48- const currentEscapeTargets = [ ...escapeTargets ] ;
49- const firstEscapeTarget = currentEscapeTargets . shift ( ) ! ;
50- const splitted = className . split ( firstEscapeTarget ) ;
51-
52- for ( let i = 0 ; i < splitted . length ; i ++ ) {
53- const part = splitted [ i ] ;
54- const partLength = part . length ;
55-
56- if ( escapeTargets . length > 0 ) {
57- yield * escapeString ( source , part , offset + count , [ ...currentEscapeTargets ] ) ;
58- } else {
59- yield [
60- part ,
61- source ,
62- offset + count ,
63- ctx . codeFeatures . navigationAndAdditionalCompletion ,
64- ] ;
65- }
66-
67- if ( i !== splitted . length - 1 ) {
68- yield '\\' ;
69-
70- yield [
71- firstEscapeTarget ,
72- source ,
73- offset + count + partLength ,
74- ctx . codeFeatures . navigationAndAdditionalCompletion ,
75- ] ;
76-
77- count += partLength + 1 ;
78- } else {
79- count += partLength ;
80- }
81- }
82- }
8353}
8454
8555export function collectStyleScopedClassReferences (
0 commit comments