@@ -69,40 +69,45 @@ export const transformSrcset: NodeTransform = (
69
69
}
70
70
}
71
71
72
- const hasQualifiedUrl = imageCandidates . some ( ( { url } ) => {
72
+ const shouldProcessUrl = ( url : string ) => {
73
73
return (
74
74
! isExternalUrl ( url ) &&
75
75
! isDataUrl ( url ) &&
76
76
( options . includeAbsolute || isRelativeUrl ( url ) )
77
77
)
78
- } )
78
+ }
79
79
// When srcset does not contain any qualified URLs, skip transforming
80
- if ( ! hasQualifiedUrl ) {
80
+ if ( ! imageCandidates . some ( ( { url } ) => shouldProcessUrl ( url ) ) ) {
81
81
return
82
82
}
83
83
84
84
if ( options . base ) {
85
85
const base = options . base
86
86
const set : string [ ] = [ ]
87
- imageCandidates . forEach ( ( { url, descriptor } ) => {
87
+ let needImportTransform = false
88
+
89
+ imageCandidates . forEach ( candidate => {
90
+ let { url, descriptor } = candidate
88
91
descriptor = descriptor ? ` ${ descriptor } ` : ``
89
- if ( isRelativeUrl ( url ) ) {
90
- set . push ( ( path . posix || path ) . join ( base , url ) + descriptor )
92
+ if ( url [ 0 ] === '.' ) {
93
+ candidate . url = ( path . posix || path ) . join ( base , url )
94
+ set . push ( candidate . url + descriptor )
95
+ } else if ( shouldProcessUrl ( url ) ) {
96
+ needImportTransform = true
91
97
} else {
92
98
set . push ( url + descriptor )
93
99
}
94
100
} )
95
- attr . value . content = set . join ( ', ' )
96
- return
101
+
102
+ if ( ! needImportTransform ) {
103
+ attr . value . content = set . join ( ', ' )
104
+ return
105
+ }
97
106
}
98
107
99
108
const compoundExpression = createCompoundExpression ( [ ] , attr . loc )
100
109
imageCandidates . forEach ( ( { url, descriptor } , index ) => {
101
- if (
102
- ! isExternalUrl ( url ) &&
103
- ! isDataUrl ( url ) &&
104
- ( options . includeAbsolute || isRelativeUrl ( url ) )
105
- ) {
110
+ if ( shouldProcessUrl ( url ) ) {
106
111
const { path } = parseUrl ( url )
107
112
let exp : SimpleExpressionNode
108
113
if ( path ) {
0 commit comments