File tree Expand file tree Collapse file tree 4 files changed +43
-13
lines changed
packages/language-core/lib Expand file tree Collapse file tree 4 files changed +43
-13
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ const _codeFeatures = {
31
31
} as VueCodeInformation ,
32
32
navigationAndCompletion : {
33
33
navigation : true ,
34
+ completion : true ,
35
+ } as VueCodeInformation ,
36
+ navigationAndAdditionalCompletion : {
37
+ navigation : true ,
38
+ completion : { isAdditional : true } ,
34
39
} as VueCodeInformation ,
35
40
withoutHighlight : {
36
41
semantic : { shouldHighlight : ( ) => false } ,
@@ -104,6 +109,7 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo
104
109
const blockConditions : string [ ] = [ ] ;
105
110
const usedComponentCtxVars = new Set < string > ( ) ;
106
111
const scopedClasses : { className : string , offset : number ; } [ ] = [ ] ;
112
+ const emptyClassOffsets : number [ ] = [ ] ;
107
113
108
114
return {
109
115
slots,
@@ -114,6 +120,7 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo
114
120
blockConditions,
115
121
usedComponentCtxVars,
116
122
scopedClasses,
123
+ emptyClassOffsets,
117
124
hasSlot : false ,
118
125
accessExternalVariable ( name : string , offset ?: number ) {
119
126
let arr = accessExternalVariables . get ( name ) ;
Original file line number Diff line number Diff line change @@ -549,20 +549,33 @@ function* generateReferencesForScopedCssClasses(
549
549
&& prop . value
550
550
) {
551
551
let startOffset = prop . value . loc . start . offset ;
552
- let tempClassName = '' ;
553
- for ( const char of ( prop . value . loc . source + ' ' ) ) {
554
- if ( char . trim ( ) === '' || char === '"' || char === "'" ) {
555
- if ( tempClassName !== '' ) {
556
- ctx . scopedClasses . push ( { className : tempClassName , offset : startOffset } ) ;
557
- startOffset += tempClassName . length ;
558
- tempClassName = '' ;
552
+ let content = prop . value . loc . source ;
553
+ if (
554
+ ( content . startsWith ( `'` ) && content . endsWith ( `'` ) )
555
+ || ( content . startsWith ( `"` ) && content . endsWith ( `"` ) )
556
+ ) {
557
+ startOffset ++ ;
558
+ content = content . slice ( 1 , - 1 ) ;
559
+ }
560
+ if ( content ) {
561
+ let currentClassName = '' ;
562
+ for ( const char of ( content + ' ' ) ) {
563
+ if ( char . trim ( ) === '' ) {
564
+ if ( currentClassName !== '' ) {
565
+ ctx . scopedClasses . push ( { className : currentClassName , offset : startOffset } ) ;
566
+ startOffset += currentClassName . length ;
567
+ currentClassName = '' ;
568
+ }
569
+ startOffset += char . length ;
570
+ }
571
+ else {
572
+ currentClassName += char ;
559
573
}
560
- startOffset += char . length ;
561
- }
562
- else {
563
- tempClassName += char ;
564
574
}
565
575
}
576
+ else {
577
+ ctx . emptyClassOffsets . push ( startOffset ) ;
578
+ }
566
579
}
567
580
else if (
568
581
prop . type === CompilerDOM . NodeTypes . DIRECTIVE
Original file line number Diff line number Diff line change @@ -86,6 +86,16 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
86
86
87
87
function * generateStyleScopedClasses ( ) : Generator < Code > {
88
88
yield `if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {${ newLine } ` ;
89
+ for ( const offset of ctx . emptyClassOffsets ) {
90
+ yield `__VLS_styleScopedClasses['` ;
91
+ yield [
92
+ '' ,
93
+ 'template' ,
94
+ offset ,
95
+ ctx . codeFeatures . additionalCompletion ,
96
+ ] ;
97
+ yield `']${ endOfLine } ` ;
98
+ }
89
99
for ( const { className, offset } of ctx . scopedClasses ) {
90
100
yield `__VLS_styleScopedClasses[` ;
91
101
yield [
@@ -99,7 +109,7 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
99
109
className ,
100
110
'template' ,
101
111
offset ,
102
- ctx . codeFeatures . navigationAndCompletion ,
112
+ ctx . codeFeatures . navigationAndAdditionalCompletion ,
103
113
] ;
104
114
yield `'` ;
105
115
yield [
Original file line number Diff line number Diff line change 1
1
import { clearComments } from './parseCssVars' ;
2
2
3
- const cssClassNameReg = / (? = ( [ \. ] { 1 } [ a - z A - Z _ ] + [ \w \_ \- ] * ) [ \s \. \+ \{ \> # \: ] { 1 } ) / g;
3
+ const cssClassNameReg = / (? = ( [ \. ] { 1 } [ a - z A - Z _ ] + [ \w \_ \- ] * ) [ \s \. \, \ +\{ \> # \: ] { 1 } ) / g;
4
4
5
5
export function * parseCssClassNames ( styleContent : string ) {
6
6
styleContent = clearComments ( styleContent ) ;
You can’t perform that action at this time.
0 commit comments