@@ -27,7 +27,7 @@ import {
27
27
setSavedComponentFilters ,
28
28
separateDisplayNameAndHOCs ,
29
29
shallowDiffers ,
30
- utfDecodeString ,
30
+ utfDecodeStringWithRanges ,
31
31
} from '../utils' ;
32
32
import { localStorageGetItem , localStorageSetItem } from '../storage' ;
33
33
import { __DEBUG__ } from '../constants' ;
@@ -450,7 +450,7 @@ export default class Store extends EventEmitter<{
450
450
}
451
451
452
452
// This build of DevTools supports the legacy profiler.
453
- // This is a static flag, controled by the Store config.
453
+ // This is a static flag, controlled by the Store config.
454
454
get supportsProfiling ( ) : boolean {
455
455
return this . _supportsProfiling ;
456
456
}
@@ -467,7 +467,7 @@ export default class Store extends EventEmitter<{
467
467
}
468
468
469
469
// This build of DevTools supports the Timeline profiler.
470
- // This is a static flag, controled by the Store config.
470
+ // This is a static flag, controlled by the Store config.
471
471
get supportsTimeline ( ) : boolean {
472
472
return this . _supportsTimeline ;
473
473
}
@@ -502,30 +502,58 @@ export default class Store extends EventEmitter<{
502
502
}
503
503
504
504
// Find which root this element is in...
505
- let rootID ;
506
505
let root ;
507
506
let rootWeight = 0 ;
508
507
for ( let i = 0 ; i < this . _roots . length ; i ++ ) {
509
- rootID = this . _roots [ i ] ;
510
- root = ( ( this . _idToElement . get ( rootID ) : any ) : Element ) ;
508
+ const rootID = this . _roots [ i ] ;
509
+ root = this . _idToElement . get ( rootID ) ;
510
+
511
+ if ( root === undefined ) {
512
+ this . _throwAndEmitError (
513
+ Error (
514
+ `Couldn't find root with id "${ rootID } ": no matching node was found in the Store.` ,
515
+ ) ,
516
+ ) ;
517
+
518
+ return null ;
519
+ }
520
+
511
521
if ( root . children . length === 0 ) {
512
522
continue ;
513
- } else if ( rootWeight + root . weight > index ) {
523
+ }
524
+
525
+ if ( rootWeight + root . weight > index ) {
514
526
break ;
515
527
} else {
516
528
rootWeight += root . weight ;
517
529
}
518
530
}
519
531
532
+ if ( root === undefined ) {
533
+ return null ;
534
+ }
535
+
520
536
// Find the element in the tree using the weight of each node...
521
537
// Skip over the root itself, because roots aren't visible in the Elements tree.
522
- let currentElement = ( ( root : any ) : Element ) ;
538
+ let currentElement : Element = root ;
523
539
let currentWeight = rootWeight - 1 ;
540
+
524
541
while ( index !== currentWeight ) {
525
542
const numChildren = currentElement . children . length ;
526
543
for ( let i = 0 ; i < numChildren ; i ++ ) {
527
544
const childID = currentElement . children [ i ] ;
528
- const child = ( ( this . _idToElement . get ( childID ) : any ) : Element ) ;
545
+ const child = this . _idToElement . get ( childID ) ;
546
+
547
+ if ( child === undefined ) {
548
+ this . _throwAndEmitError (
549
+ Error (
550
+ `Couldn't child element with id "${ childID } ": no matching node was found in the Store.` ,
551
+ ) ,
552
+ ) ;
553
+
554
+ return null ;
555
+ }
556
+
529
557
const childWeight = child . isCollapsed ? 1 : child . weight ;
530
558
531
559
if ( index <= currentWeight + childWeight ) {
@@ -538,7 +566,7 @@ export default class Store extends EventEmitter<{
538
566
}
539
567
}
540
568
541
- return ( ( currentElement : any ) : Element ) || null ;
569
+ return currentElement || null ;
542
570
}
543
571
544
572
getElementIDAtIndex ( index : number ) : number | null {
@@ -560,32 +588,31 @@ export default class Store extends EventEmitter<{
560
588
getElementsWithErrorsAndWarnings ( ) : Array < { id : number , index : number } > {
561
589
if ( this . _cachedErrorAndWarningTuples !== null ) {
562
590
return this . _cachedErrorAndWarningTuples ;
563
- } else {
564
- const errorAndWarningTuples : ErrorAndWarningTuples = [ ] ;
565
-
566
- this . _errorsAndWarnings . forEach ( ( _ , id ) => {
567
- const index = this . getIndexOfElementID ( id ) ;
568
- if ( index !== null ) {
569
- let low = 0 ;
570
- let high = errorAndWarningTuples . length ;
571
- while ( low < high ) {
572
- const mid = ( low + high ) >> 1 ;
573
- if ( errorAndWarningTuples [ mid ] . index > index ) {
574
- high = mid ;
575
- } else {
576
- low = mid + 1 ;
577
- }
578
- }
591
+ }
579
592
580
- errorAndWarningTuples . splice ( low , 0 , { id, index} ) ;
593
+ const errorAndWarningTuples : ErrorAndWarningTuples = [ ] ;
594
+
595
+ this . _errorsAndWarnings . forEach ( ( _ , id ) => {
596
+ const index = this . getIndexOfElementID ( id ) ;
597
+ if ( index !== null ) {
598
+ let low = 0 ;
599
+ let high = errorAndWarningTuples . length ;
600
+ while ( low < high ) {
601
+ const mid = ( low + high ) >> 1 ;
602
+ if ( errorAndWarningTuples [ mid ] . index > index ) {
603
+ high = mid ;
604
+ } else {
605
+ low = mid + 1 ;
606
+ }
581
607
}
582
- } ) ;
583
608
584
- // Cache for later (at least until the tree changes again).
585
- this . _cachedErrorAndWarningTuples = errorAndWarningTuples ;
609
+ errorAndWarningTuples . splice ( low , 0 , { id, index} ) ;
610
+ }
611
+ } ) ;
586
612
587
- return errorAndWarningTuples ;
588
- }
613
+ // Cache for later (at least until the tree changes again).
614
+ this . _cachedErrorAndWarningTuples = errorAndWarningTuples ;
615
+ return errorAndWarningTuples ;
589
616
}
590
617
591
618
getErrorAndWarningCountForElementID ( id : number ) : {
@@ -923,7 +950,11 @@ export default class Store extends EventEmitter<{
923
950
const nextLength = operations [ i ] ;
924
951
i ++ ;
925
952
926
- const nextString = utfDecodeString ( operations . slice ( i , i + nextLength ) ) ;
953
+ const nextString = utfDecodeStringWithRanges (
954
+ operations ,
955
+ i ,
956
+ i + nextLength - 1 ,
957
+ ) ;
927
958
stringTable . push ( nextString ) ;
928
959
i += nextLength ;
929
960
}
@@ -1035,7 +1066,7 @@ export default class Store extends EventEmitter<{
1035
1066
) ,
1036
1067
) ;
1037
1068
1038
- continue ;
1069
+ break ;
1039
1070
}
1040
1071
1041
1072
parentElement . children . push ( id ) ;
@@ -1088,7 +1119,7 @@ export default class Store extends EventEmitter<{
1088
1119
) ,
1089
1120
) ;
1090
1121
1091
- continue ;
1122
+ break ;
1092
1123
}
1093
1124
1094
1125
i += 1 ;
@@ -1126,7 +1157,7 @@ export default class Store extends EventEmitter<{
1126
1157
) ,
1127
1158
) ;
1128
1159
1129
- continue ;
1160
+ break ;
1130
1161
}
1131
1162
1132
1163
const index = parentElement . children . indexOf ( id ) ;
@@ -1172,7 +1203,17 @@ export default class Store extends EventEmitter<{
1172
1203
}
1173
1204
} ;
1174
1205
1175
- const root = ( ( this . _idToElement . get ( id ) : any ) : Element ) ;
1206
+ const root = this . _idToElement . get ( id ) ;
1207
+ if ( root === undefined ) {
1208
+ this . _throwAndEmitError (
1209
+ Error (
1210
+ `Cannot remove root "${ id } ": no matching node was found in the Store.` ,
1211
+ ) ,
1212
+ ) ;
1213
+
1214
+ break ;
1215
+ }
1216
+
1176
1217
recursivelyDeleteElements ( id ) ;
1177
1218
1178
1219
this . _rootIDToCapabilities . delete ( id ) ;
@@ -1194,7 +1235,7 @@ export default class Store extends EventEmitter<{
1194
1235
) ,
1195
1236
) ;
1196
1237
1197
- continue ;
1238
+ break ;
1198
1239
}
1199
1240
1200
1241
const children = element . children ;
@@ -1279,7 +1320,7 @@ export default class Store extends EventEmitter<{
1279
1320
1280
1321
this . _revision ++ ;
1281
1322
1282
- // Any time the tree changes (e.g. elements added, removed, or reordered) cached inidices may be invalid.
1323
+ // Any time the tree changes (e.g. elements added, removed, or reordered) cached indices may be invalid.
1283
1324
this . _cachedErrorAndWarningTuples = null ;
1284
1325
1285
1326
if ( haveErrorsOrWarningsChanged ) {
0 commit comments