@@ -181,8 +181,8 @@ describe('stringify static html', () => {
181
181
] )
182
182
} )
183
183
184
- test ( 'should bail on runtime constant v-bind bindings ' , ( ) => {
185
- const { ast } = compile (
184
+ test ( 'should bail on bindings that are hoisted but not stringifiable ' , ( ) => {
185
+ const { ast, code } = compile (
186
186
`<div><div>${ repeat (
187
187
`<span class="foo">foo</span>` ,
188
188
StringifyThresholds . ELEMENT_WITH_BINDING_COUNT
@@ -216,13 +216,62 @@ describe('stringify static html', () => {
216
216
expect ( ast . hoists ) . toMatchObject ( [
217
217
{
218
218
// the expression and the tree are still hoistable
219
- // but if it's stringified it will be NodeTypes.CALL_EXPRESSION
219
+ // but should stay NodeTypes.VNODE_CALL
220
+ // if it's stringified it will be NodeTypes.JS_CALL_EXPRESSION
220
221
type : NodeTypes . VNODE_CALL
221
222
} ,
222
223
{
223
224
type : NodeTypes . JS_ARRAY_EXPRESSION
224
225
}
225
226
] )
227
+ expect ( code ) . toMatchSnapshot ( )
228
+ } )
229
+
230
+ test ( 'should work with bindings that are non-static but stringifiable' , ( ) => {
231
+ // if a binding is non-static but marked as CAN_STRINGIFY, it means it's
232
+ // a known reference to a constant string.
233
+ const { ast, code } = compile (
234
+ `<div><div>${ repeat (
235
+ `<span class="foo">foo</span>` ,
236
+ StringifyThresholds . ELEMENT_WITH_BINDING_COUNT
237
+ ) } <img src="./foo" /></div></div>`,
238
+ {
239
+ hoistStatic : true ,
240
+ prefixIdentifiers : true ,
241
+ transformHoist : stringifyStatic ,
242
+ nodeTransforms : [
243
+ node => {
244
+ if ( node . type === NodeTypes . ELEMENT && node . tag === 'img' ) {
245
+ const exp = createSimpleExpression (
246
+ '_imports_0_' ,
247
+ false ,
248
+ node . loc ,
249
+ ConstantTypes . CAN_STRINGIFY
250
+ )
251
+ node . props [ 0 ] = {
252
+ type : NodeTypes . DIRECTIVE ,
253
+ name : 'bind' ,
254
+ arg : createSimpleExpression ( 'src' , true ) ,
255
+ exp,
256
+ modifiers : [ ] ,
257
+ loc : node . loc
258
+ }
259
+ }
260
+ }
261
+ ]
262
+ }
263
+ )
264
+ expect ( ast . hoists ) . toMatchObject ( [
265
+ {
266
+ // the hoisted node should be NodeTypes.JS_CALL_EXPRESSION
267
+ // of `createStaticVNode()` instead of dynamic NodeTypes.VNODE_CALL
268
+ type : NodeTypes . JS_CALL_EXPRESSION
269
+ } ,
270
+ {
271
+ type : NodeTypes . JS_ARRAY_EXPRESSION
272
+ }
273
+ ] )
274
+ expect ( code ) . toMatchSnapshot ( )
226
275
} )
227
276
228
277
// #1128
0 commit comments