1
1
// vue compiler module for transforming `img:srcset` to a number of `require`s
2
2
3
- module . exports = function ( ) {
4
- return {
5
- postTransformNode : node => {
6
- transform ( node )
7
- }
3
+ module . exports = ( ) => ( {
4
+ postTransformNode : node => {
5
+ transform ( node )
8
6
}
9
- }
7
+ } )
10
8
11
9
function transform ( node ) {
12
10
const tags = [ 'img' , 'source' ]
@@ -15,8 +13,8 @@ function transform (node) {
15
13
node . attrs . forEach ( attr => {
16
14
if ( attr . name === 'srcset' ) {
17
15
// same logic as in transform-require.js
18
- var value = attr . value
19
- var isStatic = value . charAt ( 0 ) === '"' && value . charAt ( value . length - 1 ) === '"'
16
+ const value = attr . value
17
+ const isStatic = value . charAt ( 0 ) === '"' && value . charAt ( value . length - 1 ) === '"'
20
18
if ( ! isStatic ) {
21
19
return
22
20
}
@@ -43,12 +41,14 @@ function transform (node) {
43
41
44
42
function urlToRequire ( url ) {
45
43
// same logic as in transform-require.js
46
- var firstChar = url . charAt ( 0 )
44
+ const firstChar = url . charAt ( 0 )
47
45
if ( firstChar === '.' || firstChar === '~' ) {
48
46
if ( firstChar === '~' ) {
49
- var secondChar = url . charAt ( 1 )
50
- url = '"' + url . slice ( secondChar === '/' ? 2 : 1 )
47
+ const secondChar = url . charAt ( 1 )
48
+ url = url . slice ( secondChar === '/' ? 2 : 1 )
51
49
}
52
50
return `require("${ url } ")`
51
+ } else {
52
+ return `"${ url } "`
53
53
}
54
54
}
0 commit comments