@@ -279,44 +279,59 @@ function stringifyElement(
279
279
context : TransformContext
280
280
) : string {
281
281
let res = `<${ node . tag } `
282
+ let innerHTML = ''
282
283
for ( let i = 0 ; i < node . props . length ; i ++ ) {
283
284
const p = node . props [ i ]
284
285
if ( p . type === NodeTypes . ATTRIBUTE ) {
285
286
res += ` ${ p . name } `
286
287
if ( p . value ) {
287
288
res += `="${ escapeHtml ( p . value . content ) } "`
288
289
}
289
- } else if ( p . type === NodeTypes . DIRECTIVE && p . name === 'bind' ) {
290
- const exp = p . exp as SimpleExpressionNode
291
- if ( exp . content [ 0 ] === '_' ) {
292
- // internally generated string constant references
293
- // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
294
- res += ` ${ ( p . arg as SimpleExpressionNode ) . content } ="__VUE_EXP_START__${
295
- exp . content
296
- } __VUE_EXP_END__"`
297
- continue
298
- }
299
- // constant v-bind, e.g. :foo="1"
300
- let evaluated = evaluateConstant ( exp )
301
- if ( evaluated != null ) {
302
- const arg = p . arg && ( p . arg as SimpleExpressionNode ) . content
303
- if ( arg === 'class' ) {
304
- evaluated = normalizeClass ( evaluated )
305
- } else if ( arg === 'style' ) {
306
- evaluated = stringifyStyle ( normalizeStyle ( evaluated ) )
290
+ } else if ( p . type === NodeTypes . DIRECTIVE ) {
291
+ if ( p . name === 'bind' ) {
292
+ const exp = p . exp as SimpleExpressionNode
293
+ if ( exp . content [ 0 ] === '_' ) {
294
+ // internally generated string constant references
295
+ // e.g. imported URL strings via compiler-sfc transformAssetUrl plugin
296
+ res += ` ${
297
+ ( p . arg as SimpleExpressionNode ) . content
298
+ } ="__VUE_EXP_START__${ exp . content } __VUE_EXP_END__"`
299
+ continue
300
+ }
301
+ // constant v-bind, e.g. :foo="1"
302
+ let evaluated = evaluateConstant ( exp )
303
+ if ( evaluated != null ) {
304
+ const arg = p . arg && ( p . arg as SimpleExpressionNode ) . content
305
+ if ( arg === 'class' ) {
306
+ evaluated = normalizeClass ( evaluated )
307
+ } else if ( arg === 'style' ) {
308
+ evaluated = stringifyStyle ( normalizeStyle ( evaluated ) )
309
+ }
310
+ res += ` ${ ( p . arg as SimpleExpressionNode ) . content } ="${ escapeHtml (
311
+ evaluated
312
+ ) } "`
307
313
}
308
- res += ` ${ ( p . arg as SimpleExpressionNode ) . content } ="${ escapeHtml (
309
- evaluated
310
- ) } "`
314
+ } else if ( p . name === 'html' ) {
315
+ // #5439 v-html with constant value
316
+ // not sure why would anyone do this but it can happen
317
+ innerHTML = evaluateConstant ( p . exp as SimpleExpressionNode )
318
+ } else if ( p . name === 'text' ) {
319
+ innerHTML = escapeHtml (
320
+ toDisplayString ( evaluateConstant ( p . exp as SimpleExpressionNode ) )
321
+ )
311
322
}
312
323
}
313
324
}
314
325
if ( context . scopeId ) {
315
326
res += ` ${ context . scopeId } `
316
327
}
317
328
res += `>`
318
- for ( let i = 0 ; i < node . children . length ; i ++ ) {
319
- res += stringifyNode ( node . children [ i ] , context )
329
+ if ( innerHTML ) {
330
+ res += innerHTML
331
+ } else {
332
+ for ( let i = 0 ; i < node . children . length ; i ++ ) {
333
+ res += stringifyNode ( node . children [ i ] , context )
334
+ }
320
335
}
321
336
if ( ! isVoidTag ( node . tag ) ) {
322
337
res += `</${ node . tag } >`
0 commit comments