1
1
import { joinWithAnd } from '../util/joinWithAnd'
2
2
import { State , Settings } from '../util/state'
3
- import type { TextDocument , DiagnosticSeverity } from 'vscode-languageserver'
3
+ import type { TextDocument } from 'vscode-languageserver'
4
4
import { CssConflictDiagnostic , DiagnosticKind } from './types'
5
5
import { findClassListsInDocument , getClassNamesInClassList } from '../util/find'
6
6
import { getClassNameDecls } from '../util/getClassNameDecls'
7
7
import { getClassNameMeta } from '../util/getClassNameMeta'
8
8
import { equal } from '../util/array'
9
9
import * 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
+ }
10
41
11
42
export async function getCssConflictDiagnostics (
12
43
state : State ,
@@ -24,38 +55,40 @@ export async function getCssConflictDiagnostics(
24
55
25
56
classNames . forEach ( ( className , index ) => {
26
57
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
+ )
28
63
if ( rules . length === 0 ) {
29
64
return
30
65
}
31
66
32
67
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 )
37
69
let context = jit . getRuleContext ( state , rule , className . className )
38
70
return { context, properties }
39
71
} )
40
72
41
73
let otherClassNames = classNames . filter ( ( _className , i ) => i !== index )
42
74
43
75
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
+ )
45
81
if ( otherRules . length !== rules . length ) {
46
82
return false
47
83
}
48
84
49
85
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 )
55
88
if ( ! equal ( info [ i ] . properties , properties ) ) {
56
89
return false
57
90
}
58
- let context = jit . getRuleContext ( state , rule , otherClassName . className )
91
+ let context = jit . getRuleContext ( state , otherRule , otherClassName . className )
59
92
if ( ! equal ( info [ i ] . context , context ) ) {
60
93
return false
61
94
}
0 commit comments