@@ -16,8 +16,16 @@ import {
1616 isDirty ,
1717 unsetDirty
1818} from './lib/util.js' ;
19- import { COMMIT , DIFF , DIFFED , RENDER , SKIP_EFFECTS } from './lib/constants.js' ;
20- import { options , Fragment } from 'preact' ;
19+ import {
20+ COMMIT ,
21+ DIFF ,
22+ DIFFED ,
23+ RENDER ,
24+ SKIP_EFFECTS ,
25+ PARENT ,
26+ CHILDREN
27+ } from './lib/constants.js' ;
28+ import { options , Fragment , h } from 'preact' ;
2129
2230// components without names, kept as a hash for later comparison to return consistent UnnamedComponentXX names.
2331const UNNAMED = [ ] ;
@@ -47,8 +55,19 @@ export default function renderToStringPretty(vnode, context, opts, _inner) {
4755 const previousSkipEffects = options [ SKIP_EFFECTS ] ;
4856 options [ SKIP_EFFECTS ] = true ;
4957
58+ const parent = h ( Fragment , null ) ;
59+ parent [ CHILDREN ] = [ vnode ] ;
60+
5061 try {
51- return _renderToStringPretty ( vnode , context || { } , opts , _inner ) ;
62+ return _renderToStringPretty (
63+ vnode ,
64+ context || { } ,
65+ opts ,
66+ _inner ,
67+ false ,
68+ undefined ,
69+ parent
70+ ) ;
5271 } finally {
5372 // options._commit, we don't schedule any effects in this library right now,
5473 // so we can pass an empty queue to this hook.
@@ -64,7 +83,8 @@ function _renderToStringPretty(
6483 opts ,
6584 inner ,
6685 isSvgMode ,
67- selectValue
86+ selectValue ,
87+ parent
6888) {
6989 if ( vnode == null || typeof vnode === 'boolean' ) {
7090 return '' ;
@@ -81,6 +101,7 @@ function _renderToStringPretty(
81101
82102 if ( Array . isArray ( vnode ) ) {
83103 let rendered = '' ;
104+ parent [ CHILDREN ] = vnode ;
84105 for ( let i = 0 ; i < vnode . length ; i ++ ) {
85106 if ( pretty && i > 0 ) rendered = rendered + '\n' ;
86107 rendered =
@@ -91,7 +112,8 @@ function _renderToStringPretty(
91112 opts ,
92113 inner ,
93114 isSvgMode ,
94- selectValue
115+ selectValue ,
116+ parent
95117 ) ;
96118 }
97119 return rendered ;
@@ -100,6 +122,7 @@ function _renderToStringPretty(
100122 // VNodes have {constructor:undefined} to prevent JSON injection:
101123 if ( vnode . constructor !== undefined ) return '' ;
102124
125+ vnode [ PARENT ] = parent ;
103126 if ( options [ DIFF ] ) options [ DIFF ] ( vnode ) ;
104127
105128 let nodeName = vnode . type ,
@@ -124,7 +147,8 @@ function _renderToStringPretty(
124147 opts ,
125148 opts . shallowHighOrder !== false ,
126149 isSvgMode ,
127- selectValue
150+ selectValue ,
151+ vnode
128152 ) ;
129153 } else {
130154 let rendered ;
@@ -203,7 +227,8 @@ function _renderToStringPretty(
203227 opts ,
204228 opts . shallowHighOrder !== false ,
205229 isSvgMode ,
206- selectValue
230+ selectValue ,
231+ vnode
207232 ) ;
208233
209234 if ( options [ DIFFED ] ) options [ DIFFED ] ( vnode ) ;
@@ -384,7 +409,8 @@ function _renderToStringPretty(
384409 opts ,
385410 true ,
386411 childSvgMode ,
387- selectValue
412+ selectValue ,
413+ vnode
388414 ) ;
389415
390416 if ( shouldPrettyFormatChildren && ! hasLarge && isLargeString ( ret ) )
0 commit comments