1
- import { generate , baseParse , transform } from '@vue/compiler-core'
1
+ import {
2
+ generate ,
3
+ baseParse ,
4
+ transform ,
5
+ TransformOptions
6
+ } from '@vue/compiler-core'
2
7
import {
3
8
transformAssetUrl ,
4
9
createAssetUrlTransformWithOptions ,
@@ -7,8 +12,13 @@ import {
7
12
} from '../src/templateTransformAssetUrl'
8
13
import { transformElement } from '../../compiler-core/src/transforms/transformElement'
9
14
import { transformBind } from '../../compiler-core/src/transforms/vBind'
15
+ import { stringifyStatic } from '../../compiler-dom/src/transforms/stringifyStatic'
10
16
11
- function compileWithAssetUrls ( template : string , options ?: AssetURLOptions ) {
17
+ function compileWithAssetUrls (
18
+ template : string ,
19
+ options ?: AssetURLOptions ,
20
+ transformOptions ?: TransformOptions
21
+ ) {
12
22
const ast = baseParse ( template )
13
23
const t = options
14
24
? createAssetUrlTransformWithOptions ( normalizeOptions ( options ) )
@@ -17,7 +27,8 @@ function compileWithAssetUrls(template: string, options?: AssetURLOptions) {
17
27
nodeTransforms : [ t , transformElement ] ,
18
28
directiveTransforms : {
19
29
bind : transformBind
20
- }
30
+ } ,
31
+ ...transformOptions
21
32
} )
22
33
return generate ( ast , { mode : 'module' } )
23
34
}
@@ -131,4 +142,26 @@ describe('compiler sfc: transform asset url', () => {
131
142
132
143
expect ( code ) . toMatchSnapshot ( )
133
144
} )
145
+
146
+ test ( 'transform with stringify' , ( ) => {
147
+ const { code } = compileWithAssetUrls (
148
+ `<div>` +
149
+ `<img src="./bar.png"/>` +
150
+ `<img src="/bar.png"/>` +
151
+ `<img src="https://foo.bar/baz.png"/>` +
152
+ `<img src="//foo.bar/baz.png"/>` +
153
+ `<img src="./bar.png"/>` +
154
+ `</div>` ,
155
+ {
156
+ includeAbsolute : true
157
+ } ,
158
+ {
159
+ hoistStatic : true ,
160
+ transformHoist : stringifyStatic
161
+ }
162
+ )
163
+ console . log ( code )
164
+ expect ( code ) . toMatch ( `_createStaticVNode` )
165
+ expect ( code ) . toMatchSnapshot ( )
166
+ } )
134
167
} )
0 commit comments