@@ -4,6 +4,7 @@ import { getLocator } from 'locate-character';
4
4
import Selector from './Selector' ;
5
5
import getCodeFrame from '../utils/getCodeFrame' ;
6
6
import hash from '../utils/hash' ;
7
+ import isKeyframesNode from '../utils/isKeyframesNode' ;
7
8
import Element from '../compile/nodes/Element' ;
8
9
import { Validator } from '../validate/index' ;
9
10
import { Node , Ast , Warning } from '../interfaces' ;
@@ -26,7 +27,7 @@ class Rule {
26
27
}
27
28
28
29
isUsed ( dev : boolean ) {
29
- if ( this . parent && this . parent . node . type === 'Atrule' && this . parent . node . name === 'keyframes' ) return true ;
30
+ if ( this . parent && this . parent . node . type === 'Atrule' && isKeyframesNode ( this . parent . node ) ) return true ;
30
31
if ( this . declarations . length === 0 ) return dev ;
31
32
return this . selectors . some ( s => s . used ) ;
32
33
}
@@ -67,7 +68,7 @@ class Rule {
67
68
}
68
69
69
70
transform ( code : MagicString , id : string , keyframes : Map < string , string > ) {
70
- if ( this . parent && this . parent . node . type === 'Atrule' && this . parent . node . name === 'keyframes' ) return true ;
71
+ if ( this . parent && this . parent . node . type === 'Atrule' && isKeyframesNode ( this . parent . node ) ) return true ;
71
72
72
73
const attr = `.${ id } ` ;
73
74
@@ -142,7 +143,7 @@ class Atrule {
142
143
} ) ;
143
144
}
144
145
145
- else if ( this . node . name === 'keyframes' ) {
146
+ else if ( isKeyframesNode ( this . node ) ) {
146
147
this . children . forEach ( ( rule : Rule ) => {
147
148
rule . selectors . forEach ( selector => {
148
149
selector . used = true ;
@@ -167,8 +168,8 @@ class Atrule {
167
168
} ) ;
168
169
169
170
code . remove ( c , this . node . block . start ) ;
170
- } else if ( this . node . name === 'keyframes' ) {
171
- let c = this . node . start + 10 ;
171
+ } else if ( isKeyframesNode ( this . node ) ) {
172
+ let c = this . node . start + this . node . name . length + 1 ;
172
173
if ( this . node . expression . start - c > 1 ) code . overwrite ( c , this . node . expression . start , ' ' ) ;
173
174
c = this . node . expression . end ;
174
175
if ( this . node . block . start - c > 0 ) code . remove ( c , this . node . block . start ) ;
@@ -200,7 +201,7 @@ class Atrule {
200
201
}
201
202
202
203
transform ( code : MagicString , id : string , keyframes : Map < string , string > ) {
203
- if ( this . node . name === 'keyframes' ) {
204
+ if ( isKeyframesNode ( this . node ) ) {
204
205
this . node . expression . children . forEach ( ( { type, name, start, end } : Node ) => {
205
206
if ( type === 'Identifier' ) {
206
207
if ( name . startsWith ( '-global-' ) ) {
@@ -287,7 +288,7 @@ export default class Stylesheet {
287
288
this . children . push ( atrule ) ;
288
289
}
289
290
290
- if ( node . name === 'keyframes' ) {
291
+ if ( isKeyframesNode ( node ) ) {
291
292
node . expression . children . forEach ( ( expression : Node ) => {
292
293
if ( expression . type === 'Identifier' && ! expression . name . startsWith ( '-global-' ) ) {
293
294
this . keyframes . set ( expression . name , `${ this . id } -${ expression . name } ` ) ;
0 commit comments