11import { joinWithAnd } from '../util/joinWithAnd'
22import { State , Settings } from '../util/state'
3- import type { TextDocument , DiagnosticSeverity } from 'vscode-languageserver'
3+ import type { TextDocument } from 'vscode-languageserver'
44import { CssConflictDiagnostic , DiagnosticKind } from './types'
55import { findClassListsInDocument , getClassNamesInClassList } from '../util/find'
66import { getClassNameDecls } from '../util/getClassNameDecls'
77import { getClassNameMeta } from '../util/getClassNameMeta'
88import { equal } from '../util/array'
99import * as jit from '../util/jit'
10+ import type { AtRule , Node , Rule } from 'postcss'
11+
12+ function isCustomProperty ( property : string ) : boolean {
13+ return property . startsWith ( '--' )
14+ }
15+
16+ function isAtRule ( node : Node ) : node is AtRule {
17+ return node . type === 'atrule'
18+ }
19+
20+ function isKeyframes ( rule : Rule ) : boolean {
21+ let parent = rule . parent
22+ if ( ! parent ) {
23+ return false
24+ }
25+ if ( isAtRule ( parent ) && parent . name === 'keyframes' ) {
26+ return true
27+ }
28+ return false
29+ }
30+
31+ function getRuleProperties ( rule : Rule ) : string [ ] {
32+ let properties : string [ ] = [ ]
33+ rule . walkDecls ( ( { prop } ) => {
34+ properties . push ( prop )
35+ } )
36+ if ( properties . findIndex ( ( p ) => ! isCustomProperty ( p ) ) > - 1 ) {
37+ properties = properties . filter ( ( p ) => ! isCustomProperty ( p ) )
38+ }
39+ return properties
40+ }
1041
1142export async function getCssConflictDiagnostics (
1243 state : State ,
@@ -24,38 +55,40 @@ export async function getCssConflictDiagnostics(
2455
2556 classNames . forEach ( ( className , index ) => {
2657 if ( state . jit ) {
27- let { rules } = jit . generateRules ( state , [ className . className ] )
58+ let { rules } = jit . generateRules (
59+ state ,
60+ [ className . className ] ,
61+ ( rule ) => ! isKeyframes ( rule )
62+ )
2863 if ( rules . length === 0 ) {
2964 return
3065 }
3166
3267 let info : Array < { context : string [ ] ; properties : string [ ] } > = rules . map ( ( rule ) => {
33- let properties : string [ ] = [ ]
34- rule . walkDecls ( ( { prop } ) => {
35- properties . push ( prop )
36- } )
68+ let properties = getRuleProperties ( rule )
3769 let context = jit . getRuleContext ( state , rule , className . className )
3870 return { context, properties }
3971 } )
4072
4173 let otherClassNames = classNames . filter ( ( _className , i ) => i !== index )
4274
4375 let conflictingClassNames = otherClassNames . filter ( ( otherClassName ) => {
44- let { rules : otherRules } = jit . generateRules ( state , [ otherClassName . className ] )
76+ let { rules : otherRules } = jit . generateRules (
77+ state ,
78+ [ otherClassName . className ] ,
79+ ( rule ) => ! isKeyframes ( rule )
80+ )
4581 if ( otherRules . length !== rules . length ) {
4682 return false
4783 }
4884
4985 for ( let i = 0 ; i < otherRules . length ; i ++ ) {
50- let rule = otherRules [ i ]
51- let properties : string [ ] = [ ]
52- rule . walkDecls ( ( { prop } ) => {
53- properties . push ( prop )
54- } )
86+ let otherRule = otherRules [ i ]
87+ let properties = getRuleProperties ( otherRule )
5588 if ( ! equal ( info [ i ] . properties , properties ) ) {
5689 return false
5790 }
58- let context = jit . getRuleContext ( state , rule , otherClassName . className )
91+ let context = jit . getRuleContext ( state , otherRule , otherClassName . className )
5992 if ( ! equal ( info [ i ] . context , context ) ) {
6093 return false
6194 }
0 commit comments