@@ -81,62 +81,60 @@ export const transformAssetUrl: NodeTransform = (
81
81
options : AssetURLOptions = defaultAssetUrlOptions
82
82
) => {
83
83
if ( node . type === NodeTypes . ELEMENT ) {
84
+ if ( ! node . props . length ) {
85
+ return
86
+ }
87
+
84
88
const tags = options . tags || defaultAssetUrlOptions . tags
85
- for ( const tag in tags ) {
86
- if ( ( tag === '*' || node . tag === tag ) && node . props . length ) {
87
- const attributes = tags [ tag ]
88
- attributes . forEach ( name => {
89
- node . props . forEach ( ( attr , index ) => {
90
- if (
91
- attr . type !== NodeTypes . ATTRIBUTE ||
92
- attr . name !== name ||
93
- ! attr . value ||
94
- ( ! options . includeAbsolute && ! isRelativeUrl ( attr . value . content ) )
95
- ) {
96
- return
97
- }
89
+ const attrs = tags [ node . tag ]
90
+ const wildCardAttrs = tags [ '*' ]
91
+ if ( ! attrs && ! wildCardAttrs ) {
92
+ return
93
+ }
98
94
99
- const url = parseUrl ( attr . value . content )
95
+ const assetAttrs = ( attrs || [ ] ) . concat ( wildCardAttrs || [ ] )
96
+ node . props . forEach ( ( attr , index ) => {
97
+ if (
98
+ attr . type !== NodeTypes . ATTRIBUTE ||
99
+ ! assetAttrs . includes ( attr . name ) ||
100
+ ! attr . value ||
101
+ ( ! options . includeAbsolute && ! isRelativeUrl ( attr . value . content ) )
102
+ ) {
103
+ return
104
+ }
100
105
101
- if ( options . base ) {
102
- // explicit base - directly rewrite the url into absolute url
103
- // does not apply to absolute urls or urls that start with `@`
104
- // since they are aliases
105
- if (
106
- attr . value . content [ 0 ] !== '@' &&
107
- isRelativeUrl ( attr . value . content )
108
- ) {
109
- // when packaged in the browser, path will be using the posix-
110
- // only version provided by rollup-plugin-node-builtins.
111
- attr . value . content = ( path . posix || path ) . join (
112
- options . base ,
113
- url . path + ( url . hash || '' )
114
- )
115
- }
116
- return
117
- }
106
+ const url = parseUrl ( attr . value . content )
107
+ if ( options . base ) {
108
+ // explicit base - directly rewrite the url into absolute url
109
+ // does not apply to absolute urls or urls that start with `@`
110
+ // since they are aliases
111
+ if (
112
+ attr . value . content [ 0 ] !== '@' &&
113
+ isRelativeUrl ( attr . value . content )
114
+ ) {
115
+ // when packaged in the browser, path will be using the posix-
116
+ // only version provided by rollup-plugin-node-builtins.
117
+ attr . value . content = ( path . posix || path ) . join (
118
+ options . base ,
119
+ url . path + ( url . hash || '' )
120
+ )
121
+ }
122
+ return
123
+ }
118
124
119
- // otherwise, transform the url into an import.
120
- // this assumes a bundler will resolve the import into the correct
121
- // absolute url (e.g. webpack file-loader)
122
- const exp = getImportsExpressionExp (
123
- url . path ,
124
- url . hash ,
125
- attr . loc ,
126
- context
127
- )
128
- node . props [ index ] = {
129
- type : NodeTypes . DIRECTIVE ,
130
- name : 'bind' ,
131
- arg : createSimpleExpression ( name , true , attr . loc ) ,
132
- exp,
133
- modifiers : [ ] ,
134
- loc : attr . loc
135
- }
136
- } )
137
- } )
125
+ // otherwise, transform the url into an import.
126
+ // this assumes a bundler will resolve the import into the correct
127
+ // absolute url (e.g. webpack file-loader)
128
+ const exp = getImportsExpressionExp ( url . path , url . hash , attr . loc , context )
129
+ node . props [ index ] = {
130
+ type : NodeTypes . DIRECTIVE ,
131
+ name : 'bind' ,
132
+ arg : createSimpleExpression ( attr . name , true , attr . loc ) ,
133
+ exp,
134
+ modifiers : [ ] ,
135
+ loc : attr . loc
138
136
}
139
- }
137
+ } )
140
138
}
141
139
}
142
140
0 commit comments