@@ -160,8 +160,11 @@ export function createSourceFile(
160
160
) ;
161
161
}
162
162
} ) ;
163
- const cssModuleClasses = useCssModuleClasses ( sfc ) ;
164
- const cssScopedClasses = useCssScopedClasses ( sfc , vueCompilerOptions ) ;
163
+ const cssModuleClasses = useStyleCssClasses ( sfc , style => ! ! style . module ) ;
164
+ const cssScopedClasses = useStyleCssClasses ( sfc , style => {
165
+ const setting = compilerOptions . experimentalResolveStyleCssClasses ?? 'scoped' ;
166
+ return ( setting === 'scoped' && style . scoped ) || setting === 'always' ;
167
+ } ) ;
165
168
const templateCodeGens = computed ( ( ) => {
166
169
167
170
if ( ! computedHtmlTemplate . value )
@@ -180,7 +183,7 @@ export function createSourceFile(
180
183
sfc . template ?. lang ?? 'html' ,
181
184
templateAstCompiled . value . ast ,
182
185
! ! sfc . scriptSetup ,
183
- Object . values ( cssScopedClasses . value ) . map ( map => Object . keys ( map ) ) . flat ( ) ,
186
+ Object . values ( cssScopedClasses . value ) . map ( style => style . classNames ) . flat ( ) ,
184
187
computedHtmlTemplate . value . mapping ,
185
188
{
186
189
getEmitCompletion : SearchTexts . EmitCompletion ,
@@ -761,34 +764,23 @@ export function createSourceFile(
761
764
}
762
765
}
763
766
764
- export function useCssModuleClasses ( sfc : Sfc ) {
767
+ export function useStyleCssClasses ( sfc : Sfc , condition : ( style : Sfc [ 'styles' ] [ number ] ) => boolean ) {
765
768
return computed ( ( ) => {
766
- const result : { style : typeof sfc . styles [ number ] , index : number , classNameRanges : TextRange [ ] ; } [ ] = [ ] ;
767
- for ( let i = 0 ; i < sfc . styles . length ; i ++ ) {
768
- const style = sfc . styles [ i ] ;
769
- if ( style . module ) {
770
- result . push ( {
771
- style : style ,
772
- index : i ,
773
- classNameRanges : [ ...parseCssClassNames ( style . content ) ] ,
774
- } ) ;
775
- }
776
- }
777
- return result ;
778
- } ) ;
779
- }
780
-
781
- export function useCssScopedClasses ( sfc : Sfc , compilerOptions : VueCompilerOptions ) {
782
- return computed ( ( ) => {
783
- const result : { style : typeof sfc . styles [ number ] , index : number , classNameRanges : TextRange [ ] ; } [ ] = [ ] ;
784
- const setting = compilerOptions . experimentalResolveStyleCssClasses ?? 'scoped' ;
769
+ const result : {
770
+ style : typeof sfc . styles [ number ] ,
771
+ index : number ,
772
+ classNameRanges : TextRange [ ] ,
773
+ classNames : string [ ] ,
774
+ } [ ] = [ ] ;
785
775
for ( let i = 0 ; i < sfc . styles . length ; i ++ ) {
786
776
const style = sfc . styles [ i ] ;
787
- if ( ( setting === 'scoped' && style . scoped ) || setting === 'always' ) {
777
+ if ( condition ( style ) ) {
778
+ const classNameRanges = [ ...parseCssClassNames ( style . content ) ] ;
788
779
result . push ( {
789
780
style : style ,
790
781
index : i ,
791
- classNameRanges : [ ...parseCssClassNames ( style . content ) ] ,
782
+ classNameRanges : classNameRanges ,
783
+ classNames : classNameRanges . map ( range => style . content . substring ( range . start + 1 , range . end ) ) ,
792
784
} ) ;
793
785
}
794
786
}
0 commit comments