@@ -111,22 +111,18 @@ export async function provideCodeActions(
111
111
112
112
function classNameToAst (
113
113
state : State ,
114
- className : string ,
115
- selector : string = `. ${ className } ` ,
114
+ classNameParts : string [ ] ,
115
+ selector : string ,
116
116
important : boolean = false
117
117
) {
118
- const parts = getClassNameParts ( state , className )
119
- if ( ! parts ) {
120
- return null
121
- }
122
118
const baseClassName = dlv (
123
119
state . classNames . classNames ,
124
- parts [ parts . length - 1 ]
120
+ classNameParts [ classNameParts . length - 1 ]
125
121
)
126
122
if ( ! baseClassName ) {
127
123
return null
128
124
}
129
- const info = dlv ( state . classNames . classNames , parts )
125
+ const info = dlv ( state . classNames . classNames , classNameParts )
130
126
let context = info . __context || [ ]
131
127
let pseudo = info . __pseudo || [ ]
132
128
const globalContexts = state . classNames . context
@@ -139,8 +135,8 @@ function classNameToAst(
139
135
screens = Object . keys ( screens )
140
136
const path = [ ]
141
137
142
- for ( let i = 0 ; i < parts . length - 1 ; i ++ ) {
143
- let part = parts [ i ]
138
+ for ( let i = 0 ; i < classNameParts . length - 1 ; i ++ ) {
139
+ let part = classNameParts [ i ]
144
140
let common = globalContexts [ part ]
145
141
if ( ! common ) return null
146
142
if ( screens . includes ( part ) ) {
@@ -158,7 +154,7 @@ function classNameToAst(
158
154
let rule = {
159
155
// TODO: use proper selector parser
160
156
[ selector + pseudo . join ( '' ) ] : {
161
- [ `@apply ${ parts [ parts . length - 1 ] } ${
157
+ [ `@apply ${ classNameParts [ classNameParts . length - 1 ] } ${
162
158
important ? ' !important' : ''
163
159
} `] : '' ,
164
160
} ,
@@ -221,6 +217,14 @@ async function provideInvalidApplyCodeActions(
221
217
/ \s + /
222
218
) . length
223
219
220
+ let className = diagnostic . className . className
221
+ let classNameParts = getClassNameParts ( state , className )
222
+ let classNameInfo = dlv ( state . classNames . classNames , classNameParts )
223
+
224
+ if ( Array . isArray ( classNameInfo ) ) {
225
+ return [ ]
226
+ }
227
+
224
228
if ( ! isCssDoc ( state , document ) ) {
225
229
let languageBoundaries = getLanguageBoundaries ( state , document )
226
230
if ( ! languageBoundaries ) return [ ]
@@ -259,10 +263,9 @@ async function provideInvalidApplyCodeActions(
259
263
return true
260
264
}
261
265
262
- let className = diagnostic . className . className
263
266
let ast = classNameToAst (
264
267
state ,
265
- className ,
268
+ classNameParts ,
266
269
rule . selector ,
267
270
diagnostic . className . classList . important
268
271
)
0 commit comments