@@ -20,11 +20,30 @@ function createRemoveTagAttrs(removingTagAttrs) {
20
20
return tag ;
21
21
} ;
22
22
}
23
-
23
+ function createWarnTagAttrs ( warnTagAttrs ) {
24
+ warnTagAttrs = warnTagAttrs || [ ] ;
25
+ var hasNoAttributes = conditions . createHasAttributes ( warnTagAttrs ) ;
26
+ return function warnTagAttrs ( tag ) {
27
+ if ( conditions . isStartTag ( tag ) ) {
28
+ var attrs = tag . attributes . filter ( hasNoAttributes ) ;
29
+ if ( attrs . length > 0 ) {
30
+ var attrList = [ ] ;
31
+ for ( var i = 0 ; i < attrs . length ; i ++ ) {
32
+ var attr = attrs [ i ] ;
33
+ attrList . push ( attr [ 0 ] ) ;
34
+ }
35
+ console . warn ( 'svg-inline-loader: tag ' + tag . tagName + ' has forbidden attrs: ' + attrList . join ( ', ' ) ) ;
36
+ }
37
+ }
38
+ return tag ;
39
+ } ;
40
+ }
24
41
function isRemovingTag ( removingTags , tag ) {
25
42
return removingTags . indexOf ( tag . tagName ) > - 1 ;
26
43
}
27
-
44
+ function isWarningTag ( warningTags , tag ) {
45
+ return warningTags . indexOf ( tag . tagName ) > - 1 ;
46
+ }
28
47
// FIXME: Due to limtation of parser, we need to implement our
29
48
// very own little state machine to express tree structure
30
49
@@ -46,6 +65,16 @@ function createRemoveTags(removingTags) {
46
65
} ;
47
66
}
48
67
68
+ function createWarnTags ( warningTags ) {
69
+ warningTags = warningTags || [ ] ;
70
+
71
+ return function warnTags ( tag ) {
72
+ if ( conditions . isStartTag ( tag ) && isWarningTag ( warningTags , tag ) ) {
73
+ console . warn ( 'svg-inline-loader: forbidden tag ' + tag . tagName ) ;
74
+ }
75
+ return tag ;
76
+ } ;
77
+ }
49
78
function getAttributeIndex ( tag , attr ) {
50
79
if ( tag . attributes !== undefined && tag . attributes . length > 0 ) {
51
80
for ( var i = 0 ; i < tag . attributes . length ; i ++ ) {
@@ -142,7 +171,9 @@ function runTransform(tokens, configOverride) {
142
171
if ( config . classPrefix !== false ) transformations . push ( createClassPrefix ( config . classPrefix ) ) ;
143
172
if ( config . idPrefix !== false ) transformations . push ( createIdPrefix ( config . idPrefix ) ) ;
144
173
if ( config . removeSVGTagAttrs === true ) transformations . push ( removeSVGTagAttrs ) ;
174
+ if ( config . warnTags . length > 0 ) transformations . push ( createWarnTags ( config . warnTags ) ) ;
145
175
if ( config . removeTags === true ) transformations . push ( createRemoveTags ( config . removingTags ) ) ;
176
+ if ( config . warnTagAttrs . length > 0 ) transformations . push ( createWarnTagAttrs ( config . warnTagAttrs ) ) ;
146
177
if ( config . removingTagAttrs . length > 0 ) transformations . push ( createRemoveTagAttrs ( config . removingTagAttrs ) ) ;
147
178
148
179
transformations . forEach ( function ( transformation ) {
0 commit comments