4
4
UNSAFE_NAME ,
5
5
NAMESPACE_REPLACE_REGEX ,
6
6
HTML_LOWER_CASE ,
7
- SVG_CAMEL_CASE
7
+ SVG_CAMEL_CASE ,
8
+ createComponent
8
9
} from './lib/util.js' ;
9
10
import { options , h , Fragment } from 'preact' ;
10
11
import {
@@ -22,7 +23,7 @@ import {
22
23
CATCH_ERROR
23
24
} from './lib/constants.js' ;
24
25
25
- const EMPTY_ARR = [ ] ;
26
+ const EMPTY_ARR = new Array ( 0 ) ;
26
27
const isArray = Array . isArray ;
27
28
const assign = Object . assign ;
28
29
const EMPTY_STR = '' ;
@@ -238,9 +239,9 @@ function _renderToString(
238
239
239
240
let vnodeType = typeof vnode ;
240
241
// Text VNodes: escape as HTML
241
- if ( vnodeType !== 'object' ) {
242
- if ( vnodeType === 'function' ) return EMPTY_STR ;
243
- return vnodeType === 'string' ? encodeEntities ( vnode ) : vnode + EMPTY_STR ;
242
+ if ( vnodeType != 'object' ) {
243
+ if ( vnodeType == 'function' ) return EMPTY_STR ;
244
+ return vnodeType == 'string' ? encodeEntities ( vnode ) : vnode + EMPTY_STR ;
244
245
}
245
246
246
247
// Recurse into children / Arrays
@@ -250,7 +251,7 @@ function _renderToString(
250
251
parent [ CHILDREN ] = vnode ;
251
252
for ( let i = 0 ; i < vnode . length ; i ++ ) {
252
253
let child = vnode [ i ] ;
253
- if ( child == null || typeof child === 'boolean' ) continue ;
254
+ if ( child == null || typeof child == 'boolean' ) continue ;
254
255
255
256
const childRender = _renderToString (
256
257
child ,
@@ -262,10 +263,10 @@ function _renderToString(
262
263
renderer
263
264
) ;
264
265
265
- if ( typeof childRender === 'string' ) {
266
+ if ( typeof childRender == 'string' ) {
266
267
rendered = rendered + childRender ;
267
268
} else {
268
- renderArray = renderArray || [ ] ;
269
+ renderArray = renderArray || new Array ( vnode . length ) ;
269
270
270
271
if ( rendered ) renderArray . push ( rendered ) ;
271
272
@@ -294,14 +295,14 @@ function _renderToString(
294
295
if ( beforeDiff ) beforeDiff ( vnode ) ;
295
296
296
297
let type = vnode . type ,
297
- props = vnode . props ,
298
- cctx = context ,
299
- contextType ,
300
- rendered ,
301
- component ;
298
+ props = vnode . props ;
302
299
303
300
// Invoke rendering on Components
304
- if ( typeof type === 'function' ) {
301
+ if ( typeof type == 'function' ) {
302
+ let cctx = context ,
303
+ contextType ,
304
+ rendered ,
305
+ component ;
305
306
if ( type === Fragment ) {
306
307
// Serialized precompiled JSX.
307
308
if ( 'tpl' in props ) {
@@ -315,7 +316,7 @@ function _renderToString(
315
316
316
317
// Check if we're dealing with a vnode or an array of nodes
317
318
if (
318
- typeof value === 'object' &&
319
+ typeof value == 'object' &&
319
320
( value . constructor === undefined || isArray ( value ) )
320
321
) {
321
322
out =
@@ -340,9 +341,7 @@ function _renderToString(
340
341
} else if ( 'UNSTABLE_comment' in props ) {
341
342
// Fragments are the least used components of core that's why
342
343
// branching here for comments has the least effect on perf.
343
- return (
344
- '<!--' + encodeEntities ( props . UNSTABLE_comment || EMPTY_STR ) + '-->'
345
- ) ;
344
+ return '<!--' + encodeEntities ( props . UNSTABLE_comment ) + '-->' ;
346
345
}
347
346
348
347
rendered = props . children ;
@@ -354,22 +353,15 @@ function _renderToString(
354
353
}
355
354
356
355
let isClassComponent =
357
- type . prototype && typeof type . prototype . render === 'function' ;
356
+ type . prototype && typeof type . prototype . render == 'function' ;
358
357
if ( isClassComponent ) {
359
358
rendered = /**#__NOINLINE__**/ renderClassComponent ( vnode , cctx ) ;
360
359
component = vnode [ COMPONENT ] ;
361
360
} else {
362
- vnode [ COMPONENT ] = component = {
363
- __v : vnode ,
364
- props,
365
- context : cctx ,
366
- // silently drop state updates
367
- setState : markAsDirty ,
368
- forceUpdate : markAsDirty ,
369
- __d : true ,
370
- // hooks
371
- __h : [ ]
372
- } ;
361
+ vnode [ COMPONENT ] = component = /**#__NOINLINE__**/ createComponent (
362
+ vnode ,
363
+ cctx
364
+ ) ;
373
365
374
366
// If a hook invokes setState() to invalidate the component during rendering,
375
367
// re-render it up to 25 times to allow "settling" of memoized states.
@@ -402,7 +394,7 @@ function _renderToString(
402
394
rendered != null &&
403
395
rendered . type === Fragment &&
404
396
rendered . key == null &&
405
- ! ( 'tpl' in rendered . props ) ;
397
+ rendered . props . tpl == null ;
406
398
rendered = isTopLevelFragment ? rendered . props . children : rendered ;
407
399
408
400
try {
@@ -416,8 +408,6 @@ function _renderToString(
416
408
renderer
417
409
) ;
418
410
} catch ( err ) {
419
- let str = EMPTY_STR ;
420
-
421
411
if ( type . getDerivedStateFromError ) {
422
412
component [ NEXT_STATE ] = type . getDerivedStateFromError ( err ) ;
423
413
}
@@ -438,10 +428,10 @@ function _renderToString(
438
428
rendered != null &&
439
429
rendered . type === Fragment &&
440
430
rendered . key == null &&
441
- ! ( 'tpl' in rendered . props ) ;
431
+ rendered . props . tpl == null ;
442
432
rendered = isTopLevelFragment ? rendered . props . children : rendered ;
443
433
444
- str = _renderToString (
434
+ return _renderToString (
445
435
rendered ,
446
436
context ,
447
437
isSvgMode ,
@@ -452,7 +442,7 @@ function _renderToString(
452
442
) ;
453
443
}
454
444
455
- return str ;
445
+ return EMPTY_STR ;
456
446
} finally {
457
447
if ( afterDiff ) afterDiff ( vnode ) ;
458
448
vnode [ PARENT ] = null ;
@@ -468,7 +458,7 @@ function _renderToString(
468
458
rendered != null &&
469
459
rendered . type === Fragment &&
470
460
rendered . key == null &&
471
- ! ( 'tpl' in rendered . props ) ;
461
+ rendered . props . tpl == null ;
472
462
rendered = isTopLevelFragment ? rendered . props . children : rendered ;
473
463
474
464
try {
@@ -513,7 +503,7 @@ function _renderToString(
513
503
514
504
if ( ! asyncMode ) throw error ;
515
505
516
- if ( ! error || typeof error . then !== 'function' ) throw error ;
506
+ if ( ! error || typeof error . then != 'function' ) throw error ;
517
507
518
508
const renderNestedChildren = ( ) => {
519
509
try {
@@ -527,7 +517,7 @@ function _renderToString(
527
517
renderer
528
518
) ;
529
519
} catch ( e ) {
530
- if ( ! e || typeof e . then !== 'function' ) throw e ;
520
+ if ( ! e || typeof e . then != 'function' ) throw e ;
531
521
532
522
return e . then (
533
523
( ) =>
@@ -557,7 +547,7 @@ function _renderToString(
557
547
for ( let name in props ) {
558
548
let v = props [ name ] ;
559
549
560
- if ( typeof v === 'function' ) continue ;
550
+ if ( typeof v == 'function' ) continue ;
561
551
562
552
switch ( name ) {
563
553
case 'children' :
@@ -663,7 +653,7 @@ function _renderToString(
663
653
' ' +
664
654
name +
665
655
'="' +
666
- ( typeof v === 'string' ? encodeEntities ( v ) : v + EMPTY_STR ) +
656
+ ( typeof v == 'string' ? encodeEntities ( v ) : v + EMPTY_STR ) +
667
657
'"' ;
668
658
}
669
659
}
@@ -711,7 +701,7 @@ function _renderToString(
711
701
const startTag = s + '>' ;
712
702
713
703
if ( isArray ( html ) ) return [ startTag , ...html , endTag ] ;
714
- else if ( typeof html !== 'string' ) return [ startTag , html , endTag ] ;
704
+ else if ( typeof html != 'string' ) return [ startTag , html , endTag ] ;
715
705
return startTag + html + endTag ;
716
706
}
717
707
0 commit comments