Skip to content

Commit f7d4a36

Browse files
committed
invalid @apply quick fix: check that base class name can be @Applied
1 parent 8c6ba84 commit f7d4a36

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/lsp/providers/codeActions/provideInvalidApplyCodeActions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import dset from 'dset'
2222
import selectorParser from 'postcss-selector-parser'
2323
import { flatten } from '../../../util/array'
2424
import { getClassNameMeta } from '../../util/getClassNameMeta'
25+
import { validateApply } from '../../util/validateApply'
2526

2627
export async function provideInvalidApplyCodeActions(
2728
state: State,
@@ -173,11 +174,12 @@ function classNameToAst(
173174
selector: string,
174175
important: boolean = false
175176
) {
176-
const baseClassName = dlv(
177-
state.classNames.classNames,
178-
classNameParts[classNameParts.length - 1]
179-
)
180-
if (!baseClassName) {
177+
const baseClassName = classNameParts[classNameParts.length - 1]
178+
const validatedBaseClassName = validateApply(state, [baseClassName])
179+
if (
180+
validatedBaseClassName === null ||
181+
validatedBaseClassName.isApplyable === false
182+
) {
181183
return null
182184
}
183185
const meta = getClassNameMeta(state, classNameParts)
@@ -216,9 +218,7 @@ function classNameToAst(
216218

217219
let rule = {
218220
[selector]: {
219-
[`@apply ${classNameParts[classNameParts.length - 1]}${
220-
important ? ' !important' : ''
221-
}`]: '',
221+
[`@apply ${baseClassName}${important ? ' !important' : ''}`]: '',
222222
},
223223
}
224224
if (path.length) {

0 commit comments

Comments
 (0)