@@ -20,11 +20,30 @@ function createRemoveTagAttrs(removingTagAttrs) {
2020 return tag ;
2121 } ;
2222}
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+ }
2441function isRemovingTag ( removingTags , tag ) {
2542 return removingTags . indexOf ( tag . tagName ) > - 1 ;
2643}
27-
44+ function isWarningTag ( warningTags , tag ) {
45+ return warningTags . indexOf ( tag . tagName ) > - 1 ;
46+ }
2847// FIXME: Due to limtation of parser, we need to implement our
2948// very own little state machine to express tree structure
3049
@@ -46,6 +65,16 @@ function createRemoveTags(removingTags) {
4665 } ;
4766}
4867
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+ }
4978function getAttributeIndex ( tag , attr ) {
5079 if ( tag . attributes !== undefined && tag . attributes . length > 0 ) {
5180 for ( var i = 0 ; i < tag . attributes . length ; i ++ ) {
@@ -142,7 +171,9 @@ function runTransform(tokens, configOverride) {
142171 if ( config . classPrefix !== false ) transformations . push ( createClassPrefix ( config . classPrefix ) ) ;
143172 if ( config . idPrefix !== false ) transformations . push ( createIdPrefix ( config . idPrefix ) ) ;
144173 if ( config . removeSVGTagAttrs === true ) transformations . push ( removeSVGTagAttrs ) ;
174+ if ( config . warnTags . length > 0 ) transformations . push ( createWarnTags ( config . warnTags ) ) ;
145175 if ( config . removeTags === true ) transformations . push ( createRemoveTags ( config . removingTags ) ) ;
176+ if ( config . warnTagAttrs . length > 0 ) transformations . push ( createWarnTagAttrs ( config . warnTagAttrs ) ) ;
146177 if ( config . removingTagAttrs . length > 0 ) transformations . push ( createRemoveTagAttrs ( config . removingTagAttrs ) ) ;
147178
148179 transformations . forEach ( function ( transformation ) {
0 commit comments